diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 80110f9704..cc7b4f1260 100644 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -296,6 +296,14 @@ sd: $(BUILD)/$(OUTPUT_FILENAME).hex pyocd-flashtool -t $(MCU_VARIANT) $(SOFTDEV_HEX) pyocd-flashtool -t $(MCU_VARIANT) $< +else ifeq ($(FLASHER), idap) + +flash: $(BUILD)/$(OUTPUT_FILENAME).hex + IDAPnRFPRog $< + +sd: $(BUILD)/$(OUTPUT_FILENAME).hex + IDAPnRFPRog $(SOFTDEV_HEX) $< + endif $(BUILD)/$(OUTPUT_FILENAME).elf: $(OBJ) diff --git a/ports/nrf/README.md b/ports/nrf/README.md index 659a556ae2..2a1667a3eb 100644 --- a/ports/nrf/README.md +++ b/ports/nrf/README.md @@ -34,6 +34,8 @@ This is a port of MicroPython to the Nordic Semiconductor nRF series of chips. * [Adafruit Feather nRF52](https://www.adafruit.com/product/3406) * [Thingy:52](http://www.nordicsemi.com/eng/Products/Nordic-Thingy-52) * [Arduino Primo](http://www.arduino.org/products/boards/arduino-primo) + * [IBK-BLYST-NANO breakout board](https://www.crowdsupply.com/i-syst/blyst-nano) + * [BLUEIO-TAG-EVIM BLYST Nano Sensor board](https://www.crowdsupply.com/i-syst/blyst-nano) * nRF52840 * [PCA10056](http://www.nordicsemi.com/eng/Products/nRF52840-Preview-DK) @@ -120,8 +122,20 @@ wt51822_s4at | s110 | Peripheral | Manual pca10040 | s132 | Peripheral and Central | [Segger](#segger-targets) feather52 | s132 | Peripheral and Central | Manual, SWDIO and SWCLK solder points on the bottom side of the board arduino_primo | s132 | Peripheral and Central | [PyOCD](#pyocdopenocd-targets) +ibk_blyst_nano | s132 | Peripheral and Central | [IDAP](#idap-midap-link-targets) +idk_blyst_nano | s132 | Peripheral and Central | [IDAP](#idap-midap-link-targets) +blueio_tag_evim | s132 | Peripheral and Central | [IDAP](#idap-midap-link-targets) pca10056 | s140 | Peripheral and Central | [Segger](#segger-targets) +## IDAP-M/IDAP-Link Targets + +Install the necessary tools to flash and debug using IDAP-M/IDAP-Link CMSIS-DAP Debug JTAG: + +[IDAPnRFProg for Linux](https://sourceforge.net/projects/idaplinkfirmware/files/Linux/IDAPnRFProg_1_7_190320.zip/download) +[IDAPnRFProg for OSX](https://sourceforge.net/projects/idaplinkfirmware/files/OSX/IDAPnRFProg_1_7_190320.zip/download) +[IDAPnRFProg for Windows](https://sourceforge.net/projects/idaplinkfirmware/files/Windows/IDAPnRFProg_1_7_190320.zip/download) + + ## Segger Targets Install the necessary tools to flash and debug using Segger: diff --git a/ports/nrf/boards/blueio_tag_evim/mpconfigboard.h b/ports/nrf/boards/blueio_tag_evim/mpconfigboard.h new file mode 100644 index 0000000000..afc3f00a81 --- /dev/null +++ b/ports/nrf/boards/blueio_tag_evim/mpconfigboard.h @@ -0,0 +1,77 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 I-SYST inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#define MICROPY_HW_BOARD_NAME "BLUEIO-TAG-EVIM" +#define MICROPY_HW_MCU_NAME "NRF52832" +#define MICROPY_PY_SYS_PLATFORM "BLYST Nano" + +#define MICROPY_PY_MACHINE_SOFT_PWM (1) +#define MICROPY_PY_MUSIC (1) + +#define MICROPY_PY_MACHINE_UART (1) +#define MICROPY_PY_MACHINE_HW_PWM (1) +#define MICROPY_PY_MACHINE_HW_SPI (1) +#define MICROPY_PY_MACHINE_TIMER (1) +#define MICROPY_PY_MACHINE_RTCOUNTER (1) +#define MICROPY_PY_MACHINE_I2C (1) +#define MICROPY_PY_MACHINE_ADC (1) +#define MICROPY_PY_MACHINE_TEMP (1) +#define MICROPY_PY_RANDOM_HW_RNG (1) + +#define MICROPY_HW_HAS_LED (1) +#define MICROPY_HW_LED_COUNT (4) +#define MICROPY_HW_LED_PULLUP (1) + +#define MICROPY_HW_LED1 (30) // LED1 +#define MICROPY_HW_LED1_LEVEL (0) +#define MICROPY_HW_LED2 (20) // LED2 +#define MICROPY_HW_LED2_LEVEL (1) +#define MICROPY_HW_LED3 (19) // LED3 +#define MICROPY_HW_LED3_LEVEL (1) +#define MICROPY_HW_LED4 (18) // LED4 +#define MICROPY_HW_LED4_LEVEL (1) + +// UART config +#define MICROPY_HW_UART1_RX (8) +#define MICROPY_HW_UART1_TX (7) +#define MICROPY_HW_UART1_CTS (12) +#define MICROPY_HW_UART1_RTS (11) +#define MICROPY_HW_UART1_HWFC (1) + +// SPI0 config +#define MICROPY_HW_SPI0_NAME "SPI0" +#define MICROPY_HW_SPI0_SCK (23) // +#define MICROPY_HW_SPI0_MOSI (24) // +#define MICROPY_HW_SPI0_MISO (25) // + +#define MICROPY_HW_PWM0_NAME "PWM0" +#define MICROPY_HW_PWM1_NAME "PWM1" +#define MICROPY_HW_PWM2_NAME "PWM2" + +// buzzer pin +#define MICROPY_HW_MUSIC_PIN (14) + +#define HELP_TEXT_BOARD_LED "1,2,3,4" diff --git a/ports/nrf/boards/blueio_tag_evim/mpconfigboard.mk b/ports/nrf/boards/blueio_tag_evim/mpconfigboard.mk new file mode 100644 index 0000000000..02a3177446 --- /dev/null +++ b/ports/nrf/boards/blueio_tag_evim/mpconfigboard.mk @@ -0,0 +1,8 @@ +MCU_SERIES = m4 +MCU_VARIANT = nrf52 +MCU_SUB_VARIANT = nrf52832 +SOFTDEV_VERSION = 6.1.1 +LD_FILES += boards/nrf52832_512k_64k.ld +FLASHER = idap + +NRF_DEFINES += -DNRF52832_XXAA diff --git a/ports/nrf/boards/blueio_tag_evim/pins.csv b/ports/nrf/boards/blueio_tag_evim/pins.csv new file mode 100644 index 0000000000..90bf84a04d --- /dev/null +++ b/ports/nrf/boards/blueio_tag_evim/pins.csv @@ -0,0 +1,30 @@ +P2,P2 +P3,P3 +P4,P4 +P5,P5 +P6,P6 +P7,P7 +P8,P8 +P9,P9 +P10,P10 +P11,P11 +P12,P12 +P13,P13 +P14,P14 +P15,P15 +P16,P16 +P17,P17 +P18,P18 +P19,P19 +P20,P20 +P21,P21 +P22,P22 +P23,P23 +P24,P24 +P25,P25 +P26,P26 +P27,P27 +P28,P28 +P29,P29 +P30,P30 +P31,P31 diff --git a/ports/nrf/boards/ibk_blyst_nano/mpconfigboard.h b/ports/nrf/boards/ibk_blyst_nano/mpconfigboard.h new file mode 100644 index 0000000000..11b8c28e38 --- /dev/null +++ b/ports/nrf/boards/ibk_blyst_nano/mpconfigboard.h @@ -0,0 +1,69 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 I-SYST inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#define MICROPY_HW_BOARD_NAME "IBK-BLYST-NANO" +#define MICROPY_HW_MCU_NAME "NRF52832" +#define MICROPY_PY_SYS_PLATFORM "BLYST Nano" + +#define MICROPY_PY_MACHINE_SOFT_PWM (1) +#define MICROPY_PY_MUSIC (1) + +#define MICROPY_PY_MACHINE_UART (1) +#define MICROPY_PY_MACHINE_HW_PWM (1) +#define MICROPY_PY_MACHINE_HW_SPI (1) +#define MICROPY_PY_MACHINE_TIMER (1) +#define MICROPY_PY_MACHINE_RTCOUNTER (1) +#define MICROPY_PY_MACHINE_I2C (1) +#define MICROPY_PY_MACHINE_ADC (1) +#define MICROPY_PY_MACHINE_TEMP (1) +#define MICROPY_PY_RANDOM_HW_RNG (1) + +#define MICROPY_HW_HAS_LED (1) +#define MICROPY_HW_LED_COUNT (3) +#define MICROPY_HW_LED_PULLUP (1) + +#define MICROPY_HW_LED1 (30) // LED1 +#define MICROPY_HW_LED2 (29) // LED2 +#define MICROPY_HW_LED3 (28) // LED3 + +// UART config +#define MICROPY_HW_UART1_RX (8) +#define MICROPY_HW_UART1_TX (7) +#define MICROPY_HW_UART1_CTS (12) +#define MICROPY_HW_UART1_RTS (11) +#define MICROPY_HW_UART1_HWFC (1) + +// SPI0 config +#define MICROPY_HW_SPI0_NAME "SPI0" +#define MICROPY_HW_SPI0_SCK (23) // +#define MICROPY_HW_SPI0_MOSI (24) // +#define MICROPY_HW_SPI0_MISO (25) // + +#define MICROPY_HW_PWM0_NAME "PWM0" +#define MICROPY_HW_PWM1_NAME "PWM1" +#define MICROPY_HW_PWM2_NAME "PWM2" + +#define HELP_TEXT_BOARD_LED "1,2,3" diff --git a/ports/nrf/boards/ibk_blyst_nano/mpconfigboard.mk b/ports/nrf/boards/ibk_blyst_nano/mpconfigboard.mk new file mode 100644 index 0000000000..02a3177446 --- /dev/null +++ b/ports/nrf/boards/ibk_blyst_nano/mpconfigboard.mk @@ -0,0 +1,8 @@ +MCU_SERIES = m4 +MCU_VARIANT = nrf52 +MCU_SUB_VARIANT = nrf52832 +SOFTDEV_VERSION = 6.1.1 +LD_FILES += boards/nrf52832_512k_64k.ld +FLASHER = idap + +NRF_DEFINES += -DNRF52832_XXAA diff --git a/ports/nrf/boards/ibk_blyst_nano/pins.csv b/ports/nrf/boards/ibk_blyst_nano/pins.csv new file mode 100644 index 0000000000..90bf84a04d --- /dev/null +++ b/ports/nrf/boards/ibk_blyst_nano/pins.csv @@ -0,0 +1,30 @@ +P2,P2 +P3,P3 +P4,P4 +P5,P5 +P6,P6 +P7,P7 +P8,P8 +P9,P9 +P10,P10 +P11,P11 +P12,P12 +P13,P13 +P14,P14 +P15,P15 +P16,P16 +P17,P17 +P18,P18 +P19,P19 +P20,P20 +P21,P21 +P22,P22 +P23,P23 +P24,P24 +P25,P25 +P26,P26 +P27,P27 +P28,P28 +P29,P29 +P30,P30 +P31,P31 diff --git a/ports/nrf/boards/idk_blyst_nano/mpconfigboard.h b/ports/nrf/boards/idk_blyst_nano/mpconfigboard.h new file mode 100644 index 0000000000..1d39ad7569 --- /dev/null +++ b/ports/nrf/boards/idk_blyst_nano/mpconfigboard.h @@ -0,0 +1,70 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 I-SYST inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#define MICROPY_HW_BOARD_NAME "IDK-BLYST-NANO" +#define MICROPY_HW_MCU_NAME "NRF52832" +#define MICROPY_PY_SYS_PLATFORM "BLYST Nano" + +#define MICROPY_PY_MACHINE_SOFT_PWM (1) +#define MICROPY_PY_MUSIC (1) + +#define MICROPY_PY_MACHINE_UART (1) +#define MICROPY_PY_MACHINE_HW_PWM (1) +#define MICROPY_PY_MACHINE_HW_SPI (1) +#define MICROPY_PY_MACHINE_TIMER (1) +#define MICROPY_PY_MACHINE_RTCOUNTER (1) +#define MICROPY_PY_MACHINE_I2C (1) +#define MICROPY_PY_MACHINE_ADC (1) +#define MICROPY_PY_MACHINE_TEMP (1) +#define MICROPY_PY_RANDOM_HW_RNG (1) + +#define MICROPY_HW_HAS_LED (1) +#define MICROPY_HW_LED_COUNT (4) +#define MICROPY_HW_LED_PULLUP (1) + +#define MICROPY_HW_LED1 (30) // LED1 +#define MICROPY_HW_LED2 (29) // LED2 +#define MICROPY_HW_LED3 (28) // LED3 +#define MICROPY_HW_LED4 (27) // LED4 + +// UART config +#define MICROPY_HW_UART1_RX (8) +#define MICROPY_HW_UART1_TX (7) +#define MICROPY_HW_UART1_CTS (12) +#define MICROPY_HW_UART1_RTS (11) +#define MICROPY_HW_UART1_HWFC (1) + +// SPI0 config +#define MICROPY_HW_SPI0_NAME "SPI0" +#define MICROPY_HW_SPI0_SCK (23) // +#define MICROPY_HW_SPI0_MOSI (24) // +#define MICROPY_HW_SPI0_MISO (25) // + +#define MICROPY_HW_PWM0_NAME "PWM0" +#define MICROPY_HW_PWM1_NAME "PWM1" +#define MICROPY_HW_PWM2_NAME "PWM2" + +#define HELP_TEXT_BOARD_LED "1,2,3,4" diff --git a/ports/nrf/boards/idk_blyst_nano/mpconfigboard.mk b/ports/nrf/boards/idk_blyst_nano/mpconfigboard.mk new file mode 100644 index 0000000000..02a3177446 --- /dev/null +++ b/ports/nrf/boards/idk_blyst_nano/mpconfigboard.mk @@ -0,0 +1,8 @@ +MCU_SERIES = m4 +MCU_VARIANT = nrf52 +MCU_SUB_VARIANT = nrf52832 +SOFTDEV_VERSION = 6.1.1 +LD_FILES += boards/nrf52832_512k_64k.ld +FLASHER = idap + +NRF_DEFINES += -DNRF52832_XXAA diff --git a/ports/nrf/boards/idk_blyst_nano/pins.csv b/ports/nrf/boards/idk_blyst_nano/pins.csv new file mode 100644 index 0000000000..90bf84a04d --- /dev/null +++ b/ports/nrf/boards/idk_blyst_nano/pins.csv @@ -0,0 +1,30 @@ +P2,P2 +P3,P3 +P4,P4 +P5,P5 +P6,P6 +P7,P7 +P8,P8 +P9,P9 +P10,P10 +P11,P11 +P12,P12 +P13,P13 +P14,P14 +P15,P15 +P16,P16 +P17,P17 +P18,P18 +P19,P19 +P20,P20 +P21,P21 +P22,P22 +P23,P23 +P24,P24 +P25,P25 +P26,P26 +P27,P27 +P28,P28 +P29,P29 +P30,P30 +P31,P31 diff --git a/ports/nrf/modules/board/led.c b/ports/nrf/modules/board/led.c index 687348cb86..8b1eb560ea 100644 --- a/ports/nrf/modules/board/led.c +++ b/ports/nrf/modules/board/led.c @@ -33,31 +33,122 @@ #if MICROPY_HW_HAS_LED -#define LED_OFF(pin) {(MICROPY_HW_LED_PULLUP) ? nrf_gpio_pin_set(pin) : nrf_gpio_pin_clear(pin); } -#define LED_ON(pin) {(MICROPY_HW_LED_PULLUP) ? nrf_gpio_pin_clear(pin) : nrf_gpio_pin_set(pin); } - typedef struct _board_led_obj_t { mp_obj_base_t base; mp_uint_t led_id; mp_uint_t hw_pin; uint8_t hw_pin_port; + bool act_level; } board_led_obj_t; -STATIC const board_led_obj_t board_led_obj[] = { +static inline void LED_OFF(board_led_obj_t * const led_obj) { + if (led_obj->act_level) { + nrf_gpio_pin_clear(led_obj->hw_pin); + } + else { + nrf_gpio_pin_set(led_obj->hw_pin); + } +} + +static inline void LED_ON(board_led_obj_t * const led_obj) { + if (led_obj->act_level) { + nrf_gpio_pin_set(led_obj->hw_pin); + } + else { + nrf_gpio_pin_clear(led_obj->hw_pin); + } +} + + +static const board_led_obj_t board_led_obj[] = { + #if MICROPY_HW_LED_TRICOLOR - {{&board_led_type}, BOARD_LED_RED, MICROPY_HW_LED_RED}, - {{&board_led_type}, BOARD_LED_GREEN, MICROPY_HW_LED_GREEN}, - {{&board_led_type}, BOARD_LED_BLUE, MICROPY_HW_LED_BLUE}, + + {{&board_led_type}, BOARD_LED_RED, MICROPY_HW_LED_RED, 0, MICROPY_HW_LED_PULLUP != 0 ? 0 : 1}, + {{&board_led_type}, BOARD_LED_GREEN, MICROPY_HW_LED_GREEN,0, MICROPY_HW_LED_PULLUP != 0 ? 0 : 1}, + {{&board_led_type}, BOARD_LED_BLUE, MICROPY_HW_LED_BLUE,0, MICROPY_HW_LED_PULLUP != 0 ? 0 : 1}, + #elif (MICROPY_HW_LED_COUNT == 1) - {{&board_led_type}, BOARD_LED1, MICROPY_HW_LED1}, + + {{&board_led_type}, BOARD_LED1, MICROPY_HW_LED1, 0, + #ifdef MICROPY_HW_LED1_LEVEL + MICROPY_HW_LED1_LEVEL, + #else + MICROPY_HW_LED_PULLUP != 0 ? 0 : 1 + #endif + }, + #elif (MICROPY_HW_LED_COUNT == 2) - {{&board_led_type}, BOARD_LED1, MICROPY_HW_LED1}, - {{&board_led_type}, BOARD_LED2, MICROPY_HW_LED2}, + + {{&board_led_type}, BOARD_LED1, MICROPY_HW_LED1, 0, + #ifdef MICROPY_HW_LED1_LEVEL + MICROPY_HW_LED1_LEVEL, + #else + MICROPY_HW_LED_PULLUP != 0 ? 0 : 1 + #endif + }, + {{&board_led_type}, BOARD_LED2, MICROPY_HW_LED2, 0, + #ifdef MICROPY_HW_LED2_LEVEL + MICROPY_HW_LED2_LEVEL, + #else + MICROPY_HW_LED_PULLUP != 0 ? 0 : 1 + #endif + }, + +#elif (MICROPY_HW_LED_COUNT == 3) + + {{&board_led_type}, BOARD_LED1, MICROPY_HW_LED1, 0, + #ifdef MICROPY_HW_LED1_LEVEL + MICROPY_HW_LED1_LEVEL, + #else + MICROPY_HW_LED_PULLUP != 0 ? 0 : 1 + #endif + }, + {{&board_led_type}, BOARD_LED2, MICROPY_HW_LED2, 0, + #ifdef MICROPY_HW_LED2_LEVEL + MICROPY_HW_LED2_LEVEL, + #else + MICROPY_HW_LED_PULLUP != 0 ? 0 : 1 + #endif + }, + {{&board_led_type}, BOARD_LED3, MICROPY_HW_LED3, 0, + #ifdef MICROPY_HW_LED3_LEVEL + MICROPY_HW_LED3_LEVEL, + #else + MICROPY_HW_LED_PULLUP != 0 ? 0 : 1 + #endif + }, + #else - {{&board_led_type}, BOARD_LED1, MICROPY_HW_LED1}, - {{&board_led_type}, BOARD_LED2, MICROPY_HW_LED2}, - {{&board_led_type}, BOARD_LED3, MICROPY_HW_LED3}, - {{&board_led_type}, BOARD_LED4, MICROPY_HW_LED4}, + + {{&board_led_type}, BOARD_LED1, MICROPY_HW_LED1, 0, + #ifdef MICROPY_HW_LED1_LEVEL + MICROPY_HW_LED1_LEVEL, + #else + MICROPY_HW_LED_PULLUP != 0 ? 0 : 1 + #endif + }, + {{&board_led_type}, BOARD_LED2, MICROPY_HW_LED2, 0, + #ifdef MICROPY_HW_LED2_LEVEL + MICROPY_HW_LED2_LEVEL, + #else + MICROPY_HW_LED_PULLUP != 0 ? 0 : 1 + #endif + }, + {{&board_led_type}, BOARD_LED3, MICROPY_HW_LED3, 0, + #ifdef MICROPY_HW_LED3_LEVEL + MICROPY_HW_LED3_LEVEL, + #else + MICROPY_HW_LED_PULLUP != 0 ? 0 : 1 + #endif + }, + {{&board_led_type}, BOARD_LED4, MICROPY_HW_LED4, 0, + #ifdef MICROPY_HW_LED4_LEVEL + MICROPY_HW_LED4_LEVEL, + #else + MICROPY_HW_LED_PULLUP != 0 ? 0 : 1 + #endif + }, #endif }; @@ -65,16 +156,17 @@ STATIC const board_led_obj_t board_led_obj[] = { void led_init(void) { for (uint8_t i = 0; i < NUM_LEDS; i++) { - LED_OFF(board_led_obj[i].hw_pin); + LED_OFF((board_led_obj_t*)&board_led_obj[i]); nrf_gpio_cfg_output(board_led_obj[i].hw_pin); } } void led_state(board_led_obj_t * led_obj, int state) { if (state == 1) { - LED_ON(led_obj->hw_pin); + LED_ON(led_obj); + } else { - LED_OFF(led_obj->hw_pin); + LED_OFF(led_obj); } } diff --git a/ports/nrf/modules/board/led.h b/ports/nrf/modules/board/led.h index 6210039f49..537b9ac546 100644 --- a/ports/nrf/modules/board/led.h +++ b/ports/nrf/modules/board/led.h @@ -38,6 +38,10 @@ typedef enum { #elif (MICROPY_HW_LED_COUNT == 2) BOARD_LED1 = 1, BOARD_LED2 = 2, +#elif (MICROPY_HW_LED_COUNT == 3) + BOARD_LED1 = 1, + BOARD_LED2 = 2, + BOARD_LED3 = 3, #else BOARD_LED1 = 1, BOARD_LED2 = 2,