aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cc3200/boards/cc3200_prefix.c1
-rw-r--r--cc3200/misc/mpcallback.c30
-rw-r--r--cc3200/misc/mpcallback.h1
-rw-r--r--cc3200/mods/modwlan.c14
-rw-r--r--cc3200/mods/pybpin.c18
-rw-r--r--cc3200/mods/pybpin.h1
-rw-r--r--cc3200/mods/pybrtc.c15
7 files changed, 36 insertions, 44 deletions
diff --git a/cc3200/boards/cc3200_prefix.c b/cc3200/boards/cc3200_prefix.c
index 394f8bfa6..26afba9a2 100644
--- a/cc3200/boards/cc3200_prefix.c
+++ b/cc3200/boards/cc3200_prefix.c
@@ -43,7 +43,6 @@
{ \
{ &pin_type }, \
.name = MP_QSTR_ ## p_pin_name, \
- .callback = mp_const_none, \
.port = PORT_A ## p_port, \
.type = PIN_TYPE_STD, \
.bit = (p_bit), \
diff --git a/cc3200/misc/mpcallback.c b/cc3200/misc/mpcallback.c
index edf3673b5..fa1d55f4c 100644
--- a/cc3200/misc/mpcallback.c
+++ b/cc3200/misc/mpcallback.c
@@ -38,11 +38,6 @@
/******************************************************************************
- DECLARE PRIVATE FUNCTIONS
- ******************************************************************************/
-STATIC mpcallback_obj_t *mpcallback_find (mp_obj_t parent);
-
-/******************************************************************************
DEFINE PUBLIC DATA
******************************************************************************/
const mp_arg_t mpcallback_init_args[] = {
@@ -73,6 +68,17 @@ mp_obj_t mpcallback_new (mp_obj_t parent, mp_obj_t handler, const mp_cb_methods_
return self;
}
+mpcallback_obj_t *mpcallback_find (mp_obj_t parent) {
+ for (mp_uint_t i = 0; i < MP_STATE_PORT(mpcallback_obj_list).len; i++) {
+ // search for the object and then remove it
+ mpcallback_obj_t *callback_obj = ((mpcallback_obj_t *)(MP_STATE_PORT(mpcallback_obj_list).items[i]));
+ if (callback_obj->parent == parent) {
+ return callback_obj;
+ }
+ }
+ return NULL;
+}
+
void mpcallback_remove (const mp_obj_t parent) {
mpcallback_obj_t *callback_obj;
if ((callback_obj = mpcallback_find(parent))) {
@@ -132,20 +138,6 @@ void mpcallback_handler (mp_obj_t self_in) {
}
}
-/******************************************************************************
- DEFINE PRIVATE FUNCTIONS
- ******************************************************************************/
-STATIC mpcallback_obj_t *mpcallback_find (mp_obj_t parent) {
- for (mp_uint_t i = 0; i < MP_STATE_PORT(mpcallback_obj_list).len; i++) {
- // search for the object and then remove it
- mpcallback_obj_t *callback_obj = ((mpcallback_obj_t *)(MP_STATE_PORT(mpcallback_obj_list).items[i]));
- if (callback_obj->parent == parent) {
- return callback_obj;
- }
- }
- return NULL;
-}
-
/******************************************************************************/
// Micro Python bindings
diff --git a/cc3200/misc/mpcallback.h b/cc3200/misc/mpcallback.h
index e0a9fc6a9..cadc73bad 100644
--- a/cc3200/misc/mpcallback.h
+++ b/cc3200/misc/mpcallback.h
@@ -62,6 +62,7 @@ extern const mp_obj_type_t pyb_callback_type;
******************************************************************************/
void mpcallback_init0 (void);
mp_obj_t mpcallback_new (mp_obj_t parent, mp_obj_t handler, const mp_cb_methods_t *methods);
+mpcallback_obj_t *mpcallback_find (mp_obj_t parent);
void mpcallback_remove (const mp_obj_t parent);
void mpcallback_handler (mp_obj_t self_in);
uint mpcallback_translate_priority (uint priority);
diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c
index 154d0aa54..8128ab39e 100644
--- a/cc3200/mods/modwlan.c
+++ b/cc3200/mods/modwlan.c
@@ -79,7 +79,6 @@ typedef enum{
typedef struct _wlan_obj_t {
mp_obj_base_t base;
- mp_obj_t callback;
SlWlanMode_t mode;
uint32_t status;
@@ -151,7 +150,6 @@ typedef struct _wlan_obj_t {
DECLARE PRIVATE DATA
******************************************************************************/
STATIC wlan_obj_t wlan_obj = {
- .callback = mp_const_none,
.mode = -1,
.status = 0,
.ip = 0,
@@ -646,7 +644,8 @@ STATIC mp_obj_t wlan_init_helper(mp_uint_t n_args, const mp_obj_t *pos_args, mp_
}
STATIC void wlan_lpds_callback_enable (mp_obj_t self_in) {
- pybsleep_set_wlan_lpds_callback (wlan_obj.callback);
+ mp_obj_t _callback = mpcallback_find(self_in);
+ pybsleep_set_wlan_lpds_callback (_callback);
}
STATIC void wlan_lpds_callback_disable (mp_obj_t self_in) {
@@ -922,8 +921,9 @@ STATIC mp_obj_t wlan_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp_ma
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mpcallback_INIT_NUM_ARGS, mpcallback_init_args, args);
wlan_obj_t *self = pos_args[0];
+ mp_obj_t _callback = mpcallback_find(self);
// check if any parameters were passed
- if (kw_args->used > 0) {
+ if (kw_args->used > 0 || _callback == mp_const_none) {
// check the power mode
if (args[4].u_int != PYB_PWR_MODE_LPDS) {
// throw an exception since WLAN only supports LPDS mode
@@ -931,12 +931,12 @@ STATIC mp_obj_t wlan_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp_ma
}
// create the callback
- self->callback = mpcallback_new (self, args[1].u_obj, &wlan_cb_methods);
+ _callback = mpcallback_new (self, args[1].u_obj, &wlan_cb_methods);
// enable network wakeup
- pybsleep_set_wlan_lpds_callback (self->callback);
+ pybsleep_set_wlan_lpds_callback (_callback);
}
- return self->callback;
+ return _callback;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_callback_obj, 1, wlan_callback);
diff --git a/cc3200/mods/pybpin.c b/cc3200/mods/pybpin.c
index ca00d765e..50727154e 100644
--- a/cc3200/mods/pybpin.c
+++ b/cc3200/mods/pybpin.c
@@ -616,7 +616,8 @@ STATIC mp_obj_t pin_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map
pin_obj_t *self = pos_args[0];
// check if any parameters were passed
- if (kw_args->used > 0 || self->callback == mp_const_none) {
+ mp_obj_t _callback = mpcallback_find(self);
+ if (kw_args->used > 0 || _callback == mp_const_none) {
// convert the priority to the correct value
uint priority = mpcallback_translate_priority (args[2].u_int);
// verify the interrupt mode
@@ -720,15 +721,15 @@ STATIC mp_obj_t pin_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map
}
// all checks have passed, now we can create the callback
- self->callback = mpcallback_new (self, args[1].u_obj, &pin_cb_methods);
+ _callback = mpcallback_new (self, args[1].u_obj, &pin_cb_methods);
if (pwrmode & PYB_PWR_MODE_LPDS) {
- pybsleep_set_gpio_lpds_callback (self->callback);
+ pybsleep_set_gpio_lpds_callback (_callback);
}
// enable the interrupt just before leaving
pin_extint_enable(self);
}
- return self->callback;
+ return _callback;
invalid_args:
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
@@ -824,12 +825,13 @@ STATIC void GPIOA3IntHandler (void) {
// common interrupt handler
STATIC void EXTI_Handler(uint port) {
- pin_obj_t *self;
uint32_t bit = MAP_GPIOIntStatus(port, true);
-
MAP_GPIOIntClear(port, bit);
- if (NULL != (self = (pin_obj_t *)pin_find_pin_by_port_bit(&pin_cpu_pins_locals_dict, port, bit))) {
- mpcallback_handler(self->callback);
+
+ pin_obj_t *self = (pin_obj_t *)pin_find_pin_by_port_bit(&pin_cpu_pins_locals_dict, port, bit);
+ mp_obj_t _callback = mpcallback_find(self);
+ if (_callback) {
+ mpcallback_handler(_callback);
}
}
diff --git a/cc3200/mods/pybpin.h b/cc3200/mods/pybpin.h
index 9cc0243d1..39ce5a4e5 100644
--- a/cc3200/mods/pybpin.h
+++ b/cc3200/mods/pybpin.h
@@ -35,7 +35,6 @@
typedef struct {
const mp_obj_base_t base;
const qstr name;
- mp_obj_t callback;
const uint32_t port;
uint16_t type;
const uint8_t bit;
diff --git a/cc3200/mods/pybrtc.c b/cc3200/mods/pybrtc.c
index b71a06cbf..548d4bf4e 100644
--- a/cc3200/mods/pybrtc.c
+++ b/cc3200/mods/pybrtc.c
@@ -57,7 +57,6 @@
DECLARE TYPES
******************************************************************************/
typedef struct {
- mp_obj_t callback;
uint32_t alarm_sec;
uint16_t alarm_msec;
uint8_t pwrmode;
@@ -66,7 +65,7 @@ typedef struct {
/******************************************************************************
DECLARE PRIVATE DATA
******************************************************************************/
-STATIC pybrtc_data_t pybrtc_data = {.callback = mp_const_none};
+STATIC pybrtc_data_t pybrtc_data;
STATIC const mp_cb_methods_t pybrtc_cb_methods;
/******************************************************************************
@@ -159,7 +158,7 @@ mp_obj_t pyb_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) {
return mp_const_none;
}
}
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_datetime_obj, 1, 2, pyb_rtc_datetime);
+STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_datetime_obj, 1, 2, pyb_rtc_datetime);
/// \method callback(handler, intmode, value, priority, pwrmode)
/// Creates a callback object associated with the real time clock
@@ -170,7 +169,8 @@ STATIC mp_obj_t pyb_rtc_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mpcallback_INIT_NUM_ARGS, mpcallback_init_args, args);
// check if any parameters were passed
- if (kw_args->used > 0 || pybrtc_data.callback == mp_const_none) {
+ mp_obj_t _callback = mpcallback_find((mp_obj_t)&pyb_rtc_obj);
+ if (kw_args->used > 0 || _callback == mp_const_none) {
uint32_t seconds;
uint16_t mseconds;
// get the seconds and the milliseconds from the RTC
@@ -195,11 +195,10 @@ STATIC mp_obj_t pyb_rtc_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp
pybrtc_data.alarm_msec = mseconds;
pybrtc_data.pwrmode = args[4].u_int;
- // create the callback
- pybrtc_data.callback = mpcallback_new ((mp_obj_t)&pyb_rtc_obj, args[1].u_obj, &pybrtc_cb_methods);
+ // create the new callback
+ _callback = mpcallback_new ((mp_obj_t)&pyb_rtc_obj, args[1].u_obj, &pybrtc_cb_methods);
}
-
- return pybrtc_data.callback;
+ return _callback;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_callback_obj, 1, pyb_rtc_callback);