From e724bc1c4eb1224aa043a1489b29ec3daaa832aa Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 14 Jun 2018 18:47:40 -0400 Subject: Fix playing audio from SD card --- extmod/vfs_fat_diskio.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'extmod') diff --git a/extmod/vfs_fat_diskio.c b/extmod/vfs_fat_diskio.c index 3b9d86037..43c390a11 100644 --- a/extmod/vfs_fat_diskio.c +++ b/extmod/vfs_fat_diskio.c @@ -131,8 +131,17 @@ DRESULT disk_read ( } else { vfs->readblocks[2] = MP_OBJ_NEW_SMALL_INT(sector); vfs->readblocks[3] = mp_obj_new_bytearray_by_ref(count * SECSIZE(&vfs->fatfs), buff); - mp_call_method_n_kw(2, 0, vfs->readblocks); - // TODO handle error return + nlr_buf_t nlr; + if (nlr_push(&nlr) == 0) { + mp_obj_t ret = mp_call_method_n_kw(2, 0, vfs->readblocks); + nlr_pop(); + if (mp_obj_get_int(ret) != 0) { + return RES_ERROR; + } + } else { + // Exception thrown by readblocks or something it calls. + return RES_ERROR; + } } return RES_OK; @@ -167,8 +176,17 @@ DRESULT disk_write ( } else { vfs->writeblocks[2] = MP_OBJ_NEW_SMALL_INT(sector); vfs->writeblocks[3] = mp_obj_new_bytearray_by_ref(count * SECSIZE(&vfs->fatfs), (void*)buff); - mp_call_method_n_kw(2, 0, vfs->writeblocks); - // TODO handle error return + nlr_buf_t nlr; + if (nlr_push(&nlr) == 0) { + mp_obj_t ret = mp_call_method_n_kw(2, 0, vfs->writeblocks); + nlr_pop(); + if (mp_obj_get_int(ret) != 0) { + return RES_ERROR; + } + } else { + // Exception thrown by writeblocks or something it calls. + return RES_ERROR; + } } return RES_OK; -- cgit v1.2.3