Skip to content

Commit

Permalink
samd/samd_flash: Make flash read/write methods access self parameters.
Browse files Browse the repository at this point in the history
Use `self` (the first argument) instead of the global `samd_flash_obj` when
accessing the `flash_base` parameter.  This allows there to be multiple
flash objects for various types of filesystem.

Signed-off-by: robert-hh <robert@hammelrath.com>
  • Loading branch information
robert-hh authored and dpgeorge committed Nov 18, 2024
1 parent 4a159d1 commit ceae0e1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ports/samd/samd_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ static mp_obj_t samd_flash_version(void) {
static MP_DEFINE_CONST_FUN_OBJ_0(samd_flash_version_obj, samd_flash_version);

static mp_obj_t samd_flash_readblocks(size_t n_args, const mp_obj_t *args) {
uint32_t offset = (mp_obj_get_int(args[1]) * BLOCK_SIZE) + samd_flash_obj.flash_base;
samd_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]);
uint32_t offset = (mp_obj_get_int(args[1]) * BLOCK_SIZE) + self->flash_base;
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_WRITE);
if (n_args == 4) {
Expand All @@ -118,7 +119,8 @@ static mp_obj_t samd_flash_readblocks(size_t n_args, const mp_obj_t *args) {
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(samd_flash_readblocks_obj, 3, 4, samd_flash_readblocks);

static mp_obj_t samd_flash_writeblocks(size_t n_args, const mp_obj_t *args) {
uint32_t offset = (mp_obj_get_int(args[1]) * BLOCK_SIZE) + samd_flash_obj.flash_base;
samd_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]);
uint32_t offset = (mp_obj_get_int(args[1]) * BLOCK_SIZE) + self->flash_base;
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_READ);
if (n_args == 3) {
Expand Down

0 comments on commit ceae0e1

Please sign in to comment.