Introduce SDCard.sync method, does nothing

This commit is contained in:
Jeff Epler 2021-10-25 10:03:07 -05:00
parent 65ffcf1465
commit 3fb12fe289
3 changed files with 25 additions and 0 deletions

View File

@ -150,6 +150,23 @@ mp_obj_t sdcardio_sdcard_readblocks(mp_obj_t self_in, mp_obj_t start_block_in, m
MP_DEFINE_CONST_FUN_OBJ_3(sdcardio_sdcard_readblocks_obj, sdcardio_sdcard_readblocks);
//| def sync(self) -> None:
//| """Ensure all blocks written are actually committed to the SD card
//|
//| :return: None"""
//| ...
mp_obj_t sdcardio_sdcard_sync(mp_obj_t self_in) {
sdcardio_sdcard_obj_t *self = (sdcardio_sdcard_obj_t *)self_in;
int result = common_hal_sdcardio_sdcard_sync(self);
if (result < 0) {
mp_raise_OSError(-result);
}
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(sdcardio_sdcard_sync_obj, sdcardio_sdcard_sync);
//| def writeblocks(self, start_block: int, buf: ReadableBuffer) -> None:
//|
//| """Write one or more blocks to the card
@ -177,6 +194,7 @@ STATIC const mp_rom_map_elem_t sdcardio_sdcard_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_count), MP_ROM_PTR(&sdcardio_sdcard_count_obj) },
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&sdcardio_sdcard_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&sdcardio_sdcard_readblocks_obj) },
{ MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&sdcardio_sdcard_sync_obj) },
{ MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&sdcardio_sdcard_writeblocks_obj) },
};
STATIC MP_DEFINE_CONST_DICT(sdcardio_sdcard_locals_dict, sdcardio_sdcard_locals_dict_table);

View File

@ -454,6 +454,12 @@ STATIC int writeblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buf
return 0;
}
int common_hal_sdcardio_sdcard_sync(sdcardio_sdcard_obj_t *self) {
common_hal_sdcardio_check_for_deinit(self);
mp_printf(&mp_plat_print, "sd sync\n");
return 0;
}
int common_hal_sdcardio_sdcard_writeblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf) {
common_hal_sdcardio_check_for_deinit(self);
if (buf->len % 512 != 0) {

View File

@ -48,4 +48,5 @@ void common_hal_sdcardio_sdcard_deinit(sdcardio_sdcard_obj_t *self);
void common_hal_sdcardio_sdcard_check_for_deinit(sdcardio_sdcard_obj_t *self);
int common_hal_sdcardio_sdcard_get_blockcount(sdcardio_sdcard_obj_t *self);
int common_hal_sdcardio_sdcard_readblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf);
int common_hal_sdcardio_sdcard_sync(sdcardio_sdcard_obj_t *self);
int common_hal_sdcardio_sdcard_writeblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf);