Skip to content

Commit 6ebc240

Browse files
committed
quectel: Switch to extmod/modos.
1 parent 2faf9b4 commit 6ebc240

File tree

6 files changed

+46
-259
lines changed

6 files changed

+46
-259
lines changed

ports/quectel/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ EXTMOD_SRC_C = extmod/vfs.c \
8686
extmod/vfs_reader.c \
8787
extmod/modre.c \
8888
extmod/modhashlib.c \
89-
extmod/moductypes.c
89+
extmod/moductypes.c \
90+
extmod/modos.c
9091

9192
EXTMOD_SRC_C += $(SRC_THIRDPARTY_C)
9293

ports/quectel/modflashdev.c

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
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

4040
struct 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

173168
MP_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);

ports/quectel/modules/_boot.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import os
1616
import ujson
17+
import flashdev
1718

1819
"""
1920
Mark.Zhu - 2022/12/02
@@ -46,14 +47,14 @@ def _repl_enable():
4647
from os import VfsLfs1 as VfsLfs
4748
except Exception:
4849
from os import VfsLfs2 as VfsLfs
49-
50-
udev = os.FlashDevice("customer_fs", 4096)
50+
dev = flashdev.FlashDevice("customer_fs", 4096)
5151
try:
52+
udev = os.VfsLfs2(dev)
53+
os.mount(udev, "/")
54+
except Exception:
55+
os.VfsLfs2.mkfs(dev)
56+
udev = os.VfsLfs2(dev)
5257
os.mount(udev, "/")
53-
except Exception as e:
54-
if "ENODEV" in str(e):
55-
VfsLfs.mkfs(udev)
56-
os.mount(udev, "/")
5758
if "usr" not in os.listdir():
5859
os.mkdir("usr")
5960
if "bak" not in os.listdir():

ports/quectel/moduos.c

Lines changed: 0 additions & 226 deletions
This file was deleted.

ports/quectel/mpconfigport.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@
4444
#define MICROPY_PY_IO (1)
4545
#define MICROPY_PY_JSON (1)
4646
#define MICROPY_VFS (1)
47-
#define MICROPY_QPY_MODULE_UOS (1)
47+
#define MICROPY_QPY_MODULE_UOS (0)
4848
#define MICROPY_PY_VFS (0)
4949
#define MICROPY_PY_TIME (0)
5050
#define MICROPY_PY_HEAPQ (0)
51-
#define MICROPY_PY_OS (0)
51+
#define MICROPY_PY_OS (1)
5252
#define MICROPY_PY_PLATFORM (0)
5353
#define MICROPY_PY_SELECT (0)
5454
#define MICROPY_PY_FRAMEBUF (0)

ports/quectel/quectel.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ QUEC_SRC += \
7878
# modules source file will used by gen
7979
QUEC_SRC_MOD += \
8080
gccollect.c \
81-
moduos.c \
8281
modflashdev.c \
8382
modhelios.c
8483

0 commit comments

Comments
 (0)