From 2f983d3ef96278610daf420d4971cdd5cea4a9d3 Mon Sep 17 00:00:00 2001 From: Glenn Ruben Bakke Date: Mon, 5 Jun 2017 17:39:47 +0200 Subject: [PATCH] nrf5: Update pyb module, and led module to only be compiled in if MICROPY_HW_HAS_LED is set to 1. --- nrf5/help.c | 2 ++ nrf5/main.c | 9 +++------ nrf5/modules/machine/led.c | 3 +++ nrf5/modules/pyb/modpyb.c | 8 +++++++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/nrf5/help.c b/nrf5/help.c index 2911d25600..8022f5bf6b 100644 --- a/nrf5/help.c +++ b/nrf5/help.c @@ -37,8 +37,10 @@ const char * nrf5_help_text = "For online help please visit http://micropython.org/help/.\n" "\n" "Quick overview of commands for the board:\n" +#if MICROPY_HW_HAS_LED " pyb.LED(n) -- create an LED object for LED n (n=" HELP_TEXT_BOARD_LED ")\n" "\n" +#endif #if BLUETOOTH_SD HELP_TEXT_SD #endif diff --git a/nrf5/main.c b/nrf5/main.c index 465a0c9513..0b5385fc3d 100644 --- a/nrf5/main.c +++ b/nrf5/main.c @@ -90,7 +90,6 @@ soft_reset: // to recover from limit hit. (Limit is measured in bytes.) mp_stack_set_limit((char*)&_ram_end - (char*)&_heap_end - 400); - led_init(); machine_init(); gc_init(&_heap_start, &_heap_end); @@ -171,11 +170,9 @@ pin_init0(); } #endif -#if MICROPY_HW_LED_TRICOLOR - do_str("import pyb\r\n" \ - "pyb.LED(1).on()", - MP_PARSE_FILE_INPUT); -#elif (MICROPY_HW_LED_COUNT > 0) +#if (MICROPY_HW_HAS_LED) + led_init(); + do_str("import pyb\r\n" \ "pyb.LED(1).on()", MP_PARSE_FILE_INPUT); diff --git a/nrf5/modules/machine/led.c b/nrf5/modules/machine/led.c index a23ef4427b..5b6aab102e 100644 --- a/nrf5/modules/machine/led.c +++ b/nrf5/modules/machine/led.c @@ -31,6 +31,8 @@ #include "led.h" #include "mpconfigboard.h" +#if MICROPY_HW_HAS_LED + #define LED_OFF(led) {(MICROPY_HW_LED_PULLUP) ? hal_gpio_pin_set(0, led) : hal_gpio_pin_clear(0, led); } #define LED_ON(led) {(MICROPY_HW_LED_PULLUP) ? hal_gpio_pin_clear(0, led) : hal_gpio_pin_set(0, led); } @@ -154,3 +156,4 @@ const mp_obj_type_t pyb_led_type = { .locals_dict = (mp_obj_dict_t*)&led_locals_dict, }; +#endif // MICROPY_HW_HAS_LED diff --git a/nrf5/modules/pyb/modpyb.c b/nrf5/modules/pyb/modpyb.c index ec49224bc7..f6cf2b1069 100644 --- a/nrf5/modules/pyb/modpyb.c +++ b/nrf5/modules/pyb/modpyb.c @@ -32,11 +32,17 @@ #include "nrf.h" // TODO: figure out where to put this import #include "pin.h" +#if MICROPY_HW_HAS_LED +#define PYB_LED_MODULE { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pyb_led_type) }, +#else +#define PYB_LED_MODULE +#endif + STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pyb) }, - { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pyb_led_type) }, { MP_ROM_QSTR(MP_QSTR_repl_info), MP_ROM_PTR(&pyb_set_repl_info_obj) }, { MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&pin_type) }, + PYB_LED_MODULE /* { MP_ROM_QSTR(MP_QSTR_main), MP_ROM_PTR(&pyb_main_obj) }*/ };