Skip to content

Commit 3fb12fe

Browse files
committed
Introduce SDCard.sync method, does nothing
1 parent 65ffcf1 commit 3fb12fe

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

shared-bindings/sdcardio/SDCard.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,23 @@ mp_obj_t sdcardio_sdcard_readblocks(mp_obj_t self_in, mp_obj_t start_block_in, m
150150

151151
MP_DEFINE_CONST_FUN_OBJ_3(sdcardio_sdcard_readblocks_obj, sdcardio_sdcard_readblocks);
152152

153+
//| def sync(self) -> None:
154+
//| """Ensure all blocks written are actually committed to the SD card
155+
//|
156+
//| :return: None"""
157+
//| ...
158+
mp_obj_t sdcardio_sdcard_sync(mp_obj_t self_in) {
159+
sdcardio_sdcard_obj_t *self = (sdcardio_sdcard_obj_t *)self_in;
160+
int result = common_hal_sdcardio_sdcard_sync(self);
161+
if (result < 0) {
162+
mp_raise_OSError(-result);
163+
}
164+
return mp_const_none;
165+
}
166+
167+
MP_DEFINE_CONST_FUN_OBJ_1(sdcardio_sdcard_sync_obj, sdcardio_sdcard_sync);
168+
169+
153170
//| def writeblocks(self, start_block: int, buf: ReadableBuffer) -> None:
154171
//|
155172
//| """Write one or more blocks to the card
@@ -177,6 +194,7 @@ STATIC const mp_rom_map_elem_t sdcardio_sdcard_locals_dict_table[] = {
177194
{ MP_ROM_QSTR(MP_QSTR_count), MP_ROM_PTR(&sdcardio_sdcard_count_obj) },
178195
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&sdcardio_sdcard_deinit_obj) },
179196
{ MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&sdcardio_sdcard_readblocks_obj) },
197+
{ MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&sdcardio_sdcard_sync_obj) },
180198
{ MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&sdcardio_sdcard_writeblocks_obj) },
181199
};
182200
STATIC MP_DEFINE_CONST_DICT(sdcardio_sdcard_locals_dict, sdcardio_sdcard_locals_dict_table);

shared-module/sdcardio/SDCard.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,12 @@ STATIC int writeblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buf
454454
return 0;
455455
}
456456

457+
int common_hal_sdcardio_sdcard_sync(sdcardio_sdcard_obj_t *self) {
458+
common_hal_sdcardio_check_for_deinit(self);
459+
mp_printf(&mp_plat_print, "sd sync\n");
460+
return 0;
461+
}
462+
457463
int common_hal_sdcardio_sdcard_writeblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf) {
458464
common_hal_sdcardio_check_for_deinit(self);
459465
if (buf->len % 512 != 0) {

shared-module/sdcardio/SDCard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ void common_hal_sdcardio_sdcard_deinit(sdcardio_sdcard_obj_t *self);
4848
void common_hal_sdcardio_sdcard_check_for_deinit(sdcardio_sdcard_obj_t *self);
4949
int common_hal_sdcardio_sdcard_get_blockcount(sdcardio_sdcard_obj_t *self);
5050
int common_hal_sdcardio_sdcard_readblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf);
51+
int common_hal_sdcardio_sdcard_sync(sdcardio_sdcard_obj_t *self);
5152
int common_hal_sdcardio_sdcard_writeblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf);

0 commit comments

Comments
 (0)