mirror of
https://github.com/micropython/micropython.git
synced 2025-12-15 17:30:14 +01:00
all: Remove the "STATIC" macro and just use "static" instead.
The STATIC macro was introduced a very long time ago in commit
d5df6cd44a. The original reason for this was
to have the option to define it to nothing so that all static functions
become global functions and therefore visible to certain debug tools, so
one could do function size comparison and other things.
This STATIC feature is rarely (if ever) used. And with the use of LTO and
heavy inline optimisation, analysing the size of individual functions when
they are not static is not a good representation of the size of code when
fully optimised.
So the macro does not have much use and it's simpler to just remove it.
Then you know exactly what it's doing. For example, newcomers don't have
to learn what the STATIC macro is and why it exists. Reading the code is
also less "loud" with a lowercase static.
One other minor point in favour of removing it, is that it stops bugs with
`STATIC inline`, which should always be `static inline`.
Methodology for this commit was:
1) git ls-files | egrep '\.[ch]$' | \
xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/"
2) Do some manual cleanup in the diff by searching for the word STATIC in
comments and changing those back.
3) "git-grep STATIC docs/", manually fixed those cases.
4) "rg -t python STATIC", manually fixed codegen lines that used STATIC.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This commit is contained in:
committed by
Damien George
parent
b3f2f18f92
commit
decf8e6a8b
@@ -162,7 +162,7 @@ class Pins:
|
||||
def print_named(self, label, pins, out_source):
|
||||
print("", file=out_source)
|
||||
print(
|
||||
"STATIC const mp_rom_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{".format(label),
|
||||
"static const mp_rom_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{".format(label),
|
||||
file=out_source,
|
||||
)
|
||||
for pin in pins:
|
||||
|
||||
@@ -201,7 +201,7 @@ static FIFO_t ftp_socketfifo;
|
||||
// all calls in an nlr handler. The wrapper functions below assume that there
|
||||
// are only FATFS filesystems mounted.
|
||||
|
||||
STATIC FATFS *lookup_path(const TCHAR **path) {
|
||||
static FATFS *lookup_path(const TCHAR **path) {
|
||||
mp_vfs_mount_t *fs = mp_vfs_lookup_path(*path, path);
|
||||
if (fs == MP_VFS_NONE || fs == MP_VFS_ROOT) {
|
||||
return NULL;
|
||||
@@ -210,7 +210,7 @@ STATIC FATFS *lookup_path(const TCHAR **path) {
|
||||
return &((fs_user_mount_t*)MP_OBJ_TO_PTR(fs->obj))->fatfs;
|
||||
}
|
||||
|
||||
STATIC FRESULT f_open_helper(FIL *fp, const TCHAR *path, BYTE mode) {
|
||||
static FRESULT f_open_helper(FIL *fp, const TCHAR *path, BYTE mode) {
|
||||
FATFS *fs = lookup_path(&path);
|
||||
if (fs == NULL) {
|
||||
return FR_NO_PATH;
|
||||
@@ -218,7 +218,7 @@ STATIC FRESULT f_open_helper(FIL *fp, const TCHAR *path, BYTE mode) {
|
||||
return f_open(fs, fp, path, mode);
|
||||
}
|
||||
|
||||
STATIC FRESULT f_opendir_helper(FF_DIR *dp, const TCHAR *path) {
|
||||
static FRESULT f_opendir_helper(FF_DIR *dp, const TCHAR *path) {
|
||||
FATFS *fs = lookup_path(&path);
|
||||
if (fs == NULL) {
|
||||
return FR_NO_PATH;
|
||||
@@ -226,7 +226,7 @@ STATIC FRESULT f_opendir_helper(FF_DIR *dp, const TCHAR *path) {
|
||||
return f_opendir(fs, dp, path);
|
||||
}
|
||||
|
||||
STATIC FRESULT f_stat_helper(const TCHAR *path, FILINFO *fno) {
|
||||
static FRESULT f_stat_helper(const TCHAR *path, FILINFO *fno) {
|
||||
FATFS *fs = lookup_path(&path);
|
||||
if (fs == NULL) {
|
||||
return FR_NO_PATH;
|
||||
@@ -234,7 +234,7 @@ STATIC FRESULT f_stat_helper(const TCHAR *path, FILINFO *fno) {
|
||||
return f_stat(fs, path, fno);
|
||||
}
|
||||
|
||||
STATIC FRESULT f_mkdir_helper(const TCHAR *path) {
|
||||
static FRESULT f_mkdir_helper(const TCHAR *path) {
|
||||
FATFS *fs = lookup_path(&path);
|
||||
if (fs == NULL) {
|
||||
return FR_NO_PATH;
|
||||
@@ -242,7 +242,7 @@ STATIC FRESULT f_mkdir_helper(const TCHAR *path) {
|
||||
return f_mkdir(fs, path);
|
||||
}
|
||||
|
||||
STATIC FRESULT f_unlink_helper(const TCHAR *path) {
|
||||
static FRESULT f_unlink_helper(const TCHAR *path) {
|
||||
FATFS *fs = lookup_path(&path);
|
||||
if (fs == NULL) {
|
||||
return FR_NO_PATH;
|
||||
@@ -250,7 +250,7 @@ STATIC FRESULT f_unlink_helper(const TCHAR *path) {
|
||||
return f_unlink(fs, path);
|
||||
}
|
||||
|
||||
STATIC FRESULT f_rename_helper(const TCHAR *path_old, const TCHAR *path_new) {
|
||||
static FRESULT f_rename_helper(const TCHAR *path_old, const TCHAR *path_new) {
|
||||
FATFS *fs_old = lookup_path(&path_old);
|
||||
if (fs_old == NULL) {
|
||||
return FR_NO_PATH;
|
||||
|
||||
@@ -50,7 +50,7 @@ const mp_arg_t mp_irq_init_args[] = {
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE DATA
|
||||
******************************************************************************/
|
||||
STATIC uint8_t mp_irq_priorities[] = { INT_PRIORITY_LVL_7, INT_PRIORITY_LVL_6, INT_PRIORITY_LVL_5, INT_PRIORITY_LVL_4,
|
||||
static uint8_t mp_irq_priorities[] = { INT_PRIORITY_LVL_7, INT_PRIORITY_LVL_6, INT_PRIORITY_LVL_5, INT_PRIORITY_LVL_4,
|
||||
INT_PRIORITY_LVL_3, INT_PRIORITY_LVL_2, INT_PRIORITY_LVL_1 };
|
||||
|
||||
/******************************************************************************
|
||||
@@ -143,7 +143,7 @@ void mp_irq_handler (mp_obj_t self_in) {
|
||||
/******************************************************************************/
|
||||
// MicroPython bindings
|
||||
|
||||
STATIC mp_obj_t mp_irq_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t mp_irq_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_irq_obj_t *self = pos_args[0];
|
||||
// this is a bit of a hack, but it let us reuse the callback_create method from our parent
|
||||
((mp_obj_t *)pos_args)[0] = self->parent;
|
||||
@@ -152,35 +152,35 @@ STATIC mp_obj_t mp_irq_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(mp_irq_init_obj, 1, mp_irq_init);
|
||||
|
||||
STATIC mp_obj_t mp_irq_enable (mp_obj_t self_in) {
|
||||
static mp_obj_t mp_irq_enable (mp_obj_t self_in) {
|
||||
mp_irq_obj_t *self = self_in;
|
||||
self->methods->enable(self->parent);
|
||||
self->isenabled = true;
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_irq_enable_obj, mp_irq_enable);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(mp_irq_enable_obj, mp_irq_enable);
|
||||
|
||||
STATIC mp_obj_t mp_irq_disable (mp_obj_t self_in) {
|
||||
static mp_obj_t mp_irq_disable (mp_obj_t self_in) {
|
||||
mp_irq_obj_t *self = self_in;
|
||||
self->methods->disable(self->parent);
|
||||
self->isenabled = false;
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_irq_disable_obj, mp_irq_disable);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(mp_irq_disable_obj, mp_irq_disable);
|
||||
|
||||
STATIC mp_obj_t mp_irq_flags (mp_obj_t self_in) {
|
||||
static mp_obj_t mp_irq_flags (mp_obj_t self_in) {
|
||||
mp_irq_obj_t *self = self_in;
|
||||
return mp_obj_new_int(self->methods->flags(self->parent));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_irq_flags_obj, mp_irq_flags);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(mp_irq_flags_obj, mp_irq_flags);
|
||||
|
||||
STATIC mp_obj_t mp_irq_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t mp_irq_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
mp_irq_handler (self_in);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_irq_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t mp_irq_locals_dict_table[] = {
|
||||
// instance methods
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&mp_irq_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_enable), MP_ROM_PTR(&mp_irq_enable_obj) },
|
||||
@@ -188,7 +188,7 @@ STATIC const mp_rom_map_elem_t mp_irq_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_flags), MP_ROM_PTR(&mp_irq_flags_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_irq_locals_dict, mp_irq_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(mp_irq_locals_dict, mp_irq_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
mp_irq_type,
|
||||
|
||||
@@ -59,7 +59,7 @@ typedef struct _machine_wdt_obj_t {
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE DATA
|
||||
******************************************************************************/
|
||||
STATIC machine_wdt_obj_t machine_wdt_obj = {.servers = false, .servers_sleeping = false, .simplelink = false, .running = false};
|
||||
static machine_wdt_obj_t machine_wdt_obj = {.servers = false, .servers_sleeping = false, .simplelink = false, .running = false};
|
||||
|
||||
/******************************************************************************
|
||||
DEFINE PUBLIC FUNCTIONS
|
||||
@@ -84,7 +84,7 @@ void pybwdt_sl_alive (void) {
|
||||
/******************************************************************************/
|
||||
// MicroPython bindings
|
||||
|
||||
STATIC machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t timeout_ms) {
|
||||
static machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t timeout_ms) {
|
||||
if (id != 0) {
|
||||
mp_raise_OSError(MP_ENODEV);
|
||||
}
|
||||
@@ -119,7 +119,7 @@ STATIC machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t
|
||||
return &machine_wdt_obj;
|
||||
}
|
||||
|
||||
STATIC void mp_machine_wdt_feed(machine_wdt_obj_t *self) {
|
||||
static void mp_machine_wdt_feed(machine_wdt_obj_t *self) {
|
||||
if ((self->servers || self->servers_sleeping) && self->simplelink && self->running) {
|
||||
self->servers = false;
|
||||
self->simplelink = false;
|
||||
|
||||
@@ -61,13 +61,13 @@ typedef struct _mp_obj_hash_t {
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC void hash_update_internal(mp_obj_t self_in, mp_obj_t data, bool digest);
|
||||
STATIC mp_obj_t hash_read (mp_obj_t self_in);
|
||||
static void hash_update_internal(mp_obj_t self_in, mp_obj_t data, bool digest);
|
||||
static mp_obj_t hash_read (mp_obj_t self_in);
|
||||
|
||||
/******************************************************************************
|
||||
DEFINE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC void hash_update_internal(mp_obj_t self_in, mp_obj_t data, bool digest) {
|
||||
static void hash_update_internal(mp_obj_t self_in, mp_obj_t data, bool digest) {
|
||||
mp_obj_hash_t *self = self_in;
|
||||
mp_buffer_info_t bufinfo;
|
||||
|
||||
@@ -95,7 +95,7 @@ STATIC void hash_update_internal(mp_obj_t self_in, mp_obj_t data, bool digest) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t hash_read (mp_obj_t self_in) {
|
||||
static mp_obj_t hash_read (mp_obj_t self_in) {
|
||||
mp_obj_hash_t *self = self_in;
|
||||
|
||||
if (!self->fixedlen) {
|
||||
@@ -119,7 +119,7 @@ STATIC mp_obj_t hash_read (mp_obj_t self_in) {
|
||||
|
||||
/// \classmethod \constructor([data[, block_size]])
|
||||
/// initial data must be given if block_size wants to be passed
|
||||
STATIC mp_obj_t hash_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t hash_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 2, false);
|
||||
mp_obj_hash_t *self = m_new0(mp_obj_hash_t, 1);
|
||||
self->base.type = type_in;
|
||||
@@ -151,24 +151,24 @@ STATIC mp_obj_t hash_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, cons
|
||||
return self;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t hash_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
static mp_obj_t hash_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
mp_obj_hash_t *self = self_in;
|
||||
hash_update_internal(self, arg, false);
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(hash_update_obj, hash_update);
|
||||
|
||||
STATIC mp_obj_t hash_digest(mp_obj_t self_in) {
|
||||
static mp_obj_t hash_digest(mp_obj_t self_in) {
|
||||
return hash_read(self_in);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(hash_digest_obj, hash_digest);
|
||||
|
||||
STATIC const mp_rom_map_elem_t hash_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t hash_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&hash_update_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&hash_digest_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(hash_locals_dict, hash_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(hash_locals_dict, hash_locals_dict_table);
|
||||
|
||||
//STATIC const mp_obj_type_t md5_type = {
|
||||
// { &mp_type_type },
|
||||
@@ -177,7 +177,7 @@ STATIC MP_DEFINE_CONST_DICT(hash_locals_dict, hash_locals_dict_table);
|
||||
// .locals_dict = (mp_obj_t)&hash_locals_dict,
|
||||
//};
|
||||
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
static MP_DEFINE_CONST_OBJ_TYPE(
|
||||
sha1_type,
|
||||
MP_QSTR_sha1,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
@@ -185,7 +185,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
locals_dict, &hash_locals_dict
|
||||
);
|
||||
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
static MP_DEFINE_CONST_OBJ_TYPE(
|
||||
sha256_type,
|
||||
MP_QSTR_sha256,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
@@ -193,14 +193,14 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
locals_dict, &hash_locals_dict
|
||||
);
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_hashlib_globals_table[] = {
|
||||
static const mp_rom_map_elem_t mp_module_hashlib_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_hashlib) },
|
||||
//{ MP_ROM_QSTR(MP_QSTR_md5), MP_ROM_PTR(&md5_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_sha1), MP_ROM_PTR(&sha1_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_sha256), MP_ROM_PTR(&sha256_type) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_hashlib_globals, mp_module_hashlib_globals_table);
|
||||
static MP_DEFINE_CONST_DICT(mp_module_hashlib_globals, mp_module_hashlib_globals_table);
|
||||
|
||||
const mp_obj_module_t mp_module_hashlib = {
|
||||
.base = { &mp_type_module },
|
||||
|
||||
@@ -93,7 +93,7 @@ extern OsiTaskHandle xSimpleLinkSpawnTaskHndl;
|
||||
/******************************************************************************/
|
||||
// MicroPython bindings;
|
||||
|
||||
NORETURN STATIC void mp_machine_reset(void) {
|
||||
NORETURN static void mp_machine_reset(void) {
|
||||
// disable wlan
|
||||
wlan_stop(SL_STOP_TIMEOUT_LONG);
|
||||
// reset the cpu and it's peripherals
|
||||
@@ -103,7 +103,7 @@ NORETURN STATIC void mp_machine_reset(void) {
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
STATIC mp_obj_t machine_info(uint n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t machine_info(uint n_args, const mp_obj_t *args) {
|
||||
// FreeRTOS info
|
||||
{
|
||||
printf("---------------------------------------------\n");
|
||||
@@ -126,24 +126,24 @@ STATIC mp_obj_t machine_info(uint n_args, const mp_obj_t *args) {
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj, 0, 1, machine_info);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj, 0, 1, machine_info);
|
||||
#endif
|
||||
|
||||
STATIC mp_obj_t mp_machine_get_freq(void) {
|
||||
static mp_obj_t mp_machine_get_freq(void) {
|
||||
return mp_obj_new_int(HAL_FCPU_HZ);
|
||||
}
|
||||
|
||||
STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
|
||||
static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
|
||||
mp_raise_NotImplementedError(NULL);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_machine_unique_id(void) {
|
||||
static mp_obj_t mp_machine_unique_id(void) {
|
||||
uint8_t mac[SL_BSSID_LENGTH];
|
||||
wlan_get_mac (mac);
|
||||
return mp_obj_new_bytes(mac, SL_BSSID_LENGTH);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t machine_main(mp_obj_t main) {
|
||||
static mp_obj_t machine_main(mp_obj_t main) {
|
||||
if (mp_obj_is_str(main)) {
|
||||
MP_STATE_PORT(machine_config_main) = main;
|
||||
} else {
|
||||
@@ -153,27 +153,27 @@ STATIC mp_obj_t machine_main(mp_obj_t main) {
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(machine_main_obj, machine_main);
|
||||
|
||||
STATIC void mp_machine_idle(void) {
|
||||
static void mp_machine_idle(void) {
|
||||
__WFI();
|
||||
}
|
||||
|
||||
STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||
static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||
pyb_sleep_sleep();
|
||||
}
|
||||
|
||||
NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
||||
NORETURN static void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
||||
pyb_sleep_deepsleep();
|
||||
for (;;) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_int_t mp_machine_reset_cause(void) {
|
||||
static mp_int_t mp_machine_reset_cause(void) {
|
||||
return pyb_sleep_get_reset_cause();
|
||||
}
|
||||
|
||||
STATIC mp_obj_t machine_wake_reason (void) {
|
||||
static mp_obj_t machine_wake_reason (void) {
|
||||
return mp_obj_new_int(pyb_sleep_get_wake_reason());
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_wake_reason_obj, machine_wake_reason);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_0(machine_wake_reason_obj, machine_wake_reason);
|
||||
|
||||
MP_REGISTER_ROOT_POINTER(mp_obj_t machine_config_main);
|
||||
|
||||
@@ -43,8 +43,8 @@ typedef struct {
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE DATA
|
||||
******************************************************************************/
|
||||
STATIC network_server_obj_t network_server_obj;
|
||||
STATIC const mp_obj_type_t network_server_type;
|
||||
static network_server_obj_t network_server_obj;
|
||||
static const mp_obj_type_t network_server_type;
|
||||
|
||||
/// \module network - network configuration
|
||||
///
|
||||
@@ -54,7 +54,7 @@ void mod_network_init0(void) {
|
||||
}
|
||||
|
||||
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
|
||||
STATIC mp_obj_t network_server_init_helper(mp_obj_t self, const mp_arg_val_t *args) {
|
||||
static mp_obj_t network_server_init_helper(mp_obj_t self, const mp_arg_val_t *args) {
|
||||
const char *user = SERVERS_DEF_USER;
|
||||
const char *pass = SERVERS_DEF_PASS;
|
||||
if (args[0].u_obj != MP_OBJ_NULL) {
|
||||
@@ -81,12 +81,12 @@ STATIC mp_obj_t network_server_init_helper(mp_obj_t self, const mp_arg_val_t *ar
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC const mp_arg_t network_server_args[] = {
|
||||
static const mp_arg_t network_server_args[] = {
|
||||
{ MP_QSTR_id, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
{ MP_QSTR_login, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
};
|
||||
STATIC mp_obj_t network_server_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t network_server_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
// parse args
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
|
||||
@@ -108,16 +108,16 @@ STATIC mp_obj_t network_server_make_new(const mp_obj_type_t *type, size_t n_args
|
||||
return (mp_obj_t)self;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t network_server_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t network_server_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
// parse args
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(network_server_args) - 1];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &network_server_args[1], args);
|
||||
return network_server_init_helper(pos_args[0], args);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(network_server_init_obj, 1, network_server_init);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(network_server_init_obj, 1, network_server_init);
|
||||
|
||||
// timeout value given in seconds
|
||||
STATIC mp_obj_t network_server_timeout(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t network_server_timeout(size_t n_args, const mp_obj_t *args) {
|
||||
if (n_args > 1) {
|
||||
uint32_t timeout = mp_obj_get_int(args[1]);
|
||||
servers_set_timeout(timeout * 1000);
|
||||
@@ -127,23 +127,23 @@ STATIC mp_obj_t network_server_timeout(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_obj_new_int(servers_get_timeout() / 1000);
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_server_timeout_obj, 1, 2, network_server_timeout);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_server_timeout_obj, 1, 2, network_server_timeout);
|
||||
|
||||
STATIC mp_obj_t network_server_running(mp_obj_t self_in) {
|
||||
static mp_obj_t network_server_running(mp_obj_t self_in) {
|
||||
// get
|
||||
return mp_obj_new_bool(servers_are_enabled());
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_server_running_obj, network_server_running);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(network_server_running_obj, network_server_running);
|
||||
|
||||
STATIC mp_obj_t network_server_deinit(mp_obj_t self_in) {
|
||||
static mp_obj_t network_server_deinit(mp_obj_t self_in) {
|
||||
// simply stop the servers
|
||||
servers_stop();
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_server_deinit_obj, network_server_deinit);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(network_server_deinit_obj, network_server_deinit);
|
||||
#endif
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = {
|
||||
static const mp_rom_map_elem_t mp_module_network_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_network) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mod_network_nic_type_wlan) },
|
||||
|
||||
@@ -152,7 +152,7 @@ STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_network_globals, mp_module_network_globals_table);
|
||||
static MP_DEFINE_CONST_DICT(mp_module_network_globals, mp_module_network_globals_table);
|
||||
|
||||
const mp_obj_module_t mp_module_network = {
|
||||
.base = { &mp_type_module },
|
||||
@@ -162,16 +162,16 @@ const mp_obj_module_t mp_module_network = {
|
||||
MP_REGISTER_MODULE(MP_QSTR_network, mp_module_network);
|
||||
|
||||
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
|
||||
STATIC const mp_rom_map_elem_t network_server_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t network_server_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&network_server_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&network_server_deinit_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_timeout), MP_ROM_PTR(&network_server_timeout_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_isrunning), MP_ROM_PTR(&network_server_running_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(network_server_locals_dict, network_server_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(network_server_locals_dict, network_server_locals_dict_table);
|
||||
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
static MP_DEFINE_CONST_OBJ_TYPE(
|
||||
network_server_type,
|
||||
MP_QSTR_Server,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include "py/runtime.h"
|
||||
#include "random.h"
|
||||
|
||||
STATIC mp_obj_t mp_os_urandom(mp_obj_t num) {
|
||||
static mp_obj_t mp_os_urandom(mp_obj_t num) {
|
||||
mp_int_t n = mp_obj_get_int(num);
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, n);
|
||||
@@ -40,4 +40,4 @@ STATIC mp_obj_t mp_os_urandom(mp_obj_t num) {
|
||||
}
|
||||
return mp_obj_new_bytes_from_vstr(&vstr);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom);
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
|
||||
#define SOCKET_TIMEOUT_QUANTA_MS (20)
|
||||
|
||||
STATIC int convert_sl_errno(int sl_errno) {
|
||||
static int convert_sl_errno(int sl_errno) {
|
||||
return -sl_errno;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ int check_timedout(mod_network_socket_obj_t *s, int ret, uint32_t *timeout_ms, i
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC int wlan_gethostbyname(const char *name, mp_uint_t len, uint8_t *out_ip, uint8_t family) {
|
||||
static int wlan_gethostbyname(const char *name, mp_uint_t len, uint8_t *out_ip, uint8_t family) {
|
||||
uint32_t ip;
|
||||
int result = sl_NetAppDnsGetHostByName((_i8 *)name, (_u16)len, (_u32*)&ip, (_u8)family);
|
||||
out_ip[0] = ip;
|
||||
@@ -103,7 +103,7 @@ STATIC int wlan_gethostbyname(const char *name, mp_uint_t len, uint8_t *out_ip,
|
||||
return result;
|
||||
}
|
||||
|
||||
STATIC int wlan_socket_socket(mod_network_socket_obj_t *s, int *_errno) {
|
||||
static int wlan_socket_socket(mod_network_socket_obj_t *s, int *_errno) {
|
||||
int16_t sd = sl_Socket(s->sock_base.u_param.domain, s->sock_base.u_param.type, s->sock_base.u_param.proto);
|
||||
if (sd < 0) {
|
||||
*_errno = sd;
|
||||
@@ -113,7 +113,7 @@ STATIC int wlan_socket_socket(mod_network_socket_obj_t *s, int *_errno) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC void wlan_socket_close(mod_network_socket_obj_t *s) {
|
||||
static void wlan_socket_close(mod_network_socket_obj_t *s) {
|
||||
// this is to prevent the finalizer to close a socket that failed when being created
|
||||
if (s->sock_base.sd >= 0) {
|
||||
modusocket_socket_delete(s->sock_base.sd);
|
||||
@@ -122,7 +122,7 @@ STATIC void wlan_socket_close(mod_network_socket_obj_t *s) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC int wlan_socket_bind(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno) {
|
||||
static int wlan_socket_bind(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno) {
|
||||
MAKE_SOCKADDR(addr, ip, port)
|
||||
int ret = sl_Bind(s->sock_base.sd, &addr, sizeof(addr));
|
||||
if (ret != 0) {
|
||||
@@ -132,7 +132,7 @@ STATIC int wlan_socket_bind(mod_network_socket_obj_t *s, byte *ip, mp_uint_t por
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC int wlan_socket_listen(mod_network_socket_obj_t *s, mp_int_t backlog, int *_errno) {
|
||||
static int wlan_socket_listen(mod_network_socket_obj_t *s, mp_int_t backlog, int *_errno) {
|
||||
int ret = sl_Listen(s->sock_base.sd, backlog);
|
||||
if (ret != 0) {
|
||||
*_errno = ret;
|
||||
@@ -141,7 +141,7 @@ STATIC int wlan_socket_listen(mod_network_socket_obj_t *s, mp_int_t backlog, int
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC int wlan_socket_accept(mod_network_socket_obj_t *s, mod_network_socket_obj_t *s2, byte *ip, mp_uint_t *port, int *_errno) {
|
||||
static int wlan_socket_accept(mod_network_socket_obj_t *s, mod_network_socket_obj_t *s2, byte *ip, mp_uint_t *port, int *_errno) {
|
||||
// accept incoming connection
|
||||
int16_t sd;
|
||||
SlSockAddr_t addr;
|
||||
@@ -163,7 +163,7 @@ STATIC int wlan_socket_accept(mod_network_socket_obj_t *s, mod_network_socket_ob
|
||||
}
|
||||
}
|
||||
|
||||
STATIC int wlan_socket_connect(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno) {
|
||||
static int wlan_socket_connect(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno) {
|
||||
MAKE_SOCKADDR(addr, ip, port)
|
||||
uint32_t timeout_ms = s->sock_base.timeout_ms;
|
||||
|
||||
@@ -195,7 +195,7 @@ STATIC int wlan_socket_connect(mod_network_socket_obj_t *s, byte *ip, mp_uint_t
|
||||
}
|
||||
}
|
||||
|
||||
STATIC int wlan_socket_send(mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, int *_errno) {
|
||||
static int wlan_socket_send(mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, int *_errno) {
|
||||
if (len == 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -211,7 +211,7 @@ STATIC int wlan_socket_send(mod_network_socket_obj_t *s, const byte *buf, mp_uin
|
||||
}
|
||||
}
|
||||
|
||||
STATIC int wlan_socket_recv(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, int *_errno) {
|
||||
static int wlan_socket_recv(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, int *_errno) {
|
||||
uint32_t timeout_ms = s->sock_base.timeout_ms;
|
||||
for (;;) {
|
||||
int ret = sl_Recv(s->sock_base.sd, buf, MIN(len, WLAN_MAX_RX_SIZE), 0);
|
||||
@@ -224,7 +224,7 @@ STATIC int wlan_socket_recv(mod_network_socket_obj_t *s, byte *buf, mp_uint_t le
|
||||
}
|
||||
}
|
||||
|
||||
STATIC int wlan_socket_sendto( mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno) {
|
||||
static int wlan_socket_sendto( mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno) {
|
||||
MAKE_SOCKADDR(addr, ip, port)
|
||||
uint32_t timeout_ms = s->sock_base.timeout_ms;
|
||||
for (;;) {
|
||||
@@ -238,7 +238,7 @@ STATIC int wlan_socket_sendto( mod_network_socket_obj_t *s, const byte *buf, mp_
|
||||
}
|
||||
}
|
||||
|
||||
STATIC int wlan_socket_recvfrom(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) {
|
||||
static int wlan_socket_recvfrom(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) {
|
||||
SlSockAddr_t addr;
|
||||
SlSocklen_t addr_len = sizeof(addr);
|
||||
uint32_t timeout_ms = s->sock_base.timeout_ms;
|
||||
@@ -254,7 +254,7 @@ STATIC int wlan_socket_recvfrom(mod_network_socket_obj_t *s, byte *buf, mp_uint_
|
||||
}
|
||||
}
|
||||
|
||||
STATIC int wlan_socket_setsockopt(mod_network_socket_obj_t *s, mp_uint_t level, mp_uint_t opt, const void *optval, mp_uint_t optlen, int *_errno) {
|
||||
static int wlan_socket_setsockopt(mod_network_socket_obj_t *s, mp_uint_t level, mp_uint_t opt, const void *optval, mp_uint_t optlen, int *_errno) {
|
||||
int ret = sl_SetSockOpt(s->sock_base.sd, level, opt, optval, optlen);
|
||||
if (ret < 0) {
|
||||
*_errno = ret;
|
||||
@@ -263,7 +263,7 @@ STATIC int wlan_socket_setsockopt(mod_network_socket_obj_t *s, mp_uint_t level,
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout_s, int *_errno) {
|
||||
static int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout_s, int *_errno) {
|
||||
SlSockNonblocking_t option;
|
||||
if (timeout_s == 0 || timeout_s == -1) {
|
||||
if (timeout_s == 0) {
|
||||
@@ -289,7 +289,7 @@ STATIC int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC int wlan_socket_ioctl (mod_network_socket_obj_t *s, mp_uint_t request, mp_uint_t arg, int *_errno) {
|
||||
static int wlan_socket_ioctl (mod_network_socket_obj_t *s, mp_uint_t request, mp_uint_t arg, int *_errno) {
|
||||
mp_int_t ret;
|
||||
if (request == MP_STREAM_POLL) {
|
||||
mp_uint_t flags = arg;
|
||||
@@ -361,9 +361,9 @@ typedef struct {
|
||||
/******************************************************************************
|
||||
DEFINE PRIVATE DATA
|
||||
******************************************************************************/
|
||||
STATIC const mp_obj_type_t socket_type;
|
||||
STATIC OsiLockObj_t modusocket_LockObj;
|
||||
STATIC modusocket_sock_t modusocket_sockets[MOD_NETWORK_MAX_SOCKETS] = {{.sd = -1}, {.sd = -1}, {.sd = -1}, {.sd = -1}, {.sd = -1},
|
||||
static const mp_obj_type_t socket_type;
|
||||
static OsiLockObj_t modusocket_LockObj;
|
||||
static modusocket_sock_t modusocket_sockets[MOD_NETWORK_MAX_SOCKETS] = {{.sd = -1}, {.sd = -1}, {.sd = -1}, {.sd = -1}, {.sd = -1},
|
||||
{.sd = -1}, {.sd = -1}, {.sd = -1}, {.sd = -1}, {.sd = -1}};
|
||||
|
||||
/******************************************************************************
|
||||
@@ -432,7 +432,7 @@ void modusocket_close_all_user_sockets (void) {
|
||||
// socket class
|
||||
|
||||
// constructor socket(family=AF_INET, type=SOCK_STREAM, proto=IPPROTO_TCP, fileno=None)
|
||||
STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 4, false);
|
||||
|
||||
// create socket object
|
||||
@@ -468,7 +468,7 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t
|
||||
}
|
||||
|
||||
// method socket.bind(address)
|
||||
STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
|
||||
static mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
|
||||
mod_network_socket_obj_t *self = self_in;
|
||||
|
||||
// get address
|
||||
@@ -482,10 +482,10 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind);
|
||||
|
||||
// method socket.listen([backlog])
|
||||
STATIC mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) {
|
||||
mod_network_socket_obj_t *self = args[0];
|
||||
|
||||
int32_t backlog = MICROPY_PY_SOCKET_LISTEN_BACKLOG_DEFAULT;
|
||||
@@ -500,10 +500,10 @@ STATIC mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_listen_obj, 1, 2, socket_listen);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_listen_obj, 1, 2, socket_listen);
|
||||
|
||||
// method socket.accept()
|
||||
STATIC mp_obj_t socket_accept(mp_obj_t self_in) {
|
||||
static mp_obj_t socket_accept(mp_obj_t self_in) {
|
||||
mod_network_socket_obj_t *self = self_in;
|
||||
|
||||
// create new socket object
|
||||
@@ -528,10 +528,10 @@ STATIC mp_obj_t socket_accept(mp_obj_t self_in) {
|
||||
client->items[1] = netutils_format_inet_addr(ip, port, NETUTILS_LITTLE);
|
||||
return client;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept);
|
||||
|
||||
// method socket.connect(address)
|
||||
STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
|
||||
static mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
|
||||
mod_network_socket_obj_t *self = self_in;
|
||||
|
||||
// get address
|
||||
@@ -548,10 +548,10 @@ STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect);
|
||||
|
||||
// method socket.send(bytes)
|
||||
STATIC mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) {
|
||||
static mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) {
|
||||
mod_network_socket_obj_t *self = self_in;
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ);
|
||||
@@ -562,10 +562,10 @@ STATIC mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) {
|
||||
}
|
||||
return mp_obj_new_int_from_uint(ret);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_send_obj, socket_send);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(socket_send_obj, socket_send);
|
||||
|
||||
// method socket.recv(bufsize)
|
||||
STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) {
|
||||
static mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) {
|
||||
mod_network_socket_obj_t *self = self_in;
|
||||
mp_int_t len = mp_obj_get_int(len_in);
|
||||
vstr_t vstr;
|
||||
@@ -582,10 +582,10 @@ STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) {
|
||||
vstr.buf[vstr.len] = '\0';
|
||||
return mp_obj_new_bytes_from_vstr(&vstr);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recv_obj, socket_recv);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(socket_recv_obj, socket_recv);
|
||||
|
||||
// method socket.sendto(bytes, address)
|
||||
STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_in) {
|
||||
static mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_in) {
|
||||
mod_network_socket_obj_t *self = self_in;
|
||||
|
||||
// get the data
|
||||
@@ -604,10 +604,10 @@ STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_
|
||||
}
|
||||
return mp_obj_new_int(ret);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(socket_sendto_obj, socket_sendto);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_3(socket_sendto_obj, socket_sendto);
|
||||
|
||||
// method socket.recvfrom(bufsize)
|
||||
STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
|
||||
static mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
|
||||
mod_network_socket_obj_t *self = self_in;
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, mp_obj_get_int(len_in));
|
||||
@@ -629,10 +629,10 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
|
||||
tuple[1] = netutils_format_inet_addr(ip, port, NETUTILS_LITTLE);
|
||||
return mp_obj_new_tuple(2, tuple);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recvfrom_obj, socket_recvfrom);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(socket_recvfrom_obj, socket_recvfrom);
|
||||
|
||||
// method socket.setsockopt(level, optname, value)
|
||||
STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
|
||||
mod_network_socket_obj_t *self = args[0];
|
||||
|
||||
mp_int_t level = mp_obj_get_int(args[1]);
|
||||
@@ -658,13 +658,13 @@ STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_setsockopt);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_setsockopt);
|
||||
|
||||
// method socket.settimeout(value)
|
||||
// timeout=0 means non-blocking
|
||||
// timeout=None means blocking
|
||||
// otherwise, timeout is in seconds
|
||||
STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) {
|
||||
static mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) {
|
||||
mod_network_socket_obj_t *self = self_in;
|
||||
mp_uint_t timeout;
|
||||
if (timeout_in == mp_const_none) {
|
||||
@@ -678,25 +678,25 @@ STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) {
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_settimeout_obj, socket_settimeout);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(socket_settimeout_obj, socket_settimeout);
|
||||
|
||||
// method socket.setblocking(flag)
|
||||
STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t blocking) {
|
||||
static mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t blocking) {
|
||||
if (mp_obj_is_true(blocking)) {
|
||||
return socket_settimeout(self_in, mp_const_none);
|
||||
} else {
|
||||
return socket_settimeout(self_in, MP_OBJ_NEW_SMALL_INT(0));
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking);
|
||||
|
||||
STATIC mp_obj_t socket_makefile(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t socket_makefile(size_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
return args[0];
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_makefile_obj, 1, 6, socket_makefile);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_makefile_obj, 1, 6, socket_makefile);
|
||||
|
||||
STATIC const mp_rom_map_elem_t socket_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t socket_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_bind), MP_ROM_PTR(&socket_bind_obj) },
|
||||
@@ -722,7 +722,7 @@ STATIC const mp_rom_map_elem_t socket_locals_dict_table[] = {
|
||||
|
||||
MP_DEFINE_CONST_DICT(socket_locals_dict, socket_locals_dict_table);
|
||||
|
||||
STATIC mp_uint_t socket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
|
||||
static mp_uint_t socket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
|
||||
mod_network_socket_obj_t *self = self_in;
|
||||
mp_int_t ret = wlan_socket_recv(self, buf, size, errcode);
|
||||
if (ret < 0) {
|
||||
@@ -737,7 +737,7 @@ STATIC mp_uint_t socket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *e
|
||||
return ret;
|
||||
}
|
||||
|
||||
STATIC mp_uint_t socket_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) {
|
||||
static mp_uint_t socket_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) {
|
||||
mod_network_socket_obj_t *self = self_in;
|
||||
mp_int_t ret = wlan_socket_send(self, buf, size, errcode);
|
||||
if (ret < 0) {
|
||||
@@ -746,7 +746,7 @@ STATIC mp_uint_t socket_write(mp_obj_t self_in, const void *buf, mp_uint_t size,
|
||||
return ret;
|
||||
}
|
||||
|
||||
STATIC mp_uint_t socket_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
|
||||
static mp_uint_t socket_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
|
||||
mod_network_socket_obj_t *self = self_in;
|
||||
return wlan_socket_ioctl(self, request, arg, errcode);
|
||||
}
|
||||
@@ -758,7 +758,7 @@ const mp_stream_p_t socket_stream_p = {
|
||||
.is_text = false,
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
static MP_DEFINE_CONST_OBJ_TYPE(
|
||||
socket_type,
|
||||
MP_QSTR_socket,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
@@ -772,7 +772,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
|
||||
// function socket.getaddrinfo(host, port)
|
||||
/// \function getaddrinfo(host, port)
|
||||
STATIC mp_obj_t mod_socket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) {
|
||||
static mp_obj_t mod_socket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) {
|
||||
size_t hlen;
|
||||
const char *host = mp_obj_str_get_data(host_in, &hlen);
|
||||
mp_int_t port = mp_obj_get_int(port_in);
|
||||
@@ -791,9 +791,9 @@ STATIC mp_obj_t mod_socket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) {
|
||||
tuple->items[4] = netutils_format_inet_addr(out_ip, port, NETUTILS_LITTLE);
|
||||
return mp_obj_new_list(1, (mp_obj_t*)&tuple);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_socket_getaddrinfo_obj, mod_socket_getaddrinfo);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(mod_socket_getaddrinfo_obj, mod_socket_getaddrinfo);
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = {
|
||||
static const mp_rom_map_elem_t mp_module_socket_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_socket) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&socket_type) },
|
||||
@@ -810,7 +810,7 @@ STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_IPPROTO_UDP), MP_ROM_INT(SL_IPPROTO_UDP) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_table);
|
||||
static MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_table);
|
||||
|
||||
const mp_obj_module_t mp_module_socket = {
|
||||
.base = { &mp_type_module },
|
||||
|
||||
@@ -53,14 +53,14 @@ typedef struct _mp_obj_ssl_socket_t {
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE DATA
|
||||
******************************************************************************/
|
||||
STATIC const mp_obj_type_t ssl_socket_type;
|
||||
static const mp_obj_type_t ssl_socket_type;
|
||||
|
||||
/******************************************************************************/
|
||||
// MicroPython bindings; SSL class
|
||||
|
||||
// ssl sockets inherit from normal socket, so we take its
|
||||
// locals and stream methods
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
static MP_DEFINE_CONST_OBJ_TYPE(
|
||||
ssl_socket_type,
|
||||
MP_QSTR_ssl,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
@@ -68,8 +68,8 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
locals_dict, &socket_locals_dict
|
||||
);
|
||||
|
||||
STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
STATIC const mp_arg_t allowed_args[] = {
|
||||
static mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_sock, MP_ARG_REQUIRED | MP_ARG_OBJ, },
|
||||
{ MP_QSTR_keyfile, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||
{ MP_QSTR_certfile, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||
@@ -133,9 +133,9 @@ socket_error:
|
||||
arg_error:
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ssl_wrap_socket_obj, 0, mod_ssl_wrap_socket);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(mod_ssl_wrap_socket_obj, 0, mod_ssl_wrap_socket);
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_ssl_globals_table[] = {
|
||||
static const mp_rom_map_elem_t mp_module_ssl_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ssl) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_wrap_socket), MP_ROM_PTR(&mod_ssl_wrap_socket_obj) },
|
||||
|
||||
@@ -153,7 +153,7 @@ STATIC const mp_rom_map_elem_t mp_module_ssl_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_PROTOCOL_TLSv1_2), MP_ROM_INT(SL_SO_SEC_METHOD_TLSV1_2) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_ssl_globals, mp_module_ssl_globals_table);
|
||||
static MP_DEFINE_CONST_DICT(mp_module_ssl_globals, mp_module_ssl_globals_table);
|
||||
|
||||
const mp_obj_module_t mp_module_ssl = {
|
||||
.base = { &mp_type_module },
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include "pybrtc.h"
|
||||
|
||||
// Return the localtime as an 8-tuple.
|
||||
STATIC mp_obj_t mp_time_localtime_get(void) {
|
||||
static mp_obj_t mp_time_localtime_get(void) {
|
||||
timeutils_struct_time_t tm;
|
||||
|
||||
// get the seconds from the RTC
|
||||
@@ -49,6 +49,6 @@ STATIC mp_obj_t mp_time_localtime_get(void) {
|
||||
}
|
||||
|
||||
// Returns the number of seconds, as an integer, since the Epoch.
|
||||
STATIC mp_obj_t mp_time_time_get(void) {
|
||||
static mp_obj_t mp_time_time_get(void) {
|
||||
return mp_obj_new_int(pyb_rtc_get_seconds());
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
/******************************************************************************/
|
||||
// MicroPython bindings
|
||||
|
||||
STATIC mp_obj_t mod_wipy_heartbeat(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t mod_wipy_heartbeat(size_t n_args, const mp_obj_t *args) {
|
||||
if (n_args) {
|
||||
mperror_enable_heartbeat (mp_obj_is_true(args[0]));
|
||||
return mp_const_none;
|
||||
@@ -15,14 +15,14 @@ STATIC mp_obj_t mod_wipy_heartbeat(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_obj_new_bool(mperror_is_heartbeat_enabled());
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_wipy_heartbeat_obj, 0, 1, mod_wipy_heartbeat);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_wipy_heartbeat_obj, 0, 1, mod_wipy_heartbeat);
|
||||
|
||||
STATIC const mp_rom_map_elem_t wipy_module_globals_table[] = {
|
||||
static const mp_rom_map_elem_t wipy_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_wipy) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_heartbeat), MP_ROM_PTR(&mod_wipy_heartbeat_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(wipy_module_globals, wipy_module_globals_table);
|
||||
static MP_DEFINE_CONST_DICT(wipy_module_globals, wipy_module_globals_table);
|
||||
|
||||
const mp_obj_module_t wipy_module = {
|
||||
.base = { &mp_type_module },
|
||||
|
||||
@@ -114,7 +114,7 @@ typedef enum{
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE DATA
|
||||
******************************************************************************/
|
||||
STATIC wlan_obj_t wlan_obj = {
|
||||
static wlan_obj_t wlan_obj = {
|
||||
.mode = -1,
|
||||
.status = 0,
|
||||
.ip = 0,
|
||||
@@ -130,7 +130,7 @@ STATIC wlan_obj_t wlan_obj = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC const mp_irq_methods_t wlan_irq_methods;
|
||||
static const mp_irq_methods_t wlan_irq_methods;
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PUBLIC DATA
|
||||
@@ -142,31 +142,31 @@ OsiLockObj_t wlan_LockObj;
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC void wlan_clear_data (void);
|
||||
STATIC void wlan_reenable (SlWlanMode_t mode);
|
||||
STATIC void wlan_servers_start (void);
|
||||
STATIC void wlan_servers_stop (void);
|
||||
STATIC void wlan_reset (void);
|
||||
STATIC void wlan_validate_mode (uint mode);
|
||||
STATIC void wlan_set_mode (uint mode);
|
||||
STATIC void wlan_validate_ssid_len (uint32_t len);
|
||||
STATIC void wlan_set_ssid (const char *ssid, uint8_t len, bool add_mac);
|
||||
STATIC void wlan_validate_security (uint8_t auth, const char *key, uint8_t len);
|
||||
STATIC void wlan_set_security (uint8_t auth, const char *key, uint8_t len);
|
||||
STATIC void wlan_validate_channel (uint8_t channel);
|
||||
STATIC void wlan_set_channel (uint8_t channel);
|
||||
static void wlan_clear_data (void);
|
||||
static void wlan_reenable (SlWlanMode_t mode);
|
||||
static void wlan_servers_start (void);
|
||||
static void wlan_servers_stop (void);
|
||||
static void wlan_reset (void);
|
||||
static void wlan_validate_mode (uint mode);
|
||||
static void wlan_set_mode (uint mode);
|
||||
static void wlan_validate_ssid_len (uint32_t len);
|
||||
static void wlan_set_ssid (const char *ssid, uint8_t len, bool add_mac);
|
||||
static void wlan_validate_security (uint8_t auth, const char *key, uint8_t len);
|
||||
static void wlan_set_security (uint8_t auth, const char *key, uint8_t len);
|
||||
static void wlan_validate_channel (uint8_t channel);
|
||||
static void wlan_set_channel (uint8_t channel);
|
||||
#if MICROPY_HW_ANTENNA_DIVERSITY
|
||||
STATIC void wlan_validate_antenna (uint8_t antenna);
|
||||
STATIC void wlan_set_antenna (uint8_t antenna);
|
||||
static void wlan_validate_antenna (uint8_t antenna);
|
||||
static void wlan_set_antenna (uint8_t antenna);
|
||||
#endif
|
||||
STATIC void wlan_sl_disconnect (void);
|
||||
STATIC modwlan_Status_t wlan_do_connect (const char* ssid, uint32_t ssid_len, const char* bssid, uint8_t sec,
|
||||
static void wlan_sl_disconnect (void);
|
||||
static modwlan_Status_t wlan_do_connect (const char* ssid, uint32_t ssid_len, const char* bssid, uint8_t sec,
|
||||
const char* key, uint32_t key_len, int32_t timeout);
|
||||
STATIC void wlan_get_sl_mac (void);
|
||||
STATIC void wlan_wep_key_unhexlify (const char *key, char *key_out);
|
||||
STATIC void wlan_lpds_irq_enable (mp_obj_t self_in);
|
||||
STATIC void wlan_lpds_irq_disable (mp_obj_t self_in);
|
||||
STATIC bool wlan_scan_result_is_unique (const mp_obj_list_t *nets, _u8 *bssid);
|
||||
static void wlan_get_sl_mac (void);
|
||||
static void wlan_wep_key_unhexlify (const char *key, char *key_out);
|
||||
static void wlan_lpds_irq_enable (mp_obj_t self_in);
|
||||
static void wlan_lpds_irq_disable (mp_obj_t self_in);
|
||||
static bool wlan_scan_result_is_unique (const mp_obj_list_t *nets, _u8 *bssid);
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
@@ -541,14 +541,14 @@ void wlan_off_on (void) {
|
||||
// DEFINE STATIC FUNCTIONS
|
||||
//*****************************************************************************
|
||||
|
||||
STATIC void wlan_clear_data (void) {
|
||||
static void wlan_clear_data (void) {
|
||||
CLR_STATUS_BIT_ALL(wlan_obj.status);
|
||||
wlan_obj.ip = 0;
|
||||
//memset(wlan_obj.ssid_o, 0, sizeof(wlan_obj.ssid));
|
||||
//memset(wlan_obj.bssid, 0, sizeof(wlan_obj.bssid));
|
||||
}
|
||||
|
||||
STATIC void wlan_reenable (SlWlanMode_t mode) {
|
||||
static void wlan_reenable (SlWlanMode_t mode) {
|
||||
// stop and start again
|
||||
#ifdef SL_PLATFORM_MULTI_THREADED
|
||||
sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER);
|
||||
@@ -562,7 +562,7 @@ STATIC void wlan_reenable (SlWlanMode_t mode) {
|
||||
ASSERT (wlan_obj.mode == mode);
|
||||
}
|
||||
|
||||
STATIC void wlan_servers_start (void) {
|
||||
static void wlan_servers_start (void) {
|
||||
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
|
||||
// start the servers if they were enabled before
|
||||
if (wlan_obj.servers_enabled) {
|
||||
@@ -571,7 +571,7 @@ STATIC void wlan_servers_start (void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC void wlan_servers_stop (void) {
|
||||
static void wlan_servers_stop (void) {
|
||||
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
|
||||
// Stop all other processes using the wlan engine
|
||||
if ((wlan_obj.servers_enabled = servers_are_enabled())) {
|
||||
@@ -580,30 +580,30 @@ STATIC void wlan_servers_stop (void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC void wlan_reset (void) {
|
||||
static void wlan_reset (void) {
|
||||
wlan_servers_stop();
|
||||
wlan_reenable (wlan_obj.mode);
|
||||
wlan_servers_start();
|
||||
}
|
||||
|
||||
STATIC void wlan_validate_mode (uint mode) {
|
||||
static void wlan_validate_mode (uint mode) {
|
||||
if (mode != ROLE_STA && mode != ROLE_AP) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void wlan_set_mode (uint mode) {
|
||||
static void wlan_set_mode (uint mode) {
|
||||
wlan_obj.mode = mode;
|
||||
ASSERT_ON_ERROR(sl_WlanSetMode(mode));
|
||||
}
|
||||
|
||||
STATIC void wlan_validate_ssid_len (uint32_t len) {
|
||||
static void wlan_validate_ssid_len (uint32_t len) {
|
||||
if (len > MODWLAN_SSID_LEN_MAX) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void wlan_set_ssid (const char *ssid, uint8_t len, bool add_mac) {
|
||||
static void wlan_set_ssid (const char *ssid, uint8_t len, bool add_mac) {
|
||||
if (ssid != NULL) {
|
||||
// save the ssid
|
||||
memcpy(&wlan_obj.ssid, ssid, len);
|
||||
@@ -618,7 +618,7 @@ STATIC void wlan_set_ssid (const char *ssid, uint8_t len, bool add_mac) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void wlan_validate_security (uint8_t auth, const char *key, uint8_t len) {
|
||||
static void wlan_validate_security (uint8_t auth, const char *key, uint8_t len) {
|
||||
if (auth != SL_SEC_TYPE_WEP && auth != SL_SEC_TYPE_WPA_WPA2) {
|
||||
goto invalid_args;
|
||||
}
|
||||
@@ -635,7 +635,7 @@ invalid_args:
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
|
||||
}
|
||||
|
||||
STATIC void wlan_set_security (uint8_t auth, const char *key, uint8_t len) {
|
||||
static void wlan_set_security (uint8_t auth, const char *key, uint8_t len) {
|
||||
wlan_obj.auth = auth;
|
||||
ASSERT_ON_ERROR(sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SECURITY_TYPE, sizeof(uint8_t), &auth));
|
||||
if (key != NULL) {
|
||||
@@ -653,31 +653,31 @@ STATIC void wlan_set_security (uint8_t auth, const char *key, uint8_t len) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void wlan_validate_channel (uint8_t channel) {
|
||||
static void wlan_validate_channel (uint8_t channel) {
|
||||
if (channel < 1 || channel > 11) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void wlan_set_channel (uint8_t channel) {
|
||||
static void wlan_set_channel (uint8_t channel) {
|
||||
wlan_obj.channel = channel;
|
||||
ASSERT_ON_ERROR(sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_CHANNEL, 1, &channel));
|
||||
}
|
||||
|
||||
#if MICROPY_HW_ANTENNA_DIVERSITY
|
||||
STATIC void wlan_validate_antenna (uint8_t antenna) {
|
||||
static void wlan_validate_antenna (uint8_t antenna) {
|
||||
if (antenna != ANTENNA_TYPE_INTERNAL && antenna != ANTENNA_TYPE_EXTERNAL) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void wlan_set_antenna (uint8_t antenna) {
|
||||
static void wlan_set_antenna (uint8_t antenna) {
|
||||
wlan_obj.antenna = antenna;
|
||||
antenna_select(antenna);
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC void wlan_sl_disconnect (void) {
|
||||
static void wlan_sl_disconnect (void) {
|
||||
// Device in station-mode. Disconnect previous connection if any
|
||||
// The function returns 0 if 'Disconnected done', negative number if already
|
||||
// disconnected Wait for 'disconnection' event if 0 is returned, Ignore
|
||||
@@ -690,7 +690,7 @@ STATIC void wlan_sl_disconnect (void) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC modwlan_Status_t wlan_do_connect (const char* ssid, uint32_t ssid_len, const char* bssid, uint8_t sec,
|
||||
static modwlan_Status_t wlan_do_connect (const char* ssid, uint32_t ssid_len, const char* bssid, uint8_t sec,
|
||||
const char* key, uint32_t key_len, int32_t timeout) {
|
||||
SlSecParams_t secParams;
|
||||
secParams.Key = (_i8*)key;
|
||||
@@ -716,13 +716,13 @@ STATIC modwlan_Status_t wlan_do_connect (const char* ssid, uint32_t ssid_len, co
|
||||
return MODWLAN_ERROR_INVALID_PARAMS;
|
||||
}
|
||||
|
||||
STATIC void wlan_get_sl_mac (void) {
|
||||
static void wlan_get_sl_mac (void) {
|
||||
// Get the MAC address
|
||||
uint8_t macAddrLen = SL_MAC_ADDR_LEN;
|
||||
sl_NetCfgGet(SL_MAC_ADDRESS_GET, NULL, &macAddrLen, wlan_obj.mac);
|
||||
}
|
||||
|
||||
STATIC void wlan_wep_key_unhexlify (const char *key, char *key_out) {
|
||||
static void wlan_wep_key_unhexlify (const char *key, char *key_out) {
|
||||
byte hex_byte = 0;
|
||||
for (mp_uint_t i = strlen(key); i > 0 ; i--) {
|
||||
hex_byte += unichar_xdigit_value(*key++);
|
||||
@@ -735,22 +735,22 @@ STATIC void wlan_wep_key_unhexlify (const char *key, char *key_out) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void wlan_lpds_irq_enable (mp_obj_t self_in) {
|
||||
static void wlan_lpds_irq_enable (mp_obj_t self_in) {
|
||||
wlan_obj_t *self = self_in;
|
||||
self->irq_enabled = true;
|
||||
}
|
||||
|
||||
STATIC void wlan_lpds_irq_disable (mp_obj_t self_in) {
|
||||
static void wlan_lpds_irq_disable (mp_obj_t self_in) {
|
||||
wlan_obj_t *self = self_in;
|
||||
self->irq_enabled = false;
|
||||
}
|
||||
|
||||
STATIC int wlan_irq_flags (mp_obj_t self_in) {
|
||||
static int wlan_irq_flags (mp_obj_t self_in) {
|
||||
wlan_obj_t *self = self_in;
|
||||
return self->irq_flags;
|
||||
}
|
||||
|
||||
STATIC bool wlan_scan_result_is_unique (const mp_obj_list_t *nets, _u8 *bssid) {
|
||||
static bool wlan_scan_result_is_unique (const mp_obj_list_t *nets, _u8 *bssid) {
|
||||
for (int i = 0; i < nets->len; i++) {
|
||||
// index 1 in the list is the bssid
|
||||
mp_obj_str_t *_bssid = (mp_obj_str_t *)((mp_obj_tuple_t *)nets->items[i])->items[1];
|
||||
@@ -766,7 +766,7 @@ STATIC bool wlan_scan_result_is_unique (const mp_obj_list_t *nets, _u8 *bssid) {
|
||||
|
||||
/// \class WLAN - WiFi driver
|
||||
|
||||
STATIC mp_obj_t wlan_init_helper(wlan_obj_t *self, const mp_arg_val_t *args) {
|
||||
static mp_obj_t wlan_init_helper(wlan_obj_t *self, const mp_arg_val_t *args) {
|
||||
// get the mode
|
||||
int8_t mode = args[0].u_int;
|
||||
wlan_validate_mode(mode);
|
||||
@@ -808,7 +808,7 @@ STATIC mp_obj_t wlan_init_helper(wlan_obj_t *self, const mp_arg_val_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC const mp_arg_t wlan_init_args[] = {
|
||||
static const mp_arg_t wlan_init_args[] = {
|
||||
{ MP_QSTR_id, MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_mode, MP_ARG_INT, {.u_int = ROLE_STA} },
|
||||
{ MP_QSTR_ssid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
@@ -818,7 +818,7 @@ STATIC const mp_arg_t wlan_init_args[] = {
|
||||
{ MP_QSTR_antenna, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = ANTENNA_TYPE_INTERNAL} },
|
||||
#endif
|
||||
};
|
||||
STATIC mp_obj_t wlan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t wlan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
// parse args
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
|
||||
@@ -844,16 +844,16 @@ STATIC mp_obj_t wlan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
|
||||
return (mp_obj_t)self;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t wlan_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t wlan_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
// parse args
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(wlan_init_args) - 1];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &wlan_init_args[1], args);
|
||||
return wlan_init_helper(pos_args[0], args);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_init_obj, 1, wlan_init);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(wlan_init_obj, 1, wlan_init);
|
||||
|
||||
STATIC mp_obj_t wlan_scan(mp_obj_t self_in) {
|
||||
STATIC const qstr wlan_scan_info_fields[] = {
|
||||
static mp_obj_t wlan_scan(mp_obj_t self_in) {
|
||||
static const qstr wlan_scan_info_fields[] = {
|
||||
MP_QSTR_ssid, MP_QSTR_bssid, MP_QSTR_sec, MP_QSTR_channel, MP_QSTR_rssi
|
||||
};
|
||||
|
||||
@@ -901,10 +901,10 @@ STATIC mp_obj_t wlan_scan(mp_obj_t self_in) {
|
||||
|
||||
return nets;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_scan_obj, wlan_scan);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(wlan_scan_obj, wlan_scan);
|
||||
|
||||
STATIC mp_obj_t wlan_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
STATIC const mp_arg_t allowed_args[] = {
|
||||
static mp_obj_t wlan_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ, },
|
||||
{ MP_QSTR_auth, MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||
{ MP_QSTR_bssid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||
@@ -967,21 +967,21 @@ STATIC mp_obj_t wlan_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_connect_obj, 1, wlan_connect);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(wlan_connect_obj, 1, wlan_connect);
|
||||
|
||||
STATIC mp_obj_t wlan_disconnect(mp_obj_t self_in) {
|
||||
static mp_obj_t wlan_disconnect(mp_obj_t self_in) {
|
||||
wlan_sl_disconnect();
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_disconnect_obj, wlan_disconnect);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(wlan_disconnect_obj, wlan_disconnect);
|
||||
|
||||
STATIC mp_obj_t wlan_isconnected(mp_obj_t self_in) {
|
||||
static mp_obj_t wlan_isconnected(mp_obj_t self_in) {
|
||||
return wlan_is_connected() ? mp_const_true : mp_const_false;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_isconnected_obj, wlan_isconnected);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(wlan_isconnected_obj, wlan_isconnected);
|
||||
|
||||
STATIC mp_obj_t wlan_ifconfig(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
STATIC const mp_arg_t wlan_ifconfig_args[] = {
|
||||
static mp_obj_t wlan_ifconfig(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t wlan_ifconfig_args[] = {
|
||||
{ MP_QSTR_id, MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_config, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
};
|
||||
@@ -1055,9 +1055,9 @@ STATIC mp_obj_t wlan_ifconfig(size_t n_args, const mp_obj_t *pos_args, mp_map_t
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_ifconfig_obj, 1, wlan_ifconfig);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(wlan_ifconfig_obj, 1, wlan_ifconfig);
|
||||
|
||||
STATIC mp_obj_t wlan_mode(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t wlan_mode(size_t n_args, const mp_obj_t *args) {
|
||||
wlan_obj_t *self = args[0];
|
||||
if (n_args == 1) {
|
||||
return mp_obj_new_int(self->mode);
|
||||
@@ -1069,9 +1069,9 @@ STATIC mp_obj_t wlan_mode(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_mode_obj, 1, 2, wlan_mode);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_mode_obj, 1, 2, wlan_mode);
|
||||
|
||||
STATIC mp_obj_t wlan_ssid(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t wlan_ssid(size_t n_args, const mp_obj_t *args) {
|
||||
wlan_obj_t *self = args[0];
|
||||
if (n_args == 1) {
|
||||
return mp_obj_new_str((const char *)self->ssid, strlen((const char *)self->ssid));
|
||||
@@ -1084,9 +1084,9 @@ STATIC mp_obj_t wlan_ssid(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_ssid_obj, 1, 2, wlan_ssid);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_ssid_obj, 1, 2, wlan_ssid);
|
||||
|
||||
STATIC mp_obj_t wlan_auth(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t wlan_auth(size_t n_args, const mp_obj_t *args) {
|
||||
wlan_obj_t *self = args[0];
|
||||
if (n_args == 1) {
|
||||
if (self->auth == SL_SEC_TYPE_OPEN) {
|
||||
@@ -1114,9 +1114,9 @@ STATIC mp_obj_t wlan_auth(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_auth_obj, 1, 2, wlan_auth);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_auth_obj, 1, 2, wlan_auth);
|
||||
|
||||
STATIC mp_obj_t wlan_channel(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t wlan_channel(size_t n_args, const mp_obj_t *args) {
|
||||
wlan_obj_t *self = args[0];
|
||||
if (n_args == 1) {
|
||||
return mp_obj_new_int(self->channel);
|
||||
@@ -1128,9 +1128,9 @@ STATIC mp_obj_t wlan_channel(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_channel_obj, 1, 2, wlan_channel);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_channel_obj, 1, 2, wlan_channel);
|
||||
|
||||
STATIC mp_obj_t wlan_antenna(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t wlan_antenna(size_t n_args, const mp_obj_t *args) {
|
||||
wlan_obj_t *self = args[0];
|
||||
if (n_args == 1) {
|
||||
return mp_obj_new_int(self->antenna);
|
||||
@@ -1143,9 +1143,9 @@ STATIC mp_obj_t wlan_antenna(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_antenna_obj, 1, 2, wlan_antenna);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_antenna_obj, 1, 2, wlan_antenna);
|
||||
|
||||
STATIC mp_obj_t wlan_mac(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t wlan_mac(size_t n_args, const mp_obj_t *args) {
|
||||
wlan_obj_t *self = args[0];
|
||||
if (n_args == 1) {
|
||||
return mp_obj_new_bytes((const byte *)self->mac, SL_BSSID_LENGTH);
|
||||
@@ -1161,9 +1161,9 @@ STATIC mp_obj_t wlan_mac(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_mac_obj, 1, 2, wlan_mac);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_mac_obj, 1, 2, wlan_mac);
|
||||
|
||||
STATIC mp_obj_t wlan_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t wlan_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_arg_val_t args[mp_irq_INIT_NUM_ARGS];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mp_irq_INIT_NUM_ARGS, mp_irq_init_args, args);
|
||||
|
||||
@@ -1191,7 +1191,7 @@ STATIC mp_obj_t wlan_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
|
||||
invalid_args:
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_irq_obj, 1, wlan_irq);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(wlan_irq_obj, 1, wlan_irq);
|
||||
|
||||
//STATIC mp_obj_t wlan_connections (mp_obj_t self_in) {
|
||||
// mp_obj_t device[2];
|
||||
@@ -1238,7 +1238,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_irq_obj, 1, wlan_irq);
|
||||
//}
|
||||
//STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_urn_obj, 1, 2, wlan_urn);
|
||||
|
||||
STATIC mp_obj_t wlan_print_ver(void) {
|
||||
static mp_obj_t wlan_print_ver(void) {
|
||||
SlVersionFull ver;
|
||||
byte config_opt = SL_DEVICE_GENERAL_VERSION;
|
||||
byte config_len = sizeof(ver);
|
||||
@@ -1250,10 +1250,10 @@ STATIC mp_obj_t wlan_print_ver(void) {
|
||||
ver.ChipFwAndPhyVersion.PhyVersion[2], ver.ChipFwAndPhyVersion.PhyVersion[3]);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(wlan_print_ver_fun_obj, wlan_print_ver);
|
||||
STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(wlan_print_ver_obj, MP_ROM_PTR(&wlan_print_ver_fun_obj));
|
||||
static MP_DEFINE_CONST_FUN_OBJ_0(wlan_print_ver_fun_obj, wlan_print_ver);
|
||||
static MP_DEFINE_CONST_STATICMETHOD_OBJ(wlan_print_ver_obj, MP_ROM_PTR(&wlan_print_ver_fun_obj));
|
||||
|
||||
STATIC const mp_rom_map_elem_t wlan_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t wlan_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&wlan_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_scan), MP_ROM_PTR(&wlan_scan_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&wlan_connect_obj) },
|
||||
@@ -1283,7 +1283,7 @@ STATIC const mp_rom_map_elem_t wlan_locals_dict_table[] = {
|
||||
#endif
|
||||
{ MP_ROM_QSTR(MP_QSTR_ANY_EVENT), MP_ROM_INT(MODWLAN_WIFI_EVENT_ANY) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(wlan_locals_dict, wlan_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(wlan_locals_dict, wlan_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
mod_network_nic_type_wlan,
|
||||
@@ -1293,7 +1293,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
|
||||
locals_dict, &wlan_locals_dict
|
||||
);
|
||||
|
||||
STATIC const mp_irq_methods_t wlan_irq_methods = {
|
||||
static const mp_irq_methods_t wlan_irq_methods = {
|
||||
.init = wlan_irq,
|
||||
.enable = wlan_lpds_irq_enable,
|
||||
.disable = wlan_lpds_irq_disable,
|
||||
|
||||
@@ -74,23 +74,23 @@ typedef struct {
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE DATA
|
||||
******************************************************************************/
|
||||
STATIC pyb_adc_channel_obj_t pyb_adc_channel_obj[PYB_ADC_NUM_CHANNELS] = { {.pin = &pin_GP2, .channel = ADC_CH_0, .id = 0, .enabled = false},
|
||||
static pyb_adc_channel_obj_t pyb_adc_channel_obj[PYB_ADC_NUM_CHANNELS] = { {.pin = &pin_GP2, .channel = ADC_CH_0, .id = 0, .enabled = false},
|
||||
{.pin = &pin_GP3, .channel = ADC_CH_1, .id = 1, .enabled = false},
|
||||
{.pin = &pin_GP4, .channel = ADC_CH_2, .id = 2, .enabled = false},
|
||||
{.pin = &pin_GP5, .channel = ADC_CH_3, .id = 3, .enabled = false} };
|
||||
STATIC pyb_adc_obj_t pyb_adc_obj = {.enabled = false};
|
||||
static pyb_adc_obj_t pyb_adc_obj = {.enabled = false};
|
||||
|
||||
STATIC const mp_obj_type_t pyb_adc_channel_type;
|
||||
static const mp_obj_type_t pyb_adc_channel_type;
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC mp_obj_t adc_channel_deinit(mp_obj_t self_in);
|
||||
static mp_obj_t adc_channel_deinit(mp_obj_t self_in);
|
||||
|
||||
/******************************************************************************
|
||||
DEFINE PUBLIC FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC void pyb_adc_init (pyb_adc_obj_t *self) {
|
||||
static void pyb_adc_init (pyb_adc_obj_t *self) {
|
||||
// enable and configure the timer
|
||||
MAP_ADCTimerConfig(ADC_BASE, (1 << 17) - 1);
|
||||
MAP_ADCTimerEnable(ADC_BASE);
|
||||
@@ -99,14 +99,14 @@ STATIC void pyb_adc_init (pyb_adc_obj_t *self) {
|
||||
self->enabled = true;
|
||||
}
|
||||
|
||||
STATIC void pyb_adc_check_init(void) {
|
||||
static void pyb_adc_check_init(void) {
|
||||
// not initialized
|
||||
if (!pyb_adc_obj.enabled) {
|
||||
mp_raise_OSError(MP_EPERM);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void pyb_adc_channel_init (pyb_adc_channel_obj_t *self) {
|
||||
static void pyb_adc_channel_init (pyb_adc_channel_obj_t *self) {
|
||||
// the ADC block must be enabled first
|
||||
pyb_adc_check_init();
|
||||
// configure the pin in analog mode
|
||||
@@ -116,7 +116,7 @@ STATIC void pyb_adc_channel_init (pyb_adc_channel_obj_t *self) {
|
||||
self->enabled = true;
|
||||
}
|
||||
|
||||
STATIC void pyb_adc_deinit_all_channels (void) {
|
||||
static void pyb_adc_deinit_all_channels (void) {
|
||||
for (int i = 0; i < PYB_ADC_NUM_CHANNELS; i++) {
|
||||
adc_channel_deinit(&pyb_adc_channel_obj[i]);
|
||||
}
|
||||
@@ -125,7 +125,7 @@ STATIC void pyb_adc_deinit_all_channels (void) {
|
||||
/******************************************************************************/
|
||||
/* MicroPython bindings : adc object */
|
||||
|
||||
STATIC void adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
pyb_adc_obj_t *self = self_in;
|
||||
if (self->enabled) {
|
||||
mp_printf(print, "ADC(0, bits=12)");
|
||||
@@ -134,11 +134,11 @@ STATIC void adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
|
||||
}
|
||||
}
|
||||
|
||||
STATIC const mp_arg_t pyb_adc_init_args[] = {
|
||||
static const mp_arg_t pyb_adc_init_args[] = {
|
||||
{ MP_QSTR_id, MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_bits, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 12} },
|
||||
};
|
||||
STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
// parse args
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
|
||||
@@ -165,7 +165,7 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
|
||||
return self;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t adc_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t adc_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
// parse args
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_adc_init_args) - 1];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_adc_init_args[1], args);
|
||||
@@ -176,9 +176,9 @@ STATIC mp_obj_t adc_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
|
||||
pyb_adc_init(pos_args[0]);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(adc_init_obj, 1, adc_init);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(adc_init_obj, 1, adc_init);
|
||||
|
||||
STATIC mp_obj_t adc_deinit(mp_obj_t self_in) {
|
||||
static mp_obj_t adc_deinit(mp_obj_t self_in) {
|
||||
pyb_adc_obj_t *self = self_in;
|
||||
// first deinit all channels
|
||||
pyb_adc_deinit_all_channels();
|
||||
@@ -188,10 +188,10 @@ STATIC mp_obj_t adc_deinit(mp_obj_t self_in) {
|
||||
pyb_sleep_remove ((const mp_obj_t)self);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_deinit_obj, adc_deinit);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(adc_deinit_obj, adc_deinit);
|
||||
|
||||
STATIC mp_obj_t adc_channel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
STATIC const mp_arg_t pyb_adc_channel_args[] = {
|
||||
static mp_obj_t adc_channel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t pyb_adc_channel_args[] = {
|
||||
{ MP_QSTR_id, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
{ MP_QSTR_pin, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||
};
|
||||
@@ -223,15 +223,15 @@ STATIC mp_obj_t adc_channel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
||||
pyb_sleep_add ((const mp_obj_t)self, (WakeUpCB_t)pyb_adc_channel_init);
|
||||
return self;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(adc_channel_obj, 1, adc_channel);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(adc_channel_obj, 1, adc_channel);
|
||||
|
||||
STATIC const mp_rom_map_elem_t adc_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t adc_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&adc_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&adc_deinit_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_channel), MP_ROM_PTR(&adc_channel_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(adc_locals_dict, adc_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(adc_locals_dict, adc_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_adc_type,
|
||||
@@ -242,7 +242,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
|
||||
locals_dict, &adc_locals_dict
|
||||
);
|
||||
|
||||
STATIC void adc_channel_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void adc_channel_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
pyb_adc_channel_obj_t *self = self_in;
|
||||
if (self->enabled) {
|
||||
mp_printf(print, "ADCChannel(%u, pin=%q)", self->id, self->pin->name);
|
||||
@@ -251,15 +251,15 @@ STATIC void adc_channel_print(const mp_print_t *print, mp_obj_t self_in, mp_prin
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t adc_channel_init(mp_obj_t self_in) {
|
||||
static mp_obj_t adc_channel_init(mp_obj_t self_in) {
|
||||
pyb_adc_channel_obj_t *self = self_in;
|
||||
// re-enable it
|
||||
pyb_adc_channel_init(self);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_channel_init_obj, adc_channel_init);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(adc_channel_init_obj, adc_channel_init);
|
||||
|
||||
STATIC mp_obj_t adc_channel_deinit(mp_obj_t self_in) {
|
||||
static mp_obj_t adc_channel_deinit(mp_obj_t self_in) {
|
||||
pyb_adc_channel_obj_t *self = self_in;
|
||||
|
||||
MAP_ADCChannelDisable(ADC_BASE, self->channel);
|
||||
@@ -268,9 +268,9 @@ STATIC mp_obj_t adc_channel_deinit(mp_obj_t self_in) {
|
||||
self->enabled = false;
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_channel_deinit_obj, adc_channel_deinit);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(adc_channel_deinit_obj, adc_channel_deinit);
|
||||
|
||||
STATIC mp_obj_t adc_channel_value(mp_obj_t self_in) {
|
||||
static mp_obj_t adc_channel_value(mp_obj_t self_in) {
|
||||
pyb_adc_channel_obj_t *self = self_in;
|
||||
uint32_t value;
|
||||
|
||||
@@ -286,22 +286,22 @@ STATIC mp_obj_t adc_channel_value(mp_obj_t self_in) {
|
||||
// the 12 bit sampled value is stored in bits [13:2]
|
||||
return MP_OBJ_NEW_SMALL_INT((value & 0x3FFF) >> 2);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_channel_value_obj, adc_channel_value);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(adc_channel_value_obj, adc_channel_value);
|
||||
|
||||
STATIC mp_obj_t adc_channel_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t adc_channel_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
return adc_channel_value (self_in);
|
||||
}
|
||||
|
||||
STATIC const mp_rom_map_elem_t adc_channel_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t adc_channel_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&adc_channel_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&adc_channel_deinit_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&adc_channel_value_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(adc_channel_locals_dict, adc_channel_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(adc_channel_locals_dict, adc_channel_locals_dict_table);
|
||||
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
static MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_adc_channel_type,
|
||||
MP_QSTR_ADCChannel,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
|
||||
@@ -37,9 +37,9 @@
|
||||
// block protocol.
|
||||
|
||||
// there is a singleton Flash object
|
||||
STATIC const mp_obj_base_t pyb_flash_obj = {&pyb_flash_type};
|
||||
static const mp_obj_base_t pyb_flash_obj = {&pyb_flash_type};
|
||||
|
||||
STATIC mp_obj_t pyb_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
|
||||
@@ -47,23 +47,23 @@ STATIC mp_obj_t pyb_flash_make_new(const mp_obj_type_t *type, size_t n_args, siz
|
||||
return (mp_obj_t)&pyb_flash_obj;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pyb_flash_readblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) {
|
||||
static mp_obj_t pyb_flash_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 = sflash_disk_read(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SFLASH_SECTOR_SIZE);
|
||||
return MP_OBJ_NEW_SMALL_INT(res != RES_OK); // return of 0 means success
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_readblocks_obj, pyb_flash_readblocks);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_readblocks_obj, pyb_flash_readblocks);
|
||||
|
||||
STATIC mp_obj_t pyb_flash_writeblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) {
|
||||
static mp_obj_t pyb_flash_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 = sflash_disk_write(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SFLASH_SECTOR_SIZE);
|
||||
return MP_OBJ_NEW_SMALL_INT(res != RES_OK); // return of 0 means success
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_writeblocks_obj, pyb_flash_writeblocks);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_writeblocks_obj, pyb_flash_writeblocks);
|
||||
|
||||
STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) {
|
||||
static mp_obj_t pyb_flash_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 MP_BLOCKDEV_IOCTL_INIT: return MP_OBJ_NEW_SMALL_INT(sflash_disk_init() != RES_OK);
|
||||
@@ -74,15 +74,15 @@ STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in)
|
||||
default: return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_ioctl_obj, pyb_flash_ioctl);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_ioctl_obj, pyb_flash_ioctl);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_flash_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_flash_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&pyb_flash_readblocks_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&pyb_flash_writeblocks_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&pyb_flash_ioctl_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_flash_locals_dict, pyb_flash_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_flash_locals_dict, pyb_flash_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_flash_type,
|
||||
|
||||
@@ -74,18 +74,18 @@ typedef struct _pyb_i2c_obj_t {
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE DATA
|
||||
******************************************************************************/
|
||||
STATIC pyb_i2c_obj_t pyb_i2c_obj = {.baudrate = 0};
|
||||
static pyb_i2c_obj_t pyb_i2c_obj = {.baudrate = 0};
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC bool pyb_i2c_write(byte addr, byte *data, uint len, bool stop);
|
||||
static bool pyb_i2c_write(byte addr, byte *data, uint len, bool stop);
|
||||
|
||||
/******************************************************************************
|
||||
DEFINE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
// only master mode is available for the moment
|
||||
STATIC void i2c_init (pyb_i2c_obj_t *self) {
|
||||
static void i2c_init (pyb_i2c_obj_t *self) {
|
||||
// Enable the I2C Peripheral
|
||||
MAP_PRCMPeripheralClkEnable(PRCM_I2CA0, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
|
||||
MAP_PRCMPeripheralReset(PRCM_I2CA0);
|
||||
@@ -93,7 +93,7 @@ STATIC void i2c_init (pyb_i2c_obj_t *self) {
|
||||
MAP_I2CMasterInitExpClk(I2CA0_BASE, self->baudrate);
|
||||
}
|
||||
|
||||
STATIC bool pyb_i2c_transaction(uint cmd) {
|
||||
static bool pyb_i2c_transaction(uint cmd) {
|
||||
// Convert the timeout to microseconds
|
||||
int32_t timeout = PYBI2C_TRANSC_TIMEOUT_MS * 1000;
|
||||
// Sanity check, t_timeout must be between 1 and 255
|
||||
@@ -137,14 +137,14 @@ STATIC bool pyb_i2c_transaction(uint cmd) {
|
||||
return true;
|
||||
}
|
||||
|
||||
STATIC void pyb_i2c_check_init(pyb_i2c_obj_t *self) {
|
||||
static void pyb_i2c_check_init(pyb_i2c_obj_t *self) {
|
||||
// not initialized
|
||||
if (!self->baudrate) {
|
||||
mp_raise_OSError(MP_EPERM);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC bool pyb_i2c_scan_device(byte devAddr) {
|
||||
static bool pyb_i2c_scan_device(byte devAddr) {
|
||||
bool ret = false;
|
||||
// Set the I2C slave address
|
||||
MAP_I2CMasterSlaveAddrSet(I2CA0_BASE, devAddr, true);
|
||||
@@ -163,7 +163,7 @@ STATIC bool pyb_i2c_scan_device(byte devAddr) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
STATIC bool pyb_i2c_mem_addr_write (byte addr, byte *mem_addr, uint mem_addr_len) {
|
||||
static bool pyb_i2c_mem_addr_write (byte addr, byte *mem_addr, uint mem_addr_len) {
|
||||
// Set I2C codec slave address
|
||||
MAP_I2CMasterSlaveAddrSet(I2CA0_BASE, addr, false);
|
||||
// Write the first byte to the controller.
|
||||
@@ -181,7 +181,7 @@ STATIC bool pyb_i2c_mem_addr_write (byte addr, byte *mem_addr, uint mem_addr_len
|
||||
return true;
|
||||
}
|
||||
|
||||
STATIC bool pyb_i2c_mem_write (byte addr, byte *mem_addr, uint mem_addr_len, byte *data, uint data_len) {
|
||||
static bool pyb_i2c_mem_write (byte addr, byte *mem_addr, uint mem_addr_len, byte *data, uint data_len) {
|
||||
if (pyb_i2c_mem_addr_write (addr, mem_addr, mem_addr_len)) {
|
||||
// Loop until the completion of transfer or error
|
||||
while (data_len--) {
|
||||
@@ -197,7 +197,7 @@ STATIC bool pyb_i2c_mem_write (byte addr, byte *mem_addr, uint mem_addr_len, byt
|
||||
return false;
|
||||
}
|
||||
|
||||
STATIC bool pyb_i2c_write(byte addr, byte *data, uint len, bool stop) {
|
||||
static bool pyb_i2c_write(byte addr, byte *data, uint len, bool stop) {
|
||||
// Set I2C codec slave address
|
||||
MAP_I2CMasterSlaveAddrSet(I2CA0_BASE, addr, false);
|
||||
// Write the first byte to the controller.
|
||||
@@ -220,7 +220,7 @@ STATIC bool pyb_i2c_write(byte addr, byte *data, uint len, bool stop) {
|
||||
return true;
|
||||
}
|
||||
|
||||
STATIC bool pyb_i2c_read(byte addr, byte *data, uint len) {
|
||||
static bool pyb_i2c_read(byte addr, byte *data, uint len) {
|
||||
// Initiate a burst or single receive sequence
|
||||
uint cmd = --len > 0 ? I2C_MASTER_CMD_BURST_RECEIVE_START : I2C_MASTER_CMD_SINGLE_RECEIVE;
|
||||
// Set I2C codec slave address
|
||||
@@ -245,7 +245,7 @@ STATIC bool pyb_i2c_read(byte addr, byte *data, uint len) {
|
||||
return true;
|
||||
}
|
||||
|
||||
STATIC void pyb_i2c_read_into (mp_arg_val_t *args, vstr_t *vstr) {
|
||||
static void pyb_i2c_read_into (mp_arg_val_t *args, vstr_t *vstr) {
|
||||
pyb_i2c_check_init(&pyb_i2c_obj);
|
||||
// get the buffer to receive into
|
||||
pyb_buf_get_for_recv(args[1].u_obj, vstr);
|
||||
@@ -256,7 +256,7 @@ STATIC void pyb_i2c_read_into (mp_arg_val_t *args, vstr_t *vstr) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void pyb_i2c_readmem_into (mp_arg_val_t *args, vstr_t *vstr) {
|
||||
static void pyb_i2c_readmem_into (mp_arg_val_t *args, vstr_t *vstr) {
|
||||
pyb_i2c_check_init(&pyb_i2c_obj);
|
||||
// get the buffer to receive into
|
||||
pyb_buf_get_for_recv(args[2].u_obj, vstr);
|
||||
@@ -281,7 +281,7 @@ STATIC void pyb_i2c_readmem_into (mp_arg_val_t *args, vstr_t *vstr) {
|
||||
/******************************************************************************/
|
||||
/* MicroPython bindings */
|
||||
/******************************************************************************/
|
||||
STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
pyb_i2c_obj_t *self = self_in;
|
||||
if (self->baudrate > 0) {
|
||||
mp_printf(print, "I2C(0, baudrate=%u)", self->baudrate);
|
||||
@@ -290,7 +290,7 @@ STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pyb_i2c_init_helper(pyb_i2c_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_i2c_init_helper(pyb_i2c_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_scl, ARG_sda, ARG_freq };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_scl, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
@@ -322,7 +322,7 @@ STATIC mp_obj_t pyb_i2c_init_helper(pyb_i2c_obj_t *self, size_t n_args, const mp
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
// check the id argument, if given
|
||||
if (n_args > 0) {
|
||||
if (all_args[0] != MP_OBJ_NEW_SMALL_INT(0)) {
|
||||
@@ -346,12 +346,12 @@ STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
||||
return (mp_obj_t)self;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pyb_i2c_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_i2c_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
return pyb_i2c_init_helper(pos_args[0], n_args - 1, pos_args + 1, kw_args);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_init_obj, 1, pyb_i2c_init);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_init_obj, 1, pyb_i2c_init);
|
||||
|
||||
STATIC mp_obj_t pyb_i2c_deinit(mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_i2c_deinit(mp_obj_t self_in) {
|
||||
// disable the peripheral
|
||||
MAP_I2CMasterDisable(I2CA0_BASE);
|
||||
MAP_PRCMPeripheralClkDisable(PRCM_I2CA0, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
|
||||
@@ -361,9 +361,9 @@ STATIC mp_obj_t pyb_i2c_deinit(mp_obj_t self_in) {
|
||||
pyb_sleep_remove ((const mp_obj_t)self_in);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_deinit_obj, pyb_i2c_deinit);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_deinit_obj, pyb_i2c_deinit);
|
||||
|
||||
STATIC mp_obj_t pyb_i2c_scan(mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_i2c_scan(mp_obj_t self_in) {
|
||||
pyb_i2c_check_init(&pyb_i2c_obj);
|
||||
mp_obj_t list = mp_obj_new_list(0, NULL);
|
||||
for (uint addr = 0x08; addr <= 0x77; addr++) {
|
||||
@@ -376,10 +376,10 @@ STATIC mp_obj_t pyb_i2c_scan(mp_obj_t self_in) {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_scan_obj, pyb_i2c_scan);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_scan_obj, pyb_i2c_scan);
|
||||
|
||||
STATIC mp_obj_t pyb_i2c_readfrom(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
STATIC const mp_arg_t pyb_i2c_readfrom_args[] = {
|
||||
static mp_obj_t pyb_i2c_readfrom(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t pyb_i2c_readfrom_args[] = {
|
||||
{ MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, },
|
||||
{ MP_QSTR_nbytes, MP_ARG_REQUIRED | MP_ARG_OBJ, },
|
||||
};
|
||||
@@ -394,10 +394,10 @@ STATIC mp_obj_t pyb_i2c_readfrom(size_t n_args, const mp_obj_t *pos_args, mp_map
|
||||
// return the received data
|
||||
return mp_obj_new_bytes_from_vstr(&vstr);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_obj, 3, pyb_i2c_readfrom);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_obj, 3, pyb_i2c_readfrom);
|
||||
|
||||
STATIC mp_obj_t pyb_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
STATIC const mp_arg_t pyb_i2c_readfrom_into_args[] = {
|
||||
static mp_obj_t pyb_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t pyb_i2c_readfrom_into_args[] = {
|
||||
{ MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, },
|
||||
{ MP_QSTR_buf, MP_ARG_REQUIRED | MP_ARG_OBJ, },
|
||||
};
|
||||
@@ -412,10 +412,10 @@ STATIC mp_obj_t pyb_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_args, m
|
||||
// return the number of bytes received
|
||||
return mp_obj_new_int(vstr.len);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_into_obj, 1, pyb_i2c_readfrom_into);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_into_obj, 1, pyb_i2c_readfrom_into);
|
||||
|
||||
STATIC mp_obj_t pyb_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
STATIC const mp_arg_t pyb_i2c_writeto_args[] = {
|
||||
static mp_obj_t pyb_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t pyb_i2c_writeto_args[] = {
|
||||
{ MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, },
|
||||
{ MP_QSTR_buf, MP_ARG_REQUIRED | MP_ARG_OBJ, },
|
||||
{ MP_QSTR_stop, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} },
|
||||
@@ -440,10 +440,10 @@ STATIC mp_obj_t pyb_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, mp_map_
|
||||
// return the number of bytes written
|
||||
return mp_obj_new_int(bufinfo.len);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_writeto_obj, 1, pyb_i2c_writeto);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_writeto_obj, 1, pyb_i2c_writeto);
|
||||
|
||||
STATIC mp_obj_t pyb_i2c_readfrom_mem(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
STATIC const mp_arg_t pyb_i2c_readfrom_mem_args[] = {
|
||||
static mp_obj_t pyb_i2c_readfrom_mem(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t pyb_i2c_readfrom_mem_args[] = {
|
||||
{ MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, },
|
||||
{ MP_QSTR_memaddr, MP_ARG_REQUIRED | MP_ARG_INT, },
|
||||
{ MP_QSTR_nbytes, MP_ARG_REQUIRED | MP_ARG_OBJ, },
|
||||
@@ -458,16 +458,16 @@ STATIC mp_obj_t pyb_i2c_readfrom_mem(size_t n_args, const mp_obj_t *pos_args, mp
|
||||
pyb_i2c_readmem_into (args, &vstr);
|
||||
return mp_obj_new_bytes_from_vstr(&vstr);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_mem_obj, 1, pyb_i2c_readfrom_mem);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_mem_obj, 1, pyb_i2c_readfrom_mem);
|
||||
|
||||
STATIC const mp_arg_t pyb_i2c_readfrom_mem_into_args[] = {
|
||||
static const mp_arg_t pyb_i2c_readfrom_mem_into_args[] = {
|
||||
{ MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, },
|
||||
{ MP_QSTR_memaddr, MP_ARG_REQUIRED | MP_ARG_INT, },
|
||||
{ MP_QSTR_buf, MP_ARG_REQUIRED | MP_ARG_OBJ, },
|
||||
{ MP_QSTR_addrsize, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 8} },
|
||||
};
|
||||
|
||||
STATIC mp_obj_t pyb_i2c_readfrom_mem_into(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_i2c_readfrom_mem_into(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
// parse args
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_i2c_readfrom_mem_into_args)];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), pyb_i2c_readfrom_mem_into_args, args);
|
||||
@@ -477,9 +477,9 @@ STATIC mp_obj_t pyb_i2c_readfrom_mem_into(size_t n_args, const mp_obj_t *pos_arg
|
||||
pyb_i2c_readmem_into (args, &vstr);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_mem_into_obj, 1, pyb_i2c_readfrom_mem_into);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_mem_into_obj, 1, pyb_i2c_readfrom_mem_into);
|
||||
|
||||
STATIC mp_obj_t pyb_i2c_writeto_mem(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_i2c_writeto_mem(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
// parse args
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_i2c_readfrom_mem_into_args)];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(pyb_i2c_readfrom_mem_into_args), pyb_i2c_readfrom_mem_into_args, args);
|
||||
@@ -504,9 +504,9 @@ STATIC mp_obj_t pyb_i2c_writeto_mem(size_t n_args, const mp_obj_t *pos_args, mp_
|
||||
|
||||
mp_raise_OSError(MP_EIO);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_writeto_mem_obj, 1, pyb_i2c_writeto_mem);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_writeto_mem_obj, 1, pyb_i2c_writeto_mem);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_i2c_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_i2c_locals_dict_table[] = {
|
||||
// instance methods
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_i2c_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_i2c_deinit_obj) },
|
||||
@@ -519,7 +519,7 @@ STATIC const mp_rom_map_elem_t pyb_i2c_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_writeto_mem), MP_ROM_PTR(&pyb_i2c_writeto_mem_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_i2c_locals_dict, pyb_i2c_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_i2c_locals_dict, pyb_i2c_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_i2c_type,
|
||||
|
||||
@@ -53,26 +53,26 @@
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name);
|
||||
STATIC pin_obj_t *pin_find_pin_by_port_bit (const mp_obj_dict_t *named_pins, uint port, uint bit);
|
||||
STATIC int8_t pin_obj_find_af (const pin_obj_t* pin, uint8_t fn, uint8_t unit, uint8_t type);
|
||||
STATIC void pin_free_af_from_pins (uint8_t fn, uint8_t unit, uint8_t type);
|
||||
STATIC void pin_deassign (pin_obj_t* pin);
|
||||
STATIC void pin_obj_configure (const pin_obj_t *self);
|
||||
STATIC void pin_get_hibernate_pin_and_idx (const pin_obj_t *self, uint *wake_pin, uint *idx);
|
||||
STATIC void pin_irq_enable (mp_obj_t self_in);
|
||||
STATIC void pin_irq_disable (mp_obj_t self_in);
|
||||
STATIC void pin_extint_register(pin_obj_t *self, uint32_t intmode, uint32_t priority);
|
||||
STATIC void pin_validate_mode (uint mode);
|
||||
STATIC void pin_validate_pull (uint pull);
|
||||
STATIC void pin_validate_drive (uint strength);
|
||||
STATIC void pin_validate_af(const pin_obj_t* pin, int8_t idx, uint8_t *fn, uint8_t *unit, uint8_t *type);
|
||||
STATIC uint8_t pin_get_value(const pin_obj_t* self);
|
||||
STATIC void GPIOA0IntHandler (void);
|
||||
STATIC void GPIOA1IntHandler (void);
|
||||
STATIC void GPIOA2IntHandler (void);
|
||||
STATIC void GPIOA3IntHandler (void);
|
||||
STATIC void EXTI_Handler(uint port);
|
||||
static pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name);
|
||||
static pin_obj_t *pin_find_pin_by_port_bit (const mp_obj_dict_t *named_pins, uint port, uint bit);
|
||||
static int8_t pin_obj_find_af (const pin_obj_t* pin, uint8_t fn, uint8_t unit, uint8_t type);
|
||||
static void pin_free_af_from_pins (uint8_t fn, uint8_t unit, uint8_t type);
|
||||
static void pin_deassign (pin_obj_t* pin);
|
||||
static void pin_obj_configure (const pin_obj_t *self);
|
||||
static void pin_get_hibernate_pin_and_idx (const pin_obj_t *self, uint *wake_pin, uint *idx);
|
||||
static void pin_irq_enable (mp_obj_t self_in);
|
||||
static void pin_irq_disable (mp_obj_t self_in);
|
||||
static void pin_extint_register(pin_obj_t *self, uint32_t intmode, uint32_t priority);
|
||||
static void pin_validate_mode (uint mode);
|
||||
static void pin_validate_pull (uint pull);
|
||||
static void pin_validate_drive (uint strength);
|
||||
static void pin_validate_af(const pin_obj_t* pin, int8_t idx, uint8_t *fn, uint8_t *unit, uint8_t *type);
|
||||
static uint8_t pin_get_value(const pin_obj_t* self);
|
||||
static void GPIOA0IntHandler (void);
|
||||
static void GPIOA1IntHandler (void);
|
||||
static void GPIOA2IntHandler (void);
|
||||
static void GPIOA3IntHandler (void);
|
||||
static void EXTI_Handler(uint port);
|
||||
|
||||
/******************************************************************************
|
||||
DEFINE CONSTANTS
|
||||
@@ -100,8 +100,8 @@ typedef struct {
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE DATA
|
||||
******************************************************************************/
|
||||
STATIC const mp_irq_methods_t pin_irq_methods;
|
||||
STATIC pybpin_wake_pin_t pybpin_wake_pin[PYBPIN_NUM_WAKE_PINS] =
|
||||
static const mp_irq_methods_t pin_irq_methods;
|
||||
static pybpin_wake_pin_t pybpin_wake_pin[PYBPIN_NUM_WAKE_PINS] =
|
||||
{ {.active = false, .lpds = PYBPIN_WAKES_NOT, .hib = PYBPIN_WAKES_NOT},
|
||||
{.active = false, .lpds = PYBPIN_WAKES_NOT, .hib = PYBPIN_WAKES_NOT},
|
||||
{.active = false, .lpds = PYBPIN_WAKES_NOT, .hib = PYBPIN_WAKES_NOT},
|
||||
@@ -205,7 +205,7 @@ int8_t pin_find_af_index (const pin_obj_t* pin, uint8_t fn, uint8_t unit, uint8_
|
||||
/******************************************************************************
|
||||
DEFINE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) {
|
||||
static pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) {
|
||||
const mp_map_t *named_map = &named_pins->map;
|
||||
mp_map_elem_t *named_elem = mp_map_lookup((mp_map_t*)named_map, name, MP_MAP_LOOKUP);
|
||||
if (named_elem != NULL && named_elem->value != NULL) {
|
||||
@@ -214,7 +214,7 @@ STATIC pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t n
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC pin_obj_t *pin_find_pin_by_port_bit (const mp_obj_dict_t *named_pins, uint port, uint bit) {
|
||||
static pin_obj_t *pin_find_pin_by_port_bit (const mp_obj_dict_t *named_pins, uint port, uint bit) {
|
||||
const mp_map_t *named_map = &named_pins->map;
|
||||
for (uint i = 0; i < named_map->used; i++) {
|
||||
if ((((pin_obj_t *)named_map->table[i].value)->port == port) &&
|
||||
@@ -225,7 +225,7 @@ STATIC pin_obj_t *pin_find_pin_by_port_bit (const mp_obj_dict_t *named_pins, uin
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC int8_t pin_obj_find_af (const pin_obj_t* pin, uint8_t fn, uint8_t unit, uint8_t type) {
|
||||
static int8_t pin_obj_find_af (const pin_obj_t* pin, uint8_t fn, uint8_t unit, uint8_t type) {
|
||||
for (int i = 0; i < pin->num_afs; i++) {
|
||||
if (pin->af_list[i].fn == fn && pin->af_list[i].unit == unit && pin->af_list[i].type == type) {
|
||||
return pin->af_list[i].idx;
|
||||
@@ -234,7 +234,7 @@ STATIC int8_t pin_obj_find_af (const pin_obj_t* pin, uint8_t fn, uint8_t unit, u
|
||||
return -1;
|
||||
}
|
||||
|
||||
STATIC void pin_free_af_from_pins (uint8_t fn, uint8_t unit, uint8_t type) {
|
||||
static void pin_free_af_from_pins (uint8_t fn, uint8_t unit, uint8_t type) {
|
||||
const mp_map_t *named_map = &pin_board_pins_locals_dict.map;
|
||||
for (uint i = 0; i < named_map->used - 1; i++) {
|
||||
pin_obj_t * pin = (pin_obj_t *)named_map->table[i].value;
|
||||
@@ -250,12 +250,12 @@ STATIC void pin_free_af_from_pins (uint8_t fn, uint8_t unit, uint8_t type) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void pin_deassign (pin_obj_t* pin) {
|
||||
static void pin_deassign (pin_obj_t* pin) {
|
||||
pin_config (pin, PIN_MODE_0, GPIO_DIR_MODE_IN, PIN_TYPE_STD, -1, PIN_STRENGTH_4MA);
|
||||
pin->used = false;
|
||||
}
|
||||
|
||||
STATIC void pin_obj_configure (const pin_obj_t *self) {
|
||||
static void pin_obj_configure (const pin_obj_t *self) {
|
||||
uint32_t type;
|
||||
if (self->mode == PIN_TYPE_ANALOG) {
|
||||
type = PIN_TYPE_ANALOG;
|
||||
@@ -299,7 +299,7 @@ STATIC void pin_obj_configure (const pin_obj_t *self) {
|
||||
MAP_PinConfigSet(self->pin_num, self->strength, type);
|
||||
}
|
||||
|
||||
STATIC void pin_get_hibernate_pin_and_idx (const pin_obj_t *self, uint *hib_pin, uint *idx) {
|
||||
static void pin_get_hibernate_pin_and_idx (const pin_obj_t *self, uint *hib_pin, uint *idx) {
|
||||
// pin_num is actually : (package_pin - 1)
|
||||
switch (self->pin_num) {
|
||||
case 56: // GP2
|
||||
@@ -332,7 +332,7 @@ STATIC void pin_get_hibernate_pin_and_idx (const pin_obj_t *self, uint *hib_pin,
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void pin_irq_enable (mp_obj_t self_in) {
|
||||
static void pin_irq_enable (mp_obj_t self_in) {
|
||||
const pin_obj_t *self = self_in;
|
||||
uint hib_pin, idx;
|
||||
|
||||
@@ -364,7 +364,7 @@ STATIC void pin_irq_enable (mp_obj_t self_in) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void pin_irq_disable (mp_obj_t self_in) {
|
||||
static void pin_irq_disable (mp_obj_t self_in) {
|
||||
const pin_obj_t *self = self_in;
|
||||
uint hib_pin, idx;
|
||||
|
||||
@@ -383,12 +383,12 @@ STATIC void pin_irq_disable (mp_obj_t self_in) {
|
||||
MAP_GPIOIntDisable(self->port, self->bit);
|
||||
}
|
||||
|
||||
STATIC int pin_irq_flags (mp_obj_t self_in) {
|
||||
static int pin_irq_flags (mp_obj_t self_in) {
|
||||
const pin_obj_t *self = self_in;
|
||||
return self->irq_flags;
|
||||
}
|
||||
|
||||
STATIC void pin_extint_register(pin_obj_t *self, uint32_t intmode, uint32_t priority) {
|
||||
static void pin_extint_register(pin_obj_t *self, uint32_t intmode, uint32_t priority) {
|
||||
void *handler;
|
||||
uint32_t intnum;
|
||||
|
||||
@@ -419,25 +419,25 @@ STATIC void pin_extint_register(pin_obj_t *self, uint32_t intmode, uint32_t prio
|
||||
MAP_IntPrioritySet(intnum, priority);
|
||||
}
|
||||
|
||||
STATIC void pin_validate_mode (uint mode) {
|
||||
static void pin_validate_mode (uint mode) {
|
||||
if (mode != GPIO_DIR_MODE_IN && mode != GPIO_DIR_MODE_OUT && mode != PIN_TYPE_OD &&
|
||||
mode != GPIO_DIR_MODE_ALT && mode != GPIO_DIR_MODE_ALT_OD) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
|
||||
}
|
||||
}
|
||||
STATIC void pin_validate_pull (uint pull) {
|
||||
static void pin_validate_pull (uint pull) {
|
||||
if (pull != PIN_TYPE_STD && pull != PIN_TYPE_STD_PU && pull != PIN_TYPE_STD_PD) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void pin_validate_drive(uint strength) {
|
||||
static void pin_validate_drive(uint strength) {
|
||||
if (strength != PIN_STRENGTH_2MA && strength != PIN_STRENGTH_4MA && strength != PIN_STRENGTH_6MA) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void pin_validate_af(const pin_obj_t* pin, int8_t idx, uint8_t *fn, uint8_t *unit, uint8_t *type) {
|
||||
static void pin_validate_af(const pin_obj_t* pin, int8_t idx, uint8_t *fn, uint8_t *unit, uint8_t *type) {
|
||||
for (int i = 0; i < pin->num_afs; i++) {
|
||||
if (pin->af_list[i].idx == idx) {
|
||||
*fn = pin->af_list[i].fn;
|
||||
@@ -449,7 +449,7 @@ STATIC void pin_validate_af(const pin_obj_t* pin, int8_t idx, uint8_t *fn, uint8
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
|
||||
}
|
||||
|
||||
STATIC uint8_t pin_get_value (const pin_obj_t* self) {
|
||||
static uint8_t pin_get_value (const pin_obj_t* self) {
|
||||
uint32_t value;
|
||||
bool setdir = false;
|
||||
if (self->mode == PIN_TYPE_OD || self->mode == GPIO_DIR_MODE_ALT_OD) {
|
||||
@@ -472,24 +472,24 @@ STATIC uint8_t pin_get_value (const pin_obj_t* self) {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
|
||||
STATIC void GPIOA0IntHandler (void) {
|
||||
static void GPIOA0IntHandler (void) {
|
||||
EXTI_Handler(GPIOA0_BASE);
|
||||
}
|
||||
|
||||
STATIC void GPIOA1IntHandler (void) {
|
||||
static void GPIOA1IntHandler (void) {
|
||||
EXTI_Handler(GPIOA1_BASE);
|
||||
}
|
||||
|
||||
STATIC void GPIOA2IntHandler (void) {
|
||||
static void GPIOA2IntHandler (void) {
|
||||
EXTI_Handler(GPIOA2_BASE);
|
||||
}
|
||||
|
||||
STATIC void GPIOA3IntHandler (void) {
|
||||
static void GPIOA3IntHandler (void) {
|
||||
EXTI_Handler(GPIOA3_BASE);
|
||||
}
|
||||
|
||||
// common interrupt handler
|
||||
STATIC void EXTI_Handler(uint port) {
|
||||
static void EXTI_Handler(uint port) {
|
||||
uint32_t bits = MAP_GPIOIntStatus(port, true);
|
||||
MAP_GPIOIntClear(port, bits);
|
||||
|
||||
@@ -517,7 +517,7 @@ STATIC void EXTI_Handler(uint port) {
|
||||
/******************************************************************************/
|
||||
// MicroPython bindings
|
||||
|
||||
STATIC const mp_arg_t pin_init_args[] = {
|
||||
static const mp_arg_t pin_init_args[] = {
|
||||
{ MP_QSTR_mode, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
{ MP_QSTR_pull, MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||
{ MP_QSTR_value, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
@@ -526,7 +526,7 @@ STATIC const mp_arg_t pin_init_args[] = {
|
||||
};
|
||||
#define pin_INIT_NUM_ARGS MP_ARRAY_SIZE(pin_init_args)
|
||||
|
||||
STATIC mp_obj_t pin_obj_init_helper(pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pin_obj_init_helper(pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
// parse args
|
||||
mp_arg_val_t args[pin_INIT_NUM_ARGS];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, pin_INIT_NUM_ARGS, pin_init_args, args);
|
||||
@@ -590,7 +590,7 @@ invalid_args:
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
|
||||
}
|
||||
|
||||
STATIC void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
pin_obj_t *self = self_in;
|
||||
uint32_t pull = self->pull;
|
||||
uint32_t drive = self->strength;
|
||||
@@ -643,7 +643,7 @@ STATIC void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
|
||||
mp_printf(print, ", alt=%d)", alt);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
// Run an argument through the mapper and return the result.
|
||||
@@ -656,12 +656,12 @@ STATIC mp_obj_t pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
|
||||
return (mp_obj_t)pin;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
return pin_obj_init_helper(args[0], n_args - 1, args + 1, kw_args);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(pin_init_obj, 1, pin_obj_init);
|
||||
|
||||
STATIC mp_obj_t pin_value(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pin_value(size_t n_args, const mp_obj_t *args) {
|
||||
pin_obj_t *self = args[0];
|
||||
if (n_args == 1) {
|
||||
// get the value
|
||||
@@ -678,15 +678,15 @@ STATIC mp_obj_t pin_value(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value);
|
||||
|
||||
STATIC mp_obj_t pin_id(mp_obj_t self_in) {
|
||||
static mp_obj_t pin_id(mp_obj_t self_in) {
|
||||
pin_obj_t *self = self_in;
|
||||
return MP_OBJ_NEW_QSTR(self->name);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_id_obj, pin_id);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_id_obj, pin_id);
|
||||
|
||||
STATIC mp_obj_t pin_mode(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pin_mode(size_t n_args, const mp_obj_t *args) {
|
||||
pin_obj_t *self = args[0];
|
||||
if (n_args == 1) {
|
||||
return mp_obj_new_int(self->mode);
|
||||
@@ -698,9 +698,9 @@ STATIC mp_obj_t pin_mode(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_mode_obj, 1, 2, pin_mode);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_mode_obj, 1, 2, pin_mode);
|
||||
|
||||
STATIC mp_obj_t pin_pull(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pin_pull(size_t n_args, const mp_obj_t *args) {
|
||||
pin_obj_t *self = args[0];
|
||||
if (n_args == 1) {
|
||||
if (self->pull == PIN_TYPE_STD) {
|
||||
@@ -720,9 +720,9 @@ STATIC mp_obj_t pin_pull(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_pull_obj, 1, 2, pin_pull);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_pull_obj, 1, 2, pin_pull);
|
||||
|
||||
STATIC mp_obj_t pin_drive(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pin_drive(size_t n_args, const mp_obj_t *args) {
|
||||
pin_obj_t *self = args[0];
|
||||
if (n_args == 1) {
|
||||
return mp_obj_new_int(self->strength);
|
||||
@@ -734,15 +734,15 @@ STATIC mp_obj_t pin_drive(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_drive_obj, 1, 2, pin_drive);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_drive_obj, 1, 2, pin_drive);
|
||||
|
||||
STATIC mp_obj_t pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_t _args[2] = {self_in, *args};
|
||||
return pin_value (n_args + 1, _args);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pin_alt_list(mp_obj_t self_in) {
|
||||
static mp_obj_t pin_alt_list(mp_obj_t self_in) {
|
||||
pin_obj_t *self = self_in;
|
||||
mp_obj_t af[2];
|
||||
mp_obj_t afs = mp_obj_new_list(0, NULL);
|
||||
@@ -754,10 +754,10 @@ STATIC mp_obj_t pin_alt_list(mp_obj_t self_in) {
|
||||
}
|
||||
return afs;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_alt_list_obj, pin_alt_list);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_alt_list_obj, pin_alt_list);
|
||||
|
||||
/// \method irq(trigger, priority, handler, wake)
|
||||
STATIC mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_arg_val_t args[mp_irq_INIT_NUM_ARGS];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mp_irq_INIT_NUM_ARGS, mp_irq_init_args, args);
|
||||
pin_obj_t *self = pos_args[0];
|
||||
@@ -896,9 +896,9 @@ STATIC mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
||||
invalid_args:
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pin_irq_obj, 1, pin_irq);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pin_irq_obj, 1, pin_irq);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pin_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pin_locals_dict_table[] = {
|
||||
// instance methods
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pin_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&pin_value_obj) },
|
||||
@@ -929,7 +929,7 @@ STATIC const mp_rom_map_elem_t pin_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_IRQ_HIGH_LEVEL), MP_ROM_INT(PYB_PIN_HIGH_LEVEL) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pin_locals_dict, pin_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pin_locals_dict, pin_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pin_type,
|
||||
@@ -941,14 +941,14 @@ MP_DEFINE_CONST_OBJ_TYPE(
|
||||
locals_dict, &pin_locals_dict
|
||||
);
|
||||
|
||||
STATIC const mp_irq_methods_t pin_irq_methods = {
|
||||
static const mp_irq_methods_t pin_irq_methods = {
|
||||
.init = pin_irq,
|
||||
.enable = pin_irq_enable,
|
||||
.disable = pin_irq_disable,
|
||||
.flags = pin_irq_flags,
|
||||
};
|
||||
|
||||
STATIC void pin_named_pins_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void pin_named_pins_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
pin_named_pins_obj_t *self = self_in;
|
||||
mp_printf(print, "<Pin.%q>", self->name);
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE DATA
|
||||
******************************************************************************/
|
||||
STATIC const mp_irq_methods_t pyb_rtc_irq_methods;
|
||||
STATIC pyb_rtc_obj_t pyb_rtc_obj;
|
||||
static const mp_irq_methods_t pyb_rtc_irq_methods;
|
||||
static pyb_rtc_obj_t pyb_rtc_obj;
|
||||
|
||||
/******************************************************************************
|
||||
FUNCTION-LIKE MACROS
|
||||
@@ -60,16 +60,16 @@ STATIC pyb_rtc_obj_t pyb_rtc_obj;
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC void pyb_rtc_set_time (uint32_t secs, uint16_t msecs);
|
||||
STATIC uint32_t pyb_rtc_reset (void);
|
||||
STATIC void pyb_rtc_disable_interupt (void);
|
||||
STATIC void pyb_rtc_irq_enable (mp_obj_t self_in);
|
||||
STATIC void pyb_rtc_irq_disable (mp_obj_t self_in);
|
||||
STATIC int pyb_rtc_irq_flags (mp_obj_t self_in);
|
||||
STATIC uint pyb_rtc_datetime_s_us(const mp_obj_t datetime, uint32_t *seconds);
|
||||
STATIC mp_obj_t pyb_rtc_datetime(mp_obj_t self, const mp_obj_t datetime);
|
||||
STATIC void pyb_rtc_set_alarm (pyb_rtc_obj_t *self, uint32_t seconds, uint16_t mseconds);
|
||||
STATIC void rtc_msec_add(uint16_t msecs_1, uint32_t *secs, uint16_t *msecs_2);
|
||||
static void pyb_rtc_set_time (uint32_t secs, uint16_t msecs);
|
||||
static uint32_t pyb_rtc_reset (void);
|
||||
static void pyb_rtc_disable_interupt (void);
|
||||
static void pyb_rtc_irq_enable (mp_obj_t self_in);
|
||||
static void pyb_rtc_irq_disable (mp_obj_t self_in);
|
||||
static int pyb_rtc_irq_flags (mp_obj_t self_in);
|
||||
static uint pyb_rtc_datetime_s_us(const mp_obj_t datetime, uint32_t *seconds);
|
||||
static mp_obj_t pyb_rtc_datetime(mp_obj_t self, const mp_obj_t datetime);
|
||||
static void pyb_rtc_set_alarm (pyb_rtc_obj_t *self, uint32_t seconds, uint16_t mseconds);
|
||||
static void rtc_msec_add(uint16_t msecs_1, uint32_t *secs, uint16_t *msecs_2);
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PUBLIC FUNCTIONS
|
||||
@@ -137,7 +137,7 @@ void pyb_rtc_disable_alarm (void) {
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC void pyb_rtc_set_time (uint32_t secs, uint16_t msecs) {
|
||||
static void pyb_rtc_set_time (uint32_t secs, uint16_t msecs) {
|
||||
// add the RTC access time
|
||||
rtc_msec_add(RTC_ACCESS_TIME_MSEC, &secs, &msecs);
|
||||
// convert from mseconds to cycles
|
||||
@@ -146,7 +146,7 @@ STATIC void pyb_rtc_set_time (uint32_t secs, uint16_t msecs) {
|
||||
MAP_PRCMRTCSet(secs, msecs);
|
||||
}
|
||||
|
||||
STATIC uint32_t pyb_rtc_reset (void) {
|
||||
static uint32_t pyb_rtc_reset (void) {
|
||||
// fresh reset; configure the RTC Calendar
|
||||
// set the date to 1st Jan 2015
|
||||
// set the time to 00:00:00
|
||||
@@ -158,14 +158,14 @@ STATIC uint32_t pyb_rtc_reset (void) {
|
||||
return seconds;
|
||||
}
|
||||
|
||||
STATIC void pyb_rtc_disable_interupt (void) {
|
||||
static void pyb_rtc_disable_interupt (void) {
|
||||
uint primsk = disable_irq();
|
||||
MAP_PRCMIntDisable(PRCM_INT_SLOW_CLK_CTR);
|
||||
(void)MAP_PRCMIntStatus();
|
||||
enable_irq(primsk);
|
||||
}
|
||||
|
||||
STATIC void pyb_rtc_irq_enable (mp_obj_t self_in) {
|
||||
static void pyb_rtc_irq_enable (mp_obj_t self_in) {
|
||||
pyb_rtc_obj_t *self = self_in;
|
||||
// we always need interrupts if repeat is enabled
|
||||
if ((self->pwrmode & PYB_PWR_MODE_ACTIVE) || self->repeat) {
|
||||
@@ -176,7 +176,7 @@ STATIC void pyb_rtc_irq_enable (mp_obj_t self_in) {
|
||||
self->irq_enabled = true;
|
||||
}
|
||||
|
||||
STATIC void pyb_rtc_irq_disable (mp_obj_t self_in) {
|
||||
static void pyb_rtc_irq_disable (mp_obj_t self_in) {
|
||||
pyb_rtc_obj_t *self = self_in;
|
||||
self->irq_enabled = false;
|
||||
if (!self->repeat) { // we always need interrupts if repeat is enabled
|
||||
@@ -184,12 +184,12 @@ STATIC void pyb_rtc_irq_disable (mp_obj_t self_in) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC int pyb_rtc_irq_flags (mp_obj_t self_in) {
|
||||
static int pyb_rtc_irq_flags (mp_obj_t self_in) {
|
||||
pyb_rtc_obj_t *self = self_in;
|
||||
return self->irq_flags;
|
||||
}
|
||||
|
||||
STATIC uint pyb_rtc_datetime_s_us(const mp_obj_t datetime, uint32_t *seconds) {
|
||||
static uint pyb_rtc_datetime_s_us(const mp_obj_t datetime, uint32_t *seconds) {
|
||||
timeutils_struct_time_t tm;
|
||||
uint32_t useconds;
|
||||
|
||||
@@ -234,7 +234,7 @@ STATIC uint pyb_rtc_datetime_s_us(const mp_obj_t datetime, uint32_t *seconds) {
|
||||
///
|
||||
/// (year, month, day, hours, minutes, seconds, milliseconds, tzinfo=None)
|
||||
///
|
||||
STATIC mp_obj_t pyb_rtc_datetime(mp_obj_t self_in, const mp_obj_t datetime) {
|
||||
static mp_obj_t pyb_rtc_datetime(mp_obj_t self_in, const mp_obj_t datetime) {
|
||||
uint32_t seconds;
|
||||
uint32_t useconds;
|
||||
|
||||
@@ -250,7 +250,7 @@ STATIC mp_obj_t pyb_rtc_datetime(mp_obj_t self_in, const mp_obj_t datetime) {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC void pyb_rtc_set_alarm (pyb_rtc_obj_t *self, uint32_t seconds, uint16_t mseconds) {
|
||||
static void pyb_rtc_set_alarm (pyb_rtc_obj_t *self, uint32_t seconds, uint16_t mseconds) {
|
||||
// disable the interrupt before updating anything
|
||||
if (self->irq_enabled) {
|
||||
MAP_PRCMIntDisable(PRCM_INT_SLOW_CLK_CTR);
|
||||
@@ -266,7 +266,7 @@ STATIC void pyb_rtc_set_alarm (pyb_rtc_obj_t *self, uint32_t seconds, uint16_t m
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void rtc_msec_add (uint16_t msecs_1, uint32_t *secs, uint16_t *msecs_2) {
|
||||
static void rtc_msec_add (uint16_t msecs_1, uint32_t *secs, uint16_t *msecs_2) {
|
||||
if (msecs_1 + *msecs_2 >= 1000) { // larger than one second
|
||||
*msecs_2 = (msecs_1 + *msecs_2) - 1000;
|
||||
*secs += 1; // carry flag
|
||||
@@ -279,11 +279,11 @@ STATIC void rtc_msec_add (uint16_t msecs_1, uint32_t *secs, uint16_t *msecs_2) {
|
||||
/******************************************************************************/
|
||||
// MicroPython bindings
|
||||
|
||||
STATIC const mp_arg_t pyb_rtc_init_args[] = {
|
||||
static const mp_arg_t pyb_rtc_init_args[] = {
|
||||
{ MP_QSTR_id, MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_datetime, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
};
|
||||
STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
// parse args
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
|
||||
@@ -309,15 +309,15 @@ STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
||||
return (mp_obj_t)&pyb_rtc_obj;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pyb_rtc_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_rtc_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
// parse args
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_rtc_init_args) - 1];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_rtc_init_args[1], args);
|
||||
return pyb_rtc_datetime(pos_args[0], args[0].u_obj);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_init_obj, 1, pyb_rtc_init);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_init_obj, 1, pyb_rtc_init);
|
||||
|
||||
STATIC mp_obj_t pyb_rtc_now (mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_rtc_now (mp_obj_t self_in) {
|
||||
timeutils_struct_time_t tm;
|
||||
uint32_t seconds;
|
||||
uint16_t mseconds;
|
||||
@@ -338,16 +338,16 @@ STATIC mp_obj_t pyb_rtc_now (mp_obj_t self_in) {
|
||||
};
|
||||
return mp_obj_new_tuple(8, tuple);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_rtc_now_obj, pyb_rtc_now);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_rtc_now_obj, pyb_rtc_now);
|
||||
|
||||
STATIC mp_obj_t pyb_rtc_deinit (mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_rtc_deinit (mp_obj_t self_in) {
|
||||
pyb_rtc_reset();
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_rtc_deinit_obj, pyb_rtc_deinit);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_rtc_deinit_obj, pyb_rtc_deinit);
|
||||
|
||||
STATIC mp_obj_t pyb_rtc_alarm(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
STATIC const mp_arg_t allowed_args[] = {
|
||||
static mp_obj_t pyb_rtc_alarm(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_id, MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_time, MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||
{ MP_QSTR_repeat, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
|
||||
@@ -385,9 +385,9 @@ STATIC mp_obj_t pyb_rtc_alarm(size_t n_args, const mp_obj_t *pos_args, mp_map_t
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_alarm_obj, 1, pyb_rtc_alarm);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_alarm_obj, 1, pyb_rtc_alarm);
|
||||
|
||||
STATIC mp_obj_t pyb_rtc_alarm_left(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_rtc_alarm_left(size_t n_args, const mp_obj_t *args) {
|
||||
pyb_rtc_obj_t *self = args[0];
|
||||
int32_t ms_left;
|
||||
uint32_t c_seconds;
|
||||
@@ -408,9 +408,9 @@ STATIC mp_obj_t pyb_rtc_alarm_left(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
return mp_obj_new_int(ms_left);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_alarm_left_obj, 1, 2, pyb_rtc_alarm_left);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_alarm_left_obj, 1, 2, pyb_rtc_alarm_left);
|
||||
|
||||
STATIC mp_obj_t pyb_rtc_alarm_cancel(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_rtc_alarm_cancel(size_t n_args, const mp_obj_t *args) {
|
||||
// only alarm id 0 is available
|
||||
if (n_args > 1 && mp_obj_get_int(args[1]) != 0) {
|
||||
mp_raise_OSError(MP_ENODEV);
|
||||
@@ -419,10 +419,10 @@ STATIC mp_obj_t pyb_rtc_alarm_cancel(size_t n_args, const mp_obj_t *args) {
|
||||
pyb_rtc_disable_alarm();
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_alarm_cancel_obj, 1, 2, pyb_rtc_alarm_cancel);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_alarm_cancel_obj, 1, 2, pyb_rtc_alarm_cancel);
|
||||
|
||||
/// \method irq(trigger, priority, handler, wake)
|
||||
STATIC mp_obj_t pyb_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_arg_val_t args[mp_irq_INIT_NUM_ARGS];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mp_irq_INIT_NUM_ARGS, mp_irq_init_args, args);
|
||||
pyb_rtc_obj_t *self = pos_args[0];
|
||||
@@ -453,9 +453,9 @@ STATIC mp_obj_t pyb_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
||||
invalid_args:
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_irq_obj, 1, pyb_rtc_irq);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_irq_obj, 1, pyb_rtc_irq);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_rtc_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_rtc_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_rtc_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_rtc_deinit_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_now), MP_ROM_PTR(&pyb_rtc_now_obj) },
|
||||
@@ -467,7 +467,7 @@ STATIC const mp_rom_map_elem_t pyb_rtc_locals_dict_table[] = {
|
||||
// class constants
|
||||
{ MP_ROM_QSTR(MP_QSTR_ALARM0), MP_ROM_INT(PYB_RTC_ALARM0) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_rtc_locals_dict, pyb_rtc_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_rtc_locals_dict, pyb_rtc_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_rtc_type,
|
||||
@@ -477,7 +477,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
|
||||
locals_dict, &pyb_rtc_locals_dict
|
||||
);
|
||||
|
||||
STATIC const mp_irq_methods_t pyb_rtc_irq_methods = {
|
||||
static const mp_irq_methods_t pyb_rtc_irq_methods = {
|
||||
.init = pyb_rtc_irq,
|
||||
.enable = pyb_rtc_irq_enable,
|
||||
.disable = pyb_rtc_irq_disable,
|
||||
|
||||
@@ -59,20 +59,20 @@ pybsd_obj_t pybsd_obj;
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE DATA
|
||||
******************************************************************************/
|
||||
STATIC const mp_obj_t pyb_sd_def_pin[3] = {&pin_GP10, &pin_GP11, &pin_GP15};
|
||||
static const mp_obj_t pyb_sd_def_pin[3] = {&pin_GP10, &pin_GP11, &pin_GP15};
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC void pyb_sd_hw_init (pybsd_obj_t *self);
|
||||
STATIC mp_obj_t pyb_sd_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
||||
STATIC mp_obj_t pyb_sd_deinit (mp_obj_t self_in);
|
||||
static void pyb_sd_hw_init (pybsd_obj_t *self);
|
||||
static mp_obj_t pyb_sd_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
||||
static mp_obj_t pyb_sd_deinit (mp_obj_t self_in);
|
||||
|
||||
/******************************************************************************
|
||||
DEFINE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
/// Initializes the sd card hardware driver
|
||||
STATIC void pyb_sd_hw_init (pybsd_obj_t *self) {
|
||||
static void pyb_sd_hw_init (pybsd_obj_t *self) {
|
||||
if (self->pin_clk) {
|
||||
// Configure the clock pin as output only
|
||||
MAP_PinDirModeSet(((pin_obj_t *)(self->pin_clk))->pin_num, PIN_DIR_MODE_OUT);
|
||||
@@ -90,7 +90,7 @@ STATIC void pyb_sd_hw_init (pybsd_obj_t *self) {
|
||||
self->enabled = true;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pyb_sd_init_helper (pybsd_obj_t *self, const mp_arg_val_t *args) {
|
||||
static mp_obj_t pyb_sd_init_helper (pybsd_obj_t *self, const mp_arg_val_t *args) {
|
||||
// assign the pins
|
||||
mp_obj_t pins_o = args[0].u_obj;
|
||||
if (pins_o != mp_const_none) {
|
||||
@@ -120,11 +120,11 @@ STATIC mp_obj_t pyb_sd_init_helper (pybsd_obj_t *self, const mp_arg_val_t *args)
|
||||
// MicroPython bindings
|
||||
//
|
||||
|
||||
STATIC const mp_arg_t pyb_sd_init_args[] = {
|
||||
static const mp_arg_t pyb_sd_init_args[] = {
|
||||
{ MP_QSTR_id, MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_pins, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
};
|
||||
STATIC mp_obj_t pyb_sd_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t pyb_sd_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
// parse args
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
|
||||
@@ -143,15 +143,15 @@ STATIC mp_obj_t pyb_sd_make_new(const mp_obj_type_t *type, size_t n_args, size_t
|
||||
return self;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pyb_sd_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_sd_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
// parse args
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_sd_init_args) - 1];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_sd_init_args[1], args);
|
||||
return pyb_sd_init_helper(pos_args[0], args);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_sd_init_obj, 1, pyb_sd_init);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_sd_init_obj, 1, pyb_sd_init);
|
||||
|
||||
STATIC mp_obj_t pyb_sd_deinit (mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_sd_deinit (mp_obj_t self_in) {
|
||||
pybsd_obj_t *self = self_in;
|
||||
// disable the peripheral
|
||||
self->enabled = false;
|
||||
@@ -162,25 +162,25 @@ STATIC mp_obj_t pyb_sd_deinit (mp_obj_t self_in) {
|
||||
pyb_sleep_remove (self);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_sd_deinit_obj, pyb_sd_deinit);
|
||||
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) {
|
||||
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_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) {
|
||||
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_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) {
|
||||
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 MP_BLOCKDEV_IOCTL_INIT:
|
||||
@@ -199,9 +199,9 @@ STATIC mp_obj_t pyb_sd_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) {
|
||||
return MP_OBJ_NEW_SMALL_INT(-1); // error
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sd_ioctl_obj, pyb_sd_ioctl);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_3(pyb_sd_ioctl_obj, pyb_sd_ioctl);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_sd_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_sd_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_sd_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_sd_deinit_obj) },
|
||||
// block device protocol
|
||||
@@ -210,7 +210,7 @@ STATIC const mp_rom_map_elem_t pyb_sd_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&pyb_sd_ioctl_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_sd_locals_dict, pyb_sd_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_sd_locals_dict, pyb_sd_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_sd_type,
|
||||
|
||||
@@ -120,12 +120,12 @@ typedef struct {
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE DATA
|
||||
******************************************************************************/
|
||||
STATIC nvic_reg_store_t *nvic_reg_store;
|
||||
STATIC pybsleep_data_t pybsleep_data = {NULL, NULL, NULL};
|
||||
static nvic_reg_store_t *nvic_reg_store;
|
||||
static pybsleep_data_t pybsleep_data = {NULL, NULL, NULL};
|
||||
volatile arm_cm4_core_regs_t vault_arm_registers;
|
||||
STATIC pybsleep_reset_cause_t pybsleep_reset_cause = PYB_SLP_PWRON_RESET;
|
||||
STATIC pybsleep_wake_reason_t pybsleep_wake_reason = PYB_SLP_WAKED_PWRON;
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
static pybsleep_reset_cause_t pybsleep_reset_cause = PYB_SLP_PWRON_RESET;
|
||||
static pybsleep_wake_reason_t pybsleep_wake_reason = PYB_SLP_WAKED_PWRON;
|
||||
static MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_sleep_type,
|
||||
MP_QSTR_sleep,
|
||||
MP_TYPE_FLAG_NONE
|
||||
@@ -134,15 +134,15 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC pyb_sleep_obj_t *pyb_sleep_find (mp_obj_t obj);
|
||||
STATIC void pyb_sleep_flash_powerdown (void);
|
||||
STATIC NORETURN void pyb_sleep_suspend_enter (void);
|
||||
static pyb_sleep_obj_t *pyb_sleep_find (mp_obj_t obj);
|
||||
static void pyb_sleep_flash_powerdown (void);
|
||||
static NORETURN void pyb_sleep_suspend_enter (void);
|
||||
void pyb_sleep_suspend_exit (void);
|
||||
STATIC void pyb_sleep_obj_wakeup (void);
|
||||
STATIC void PRCMInterruptHandler (void);
|
||||
STATIC void pyb_sleep_iopark (bool hibernate);
|
||||
STATIC bool setup_timer_lpds_wake (void);
|
||||
STATIC bool setup_timer_hibernate_wake (void);
|
||||
static void pyb_sleep_obj_wakeup (void);
|
||||
static void PRCMInterruptHandler (void);
|
||||
static void pyb_sleep_iopark (bool hibernate);
|
||||
static bool setup_timer_lpds_wake (void);
|
||||
static bool setup_timer_hibernate_wake (void);
|
||||
|
||||
/******************************************************************************
|
||||
DEFINE PUBLIC FUNCTIONS
|
||||
@@ -304,7 +304,7 @@ pybsleep_wake_reason_t pyb_sleep_get_wake_reason (void) {
|
||||
/******************************************************************************
|
||||
DEFINE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC pyb_sleep_obj_t *pyb_sleep_find (mp_obj_t obj) {
|
||||
static pyb_sleep_obj_t *pyb_sleep_find (mp_obj_t obj) {
|
||||
for (mp_uint_t i = 0; i < MP_STATE_PORT(pyb_sleep_obj_list).len; i++) {
|
||||
// search for the object and then remove it
|
||||
pyb_sleep_obj_t *sleep_obj = ((pyb_sleep_obj_t *)(MP_STATE_PORT(pyb_sleep_obj_list).items[i]));
|
||||
@@ -315,7 +315,7 @@ STATIC pyb_sleep_obj_t *pyb_sleep_find (mp_obj_t obj) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC void pyb_sleep_flash_powerdown (void) {
|
||||
static void pyb_sleep_flash_powerdown (void) {
|
||||
uint32_t status;
|
||||
|
||||
// Enable clock for SSPI module
|
||||
@@ -360,7 +360,7 @@ STATIC void pyb_sleep_flash_powerdown (void) {
|
||||
MAP_SPICSDisable(SSPI_BASE);
|
||||
}
|
||||
|
||||
STATIC NORETURN void pyb_sleep_suspend_enter (void) {
|
||||
static NORETURN void pyb_sleep_suspend_enter (void) {
|
||||
// enable full RAM retention
|
||||
MAP_PRCMSRAMRetentionEnable(PRCM_SRAM_COL_1 | PRCM_SRAM_COL_2 | PRCM_SRAM_COL_3 | PRCM_SRAM_COL_4, PRCM_SRAM_LPDS_RET);
|
||||
|
||||
@@ -479,7 +479,7 @@ void pyb_sleep_suspend_exit (void) {
|
||||
mp_raise_type(&mp_type_SystemExit);
|
||||
}
|
||||
|
||||
STATIC void PRCMInterruptHandler (void) {
|
||||
static void PRCMInterruptHandler (void) {
|
||||
// reading the interrupt status automatically clears the interrupt
|
||||
if (PRCM_INT_SLOW_CLK_CTR == MAP_PRCMIntStatus()) {
|
||||
// reconfigure it again (if repeat is true)
|
||||
@@ -519,14 +519,14 @@ STATIC void PRCMInterruptHandler (void) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void pyb_sleep_obj_wakeup (void) {
|
||||
static void pyb_sleep_obj_wakeup (void) {
|
||||
for (mp_uint_t i = 0; i < MP_STATE_PORT(pyb_sleep_obj_list).len; i++) {
|
||||
pyb_sleep_obj_t *sleep_obj = ((pyb_sleep_obj_t *)MP_STATE_PORT(pyb_sleep_obj_list).items[i]);
|
||||
sleep_obj->wakeup(sleep_obj->obj);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void pyb_sleep_iopark (bool hibernate) {
|
||||
static void pyb_sleep_iopark (bool hibernate) {
|
||||
const mp_map_t *named_map = &pin_board_pins_locals_dict.map;
|
||||
for (uint i = 0; i < named_map->used; i++) {
|
||||
pin_obj_t * pin = (pin_obj_t *)named_map->table[i].value;
|
||||
@@ -583,7 +583,7 @@ STATIC void pyb_sleep_iopark (bool hibernate) {
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC bool setup_timer_lpds_wake (void) {
|
||||
static bool setup_timer_lpds_wake (void) {
|
||||
uint64_t t_match, t_curr;
|
||||
int64_t t_remaining;
|
||||
|
||||
@@ -618,7 +618,7 @@ STATIC bool setup_timer_lpds_wake (void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
STATIC bool setup_timer_hibernate_wake (void) {
|
||||
static bool setup_timer_hibernate_wake (void) {
|
||||
uint64_t t_match, t_curr;
|
||||
int64_t t_remaining;
|
||||
|
||||
|
||||
@@ -68,15 +68,15 @@ typedef struct _pyb_spi_obj_t {
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE DATA
|
||||
******************************************************************************/
|
||||
STATIC pyb_spi_obj_t pyb_spi_obj = {.baudrate = 0};
|
||||
static pyb_spi_obj_t pyb_spi_obj = {.baudrate = 0};
|
||||
|
||||
STATIC const mp_obj_t pyb_spi_def_pin[3] = {&pin_GP14, &pin_GP16, &pin_GP30};
|
||||
static const mp_obj_t pyb_spi_def_pin[3] = {&pin_GP14, &pin_GP16, &pin_GP30};
|
||||
|
||||
/******************************************************************************
|
||||
DEFINE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
// only master mode is available for the moment
|
||||
STATIC void pybspi_init (const pyb_spi_obj_t *self) {
|
||||
static void pybspi_init (const pyb_spi_obj_t *self) {
|
||||
// enable the peripheral clock
|
||||
MAP_PRCMPeripheralClkEnable(PRCM_GSPI, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
|
||||
MAP_PRCMPeripheralReset(PRCM_GSPI);
|
||||
@@ -90,7 +90,7 @@ STATIC void pybspi_init (const pyb_spi_obj_t *self) {
|
||||
MAP_SPIEnable(GSPI_BASE);
|
||||
}
|
||||
|
||||
STATIC void pybspi_tx (pyb_spi_obj_t *self, const void *data) {
|
||||
static void pybspi_tx (pyb_spi_obj_t *self, const void *data) {
|
||||
uint32_t txdata;
|
||||
switch (self->wlen) {
|
||||
case 1:
|
||||
@@ -108,7 +108,7 @@ STATIC void pybspi_tx (pyb_spi_obj_t *self, const void *data) {
|
||||
MAP_SPIDataPut (GSPI_BASE, txdata);
|
||||
}
|
||||
|
||||
STATIC void pybspi_rx (pyb_spi_obj_t *self, void *data) {
|
||||
static void pybspi_rx (pyb_spi_obj_t *self, void *data) {
|
||||
uint32_t rxdata;
|
||||
MAP_SPIDataGet (GSPI_BASE, &rxdata);
|
||||
if (data) {
|
||||
@@ -128,7 +128,7 @@ STATIC void pybspi_rx (pyb_spi_obj_t *self, void *data) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void pybspi_transfer (pyb_spi_obj_t *self, const char *txdata, char *rxdata, uint32_t len, uint32_t *txchar) {
|
||||
static void pybspi_transfer (pyb_spi_obj_t *self, const char *txdata, char *rxdata, uint32_t len, uint32_t *txchar) {
|
||||
if (!self->baudrate) {
|
||||
mp_raise_OSError(MP_EPERM);
|
||||
}
|
||||
@@ -144,7 +144,7 @@ STATIC void pybspi_transfer (pyb_spi_obj_t *self, const char *txdata, char *rxda
|
||||
/******************************************************************************/
|
||||
/* MicroPython bindings */
|
||||
/******************************************************************************/
|
||||
STATIC void pyb_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void pyb_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
pyb_spi_obj_t *self = self_in;
|
||||
if (self->baudrate > 0) {
|
||||
mp_printf(print, "SPI(0, baudrate=%u, bits=%u, polarity=%u, phase=%u, firstbit=SPI.MSB)",
|
||||
@@ -154,7 +154,7 @@ STATIC void pyb_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pyb_spi_init_helper(pyb_spi_obj_t *self, const mp_arg_val_t *args) {
|
||||
static mp_obj_t pyb_spi_init_helper(pyb_spi_obj_t *self, const mp_arg_val_t *args) {
|
||||
uint bits;
|
||||
switch (args[1].u_int) {
|
||||
case 8:
|
||||
@@ -224,7 +224,7 @@ static const mp_arg_t pyb_spi_init_args[] = {
|
||||
{ MP_QSTR_firstbit, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = PYBSPI_FIRST_BIT_MSB} },
|
||||
{ MP_QSTR_pins, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
};
|
||||
STATIC mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
// parse args
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
|
||||
@@ -246,17 +246,17 @@ STATIC mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
||||
return self;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pyb_spi_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_spi_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
// parse args
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_spi_init_args) - 1];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_spi_init_args[1], args);
|
||||
return pyb_spi_init_helper(pos_args[0], args);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_init_obj, 1, pyb_spi_init);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_init_obj, 1, pyb_spi_init);
|
||||
|
||||
/// \method deinit()
|
||||
/// Turn off the spi bus.
|
||||
STATIC mp_obj_t pyb_spi_deinit(mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_spi_deinit(mp_obj_t self_in) {
|
||||
// disable the peripheral
|
||||
MAP_SPIDisable(GSPI_BASE);
|
||||
MAP_PRCMPeripheralClkDisable(PRCM_GSPI, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
|
||||
@@ -266,9 +266,9 @@ STATIC mp_obj_t pyb_spi_deinit(mp_obj_t self_in) {
|
||||
pyb_sleep_remove((const mp_obj_t)self_in);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_spi_deinit_obj, pyb_spi_deinit);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_spi_deinit_obj, pyb_spi_deinit);
|
||||
|
||||
STATIC mp_obj_t pyb_spi_write (mp_obj_t self_in, mp_obj_t buf) {
|
||||
static mp_obj_t pyb_spi_write (mp_obj_t self_in, mp_obj_t buf) {
|
||||
// parse args
|
||||
pyb_spi_obj_t *self = self_in;
|
||||
|
||||
@@ -283,9 +283,9 @@ STATIC mp_obj_t pyb_spi_write (mp_obj_t self_in, mp_obj_t buf) {
|
||||
// return the number of bytes written
|
||||
return mp_obj_new_int(bufinfo.len);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_spi_write_obj, pyb_spi_write);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(pyb_spi_write_obj, pyb_spi_write);
|
||||
|
||||
STATIC mp_obj_t pyb_spi_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_spi_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_nbytes, MP_ARG_REQUIRED | MP_ARG_OBJ, },
|
||||
{ MP_QSTR_write, MP_ARG_INT, {.u_int = 0x00} },
|
||||
@@ -307,9 +307,9 @@ STATIC mp_obj_t pyb_spi_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
|
||||
// return the received data
|
||||
return mp_obj_new_bytes_from_vstr(&vstr);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_read_obj, 1, pyb_spi_read);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_read_obj, 1, pyb_spi_read);
|
||||
|
||||
STATIC mp_obj_t pyb_spi_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_spi_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_buf, MP_ARG_REQUIRED | MP_ARG_OBJ, },
|
||||
{ MP_QSTR_write, MP_ARG_INT, {.u_int = 0x00} },
|
||||
@@ -331,9 +331,9 @@ STATIC mp_obj_t pyb_spi_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map
|
||||
// return the number of bytes received
|
||||
return mp_obj_new_int(vstr.len);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_readinto_obj, 1, pyb_spi_readinto);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_readinto_obj, 1, pyb_spi_readinto);
|
||||
|
||||
STATIC mp_obj_t pyb_spi_write_readinto (mp_obj_t self, mp_obj_t writebuf, mp_obj_t readbuf) {
|
||||
static mp_obj_t pyb_spi_write_readinto (mp_obj_t self, mp_obj_t writebuf, mp_obj_t readbuf) {
|
||||
// get buffers to write from/read to
|
||||
mp_buffer_info_t bufinfo_write;
|
||||
uint8_t data_send[1];
|
||||
@@ -360,9 +360,9 @@ STATIC mp_obj_t pyb_spi_write_readinto (mp_obj_t self, mp_obj_t writebuf, mp_obj
|
||||
// return the number of transferred bytes
|
||||
return mp_obj_new_int(bufinfo_write.len);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_spi_write_readinto_obj, pyb_spi_write_readinto);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_3(pyb_spi_write_readinto_obj, pyb_spi_write_readinto);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_spi_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_spi_locals_dict_table[] = {
|
||||
// instance methods
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_spi_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_spi_deinit_obj) },
|
||||
@@ -375,7 +375,7 @@ STATIC const mp_rom_map_elem_t pyb_spi_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_MSB), MP_ROM_INT(PYBSPI_FIRST_BIT_MSB) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_spi_locals_dict, pyb_spi_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_spi_locals_dict, pyb_spi_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_spi_type,
|
||||
|
||||
@@ -96,28 +96,28 @@ typedef struct _pyb_timer_channel_obj_t {
|
||||
/******************************************************************************
|
||||
DEFINE PRIVATE DATA
|
||||
******************************************************************************/
|
||||
STATIC const mp_irq_methods_t pyb_timer_channel_irq_methods;
|
||||
STATIC pyb_timer_obj_t pyb_timer_obj[PYBTIMER_NUM_TIMERS] = {{.timer = TIMERA0_BASE, .peripheral = PRCM_TIMERA0},
|
||||
static const mp_irq_methods_t pyb_timer_channel_irq_methods;
|
||||
static pyb_timer_obj_t pyb_timer_obj[PYBTIMER_NUM_TIMERS] = {{.timer = TIMERA0_BASE, .peripheral = PRCM_TIMERA0},
|
||||
{.timer = TIMERA1_BASE, .peripheral = PRCM_TIMERA1},
|
||||
{.timer = TIMERA2_BASE, .peripheral = PRCM_TIMERA2},
|
||||
{.timer = TIMERA3_BASE, .peripheral = PRCM_TIMERA3}};
|
||||
STATIC const mp_obj_type_t pyb_timer_channel_type;
|
||||
STATIC const mp_obj_t pyb_timer_pwm_pin[8] = {&pin_GP24, MP_OBJ_NULL, &pin_GP25, MP_OBJ_NULL, MP_OBJ_NULL, &pin_GP9, &pin_GP10, &pin_GP11};
|
||||
static const mp_obj_type_t pyb_timer_channel_type;
|
||||
static const mp_obj_t pyb_timer_pwm_pin[8] = {&pin_GP24, MP_OBJ_NULL, &pin_GP25, MP_OBJ_NULL, MP_OBJ_NULL, &pin_GP9, &pin_GP10, &pin_GP11};
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC mp_obj_t pyb_timer_channel_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
STATIC void timer_disable (pyb_timer_obj_t *tim);
|
||||
STATIC void timer_channel_init (pyb_timer_channel_obj_t *ch);
|
||||
STATIC void TIMER0AIntHandler(void);
|
||||
STATIC void TIMER0BIntHandler(void);
|
||||
STATIC void TIMER1AIntHandler(void);
|
||||
STATIC void TIMER1BIntHandler(void);
|
||||
STATIC void TIMER2AIntHandler(void);
|
||||
STATIC void TIMER2BIntHandler(void);
|
||||
STATIC void TIMER3AIntHandler(void);
|
||||
STATIC void TIMER3BIntHandler(void);
|
||||
static mp_obj_t pyb_timer_channel_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
static void timer_disable (pyb_timer_obj_t *tim);
|
||||
static void timer_channel_init (pyb_timer_channel_obj_t *ch);
|
||||
static void TIMER0AIntHandler(void);
|
||||
static void TIMER0BIntHandler(void);
|
||||
static void TIMER1AIntHandler(void);
|
||||
static void TIMER1BIntHandler(void);
|
||||
static void TIMER2AIntHandler(void);
|
||||
static void TIMER2BIntHandler(void);
|
||||
static void TIMER3AIntHandler(void);
|
||||
static void TIMER3BIntHandler(void);
|
||||
|
||||
/******************************************************************************
|
||||
DEFINE PUBLIC FUNCTIONS
|
||||
@@ -129,23 +129,23 @@ void timer_init0 (void) {
|
||||
/******************************************************************************
|
||||
DEFINE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC void pyb_timer_channel_irq_enable (mp_obj_t self_in) {
|
||||
static void pyb_timer_channel_irq_enable (mp_obj_t self_in) {
|
||||
pyb_timer_channel_obj_t *self = self_in;
|
||||
MAP_TimerIntClear(self->timer->timer, self->timer->irq_trigger & self->channel);
|
||||
MAP_TimerIntEnable(self->timer->timer, self->timer->irq_trigger & self->channel);
|
||||
}
|
||||
|
||||
STATIC void pyb_timer_channel_irq_disable (mp_obj_t self_in) {
|
||||
static void pyb_timer_channel_irq_disable (mp_obj_t self_in) {
|
||||
pyb_timer_channel_obj_t *self = self_in;
|
||||
MAP_TimerIntDisable(self->timer->timer, self->timer->irq_trigger & self->channel);
|
||||
}
|
||||
|
||||
STATIC int pyb_timer_channel_irq_flags (mp_obj_t self_in) {
|
||||
static int pyb_timer_channel_irq_flags (mp_obj_t self_in) {
|
||||
pyb_timer_channel_obj_t *self = self_in;
|
||||
return self->timer->irq_flags;
|
||||
}
|
||||
|
||||
STATIC pyb_timer_channel_obj_t *pyb_timer_channel_find (uint32_t timer, uint16_t channel_n) {
|
||||
static pyb_timer_channel_obj_t *pyb_timer_channel_find (uint32_t timer, uint16_t channel_n) {
|
||||
for (mp_uint_t i = 0; i < MP_STATE_PORT(pyb_timer_channel_obj_list).len; i++) {
|
||||
pyb_timer_channel_obj_t *ch = ((pyb_timer_channel_obj_t *)(MP_STATE_PORT(pyb_timer_channel_obj_list).items[i]));
|
||||
// any 32-bit timer must be matched by any of its 16-bit versions
|
||||
@@ -156,7 +156,7 @@ STATIC pyb_timer_channel_obj_t *pyb_timer_channel_find (uint32_t timer, uint16_t
|
||||
return MP_OBJ_NULL;
|
||||
}
|
||||
|
||||
STATIC void pyb_timer_channel_remove (pyb_timer_channel_obj_t *ch) {
|
||||
static void pyb_timer_channel_remove (pyb_timer_channel_obj_t *ch) {
|
||||
pyb_timer_channel_obj_t *channel;
|
||||
if ((channel = pyb_timer_channel_find(ch->timer->timer, ch->channel))) {
|
||||
mp_obj_list_remove(&MP_STATE_PORT(pyb_timer_channel_obj_list), channel);
|
||||
@@ -165,7 +165,7 @@ STATIC void pyb_timer_channel_remove (pyb_timer_channel_obj_t *ch) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void pyb_timer_channel_add (pyb_timer_channel_obj_t *ch) {
|
||||
static void pyb_timer_channel_add (pyb_timer_channel_obj_t *ch) {
|
||||
// remove it in case it already exists
|
||||
pyb_timer_channel_remove(ch);
|
||||
mp_obj_list_append(&MP_STATE_PORT(pyb_timer_channel_obj_list), ch);
|
||||
@@ -173,7 +173,7 @@ STATIC void pyb_timer_channel_add (pyb_timer_channel_obj_t *ch) {
|
||||
pyb_sleep_add((const mp_obj_t)ch, (WakeUpCB_t)timer_channel_init);
|
||||
}
|
||||
|
||||
STATIC void timer_disable (pyb_timer_obj_t *tim) {
|
||||
static void timer_disable (pyb_timer_obj_t *tim) {
|
||||
// disable all timers and it's interrupts
|
||||
MAP_TimerDisable(tim->timer, TIMER_A | TIMER_B);
|
||||
MAP_TimerIntDisable(tim->timer, tim->irq_trigger);
|
||||
@@ -190,7 +190,7 @@ STATIC void timer_disable (pyb_timer_obj_t *tim) {
|
||||
}
|
||||
|
||||
// computes prescaler period and match value so timer triggers at freq-Hz
|
||||
STATIC uint32_t compute_prescaler_period_and_match_value(pyb_timer_channel_obj_t *ch, uint32_t *period_out, uint32_t *match_out) {
|
||||
static uint32_t compute_prescaler_period_and_match_value(pyb_timer_channel_obj_t *ch, uint32_t *period_out, uint32_t *match_out) {
|
||||
uint32_t maxcount = (ch->channel == (TIMER_A | TIMER_B)) ? 0xFFFFFFFF : 0xFFFF;
|
||||
uint32_t prescaler;
|
||||
uint32_t period_c = (ch->frequency > 0) ? PYBTIMER_SRC_FREQ_HZ / ch->frequency : ((PYBTIMER_SRC_FREQ_HZ / 1000000) * ch->period);
|
||||
@@ -223,13 +223,13 @@ error:
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
|
||||
}
|
||||
|
||||
STATIC void timer_init (pyb_timer_obj_t *tim) {
|
||||
static void timer_init (pyb_timer_obj_t *tim) {
|
||||
MAP_PRCMPeripheralClkEnable(tim->peripheral, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
|
||||
MAP_PRCMPeripheralReset(tim->peripheral);
|
||||
MAP_TimerConfigure(tim->timer, tim->config);
|
||||
}
|
||||
|
||||
STATIC void timer_channel_init (pyb_timer_channel_obj_t *ch) {
|
||||
static void timer_channel_init (pyb_timer_channel_obj_t *ch) {
|
||||
// calculate the period, the prescaler and the match value
|
||||
uint32_t period_c;
|
||||
uint32_t match;
|
||||
@@ -262,7 +262,7 @@ STATIC void timer_channel_init (pyb_timer_channel_obj_t *ch) {
|
||||
/******************************************************************************/
|
||||
/* MicroPython bindings */
|
||||
|
||||
STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
pyb_timer_obj_t *tim = self_in;
|
||||
uint32_t mode = tim->config & 0xFF;
|
||||
|
||||
@@ -281,7 +281,7 @@ STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_
|
||||
mp_printf(print, "Timer(%u, mode=Timer.%q)", tim->id, mode_qst);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *tim, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *tim, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT, },
|
||||
{ MP_QSTR_width, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 16} },
|
||||
@@ -319,7 +319,7 @@ error:
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
@@ -342,19 +342,19 @@ STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, siz
|
||||
return (mp_obj_t)tim;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pyb_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
return pyb_timer_init_helper(args[0], n_args - 1, args + 1, kw_args);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_init_obj, 1, pyb_timer_init);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_init_obj, 1, pyb_timer_init);
|
||||
|
||||
STATIC mp_obj_t pyb_timer_deinit(mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_timer_deinit(mp_obj_t self_in) {
|
||||
pyb_timer_obj_t *self = self_in;
|
||||
timer_disable(self);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit);
|
||||
|
||||
STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_period, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
|
||||
@@ -438,9 +438,9 @@ STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_ma
|
||||
error:
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_channel_obj, 2, pyb_timer_channel);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_channel_obj, 2, pyb_timer_channel);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = {
|
||||
// instance methods
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_timer_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_timer_deinit_obj) },
|
||||
@@ -457,7 +457,7 @@ STATIC const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_TIMEOUT), MP_ROM_INT(PYBTIMER_TIMEOUT_TRIGGER) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_MATCH), MP_ROM_INT(PYBTIMER_MATCH_TRIGGER) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_timer_locals_dict, pyb_timer_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_timer_locals_dict, pyb_timer_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_timer_type,
|
||||
@@ -468,14 +468,14 @@ MP_DEFINE_CONST_OBJ_TYPE(
|
||||
locals_dict, &pyb_timer_locals_dict
|
||||
);
|
||||
|
||||
STATIC const mp_irq_methods_t pyb_timer_channel_irq_methods = {
|
||||
static const mp_irq_methods_t pyb_timer_channel_irq_methods = {
|
||||
.init = pyb_timer_channel_irq,
|
||||
.enable = pyb_timer_channel_irq_enable,
|
||||
.disable = pyb_timer_channel_irq_disable,
|
||||
.flags = pyb_timer_channel_irq_flags,
|
||||
};
|
||||
|
||||
STATIC void TIMERGenericIntHandler(uint32_t timer, uint16_t channel) {
|
||||
static void TIMERGenericIntHandler(uint32_t timer, uint16_t channel) {
|
||||
pyb_timer_channel_obj_t *self;
|
||||
uint32_t status;
|
||||
if ((self = pyb_timer_channel_find(timer, channel))) {
|
||||
@@ -485,39 +485,39 @@ STATIC void TIMERGenericIntHandler(uint32_t timer, uint16_t channel) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void TIMER0AIntHandler(void) {
|
||||
static void TIMER0AIntHandler(void) {
|
||||
TIMERGenericIntHandler(TIMERA0_BASE, TIMER_A);
|
||||
}
|
||||
|
||||
STATIC void TIMER0BIntHandler(void) {
|
||||
static void TIMER0BIntHandler(void) {
|
||||
TIMERGenericIntHandler(TIMERA0_BASE, TIMER_B);
|
||||
}
|
||||
|
||||
STATIC void TIMER1AIntHandler(void) {
|
||||
static void TIMER1AIntHandler(void) {
|
||||
TIMERGenericIntHandler(TIMERA1_BASE, TIMER_A);
|
||||
}
|
||||
|
||||
STATIC void TIMER1BIntHandler(void) {
|
||||
static void TIMER1BIntHandler(void) {
|
||||
TIMERGenericIntHandler(TIMERA1_BASE, TIMER_B);
|
||||
}
|
||||
|
||||
STATIC void TIMER2AIntHandler(void) {
|
||||
static void TIMER2AIntHandler(void) {
|
||||
TIMERGenericIntHandler(TIMERA2_BASE, TIMER_A);
|
||||
}
|
||||
|
||||
STATIC void TIMER2BIntHandler(void) {
|
||||
static void TIMER2BIntHandler(void) {
|
||||
TIMERGenericIntHandler(TIMERA2_BASE, TIMER_B);
|
||||
}
|
||||
|
||||
STATIC void TIMER3AIntHandler(void) {
|
||||
static void TIMER3AIntHandler(void) {
|
||||
TIMERGenericIntHandler(TIMERA3_BASE, TIMER_A);
|
||||
}
|
||||
|
||||
STATIC void TIMER3BIntHandler(void) {
|
||||
static void TIMER3BIntHandler(void) {
|
||||
TIMERGenericIntHandler(TIMERA3_BASE, TIMER_B);
|
||||
}
|
||||
|
||||
STATIC void pyb_timer_channel_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void pyb_timer_channel_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
pyb_timer_channel_obj_t *ch = self_in;
|
||||
char *ch_id = "AB";
|
||||
// timer channel
|
||||
@@ -548,7 +548,7 @@ STATIC void pyb_timer_channel_print(const mp_print_t *print, mp_obj_t self_in, m
|
||||
mp_printf(print, ")");
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pyb_timer_channel_freq(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_timer_channel_freq(size_t n_args, const mp_obj_t *args) {
|
||||
pyb_timer_channel_obj_t *ch = args[0];
|
||||
if (n_args == 1) {
|
||||
// get
|
||||
@@ -565,9 +565,9 @@ STATIC mp_obj_t pyb_timer_channel_freq(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_freq_obj, 1, 2, pyb_timer_channel_freq);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_freq_obj, 1, 2, pyb_timer_channel_freq);
|
||||
|
||||
STATIC mp_obj_t pyb_timer_channel_period(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_timer_channel_period(size_t n_args, const mp_obj_t *args) {
|
||||
pyb_timer_channel_obj_t *ch = args[0];
|
||||
if (n_args == 1) {
|
||||
// get
|
||||
@@ -584,9 +584,9 @@ STATIC mp_obj_t pyb_timer_channel_period(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_period_obj, 1, 2, pyb_timer_channel_period);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_period_obj, 1, 2, pyb_timer_channel_period);
|
||||
|
||||
STATIC mp_obj_t pyb_timer_channel_duty_cycle(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pyb_timer_channel_duty_cycle(size_t n_args, const mp_obj_t *args) {
|
||||
pyb_timer_channel_obj_t *ch = args[0];
|
||||
if (n_args == 1) {
|
||||
// get
|
||||
@@ -608,9 +608,9 @@ STATIC mp_obj_t pyb_timer_channel_duty_cycle(size_t n_args, const mp_obj_t *args
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_duty_cycle_obj, 1, 3, pyb_timer_channel_duty_cycle);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_duty_cycle_obj, 1, 3, pyb_timer_channel_duty_cycle);
|
||||
|
||||
STATIC mp_obj_t pyb_timer_channel_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_timer_channel_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_arg_val_t args[mp_irq_INIT_NUM_ARGS];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mp_irq_INIT_NUM_ARGS, mp_irq_init_args, args);
|
||||
pyb_timer_channel_obj_t *ch = pos_args[0];
|
||||
@@ -711,18 +711,18 @@ STATIC mp_obj_t pyb_timer_channel_irq(size_t n_args, const mp_obj_t *pos_args, m
|
||||
invalid_args:
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_channel_irq_obj, 1, pyb_timer_channel_irq);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_channel_irq_obj, 1, pyb_timer_channel_irq);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_timer_channel_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_timer_channel_locals_dict_table[] = {
|
||||
// instance methods
|
||||
{ MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&pyb_timer_channel_freq_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_period), MP_ROM_PTR(&pyb_timer_channel_period_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_duty_cycle), MP_ROM_PTR(&pyb_timer_channel_duty_cycle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&pyb_timer_channel_irq_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_timer_channel_locals_dict, pyb_timer_channel_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_timer_channel_locals_dict, pyb_timer_channel_locals_dict_table);
|
||||
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
static MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pyb_timer_channel_type,
|
||||
MP_QSTR_TimerChannel,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
|
||||
@@ -76,15 +76,15 @@
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC void uart_init (pyb_uart_obj_t *self);
|
||||
STATIC bool uart_rx_wait (pyb_uart_obj_t *self);
|
||||
STATIC void uart_check_init(pyb_uart_obj_t *self);
|
||||
STATIC mp_obj_t uart_irq_new (pyb_uart_obj_t *self, byte trigger, mp_int_t priority, mp_obj_t handler);
|
||||
STATIC void UARTGenericIntHandler(uint32_t uart_id);
|
||||
STATIC void UART0IntHandler(void);
|
||||
STATIC void UART1IntHandler(void);
|
||||
STATIC void uart_irq_enable (mp_obj_t self_in);
|
||||
STATIC void uart_irq_disable (mp_obj_t self_in);
|
||||
static void uart_init (pyb_uart_obj_t *self);
|
||||
static bool uart_rx_wait (pyb_uart_obj_t *self);
|
||||
static void uart_check_init(pyb_uart_obj_t *self);
|
||||
static mp_obj_t uart_irq_new (pyb_uart_obj_t *self, byte trigger, mp_int_t priority, mp_obj_t handler);
|
||||
static void UARTGenericIntHandler(uint32_t uart_id);
|
||||
static void UART0IntHandler(void);
|
||||
static void UART1IntHandler(void);
|
||||
static void uart_irq_enable (mp_obj_t self_in);
|
||||
static void uart_irq_disable (mp_obj_t self_in);
|
||||
|
||||
/******************************************************************************
|
||||
DEFINE PRIVATE TYPES
|
||||
@@ -108,11 +108,11 @@ struct _pyb_uart_obj_t {
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE DATA
|
||||
******************************************************************************/
|
||||
STATIC pyb_uart_obj_t pyb_uart_obj[PYB_NUM_UARTS] = { {.reg = UARTA0_BASE, .baudrate = 0, .read_buf = NULL, .peripheral = PRCM_UARTA0},
|
||||
static pyb_uart_obj_t pyb_uart_obj[PYB_NUM_UARTS] = { {.reg = UARTA0_BASE, .baudrate = 0, .read_buf = NULL, .peripheral = PRCM_UARTA0},
|
||||
{.reg = UARTA1_BASE, .baudrate = 0, .read_buf = NULL, .peripheral = PRCM_UARTA1} };
|
||||
STATIC const mp_irq_methods_t uart_irq_methods;
|
||||
static const mp_irq_methods_t uart_irq_methods;
|
||||
|
||||
STATIC const mp_obj_t pyb_uart_def_pin[PYB_NUM_UARTS][2] = { {&pin_GP1, &pin_GP2}, {&pin_GP3, &pin_GP4} };
|
||||
static const mp_obj_t pyb_uart_def_pin[PYB_NUM_UARTS][2] = { {&pin_GP1, &pin_GP2}, {&pin_GP3, &pin_GP4} };
|
||||
|
||||
/******************************************************************************
|
||||
DEFINE PUBLIC FUNCTIONS
|
||||
@@ -168,7 +168,7 @@ bool uart_tx_strn(pyb_uart_obj_t *self, const char *str, uint len) {
|
||||
DEFINE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
// assumes init parameters have been set up correctly
|
||||
STATIC void uart_init (pyb_uart_obj_t *self) {
|
||||
static void uart_init (pyb_uart_obj_t *self) {
|
||||
// Enable the peripheral clock
|
||||
MAP_PRCMPeripheralClkEnable(self->peripheral, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
|
||||
|
||||
@@ -198,7 +198,7 @@ STATIC void uart_init (pyb_uart_obj_t *self) {
|
||||
// Waits at most timeout microseconds for at least 1 char to become ready for
|
||||
// reading (from buf or for direct reading).
|
||||
// Returns true if something available, false if not.
|
||||
STATIC bool uart_rx_wait (pyb_uart_obj_t *self) {
|
||||
static bool uart_rx_wait (pyb_uart_obj_t *self) {
|
||||
int timeout = PYBUART_RX_TIMEOUT_US(self->baudrate);
|
||||
for ( ; ; ) {
|
||||
if (uart_rx_any(self)) {
|
||||
@@ -214,7 +214,7 @@ STATIC bool uart_rx_wait (pyb_uart_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uart_irq_new (pyb_uart_obj_t *self, byte trigger, mp_int_t priority, mp_obj_t handler) {
|
||||
static mp_obj_t uart_irq_new (pyb_uart_obj_t *self, byte trigger, mp_int_t priority, mp_obj_t handler) {
|
||||
// disable the uart interrupts before updating anything
|
||||
uart_irq_disable (self);
|
||||
|
||||
@@ -235,7 +235,7 @@ STATIC mp_obj_t uart_irq_new (pyb_uart_obj_t *self, byte trigger, mp_int_t prior
|
||||
return _irq;
|
||||
}
|
||||
|
||||
STATIC void UARTGenericIntHandler(uint32_t uart_id) {
|
||||
static void UARTGenericIntHandler(uint32_t uart_id) {
|
||||
pyb_uart_obj_t *self;
|
||||
uint32_t status;
|
||||
|
||||
@@ -272,22 +272,22 @@ STATIC void UARTGenericIntHandler(uint32_t uart_id) {
|
||||
self->irq_flags = 0;
|
||||
}
|
||||
|
||||
STATIC void uart_check_init(pyb_uart_obj_t *self) {
|
||||
static void uart_check_init(pyb_uart_obj_t *self) {
|
||||
// not initialized
|
||||
if (!self->baudrate) {
|
||||
mp_raise_OSError(MP_EPERM);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void UART0IntHandler(void) {
|
||||
static void UART0IntHandler(void) {
|
||||
UARTGenericIntHandler(0);
|
||||
}
|
||||
|
||||
STATIC void UART1IntHandler(void) {
|
||||
static void UART1IntHandler(void) {
|
||||
UARTGenericIntHandler(1);
|
||||
}
|
||||
|
||||
STATIC void uart_irq_enable (mp_obj_t self_in) {
|
||||
static void uart_irq_enable (mp_obj_t self_in) {
|
||||
pyb_uart_obj_t *self = self_in;
|
||||
// check for any of the rx interrupt types
|
||||
if (self->irq_trigger & (UART_TRIGGER_RX_ANY | UART_TRIGGER_RX_HALF | UART_TRIGGER_RX_FULL)) {
|
||||
@@ -297,12 +297,12 @@ STATIC void uart_irq_enable (mp_obj_t self_in) {
|
||||
self->irq_enabled = true;
|
||||
}
|
||||
|
||||
STATIC void uart_irq_disable (mp_obj_t self_in) {
|
||||
static void uart_irq_disable (mp_obj_t self_in) {
|
||||
pyb_uart_obj_t *self = self_in;
|
||||
self->irq_enabled = false;
|
||||
}
|
||||
|
||||
STATIC int uart_irq_flags (mp_obj_t self_in) {
|
||||
static int uart_irq_flags (mp_obj_t self_in) {
|
||||
pyb_uart_obj_t *self = self_in;
|
||||
return self->irq_flags;
|
||||
}
|
||||
@@ -310,7 +310,7 @@ STATIC int uart_irq_flags (mp_obj_t self_in) {
|
||||
/******************************************************************************/
|
||||
/* MicroPython bindings */
|
||||
|
||||
STATIC void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
pyb_uart_obj_t *self = self_in;
|
||||
if (self->baudrate > 0) {
|
||||
mp_printf(print, "UART(%u, baudrate=%u, bits=", self->uart_id, self->baudrate);
|
||||
@@ -342,7 +342,7 @@ STATIC void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_k
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, const mp_arg_val_t *args) {
|
||||
static mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, const mp_arg_val_t *args) {
|
||||
// get the baudrate
|
||||
if (args[0].u_int <= 0) {
|
||||
goto error;
|
||||
@@ -433,7 +433,7 @@ error:
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
|
||||
}
|
||||
|
||||
STATIC const mp_arg_t pyb_uart_init_args[] = {
|
||||
static const mp_arg_t pyb_uart_init_args[] = {
|
||||
{ MP_QSTR_id, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
{ MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 9600} },
|
||||
{ MP_QSTR_bits, MP_ARG_INT, {.u_int = 8} },
|
||||
@@ -441,7 +441,7 @@ STATIC const mp_arg_t pyb_uart_init_args[] = {
|
||||
{ MP_QSTR_stop, MP_ARG_INT, {.u_int = 1} },
|
||||
{ MP_QSTR_pins, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
};
|
||||
STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
// parse args
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
|
||||
@@ -484,15 +484,15 @@ STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size
|
||||
return self;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pyb_uart_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_uart_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
// parse args
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_uart_init_args) - 1];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_uart_init_args[1], args);
|
||||
return pyb_uart_init_helper(pos_args[0], args);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_uart_init_obj, 1, pyb_uart_init);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_uart_init_obj, 1, pyb_uart_init);
|
||||
|
||||
STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_uart_deinit(mp_obj_t self_in) {
|
||||
pyb_uart_obj_t *self = self_in;
|
||||
|
||||
// unregister it with the sleep module
|
||||
@@ -506,16 +506,16 @@ STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) {
|
||||
MAP_PRCMPeripheralClkDisable(self->peripheral, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_deinit_obj, pyb_uart_deinit);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_deinit_obj, pyb_uart_deinit);
|
||||
|
||||
STATIC mp_obj_t pyb_uart_any(mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_uart_any(mp_obj_t self_in) {
|
||||
pyb_uart_obj_t *self = self_in;
|
||||
uart_check_init(self);
|
||||
return mp_obj_new_int(uart_rx_any(self));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_any_obj, pyb_uart_any);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_any_obj, pyb_uart_any);
|
||||
|
||||
STATIC mp_obj_t pyb_uart_sendbreak(mp_obj_t self_in) {
|
||||
static mp_obj_t pyb_uart_sendbreak(mp_obj_t self_in) {
|
||||
pyb_uart_obj_t *self = self_in;
|
||||
uart_check_init(self);
|
||||
// send a break signal for at least 2 complete frames
|
||||
@@ -524,10 +524,10 @@ STATIC mp_obj_t pyb_uart_sendbreak(mp_obj_t self_in) {
|
||||
MAP_UARTBreakCtl(self->reg, false);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_sendbreak_obj, pyb_uart_sendbreak);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_sendbreak_obj, pyb_uart_sendbreak);
|
||||
|
||||
/// \method irq(trigger, priority, handler, wake)
|
||||
STATIC mp_obj_t pyb_uart_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pyb_uart_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_arg_val_t args[mp_irq_INIT_NUM_ARGS];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mp_irq_INIT_NUM_ARGS, mp_irq_init_args, args);
|
||||
|
||||
@@ -556,9 +556,9 @@ STATIC mp_obj_t pyb_uart_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
|
||||
invalid_args:
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value"));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_uart_irq_obj, 1, pyb_uart_irq);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_uart_irq_obj, 1, pyb_uart_irq);
|
||||
|
||||
STATIC mp_obj_t machine_uart_txdone(mp_obj_t self_in) {
|
||||
static mp_obj_t machine_uart_txdone(mp_obj_t self_in) {
|
||||
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
if (MAP_UARTBusy(self->reg) == false) {
|
||||
@@ -567,9 +567,9 @@ STATIC mp_obj_t machine_uart_txdone(mp_obj_t self_in) {
|
||||
return mp_const_false;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_txdone_obj, machine_uart_txdone);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_txdone_obj, machine_uart_txdone);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_uart_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pyb_uart_locals_dict_table[] = {
|
||||
// instance methods
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_uart_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_uart_deinit_obj) },
|
||||
@@ -592,9 +592,9 @@ STATIC const mp_rom_map_elem_t pyb_uart_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_RX_ANY), MP_ROM_INT(UART_TRIGGER_RX_ANY) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_uart_locals_dict, pyb_uart_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pyb_uart_locals_dict, pyb_uart_locals_dict_table);
|
||||
|
||||
STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) {
|
||||
static mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) {
|
||||
pyb_uart_obj_t *self = self_in;
|
||||
byte *buf = buf_in;
|
||||
uart_check_init(self);
|
||||
@@ -622,7 +622,7 @@ STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, i
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) {
|
||||
static mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) {
|
||||
pyb_uart_obj_t *self = self_in;
|
||||
const char *buf = buf_in;
|
||||
uart_check_init(self);
|
||||
@@ -634,7 +634,7 @@ STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t
|
||||
return size;
|
||||
}
|
||||
|
||||
STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
|
||||
static mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
|
||||
pyb_uart_obj_t *self = self_in;
|
||||
mp_uint_t ret;
|
||||
uart_check_init(self);
|
||||
@@ -670,14 +670,14 @@ STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t a
|
||||
return ret;
|
||||
}
|
||||
|
||||
STATIC const mp_stream_p_t uart_stream_p = {
|
||||
static const mp_stream_p_t uart_stream_p = {
|
||||
.read = pyb_uart_read,
|
||||
.write = pyb_uart_write,
|
||||
.ioctl = pyb_uart_ioctl,
|
||||
.is_text = false,
|
||||
};
|
||||
|
||||
STATIC const mp_irq_methods_t uart_irq_methods = {
|
||||
static const mp_irq_methods_t uart_irq_methods = {
|
||||
.init = pyb_uart_irq,
|
||||
.enable = uart_irq_enable,
|
||||
.disable = uart_irq_disable,
|
||||
|
||||
@@ -80,10 +80,10 @@
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC void mptask_pre_init(void);
|
||||
STATIC void mptask_init_sflash_filesystem(void);
|
||||
STATIC void mptask_enter_ap_mode(void);
|
||||
STATIC void mptask_create_main_py(void);
|
||||
static void mptask_pre_init(void);
|
||||
static void mptask_init_sflash_filesystem(void);
|
||||
static void mptask_enter_ap_mode(void);
|
||||
static void mptask_create_main_py(void);
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PUBLIC DATA
|
||||
@@ -256,7 +256,7 @@ soft_reset_exit:
|
||||
DEFINE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
__attribute__ ((section(".boot")))
|
||||
STATIC void mptask_pre_init(void) {
|
||||
static void mptask_pre_init(void) {
|
||||
// this one only makes sense after a poweron reset
|
||||
pyb_rtc_pre_init();
|
||||
|
||||
@@ -288,7 +288,7 @@ STATIC void mptask_pre_init(void) {
|
||||
ASSERT(svTaskHandle != NULL);
|
||||
}
|
||||
|
||||
STATIC void mptask_init_sflash_filesystem(void) {
|
||||
static void mptask_init_sflash_filesystem(void) {
|
||||
FILINFO fno;
|
||||
|
||||
// Initialise the local flash filesystem.
|
||||
@@ -371,7 +371,7 @@ STATIC void mptask_init_sflash_filesystem(void) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void mptask_enter_ap_mode(void) {
|
||||
static void mptask_enter_ap_mode(void) {
|
||||
// append the mac only if it's not the first boot
|
||||
bool add_mac = !PRCMGetSpecialBit(PRCM_FIRST_BOOT_BIT);
|
||||
// enable simplelink in ap mode (use the MAC address to make the ssid unique)
|
||||
@@ -380,7 +380,7 @@ STATIC void mptask_enter_ap_mode(void) {
|
||||
MICROPY_PORT_WLAN_AP_CHANNEL, ANTENNA_TYPE_INTERNAL, add_mac);
|
||||
}
|
||||
|
||||
STATIC void mptask_create_main_py(void) {
|
||||
static void mptask_create_main_py(void) {
|
||||
// create empty main.py
|
||||
FIL fp;
|
||||
f_open(&sflash_vfs_fat->fatfs, &fp, "/main.py", FA_WRITE | FA_CREATE_ALWAYS);
|
||||
|
||||
@@ -46,9 +46,9 @@ typedef struct _mp_thread_t {
|
||||
} mp_thread_t;
|
||||
|
||||
// the mutex controls access to the linked list
|
||||
STATIC mp_thread_mutex_t thread_mutex;
|
||||
STATIC mp_thread_t thread_entry0;
|
||||
STATIC mp_thread_t *thread; // root pointer, handled bp mp_thread_gc_others
|
||||
static mp_thread_mutex_t thread_mutex;
|
||||
static mp_thread_t thread_entry0;
|
||||
static mp_thread_t *thread; // root pointer, handled bp mp_thread_gc_others
|
||||
|
||||
void mp_thread_init(void) {
|
||||
mp_thread_mutex_init(&thread_mutex);
|
||||
@@ -103,9 +103,9 @@ void mp_thread_start(void) {
|
||||
mp_thread_mutex_unlock(&thread_mutex);
|
||||
}
|
||||
|
||||
STATIC void *(*ext_thread_entry)(void *) = NULL;
|
||||
static void *(*ext_thread_entry)(void *) = NULL;
|
||||
|
||||
STATIC void freertos_entry(void *arg) {
|
||||
static void freertos_entry(void *arg) {
|
||||
if (ext_thread_entry) {
|
||||
ext_thread_entry(arg);
|
||||
}
|
||||
|
||||
@@ -56,12 +56,12 @@ static uint32_t s_seed;
|
||||
/******************************************************************************
|
||||
* LOCAL FUNCTION DECLARATIONS
|
||||
******************************************************************************/
|
||||
STATIC uint32_t lfsr (uint32_t input);
|
||||
static uint32_t lfsr (uint32_t input);
|
||||
|
||||
/******************************************************************************
|
||||
* PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC uint32_t lfsr (uint32_t input) {
|
||||
static uint32_t lfsr (uint32_t input) {
|
||||
assert( input != 0 );
|
||||
return (input >> 1) ^ (-(input & 0x01) & 0x00E10000);
|
||||
}
|
||||
@@ -69,7 +69,7 @@ STATIC uint32_t lfsr (uint32_t input) {
|
||||
/******************************************************************************/
|
||||
// MicroPython bindings;
|
||||
|
||||
STATIC mp_obj_t machine_rng_get(void) {
|
||||
static mp_obj_t machine_rng_get(void) {
|
||||
return mp_obj_new_int(rng_get());
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_rng_get_obj, machine_rng_get);
|
||||
|
||||
Reference in New Issue
Block a user