mimxrt/led: Add support for up to four LEDs.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This commit is contained in:
parent
0f0dcec984
commit
8d446b2ad5
|
@ -31,16 +31,23 @@
|
|||
#include "py/mphal.h"
|
||||
#include "led.h"
|
||||
|
||||
#if NUM_LEDS
|
||||
#if defined(MICROPY_HW_LED1_PIN)
|
||||
|
||||
const machine_led_obj_t machine_led_obj[NUM_LEDS] = {
|
||||
{
|
||||
.base = {&machine_led_type},
|
||||
.led_id = 1U,
|
||||
.led_pin = &MICROPY_HW_LED1_PIN,
|
||||
}
|
||||
const machine_led_obj_t machine_led_obj[] = {
|
||||
{ .base = {&machine_led_type}, .led_id = 1U, .led_pin = &MICROPY_HW_LED1_PIN, },
|
||||
#if defined(MICROPY_HW_LED2_PIN)
|
||||
{ .base = {&machine_led_type}, .led_id = 2U, .led_pin = &MICROPY_HW_LED2_PIN, },
|
||||
#if defined(MICROPY_HW_LED3_PIN)
|
||||
{ .base = {&machine_led_type}, .led_id = 3U, .led_pin = &MICROPY_HW_LED3_PIN, },
|
||||
#if defined(MICROPY_HW_LED4_PIN)
|
||||
{ .base = {&machine_led_type}, .led_id = 4U, .led_pin = &MICROPY_HW_LED4_PIN, },
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
#define NUM_LEDS MP_ARRAY_SIZE(machine_led_obj)
|
||||
|
||||
void led_init(void) {
|
||||
// Turn off LEDs and initialize
|
||||
for (mp_int_t led = 0; led < NUM_LEDS; led++) {
|
||||
|
@ -94,9 +101,4 @@ void led_debug(int value, int delay) {
|
|||
mp_hal_delay_ms(delay);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void led_init(void) {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,14 +29,20 @@
|
|||
|
||||
#include "pin.h"
|
||||
|
||||
#if defined(MICROPY_HW_LED1_PIN)
|
||||
#define NUM_LEDS (1)
|
||||
#else
|
||||
#define NUM_LEDS (0)
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
MACHINE_BOARD_LED = 1,
|
||||
#if defined(MICROPY_HW_LED1_PIN)
|
||||
MACHINE_BOARD_LED1 = 1,
|
||||
#if defined(MICROPY_HW_LED2_PIN)
|
||||
MACHINE_BOARD_LED2 = 2,
|
||||
#if defined(MICROPY_HW_LED3_PIN)
|
||||
MACHINE_BOARD_LED3 = 3,
|
||||
#if defined(MICROPY_HW_LED4_PIN)
|
||||
MACHINE_BOARD_LED4 = 4,
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
MICROPY_HW_LED_MAX
|
||||
} machine_led_t;
|
||||
|
||||
typedef struct _machine_led_obj_t {
|
||||
|
@ -51,6 +57,6 @@ void led_toggle(machine_led_t led);
|
|||
void led_debug(int value, int delay);
|
||||
|
||||
extern const mp_obj_type_t machine_led_type;
|
||||
extern const machine_led_obj_t machine_led_obj[NUM_LEDS];
|
||||
extern const machine_led_obj_t machine_led_obj[];
|
||||
|
||||
#endif // MICROPY_INCLUDED_MIMXRT_LED_H
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include "py/mphal.h"
|
||||
#include "led.h"
|
||||
|
||||
#if NUM_LEDS
|
||||
#if defined(MICROPY_HW_LED1_PIN)
|
||||
|
||||
STATIC void led_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
(void)kind;
|
||||
|
@ -43,7 +43,7 @@ STATIC mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
|||
mp_int_t led_id = mp_obj_get_int(args[0]);
|
||||
|
||||
// Check led id is in range
|
||||
if (!(1 <= led_id && led_id <= NUM_LEDS)) {
|
||||
if (!(1 <= led_id && led_id < MICROPY_HW_LED_MAX)) {
|
||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("LED(%d) doesn't exist"), led_id);
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,6 @@ int main(void) {
|
|||
board_init();
|
||||
ticks_init();
|
||||
tusb_init();
|
||||
led_init();
|
||||
pendsv_init();
|
||||
|
||||
#if MICROPY_PY_LWIP
|
||||
|
@ -71,6 +70,10 @@ int main(void) {
|
|||
#endif
|
||||
|
||||
for (;;) {
|
||||
#if defined(MICROPY_HW_LED1)
|
||||
led_init();
|
||||
#endif
|
||||
|
||||
mp_stack_set_top(&_estack);
|
||||
mp_stack_set_limit(&_estack - &_sstack - 1024);
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
|
|||
{ MP_ROM_QSTR(MP_QSTR_mem8), MP_ROM_PTR(&machine_mem8_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_mem16), MP_ROM_PTR(&machine_mem16_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_mem32), MP_ROM_PTR(&machine_mem32_obj) },
|
||||
#if NUM_LEDS
|
||||
#if defined(MICROPY_HW_LED1_PIN)
|
||||
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&machine_led_type) },
|
||||
#endif
|
||||
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) },
|
||||
|
|
Loading…
Reference in New Issue