summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobert-hh <robert@hammelrath.com>2024-11-18 10:56:07 +0100
committerDamien George <damien@micropython.org>2024-11-18 23:54:42 +1100
commitceae0e14946b48f0e4b01669f241e66467bedddc (patch)
treea559ccc7584cbcefcc7f48524677c26b0059f70c
parent4a159d16febeba65b2de52cb05657b9515a9bcae (diff)
samd/samd_flash: Make flash read/write methods access self parameters.
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>
-rw-r--r--ports/samd/samd_flash.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/ports/samd/samd_flash.c b/ports/samd/samd_flash.c
index ef0de7b6f..f68bdf140 100644
--- a/ports/samd/samd_flash.c
+++ b/ports/samd/samd_flash.c
@@ -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) {
@@ -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) {