diff options
| author | Damien George <damien@micropython.org> | 2024-12-24 00:19:20 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-04-09 00:22:32 +1000 |
| commit | d895a62b0703d28fb2b15427760aae8a67ad666f (patch) | |
| tree | 61f0a95b97e65f5e1af0366154df103907b440f2 | |
| parent | af574a86c2ec3af02b167d449b8a8718f39f1ca8 (diff) | |
alif/alif_flash: Make flash respond to the buffer protocol.
Signed-off-by: Damien George <damien@micropython.org>
| -rw-r--r-- | ports/alif/alif_flash.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/ports/alif/alif_flash.c b/ports/alif/alif_flash.c index de7b37804..722afadae 100644 --- a/ports/alif/alif_flash.c +++ b/ports/alif/alif_flash.c @@ -80,6 +80,19 @@ static mp_obj_t alif_flash_make_new(const mp_obj_type_t *type, size_t n_args, si return MP_OBJ_FROM_PTR(self); } +static mp_int_t alif_flash_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { + alif_flash_obj_t *self = MP_OBJ_TO_PTR(self_in); + if (flags == MP_BUFFER_READ) { + bufinfo->buf = (void *)(ospi_flash_get_xip_base() + self->flash_base_addr); + bufinfo->len = self->flash_size; + bufinfo->typecode = 'B'; + return 0; + } else { + // Can't return a writable buffer. + return 1; + } +} + static mp_obj_t alif_flash_readblocks(size_t n_args, const mp_obj_t *args) { alif_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]); uint32_t offset = mp_obj_get_int(args[1]) * MICROPY_HW_FLASH_BLOCK_SIZE_BYTES; @@ -157,6 +170,7 @@ MP_DEFINE_CONST_OBJ_TYPE( MP_QSTR_Flash, MP_TYPE_FLAG_NONE, make_new, alif_flash_make_new, + buffer, alif_flash_get_buffer, locals_dict, &alif_flash_locals_dict ); #endif // MICROPY_HW_ENABLE_OSPI |
