Skip to content

Commit c92e6a4

Browse files
author
Daniel Campora
committed
cc3200: Rename pyb module to machine.
1 parent 0a7e4fa commit c92e6a4

35 files changed

+326
-347
lines changed

cc3200/application.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ APP_MISC_SRC_C = $(addprefix misc/,\
8585
)
8686

8787
APP_MODS_SRC_C = $(addprefix mods/,\
88+
modmachine.c \
8889
modnetwork.c \
8990
moduhashlib.c \
9091
modubinascii.c \
91-
modpyb.c \
9292
moduos.c \
9393
modusocket.c \
9494
modussl.c \
Lines changed: 71 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,23 @@ extern OsiTaskHandle xSimpleLinkSpawnTaskHndl;
7777
#endif
7878

7979

80-
/// \module pyb - functions related to the pyboard
80+
/// \module machine - functions related to the SoC
8181
///
82-
/// The `pyb` module contains specific functions related to the pyboard.
8382

84-
/// \function reset()
85-
/// Resets the pyboard in a manner similar to pushing the external
86-
/// reset button.
87-
STATIC mp_obj_t pyb_reset(void) {
83+
/******************************************************************************/
84+
// Micro Python bindings;
85+
86+
STATIC mp_obj_t machine_reset(void) {
8887
// disable wlan
8988
wlan_stop(SL_STOP_TIMEOUT_LONG);
9089
// reset the cpu and it's peripherals
9190
MAP_PRCMMCUReset(true);
9291
return mp_const_none;
9392
}
94-
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_reset_obj, pyb_reset);
93+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
9594

9695
#ifdef DEBUG
97-
/// \function info([dump_alloc_table])
98-
/// Print out some run time info which is helpful during development.
99-
STATIC mp_obj_t pyb_info(uint n_args, const mp_obj_t *args) {
96+
STATIC mp_obj_t machine_info(uint n_args, const mp_obj_t *args) {
10097
// FreeRTOS info
10198
{
10299
printf("---------------------------------------------\n");
@@ -119,46 +116,74 @@ STATIC mp_obj_t pyb_info(uint n_args, const mp_obj_t *args) {
119116

120117
return mp_const_none;
121118
}
122-
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_info_obj, 0, 1, pyb_info);
119+
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj, 0, 1, machine_info);
123120
#endif
124121

125-
/// \function freq()
126-
/// Returns the CPU frequency: (F_CPU).
127-
STATIC mp_obj_t pyb_freq(void) {
122+
STATIC mp_obj_t machine_freq(void) {
128123
mp_obj_t tuple[1] = {
129124
mp_obj_new_int(HAL_FCPU_HZ),
130125
};
131126
return mp_obj_new_tuple(1, tuple);
132127
}
133-
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_freq_obj, pyb_freq);
128+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_freq_obj, machine_freq);
134129

135-
/// \function unique_id()
136-
/// Returns a string of 6 bytes (48 bits), which is the unique ID for the MCU.
137-
STATIC mp_obj_t pyb_unique_id(void) {
130+
STATIC mp_obj_t machine_unique_id(void) {
138131
uint8_t mac[SL_BSSID_LENGTH];
139132
wlan_get_mac (mac);
140133
return mp_obj_new_bytes(mac, SL_BSSID_LENGTH);
141134
}
142-
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_unique_id_obj, pyb_unique_id);
135+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id);
136+
137+
STATIC mp_obj_t machine_idle(void) {
138+
__WFI();
139+
return mp_const_none;
140+
}
141+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_idle_obj, machine_idle);
142+
143+
STATIC mp_obj_t machine_sleep (void) {
144+
pyb_sleep_sleep();
145+
return mp_const_none;
146+
}
147+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_sleep_obj, machine_sleep);
148+
149+
STATIC mp_obj_t machine_deepsleep (void) {
150+
pyb_sleep_deepsleep();
151+
return mp_const_none;
152+
}
153+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_deepsleep_obj, machine_deepsleep);
154+
155+
STATIC mp_obj_t machine_reset_cause (void) {
156+
return mp_obj_new_int(pyb_sleep_get_reset_cause());
157+
}
158+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause);
143159

144-
MP_DECLARE_CONST_FUN_OBJ(pyb_main_obj); // defined in main.c
160+
STATIC mp_obj_t machine_wake_reason (void) {
161+
return mp_obj_new_int(pyb_sleep_get_wake_reason());
162+
}
163+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_wake_reason_obj, machine_wake_reason);
164+
165+
MP_DECLARE_CONST_FUN_OBJ(machine_main_obj); // defined in main.c
145166

146-
STATIC const mp_map_elem_t pyb_module_globals_table[] = {
147-
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_pyb) },
167+
STATIC const mp_map_elem_t machine_module_globals_table[] = {
168+
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_machine) },
148169

149-
{ MP_OBJ_NEW_QSTR(MP_QSTR_reset), (mp_obj_t)&pyb_reset_obj },
170+
{ MP_OBJ_NEW_QSTR(MP_QSTR_reset), (mp_obj_t)&machine_reset_obj },
150171
#ifdef DEBUG
151-
{ MP_OBJ_NEW_QSTR(MP_QSTR_info), (mp_obj_t)&pyb_info_obj },
172+
{ MP_OBJ_NEW_QSTR(MP_QSTR_info), (mp_obj_t)&machine_info_obj },
152173
#endif
153-
{ MP_OBJ_NEW_QSTR(MP_QSTR_freq), (mp_obj_t)&pyb_freq_obj },
154-
{ MP_OBJ_NEW_QSTR(MP_QSTR_unique_id), (mp_obj_t)&pyb_unique_id_obj },
174+
{ MP_OBJ_NEW_QSTR(MP_QSTR_freq), (mp_obj_t)&machine_freq_obj },
175+
{ MP_OBJ_NEW_QSTR(MP_QSTR_unique_id), (mp_obj_t)&machine_unique_id_obj },
176+
{ MP_OBJ_NEW_QSTR(MP_QSTR_main), (mp_obj_t)&machine_main_obj },
177+
{ MP_OBJ_NEW_QSTR(MP_QSTR_rng), (mp_obj_t)&machine_rng_get_obj },
178+
{ MP_OBJ_NEW_QSTR(MP_QSTR_idle), (mp_obj_t)&machine_idle_obj },
179+
{ MP_OBJ_NEW_QSTR(MP_QSTR_sleep), (mp_obj_t)&machine_sleep_obj },
180+
{ MP_OBJ_NEW_QSTR(MP_QSTR_deepsleep), (mp_obj_t)&machine_deepsleep_obj },
181+
{ MP_OBJ_NEW_QSTR(MP_QSTR_reset_cause), (mp_obj_t)&machine_reset_cause_obj },
182+
{ MP_OBJ_NEW_QSTR(MP_QSTR_wake_reason), (mp_obj_t)&machine_wake_reason_obj },
155183

156184
{ MP_OBJ_NEW_QSTR(MP_QSTR_disable_irq), (mp_obj_t)&pyb_disable_irq_obj },
157185
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable_irq), (mp_obj_t)&pyb_enable_irq_obj },
158186

159-
{ MP_OBJ_NEW_QSTR(MP_QSTR_main), (mp_obj_t)&pyb_main_obj },
160-
{ MP_OBJ_NEW_QSTR(MP_QSTR_rng), (mp_obj_t)&pyb_rng_get_obj },
161-
162187
{ MP_OBJ_NEW_QSTR(MP_QSTR_RTC), (mp_obj_t)&pyb_rtc_type },
163188
{ MP_OBJ_NEW_QSTR(MP_QSTR_Pin), (mp_obj_t)&pin_type },
164189
{ MP_OBJ_NEW_QSTR(MP_QSTR_ADC), (mp_obj_t)&pyb_adc_type },
@@ -167,15 +192,27 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
167192
{ MP_OBJ_NEW_QSTR(MP_QSTR_UART), (mp_obj_t)&pyb_uart_type },
168193
{ MP_OBJ_NEW_QSTR(MP_QSTR_Timer), (mp_obj_t)&pyb_timer_type },
169194
{ MP_OBJ_NEW_QSTR(MP_QSTR_WDT), (mp_obj_t)&pyb_wdt_type },
170-
{ MP_OBJ_NEW_QSTR(MP_QSTR_Sleep), (mp_obj_t)&pyb_sleep_obj },
171195
{ MP_OBJ_NEW_QSTR(MP_QSTR_HeartBeat), (mp_obj_t)&pyb_heartbeat_type },
172196
{ MP_OBJ_NEW_QSTR(MP_QSTR_SD), (mp_obj_t)&pyb_sd_type },
197+
198+
// class constants
199+
{ MP_OBJ_NEW_QSTR(MP_QSTR_IDLE), MP_OBJ_NEW_SMALL_INT(PYB_PWR_MODE_ACTIVE) },
200+
{ MP_OBJ_NEW_QSTR(MP_QSTR_SLEEP), MP_OBJ_NEW_SMALL_INT(PYB_PWR_MODE_LPDS) },
201+
{ MP_OBJ_NEW_QSTR(MP_QSTR_DEEPSLEEP), MP_OBJ_NEW_SMALL_INT(PYB_PWR_MODE_HIBERNATE) },
202+
{ MP_OBJ_NEW_QSTR(MP_QSTR_POWER_ON), MP_OBJ_NEW_SMALL_INT(PYB_SLP_PWRON_RESET) },
203+
{ MP_OBJ_NEW_QSTR(MP_QSTR_HARD_RESET), MP_OBJ_NEW_SMALL_INT(PYB_SLP_HARD_RESET) },
204+
{ MP_OBJ_NEW_QSTR(MP_QSTR_WDT_RESET), MP_OBJ_NEW_SMALL_INT(PYB_SLP_WDT_RESET) },
205+
{ MP_OBJ_NEW_QSTR(MP_QSTR_DEEPSLEEP_RESET), MP_OBJ_NEW_SMALL_INT(PYB_SLP_HIB_RESET) },
206+
{ MP_OBJ_NEW_QSTR(MP_QSTR_SOFT_RESET), MP_OBJ_NEW_SMALL_INT(PYB_SLP_SOFT_RESET) },
207+
{ MP_OBJ_NEW_QSTR(MP_QSTR_WLAN_WAKE), MP_OBJ_NEW_SMALL_INT(PYB_SLP_WAKED_BY_WLAN) },
208+
{ MP_OBJ_NEW_QSTR(MP_QSTR_PIN_WAKE), MP_OBJ_NEW_SMALL_INT(PYB_SLP_WAKED_BY_GPIO) },
209+
{ MP_OBJ_NEW_QSTR(MP_QSTR_RTC_WAKE), MP_OBJ_NEW_SMALL_INT(PYB_SLP_WAKED_BY_RTC) },
173210
};
174211

175-
STATIC MP_DEFINE_CONST_DICT(pyb_module_globals, pyb_module_globals_table);
212+
STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table);
176213

177-
const mp_obj_module_t pyb_module = {
214+
const mp_obj_module_t machine_module = {
178215
.base = { &mp_type_module },
179-
.name = MP_QSTR_pyb,
180-
.globals = (mp_obj_dict_t*)&pyb_module_globals,
216+
.name = MP_QSTR_machine,
217+
.globals = (mp_obj_dict_t*)&machine_module_globals,
181218
};

cc3200/mods/modwlan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ STATIC mp_obj_t wlan_make_new (mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_k
844844
wlan_init_helper(self, &args[1]);
845845

846846
// pass it to the sleep module
847-
pybsleep_set_wlan_obj(self);
847+
pyb_sleep_set_wlan_obj(self);
848848

849849
return (mp_obj_t)self;
850850
}

cc3200/mods/pybadc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ STATIC mp_obj_t adc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw,
164164

165165
// initialize and register with the sleep module
166166
pyb_adc_init(self);
167-
pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)pyb_adc_init);
167+
pyb_sleep_add ((const mp_obj_t)self, (WakeUpCB_t)pyb_adc_init);
168168
return self;
169169
}
170170

@@ -188,7 +188,7 @@ STATIC mp_obj_t adc_deinit(mp_obj_t self_in) {
188188
MAP_ADCDisable(ADC_BASE);
189189
self->enabled = false;
190190
// unregister it with the sleep module
191-
pybsleep_remove ((const mp_obj_t)self);
191+
pyb_sleep_remove ((const mp_obj_t)self);
192192
return mp_const_none;
193193
}
194194
STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_deinit_obj, adc_deinit);
@@ -224,7 +224,7 @@ STATIC mp_obj_t adc_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
224224
self->base.type = &pyb_adc_channel_type;
225225
pyb_adc_channel_init (self);
226226
// register it with the sleep module
227-
pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)pyb_adc_channel_init);
227+
pyb_sleep_add ((const mp_obj_t)self, (WakeUpCB_t)pyb_adc_channel_init);
228228
return self;
229229
}
230230
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(adc_channel_obj, 1, adc_channel);
@@ -267,7 +267,7 @@ STATIC mp_obj_t adc_channel_deinit(mp_obj_t self_in) {
267267

268268
MAP_ADCChannelDisable(ADC_BASE, self->channel);
269269
// unregister it with the sleep module
270-
pybsleep_remove ((const mp_obj_t)self);
270+
pyb_sleep_remove ((const mp_obj_t)self);
271271
self->enabled = false;
272272
return mp_const_none;
273273
}

cc3200/mods/pybi2c.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ STATIC mp_obj_t pyb_i2c_init_helper(pyb_i2c_obj_t *self, const mp_arg_val_t *arg
305305
i2c_init(self);
306306

307307
// register it with the sleep module
308-
pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)i2c_init);
308+
pyb_sleep_add ((const mp_obj_t)self, (WakeUpCB_t)i2c_init);
309309

310310
return mp_const_none;
311311

@@ -356,7 +356,7 @@ STATIC mp_obj_t pyb_i2c_deinit(mp_obj_t self_in) {
356356
// invalidate the baudrate
357357
pyb_i2c_obj.baudrate = 0;
358358
// unregister it with the sleep module
359-
pybsleep_remove ((const mp_obj_t)self_in);
359+
pyb_sleep_remove ((const mp_obj_t)self_in);
360360
return mp_const_none;
361361
}
362362
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_deinit_obj, pyb_i2c_deinit);

cc3200/mods/pybpin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void pin_config (pin_obj_t *self, int af, uint mode, uint pull, int value, uint
166166
pin_obj_configure ((const pin_obj_t *)self);
167167

168168
// register it with the sleep module
169-
pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)pin_obj_configure);
169+
pyb_sleep_add ((const mp_obj_t)self, (WakeUpCB_t)pin_obj_configure);
170170
}
171171

172172
void pin_assign_pins_af (mp_obj_t *pins, uint32_t n_pins, uint32_t pull, uint32_t fn, uint32_t unit) {
@@ -873,7 +873,7 @@ STATIC mp_obj_t pin_irq (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *k
873873
// all checks have passed, we can create the irq object
874874
mp_obj_t _irq = mp_irq_new (self, args[2].u_obj, &pin_irq_methods);
875875
if (pwrmode & PYB_PWR_MODE_LPDS) {
876-
pybsleep_set_gpio_lpds_callback (_irq);
876+
pyb_sleep_set_gpio_lpds_callback (_irq);
877877
}
878878

879879
// save the mp_trigge for later

cc3200/mods/pybrtc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ STATIC mp_obj_t pyb_rtc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n
306306
pyb_rtc_datetime((mp_obj_t)&pyb_rtc_obj, args[1].u_obj);
307307

308308
// pass it to the sleep module
309-
pybsleep_set_rtc_obj (self);
309+
pyb_sleep_set_rtc_obj (self);
310310

311311
// return constant object
312312
return (mp_obj_t)&pyb_rtc_obj;

cc3200/mods/pybsd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ STATIC mp_obj_t pyb_sd_init_helper (pybsd_obj_t *self, const mp_arg_val_t *args)
112112
}
113113

114114
// register it with the sleep module
115-
pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)pyb_sd_hw_init);
115+
pyb_sleep_add ((const mp_obj_t)self, (WakeUpCB_t)pyb_sd_hw_init);
116116
return mp_const_none;
117117
}
118118

@@ -159,7 +159,7 @@ STATIC mp_obj_t pyb_sd_deinit (mp_obj_t self_in) {
159159
// de-initialze the sd card at diskio level
160160
sd_disk_deinit();
161161
// unregister it from the sleep module
162-
pybsleep_remove (self);
162+
pyb_sleep_remove (self);
163163
return mp_const_none;
164164
}
165165
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_sd_deinit_obj, pyb_sd_deinit);

0 commit comments

Comments
 (0)