Skip to content

Commit ab4ab2a

Browse files
authored
Merge pull request #5241 from capellini/mp-register-module-pybadge-b-m
Convert more modules to use MP_REGISTER_MODULE
2 parents 12f3213 + b8f2799 commit ab4ab2a

File tree

16 files changed

+51
-114
lines changed

16 files changed

+51
-114
lines changed

py/circuitpy_mpconfig.h

Lines changed: 16 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -280,19 +280,8 @@ extern const struct _mp_obj_module_t audiopwmio_module;
280280
#define BINASCII_MODULE
281281
#endif
282282

283-
#if CIRCUITPY_BITBANGIO
284-
#define BITBANGIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_bitbangio), (mp_obj_t)&bitbangio_module },
285-
extern const struct _mp_obj_module_t bitbangio_module;
286-
#else
287-
#define BITBANGIO_MODULE
288-
#endif
289-
290-
#if CIRCUITPY_BITMAPTOOLS
291-
#define BITMAPTOOLS_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_bitmaptools), (mp_obj_t)&bitmaptools_module },
292-
extern const struct _mp_obj_module_t bitmaptools_module;
293-
#else
294-
#define BITMAPTOOLS_MODULE
295-
#endif
283+
// CIRCUITPY_BITBANGIO uses MP_REGISTER_MODULE
284+
// CIRCUITPY_BITMAPTOOLS uses MP_REGISTER_MODULE
296285

297286
#if CIRCUITPY_BITOPS
298287
extern const struct _mp_obj_module_t bitops_module;
@@ -301,17 +290,10 @@ extern const struct _mp_obj_module_t bitops_module;
301290
#define BITOPS_MODULE
302291
#endif
303292

304-
#if CIRCUITPY_BLEIO
305-
#define BLEIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR__bleio), (mp_obj_t)&bleio_module },
306-
extern const struct _mp_obj_module_t bleio_module;
307-
#else
308-
#define BLEIO_MODULE
309-
#endif
293+
// CIRCUITPY_BLEIO uses MP_REGISTER_MODULE
294+
// CIRCUITPY_BOARD uses MP_REGISTER_MODULE
310295

311296
#if CIRCUITPY_BOARD
312-
#define BOARD_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_board), (mp_obj_t)&board_module },
313-
extern const struct _mp_obj_module_t board_module;
314-
315297
#define BOARD_I2C (defined(DEFAULT_I2C_BUS_SDA) && defined(DEFAULT_I2C_BUS_SCL))
316298
#define BOARD_SPI (defined(DEFAULT_SPI_BUS_SCK) && defined(DEFAULT_SPI_BUS_MISO) && defined(DEFAULT_SPI_BUS_MOSI))
317299
#define BOARD_UART (defined(DEFAULT_UART_BUS_RX) && defined(DEFAULT_UART_BUS_TX))
@@ -325,18 +307,11 @@ extern const struct _mp_obj_module_t board_module;
325307
#endif
326308

327309
#else
328-
#define BOARD_MODULE
329310
#define BOARD_UART_ROOT_POINTER
330311
#endif
331312

332313
// CIRCUITPY_BUSDEVICE (adafruit_bus_device_module) uses MP_REGISTER_MODULE
333-
334-
#if CIRCUITPY_BUSIO
335-
extern const struct _mp_obj_module_t busio_module;
336-
#define BUSIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_busio), (mp_obj_t)&busio_module },
337-
#else
338-
#define BUSIO_MODULE
339-
#endif
314+
// CIRCUITPY_BUSIO uses MP_REGISTER_MODULE
340315

341316
#if CIRCUITPY_CAMERA
342317
extern const struct _mp_obj_module_t camera_module;
@@ -352,20 +327,8 @@ extern const struct _mp_obj_module_t canio_module;
352327
#define CANIO_MODULE
353328
#endif
354329

355-
#if CIRCUITPY_COUNTIO
356-
extern const struct _mp_obj_module_t countio_module;
357-
#define COUNTIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_countio), (mp_obj_t)&countio_module },
358-
#else
359-
#define COUNTIO_MODULE
360-
#endif
361-
362-
#if CIRCUITPY_DIGITALIO
363-
extern const struct _mp_obj_module_t digitalio_module;
364-
#define DIGITALIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_digitalio), (mp_obj_t)&digitalio_module },
365-
#else
366-
#define DIGITALIO_MODULE
367-
#endif
368-
330+
// CIRCUITPY_COUNTIO uses MP_REGISTER_MODULE
331+
// CIRCUITPY_DIGITALIO uses MP_REGISTER_MODULE
369332
// CIRCUITPY_DISPLAYIO uses MP_REGISTER_MODULE
370333
// CIRCUITPY_TERMINALIO uses MP_REGISTER_MODULE
371334
// CIRCUITPY_FONTIO uses MP_REGISTER_MODULE
@@ -409,12 +372,7 @@ extern const struct _mp_obj_module_t _eve_module;
409372
#define _EVE_MODULE
410373
#endif
411374

412-
#if CIRCUITPY_FRAMEBUFFERIO
413-
extern const struct _mp_obj_module_t framebufferio_module;
414-
#define FRAMEBUFFERIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_framebufferio), (mp_obj_t)&framebufferio_module },
415-
#else
416-
#define FRAMEBUFFERIO_MODULE
417-
#endif
375+
// CIRCUITPY_FRAMEBUFFERIO uses MP_REGISTER_MODULE
418376

419377
#if CIRCUITPY_VECTORIO
420378
extern const struct _mp_obj_module_t vectorio_module;
@@ -423,19 +381,8 @@ extern const struct _mp_obj_module_t vectorio_module;
423381
#define VECTORIO_MODULE
424382
#endif
425383

426-
#if CIRCUITPY_FREQUENCYIO
427-
extern const struct _mp_obj_module_t frequencyio_module;
428-
#define FREQUENCYIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_frequencyio), (mp_obj_t)&frequencyio_module },
429-
#else
430-
#define FREQUENCYIO_MODULE
431-
#endif
432-
433-
#if CIRCUITPY_GAMEPADSHIFT
434-
extern const struct _mp_obj_module_t gamepadshift_module;
435-
#define GAMEPADSHIFT_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_gamepadshift),(mp_obj_t)&gamepadshift_module },
436-
#else
437-
#define GAMEPADSHIFT_MODULE
438-
#endif
384+
// CIRCUITPY_FREQUENCYIO uses MP_REGISTER_MODULE
385+
// CIRCUITPY_GAMEPADSHIFT uses MP_REGISTER_MODULE
439386

440387
#if CIRCUITPY_GAMEPADSHIFT
441388
// Scan gamepad every 32ms
@@ -445,12 +392,7 @@ extern const struct _mp_obj_module_t gamepadshift_module;
445392
#define GAMEPAD_ROOT_POINTERS
446393
#endif
447394

448-
#if CIRCUITPY_GETPASS
449-
extern const struct _mp_obj_module_t getpass_module;
450-
#define GETPASS_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_getpass), (mp_obj_t)&getpass_module },
451-
#else
452-
#define GETPASS_MODULE
453-
#endif
395+
// CIRCUITPY_GETPASS uses MP_REGISTER_MODULE
454396

455397
#if CIRCUITPY_GNSS
456398
extern const struct _mp_obj_module_t gnss_module;
@@ -492,29 +434,15 @@ extern const struct _mp_obj_module_t ipaddress_module;
492434
#define JSON_MODULE
493435
#endif
494436

437+
// CIRCUITPY_KEYPAD uses MP_REGISTER_MODULE
438+
495439
#if CIRCUITPY_KEYPAD
496-
extern const struct _mp_obj_module_t keypad_module;
497-
#define KEYPAD_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_keypad), (mp_obj_t)&keypad_module },
498440
#define KEYPAD_ROOT_POINTERS mp_obj_t keypad_scanners_linked_list;
499441
#else
500-
#define KEYPAD_MODULE
501442
#define KEYPAD_ROOT_POINTERS
502443
#endif
503444

504-
#if CIRCUITPY_GAMEPADSHIFT
505-
// Scan gamepadshift every 32ms
506-
#define CIRCUITPY_GAMEPAD_TICKS 0x1f
507-
#define GAMEPAD_ROOT_POINTERS mp_obj_t gamepad_singleton;
508-
#else
509-
#define GAMEPAD_ROOT_POINTERS
510-
#endif
511-
512-
#if CIRCUITPY_MATH
513-
extern const struct _mp_obj_module_t math_module;
514-
#define MATH_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_math), (mp_obj_t)&math_module },
515-
#else
516-
#define MATH_MODULE
517-
#endif
445+
// CIRCUITPY_MATH uses MP_REGISTER_MODULE
518446

519447
#if CIRCUITPY_MEMORYMONITOR
520448
extern const struct _mp_obj_module_t memorymonitor_module;
@@ -526,12 +454,7 @@ extern const struct _mp_obj_module_t memorymonitor_module;
526454
#define MEMORYMONITOR_ROOT_POINTERS
527455
#endif
528456

529-
#if CIRCUITPY_MICROCONTROLLER
530-
extern const struct _mp_obj_module_t microcontroller_module;
531-
#define MICROCONTROLLER_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_microcontroller), (mp_obj_t)&microcontroller_module },
532-
#else
533-
#define MICROCONTROLLER_MODULE
534-
#endif
457+
// CIRCUITPY_MICROCONTROLLER uses MP_REGISTER_MODULE
535458

536459
#if CIRCUITPY_NEOPIXEL_WRITE
537460
extern const struct _mp_obj_module_t neopixel_write_module;
@@ -803,12 +726,7 @@ extern const struct _mp_obj_module_t wifi_module;
803726
#define WIFI_MODULE
804727
#endif
805728

806-
#if CIRCUITPY_MSGPACK
807-
extern const struct _mp_obj_module_t msgpack_module;
808-
#define MSGPACK_MODULE { MP_ROM_QSTR(MP_QSTR_msgpack), MP_ROM_PTR(&msgpack_module) },
809-
#else
810-
#define MSGPACK_MODULE
811-
#endif
729+
// CIRCUITPY_MSGPACK uses MP_REGISTER_MODULE
812730

813731
// Define certain native modules with weak links so they can be replaced with Python
814732
// implementations. This list may grow over time.
@@ -833,35 +751,20 @@ extern const struct _mp_obj_module_t msgpack_module;
833751
ALARM_MODULE \
834752
AUDIOPWMIO_MODULE \
835753
BINASCII_MODULE \
836-
BITBANGIO_MODULE \
837-
BITMAPTOOLS_MODULE \
838754
BITOPS_MODULE \
839-
BLEIO_MODULE \
840-
BOARD_MODULE \
841-
BUSIO_MODULE \
842755
CAMERA_MODULE \
843756
CANIO_MODULE \
844-
COUNTIO_MODULE \
845-
DIGITALIO_MODULE \
846757
DUALBANK_MODULE \
847758
VECTORIO_MODULE \
848759
ERRNO_MODULE \
849760
ESPIDF_MODULE \
850761
_EVE_MODULE \
851-
FRAMEBUFFERIO_MODULE \
852-
FREQUENCYIO_MODULE \
853-
GAMEPADSHIFT_MODULE \
854-
GETPASS_MODULE \
855762
GNSS_MODULE \
856763
I2CPERIPHERAL_MODULE \
857764
IPADDRESS_MODULE \
858765
IMAGECAPTURE_MODULE \
859766
JSON_MODULE \
860-
KEYPAD_MODULE \
861-
MATH_MODULE \
862767
MEMORYMONITOR_MODULE \
863-
MICROCONTROLLER_MODULE \
864-
MSGPACK_MODULE \
865768
NEOPIXEL_WRITE_MODULE \
866769
ONEWIREIO_MODULE \
867770
PEW_MODULE \

shared-bindings/_bleio/__init__.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,5 @@ const mp_obj_module_t bleio_module = {
201201
.base = { &mp_type_module },
202202
.globals = (mp_obj_dict_t *)&bleio_module_globals,
203203
};
204+
205+
MP_REGISTER_MODULE(MP_QSTR__bleio, bleio_module, CIRCUITPY_BLEIO);

shared-bindings/bitbangio/__init__.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,5 @@ const mp_obj_module_t bitbangio_module = {
8484
.base = { &mp_type_module },
8585
.globals = (mp_obj_dict_t *)&bitbangio_module_globals,
8686
};
87+
88+
MP_REGISTER_MODULE(MP_QSTR_bitbangio, bitbangio_module, CIRCUITPY_BITBANGIO);

shared-bindings/bitmaptools/__init__.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ STATIC mp_obj_t bitmaptools_readinto(size_t n_args, const mp_obj_t *pos_args, mp
578578
MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_readinto_obj, 0, bitmaptools_readinto);
579579

580580
STATIC const mp_rom_map_elem_t bitmaptools_module_globals_table[] = {
581+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bitmaptools) },
581582
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&bitmaptools_readinto_obj) },
582583
{ MP_ROM_QSTR(MP_QSTR_rotozoom), MP_ROM_PTR(&bitmaptools_rotozoom_obj) },
583584
{ MP_ROM_QSTR(MP_QSTR_arrayblit), MP_ROM_PTR(&bitmaptools_arrayblit_obj) },
@@ -591,3 +592,5 @@ const mp_obj_module_t bitmaptools_module = {
591592
.base = {&mp_type_module },
592593
.globals = (mp_obj_dict_t *)&bitmaptools_module_globals,
593594
};
595+
596+
MP_REGISTER_MODULE(MP_QSTR_bitmaptools, bitmaptools_module, CIRCUITPY_BITMAPTOOLS);

shared-bindings/board/__init__.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,5 @@ const mp_obj_module_t board_module = {
124124
.base = { &mp_type_module },
125125
.globals = (mp_obj_dict_t *)&board_module_globals,
126126
};
127+
128+
MP_REGISTER_MODULE(MP_QSTR_board, board_module, CIRCUITPY_BOARD);

shared-bindings/busio/__init__.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,5 @@ const mp_obj_module_t busio_module = {
8585
.base = { &mp_type_module },
8686
.globals = (mp_obj_dict_t *)&busio_module_globals,
8787
};
88+
89+
MP_REGISTER_MODULE(MP_QSTR_busio, busio_module, CIRCUITPY_BUSIO);

shared-bindings/countio/__init__.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ const mp_obj_module_t countio_module = {
3434
.base = { &mp_type_module },
3535
.globals = (mp_obj_dict_t *)&countio_module_globals,
3636
};
37+
38+
MP_REGISTER_MODULE(MP_QSTR_countio, countio_module, CIRCUITPY_COUNTIO);

shared-bindings/digitalio/__init__.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,5 @@ const mp_obj_module_t digitalio_module = {
9090
.base = { &mp_type_module },
9191
.globals = (mp_obj_dict_t *)&digitalio_module_globals,
9292
};
93+
94+
MP_REGISTER_MODULE(MP_QSTR_digitalio, digitalio_module, CIRCUITPY_DIGITALIO);

shared-bindings/framebufferio/__init__.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@ static const mp_rom_map_elem_t framebufferio_module_globals_table[] = {
4242
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_framebufferio) },
4343
{ MP_ROM_QSTR(MP_QSTR_FramebufferDisplay), MP_ROM_PTR(&framebufferio_framebufferdisplay_type) },
4444
};
45+
4546
STATIC MP_DEFINE_CONST_DICT(framebufferio_module_globals, framebufferio_module_globals_table);
47+
4648
const mp_obj_module_t framebufferio_module = {
4749
.base = { &mp_type_module },
4850
.globals = (mp_obj_dict_t *)&framebufferio_module_globals,
4951
};
52+
53+
MP_REGISTER_MODULE(MP_QSTR_framebufferio, framebufferio_module, CIRCUITPY_FRAMEBUFFERIO);
5054
#endif

shared-bindings/frequencyio/__init__.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,5 @@ const mp_obj_module_t frequencyio_module = {
7272
.base = { &mp_type_module },
7373
.globals = (mp_obj_dict_t *)&frequencyio_module_globals,
7474
};
75+
76+
MP_REGISTER_MODULE(MP_QSTR_frequencyio, frequencyio_module, CIRCUITPY_FREQUENCYIO);

shared-bindings/gamepadshift/__init__.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ STATIC const mp_rom_map_elem_t gamepadshift_module_globals_table[] = {
4040
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gamepadshift) },
4141
{ MP_OBJ_NEW_QSTR(MP_QSTR_GamePadShift), MP_ROM_PTR(&gamepadshift_type)},
4242
};
43+
4344
STATIC MP_DEFINE_CONST_DICT(gamepadshift_module_globals, gamepadshift_module_globals_table);
4445

4546
const mp_obj_module_t gamepadshift_module = {
4647
.base = { &mp_type_module },
4748
.globals = (mp_obj_dict_t *)&gamepadshift_module_globals,
4849
};
50+
51+
MP_REGISTER_MODULE(MP_QSTR_gamepadshift, gamepadshift_module, CIRCUITPY_GAMEPADSHIFT);

shared-bindings/getpass/__init__.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,5 @@ const mp_obj_module_t getpass_module = {
8484
.base = { &mp_type_module },
8585
.globals = (mp_obj_dict_t *)&getpass_module_globals,
8686
};
87+
88+
MP_REGISTER_MODULE(MP_QSTR_getpass, getpass_module, CIRCUITPY_GETPASS);

shared-bindings/keypad/__init__.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ const mp_obj_module_t keypad_module = {
5757
.base = { &mp_type_module },
5858
.globals = (mp_obj_dict_t *)&keypad_module_globals,
5959
};
60+
61+
MP_REGISTER_MODULE(MP_QSTR_keypad, keypad_module, CIRCUITPY_KEYPAD);

shared-bindings/math/__init__.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,4 +427,6 @@ const mp_obj_module_t math_module = {
427427
.globals = (mp_obj_dict_t *)&mp_module_math_globals,
428428
};
429429

430-
#endif // MICROPY_PY_BUILTINS_FLOAT && MICROPY_PY_MATH
430+
MP_REGISTER_MODULE(MP_QSTR_math, math_module, CIRCUITPY_MATH);
431+
432+
#endif // MICROPY_PY_BUILTINS_FLOAT

shared-bindings/microcontroller/__init__.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,5 @@ const mp_obj_module_t microcontroller_module = {
193193
.base = { &mp_type_module },
194194
.globals = (mp_obj_dict_t *)&mcu_module_globals,
195195
};
196+
197+
MP_REGISTER_MODULE(MP_QSTR_microcontroller, microcontroller_module, CIRCUITPY_MICROCONTROLLER);

shared-bindings/msgpack/__init__.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,5 @@ const mp_obj_module_t msgpack_module = {
160160
.base = { &mp_type_module },
161161
.globals = (mp_obj_dict_t *)&msgpack_module_globals,
162162
};
163+
164+
MP_REGISTER_MODULE(MP_QSTR_msgpack, msgpack_module, CIRCUITPY_MSGPACK);

0 commit comments

Comments
 (0)