Skip to content

Commit 6c75c8b

Browse files
committed
family/samx7x: implement eefc blockdev hal
Signed-off-by: Rafael Silva <[email protected]>
1 parent 3f09ce1 commit 6c75c8b

File tree

4 files changed

+86
-2
lines changed

4 files changed

+86
-2
lines changed

config/families/samx7x.toml

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ source = [
4242
'hal/hid.c',
4343
'hal/spi.c',
4444
'hal/ticks.c',
45+
'hal/blockdev.c',
4546
]
4647

4748
[dependencies]

src/platform/samx7x/hal/blockdev.c

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* SPDX-License-Identifier: MIT
3+
* SPDX-FileCopyrightText: 2022 Rafael Silva <[email protected]>
4+
*/
5+
6+
#include "platform/samx7x/hal/blockdev.h"
7+
8+
s8 eefc_hal_read(struct blockdev_hal_t mem_block, u16 block, u16 offset, void *buffer, u16 size)
9+
{
10+
struct blockdev_drv_t *drv_data = mem_block.drv_data;
11+
eefc_read(buffer, (block * mem_block.block_size) + drv_data->start_addr + offset, size);
12+
}
13+
14+
s8 eefc_hal_write(struct blockdev_hal_t mem_block, u16 block, u16 offset, void *buffer, u16 size)
15+
{
16+
struct blockdev_drv_t *drv_data = mem_block.drv_data;
17+
eefc_write((block * mem_block.block_size) + drv_data->start_addr + offset, buffer, size);
18+
}
19+
20+
s8 eefc_hal_erase(struct blockdev_hal_t mem_block, u16 block)
21+
{
22+
struct blockdev_drv_t *drv_data = mem_block.drv_data;
23+
/* erase in 16 page groups */
24+
eefc_erase_16((block * mem_block.block_size) + drv_data->start_addr);
25+
}
26+
27+
s8 eefc_hal_sync(struct blockdev_hal_t mem_block)
28+
{
29+
/* not used */
30+
(void) mem_block;
31+
}
32+
33+
struct blockdev_hal_t blockdev_hal_init_eefc(struct blockdev_drv_t *drv_data)
34+
{
35+
const struct flash_info_t *info = eefc_get_info();
36+
37+
struct blockdev_hal_t hal = {
38+
.read_size = 1,
39+
.write_size = 16,
40+
/* in large sectors we are only allowed to erase in 16 page groups*/
41+
.block_size = info->page_size * 16,
42+
.block_count = drv_data->size / (16 * info->page_size),
43+
44+
.read = eefc_hal_read,
45+
.write = eefc_hal_write,
46+
.erase = eefc_hal_erase,
47+
.sync = eefc_hal_sync,
48+
49+
.drv_data = drv_data,
50+
};
51+
return hal;
52+
}

src/platform/samx7x/hal/blockdev.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* SPDX-License-Identifier: MIT
3+
* SPDX-FileCopyrightText: 2021 Rafael Silva <[email protected]>
4+
*/
5+
6+
#pragma once
7+
8+
#include "hal/blockdev.h"
9+
#include "platform/samx7x/eefc.h"
10+
#include "util/types.h"
11+
12+
struct blockdev_drv_t {
13+
s32 start_addr;
14+
u32 size;
15+
};
16+
17+
struct blockdev_hal_t blockdev_hal_init_eefc(struct blockdev_drv_t *drv_data);

src/targets/sams70-generic/main.c

+16-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "util/types.h"
88

99
#include "platform/samx7x/eefc.h"
10+
#include "platform/samx7x/hal/blockdev.h"
1011
#include "platform/samx7x/hal/hid.h"
1112
#include "platform/samx7x/hal/spi.h"
1213
#include "platform/samx7x/hal/ticks.h"
@@ -31,6 +32,7 @@ extern u32 _stable;
3132

3233
void main()
3334
{
35+
eefc_init();
3436
eefc_tcm_disable();
3537

3638
pmc_init(EXTERNAL_CLOCK_VALUE, 0UL);
@@ -47,6 +49,18 @@ void main()
4749

4850
const struct partition_table_entry_t *sensor_blob = partition_from_type(partition_table, PARTITION_TYPE_BLOB);
4951

52+
const struct partition_table_entry_t *nvs_data = partition_from_type(partition_table, PARTITION_TYPE_NVS);
53+
54+
// static struct blockdev_drv_t nvs_block_drv;
55+
// nvs_block_drv.start_addr = nvs_data->start_addr;
56+
// nvs_block_drv.size = (nvs_data->end_addr - nvs_data->start_addr);
57+
// struct blockdev_hal_t data_blockdev_hal = blockdev_hal_init_eefc(&nvs_block_drv);
58+
59+
// data_blockdev_hal.erase(data_blockdev_hal, 0);
60+
// u8 buffer[512];
61+
// memset(buffer, 0x5A, 512);
62+
// data_blockdev_hal.write(data_blockdev_hal, 0, 16, buffer, 496);
63+
5064
/* could not find sensor blob, halt */
5165
if (!sensor_blob)
5266
while (1) continue;
@@ -118,8 +132,8 @@ void main()
118132
/* fill report */
119133
memset(&report, 0, sizeof(report));
120134
report.id = MOUSE_REPORT_ID;
121-
report.x = 1;
122-
report.y = 0;
135+
report.x = deltas.dx;
136+
report.y = deltas.dy;
123137

124138
tud_hid_n_report(1, 0, &report, sizeof(report));
125139

0 commit comments

Comments
 (0)