summaryrefslogtreecommitdiff
path: root/cc3200/mods/pybsd.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-01-29 15:15:16 +1100
committerDamien George <damien.p.george@gmail.com>2017-01-30 12:26:07 +1100
commit56506fd64a40f9c5ea97888245df6f2cb8b20744 (patch)
tree152a6a95d1f3393e0b8b535e2a8f6f7a18692fd2 /cc3200/mods/pybsd.c
parent6eafa544865a5d6dcb18f9161f7a18bd4fb6229f (diff)
cc3200: Convert to use new VFS sub-system and new ooFatFs library.
Diffstat (limited to 'cc3200/mods/pybsd.c')
-rw-r--r--cc3200/mods/pybsd.c46
1 files changed, 44 insertions, 2 deletions
diff --git a/cc3200/mods/pybsd.c b/cc3200/mods/pybsd.c
index b8d5b4cc1..bac5a270c 100644
--- a/cc3200/mods/pybsd.c
+++ b/cc3200/mods/pybsd.c
@@ -27,6 +27,9 @@
#include "py/mpconfig.h"
#include "py/obj.h"
#include "py/runtime.h"
+#include "lib/oofatfs/ff.h"
+#include "lib/oofatfs/diskio.h"
+#include "extmod/fsusermount.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_ints.h"
@@ -36,8 +39,6 @@
#include "prcm.h"
#include "gpio.h"
#include "sdhost.h"
-#include "ff.h"
-#include "diskio.h"
#include "sd_diskio.h"
#include "pybsd.h"
#include "mpexception.h"
@@ -163,9 +164,50 @@ STATIC mp_obj_t pyb_sd_deinit (mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_sd_deinit_obj, pyb_sd_deinit);
+STATIC mp_obj_t pyb_sd_readblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) {
+ mp_buffer_info_t bufinfo;
+ mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE);
+ DRESULT res = sd_disk_read(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SD_SECTOR_SIZE);
+ return MP_OBJ_NEW_SMALL_INT(res != RES_OK); // return of 0 means success
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sd_readblocks_obj, pyb_sd_readblocks);
+
+STATIC mp_obj_t pyb_sd_writeblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) {
+ mp_buffer_info_t bufinfo;
+ mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
+ DRESULT res = sd_disk_write(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SD_SECTOR_SIZE);
+ return MP_OBJ_NEW_SMALL_INT(res != RES_OK); // return of 0 means success
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sd_writeblocks_obj, pyb_sd_writeblocks);
+
+STATIC mp_obj_t pyb_sd_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) {
+ mp_int_t cmd = mp_obj_get_int(cmd_in);
+ switch (cmd) {
+ case BP_IOCTL_INIT:
+ case BP_IOCTL_DEINIT:
+ case BP_IOCTL_SYNC:
+ // nothing to do
+ return MP_OBJ_NEW_SMALL_INT(0); // success
+
+ case BP_IOCTL_SEC_COUNT:
+ return MP_OBJ_NEW_SMALL_INT(sd_disk_info.ulNofBlock * (sd_disk_info.ulBlockSize / 512));
+
+ case BP_IOCTL_SEC_SIZE:
+ return MP_OBJ_NEW_SMALL_INT(SD_SECTOR_SIZE);
+
+ default: // unknown command
+ return MP_OBJ_NEW_SMALL_INT(-1); // error
+ }
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sd_ioctl_obj, pyb_sd_ioctl);
+
STATIC const mp_map_elem_t pyb_sd_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pyb_sd_init_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&pyb_sd_deinit_obj },
+ // block device protocol
+ { MP_OBJ_NEW_QSTR(MP_QSTR_readblocks), (mp_obj_t)&pyb_sd_readblocks_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_writeblocks), (mp_obj_t)&pyb_sd_writeblocks_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_ioctl), (mp_obj_t)&pyb_sd_ioctl_obj },
};
STATIC MP_DEFINE_CONST_DICT(pyb_sd_locals_dict, pyb_sd_locals_dict_table);