3535
3636#define MOD_FLASHDEV_LOG (msg , ...) custom_log('flashdev', msg,##__VA_ARGS__)
3737
38- const mp_obj_type_t helios_flash_device_type ;
38+ const mp_obj_type_t flash_device_type ;
3939
4040struct lfs_flash_info
4141{
@@ -44,17 +44,17 @@ struct lfs_flash_info
4444 uint32_t LfsEndAddress ;
4545};
4646
47- typedef struct _helios_flash_device_obj_t {
47+ typedef struct flash_device_obj_t {
4848 mp_obj_base_t base ;
4949 int block_size ;
5050 int block_count ;
5151 struct lfs_flash_info info ;
5252 char partition_name [32 ];
53- } helios_flash_device_obj_t ;
53+ } flash_device_obj_t ;
5454
55- static mp_obj_t helios_flash_device_make_new (const mp_obj_type_t * type , size_t n_args , size_t n_kw , const mp_obj_t * args ) {
55+ static mp_obj_t flash_init (const mp_obj_type_t * type , size_t n_args , size_t n_kw , const mp_obj_t * args ) {
5656 mp_arg_check_num (n_args , n_kw , 2 , 2 , false);
57- helios_flash_device_obj_t * self = mp_obj_malloc (helios_flash_device_obj_t , type );
57+ flash_device_obj_t * self = mp_obj_malloc (flash_device_obj_t , type );
5858
5959 mp_buffer_info_t bufinfo ;
6060 memset (self -> partition_name , 0x0 , sizeof (self -> partition_name ));
@@ -91,8 +91,8 @@ static mp_obj_t helios_flash_device_make_new(const mp_obj_type_t *type, size_t n
9191 return MP_OBJ_FROM_PTR (self );
9292}
9393
94- static mp_obj_t helios_flash_device_readblocks (size_t n_args , const mp_obj_t * args ) {
95- helios_flash_device_obj_t * self = MP_OBJ_TO_PTR (args [0 ]);
94+ static mp_obj_t flash_readblocks (size_t n_args , const mp_obj_t * args ) {
95+ flash_device_obj_t * self = MP_OBJ_TO_PTR (args [0 ]);
9696 uint32_t FlashAddrss = 0 ;
9797 uint32_t block_num = mp_obj_get_int (args [1 ]);
9898 uint32_t offset = block_num * self -> block_size ;
@@ -108,10 +108,10 @@ static mp_obj_t helios_flash_device_readblocks(size_t n_args, const mp_obj_t *ar
108108 ret = Helios_Flash_Read ((uint32_t )FlashAddrss , bufinfo .buf , bufinfo .len );
109109 return MP_OBJ_NEW_SMALL_INT (ret );
110110}
111- static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (helios_flash_device_readblocks_obj , 3 , 4 , helios_flash_device_readblocks ) ;
111+ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (flash_readblocks_obj , 3 , 4 , flash_readblocks ) ;
112112
113- static mp_obj_t helios_flash_device_writeblocks (size_t n_args , const mp_obj_t * args ) {
114- helios_flash_device_obj_t * self = MP_OBJ_TO_PTR (args [0 ]);
113+ static mp_obj_t flash_writeblocks (size_t n_args , const mp_obj_t * args ) {
114+ flash_device_obj_t * self = MP_OBJ_TO_PTR (args [0 ]);
115115 uint32_t block_num = mp_obj_get_int (args [1 ]);
116116 uint32_t offset = block_num * self -> block_size ;
117117 mp_buffer_info_t bufinfo ;
@@ -131,10 +131,10 @@ static mp_obj_t helios_flash_device_writeblocks(size_t n_args, const mp_obj_t *a
131131 ret = Helios_Flash_Write (FlashAddrss , bufinfo .buf , bufinfo .len );
132132 return MP_OBJ_NEW_SMALL_INT (ret );
133133}
134- static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (helios_flash_device_writeblocks_obj , 3 , 4 , helios_flash_device_writeblocks ) ;
134+ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (flash_writeblocks_obj , 3 , 4 , flash_writeblocks ) ;
135135
136- static mp_obj_t helios_flash_device_ioctl (mp_obj_t self_in , mp_obj_t cmd_in , mp_obj_t arg_in ) {
137- helios_flash_device_obj_t * self = self_in ;
136+ static mp_obj_t flash_ioctl (mp_obj_t self_in , mp_obj_t cmd_in , mp_obj_t arg_in ) {
137+ flash_device_obj_t * self = self_in ;
138138 mp_int_t cmd = mp_obj_get_int (cmd_in );
139139 mp_int_t block_num = mp_obj_get_int (arg_in );
140140 int ret ;
@@ -161,19 +161,31 @@ static mp_obj_t helios_flash_device_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_
161161 return MP_OBJ_NEW_SMALL_INT (-1 );
162162 }
163163}
164- static MP_DEFINE_CONST_FUN_OBJ_3 (helios_flash_device_ioctl_obj , helios_flash_device_ioctl ) ;
164+ static MP_DEFINE_CONST_FUN_OBJ_3 (flash_ioctl_obj , flash_ioctl ) ;
165165
166- static const mp_rom_map_elem_t helios_flash_device_locals_dict_table [] = {
167- { MP_ROM_QSTR (MP_QSTR_readblocks ), MP_ROM_PTR (& helios_flash_device_readblocks_obj ) },
168- { MP_ROM_QSTR (MP_QSTR_writeblocks ), MP_ROM_PTR (& helios_flash_device_writeblocks_obj ) },
169- { MP_ROM_QSTR (MP_QSTR_ioctl ), MP_ROM_PTR (& helios_flash_device_ioctl_obj ) },
170- };
171- static MP_DEFINE_CONST_DICT (helios_flash_device_locals_dict , helios_flash_device_locals_dict_table ) ;
166+ static const mp_obj_dict_t flash_device_locals_dict ;
172167
173168MP_DEFINE_CONST_OBJ_TYPE (
174- helios_flash_device_type ,
169+ flash_device_type ,
175170 MP_QSTR_FlashDevice ,
176171 MP_TYPE_FLAG_NONE ,
177- make_new , helios_flash_device_make_new ,
178- locals_dict , & helios_flash_device_locals_dict
172+ make_new , flash_init ,
173+ locals_dict , & flash_device_locals_dict
179174 );
175+
176+ static const mp_rom_map_elem_t flash_device_locals_dict_table [] = {
177+ { MP_ROM_QSTR (MP_QSTR___name__ ), MP_ROM_QSTR (MP_QSTR_myflash ) },
178+ { MP_ROM_QSTR (MP_QSTR_FlashDevice ), MP_ROM_PTR (& flash_device_type )},
179+ { MP_ROM_QSTR (MP_QSTR_readblocks ), MP_ROM_PTR (& flash_readblocks_obj ) },
180+ { MP_ROM_QSTR (MP_QSTR_writeblocks ), MP_ROM_PTR (& flash_writeblocks_obj ) },
181+ { MP_ROM_QSTR (MP_QSTR_ioctl ), MP_ROM_PTR (& flash_ioctl_obj ) },
182+ };
183+
184+ static MP_DEFINE_CONST_DICT (flash_device_locals_dict , flash_device_locals_dict_table ) ;
185+
186+ const mp_obj_module_t flashdev_module = {
187+ .base = { & mp_type_module },
188+ .globals = (mp_obj_dict_t * )& flash_device_locals_dict ,
189+ };
190+
191+ MP_REGISTER_MODULE (MP_QSTR_flashdev , flashdev_module );
0 commit comments