Skip to content

Commit a6aa35a

Browse files
committed
esp8266: Move pyb.info() function to esp module and remove pyb module.
All functionality of the pyb module is available in other modules, like time, machine and os. The only outstanding function, info(), is (temporarily) moved to the esp module and the pyb module is removed.
1 parent 3c2e40b commit a6aa35a

5 files changed

Lines changed: 10 additions & 82 deletions

File tree

esp8266/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ deploy: $(BUILD)/firmware-combined.bin
163163
#$(Q)esptool.py --port $(PORT) --baud $(BAUD) write_flash --flash_size=8m 0 $(BUILD)/firmware.elf-0x00000.bin 0x9000 $(BUILD)/firmware.elf-0x0[1-f]000.bin
164164

165165
reset:
166-
echo -e "\r\nimport pyb; pyb.hard_reset()\r\n" >$(PORT)
166+
echo -e "\r\nimport machine; machine.reset()\r\n" >$(PORT)
167167

168168
$(BUILD)/firmware-combined.bin: $(BUILD)/firmware.elf
169169
$(ECHO) "Create $@"

esp8266/modesp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ STATIC const mp_map_elem_t esp_module_globals_table[] = {
663663
{ MP_OBJ_NEW_QSTR(MP_QSTR_neopixel_write), (mp_obj_t)&esp_neopixel_write_obj },
664664
{ MP_OBJ_NEW_QSTR(MP_QSTR_freemem), (mp_obj_t)&esp_freemem_obj },
665665
{ MP_OBJ_NEW_QSTR(MP_QSTR_meminfo), (mp_obj_t)&esp_meminfo_obj },
666+
{ MP_OBJ_NEW_QSTR(MP_QSTR_info), (mp_obj_t)&pyb_info_obj }, // TODO delete/rename/move elsewhere
666667

667668
#if MODESP_INCLUDE_CONSTANTS
668669
{ MP_OBJ_NEW_QSTR(MP_QSTR_SLEEP_NONE),

esp8266/modpyb.c

Lines changed: 6 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626

2727
#include <stdio.h>
2828

29-
#include "py/nlr.h"
30-
#include "py/obj.h"
3129
#include "py/gc.h"
32-
#include "py/mphal.h"
3330
#include "gccollect.h"
34-
#include "user_interface.h"
3531
#include "modpyb.h"
3632

33+
// The pyb module no longer exists since all functionality now appears
34+
// elsewhere, in more standard places (eg time, machine modules). The
35+
// only remaining function is pyb.info() which has been moved to the
36+
// esp module, pending deletion/renaming/moving elsewher.
37+
3738
STATIC mp_obj_t pyb_info(mp_uint_t n_args, const mp_obj_t *args) {
3839
// print info about memory
3940
{
@@ -75,78 +76,4 @@ STATIC mp_obj_t pyb_info(mp_uint_t n_args, const mp_obj_t *args) {
7576

7677
return mp_const_none;
7778
}
78-
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_info_obj, 0, 1, pyb_info);
79-
80-
STATIC mp_obj_t pyb_sync(void) {
81-
//storage_flush();
82-
return mp_const_none;
83-
}
84-
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_sync_obj, pyb_sync);
85-
86-
STATIC mp_obj_t pyb_millis(void) {
87-
return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms());
88-
}
89-
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_millis_obj, pyb_millis);
90-
91-
STATIC mp_obj_t pyb_elapsed_millis(mp_obj_t start) {
92-
uint32_t startMillis = mp_obj_get_int(start);
93-
uint32_t currMillis = mp_hal_ticks_ms();
94-
return MP_OBJ_NEW_SMALL_INT((currMillis - startMillis) & 0x3fffffff);
95-
}
96-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_millis_obj, pyb_elapsed_millis);
97-
98-
STATIC mp_obj_t pyb_micros(void) {
99-
return MP_OBJ_NEW_SMALL_INT(system_get_time());
100-
}
101-
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_micros_obj, pyb_micros);
102-
103-
STATIC mp_obj_t pyb_elapsed_micros(mp_obj_t start) {
104-
uint32_t startMicros = mp_obj_get_int(start);
105-
uint32_t currMicros = system_get_time();
106-
return MP_OBJ_NEW_SMALL_INT((currMicros - startMicros) & 0x3fffffff);
107-
}
108-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_micros_obj, pyb_elapsed_micros);
109-
110-
STATIC mp_obj_t pyb_delay(mp_obj_t ms_in) {
111-
mp_int_t ms = mp_obj_get_int(ms_in);
112-
if (ms >= 0) {
113-
mp_hal_delay_ms(ms);
114-
}
115-
return mp_const_none;
116-
}
117-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_delay_obj, pyb_delay);
118-
119-
STATIC mp_obj_t pyb_udelay(mp_obj_t usec_in) {
120-
mp_int_t usec = mp_obj_get_int(usec_in);
121-
if (usec >= 0) {
122-
mp_hal_delay_us(usec);
123-
}
124-
return mp_const_none;
125-
}
126-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_udelay_obj, pyb_udelay);
127-
128-
STATIC const mp_map_elem_t pyb_module_globals_table[] = {
129-
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_pyb) },
130-
131-
{ MP_OBJ_NEW_QSTR(MP_QSTR_info), (mp_obj_t)&pyb_info_obj },
132-
133-
{ MP_OBJ_NEW_QSTR(MP_QSTR_millis), (mp_obj_t)&pyb_millis_obj },
134-
{ MP_OBJ_NEW_QSTR(MP_QSTR_elapsed_millis), (mp_obj_t)&pyb_elapsed_millis_obj },
135-
{ MP_OBJ_NEW_QSTR(MP_QSTR_micros), (mp_obj_t)&pyb_micros_obj },
136-
{ MP_OBJ_NEW_QSTR(MP_QSTR_elapsed_micros), (mp_obj_t)&pyb_elapsed_micros_obj },
137-
{ MP_OBJ_NEW_QSTR(MP_QSTR_delay), (mp_obj_t)&pyb_delay_obj },
138-
{ MP_OBJ_NEW_QSTR(MP_QSTR_udelay), (mp_obj_t)&pyb_udelay_obj },
139-
{ MP_OBJ_NEW_QSTR(MP_QSTR_sync), (mp_obj_t)&pyb_sync_obj },
140-
141-
{ MP_OBJ_NEW_QSTR(MP_QSTR_Pin), (mp_obj_t)&pyb_pin_type },
142-
{ MP_OBJ_NEW_QSTR(MP_QSTR_ADC), (mp_obj_t)&pyb_adc_type },
143-
{ MP_OBJ_NEW_QSTR(MP_QSTR_RTC), (mp_obj_t)&pyb_rtc_type },
144-
};
145-
146-
STATIC MP_DEFINE_CONST_DICT(pyb_module_globals, pyb_module_globals_table);
147-
148-
const mp_obj_module_t pyb_module = {
149-
.base = { &mp_type_module },
150-
.name = MP_QSTR_pyb,
151-
.globals = (mp_obj_dict_t*)&pyb_module_globals,
152-
};
79+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_info_obj, 0, 1, pyb_info);

esp8266/modpyb.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ extern const mp_obj_type_t pyb_uart_type;
1111
extern const mp_obj_type_t pyb_i2c_type;
1212
extern const mp_obj_type_t pyb_spi_type;
1313

14+
MP_DECLARE_CONST_FUN_OBJ(pyb_info_obj);
15+
1416
typedef struct _pyb_pin_obj_t {
1517
mp_obj_base_t base;
1618
uint16_t phys_port;

esp8266/mpconfigport.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ typedef uint32_t sys_prot_t; // for modlwip
109109
{ MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },
110110

111111
// extra built in modules to add to the list of known ones
112-
extern const struct _mp_obj_module_t pyb_module;
113112
extern const struct _mp_obj_module_t esp_module;
114113
extern const struct _mp_obj_module_t network_module;
115114
extern const struct _mp_obj_module_t utime_module;
@@ -119,7 +118,6 @@ extern const struct _mp_obj_module_t mp_module_machine;
119118
extern const struct _mp_obj_module_t onewire_module;
120119

121120
#define MICROPY_PORT_BUILTIN_MODULES \
122-
{ MP_OBJ_NEW_QSTR(MP_QSTR_pyb), (mp_obj_t)&pyb_module }, \
123121
{ MP_OBJ_NEW_QSTR(MP_QSTR_esp), (mp_obj_t)&esp_module }, \
124122
{ MP_OBJ_NEW_QSTR(MP_QSTR_lwip), (mp_obj_t)&mp_module_lwip }, \
125123
{ MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&mp_module_lwip }, \

0 commit comments

Comments
 (0)