stmhal/led: Refactor LED to use mp_hal_pin_output() init function.
As part of this patch the MICROPY_HW_LED_OTYPE setting is removed because it is now unused (all boards anyway had this as OUTPUT_PP).
This commit is contained in:
parent
d49d81b167
commit
b4cc68e4a4
@ -66,6 +66,5 @@
|
||||
#define MICROPY_HW_LED2 (pin_B12) // green
|
||||
#define MICROPY_HW_LED3 (pin_B12) // green
|
||||
#define MICROPY_HW_LED4 (pin_B12) // green
|
||||
#define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP)
|
||||
#define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRRL = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRRH = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin))
|
||||
#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin))
|
||||
|
@ -69,9 +69,8 @@
|
||||
#define MICROPY_HW_LED2 (pin_A4) // same as LED1
|
||||
#define MICROPY_HW_LED3 (pin_A4) // same as LED1
|
||||
#define MICROPY_HW_LED4 (pin_A4) // same as LED1
|
||||
#define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP)
|
||||
#define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRRL = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRRH = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin))
|
||||
#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin))
|
||||
|
||||
// SD card detect switch (not used, always on)
|
||||
#define MICROPY_HW_SDCARD_DETECT_PIN (pin_A8)
|
||||
|
@ -63,9 +63,8 @@ void LIMIFROG_board_early_init(void);
|
||||
|
||||
// LEDs
|
||||
#define MICROPY_HW_LED1 (pin_C3) // red
|
||||
#define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP)
|
||||
#define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRR = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRR = pin->pin_mask<<16)
|
||||
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin))
|
||||
#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin))
|
||||
|
||||
// USB config
|
||||
// #define MICROPY_HW_USB_OTG_ID_PIN (pin_C12) // This is not the official ID Pin which should be PA10
|
||||
|
@ -64,9 +64,8 @@ void NETDUINO_PLUS_2_board_early_init(void);
|
||||
#define MICROPY_HW_LED2 (pin_C13) // White LED (aka Power)
|
||||
#define MICROPY_HW_LED3 (pin_A10) // Same as Led(1)
|
||||
#define MICROPY_HW_LED4 (pin_C13) // Same as Led(2)
|
||||
#define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP)
|
||||
#define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRRL = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRRH = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin))
|
||||
#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin))
|
||||
|
||||
// USB VBUS detect pin
|
||||
#define MICROPY_HW_USB_VBUS_DETECT_PIN (pin_A9)
|
||||
|
@ -54,6 +54,5 @@
|
||||
|
||||
// LEDs
|
||||
#define MICROPY_HW_LED1 (pin_A5) // Green LD2 LED on Nucleo
|
||||
#define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP)
|
||||
#define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRRL = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRRH = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin))
|
||||
#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin))
|
||||
|
@ -65,6 +65,5 @@
|
||||
|
||||
// LEDs
|
||||
#define MICROPY_HW_LED1 (pin_A5) // Green LD2 LED on Nucleo
|
||||
#define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP)
|
||||
#define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRRL = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRRH = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin))
|
||||
#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin))
|
||||
|
@ -71,9 +71,8 @@
|
||||
|
||||
// LEDs
|
||||
#define MICROPY_HW_LED1 (pin_C13)
|
||||
#define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP)
|
||||
#define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRRH = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRRL = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_low(pin))
|
||||
#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_high(pin))
|
||||
|
||||
// SD card detect switch
|
||||
#define MICROPY_HW_SDCARD_DETECT_PIN (pin_C11)
|
||||
|
@ -73,9 +73,8 @@
|
||||
#define MICROPY_HW_LED4 (pin_B4) // blue
|
||||
#define MICROPY_HW_LED3_PWM { TIM2, 2, TIM_CHANNEL_1, GPIO_AF1_TIM2 }
|
||||
#define MICROPY_HW_LED4_PWM { TIM3, 3, TIM_CHANNEL_1, GPIO_AF2_TIM3 }
|
||||
#define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP)
|
||||
#define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRRL = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRRH = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin))
|
||||
#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin))
|
||||
|
||||
// SD card detect switch
|
||||
#define MICROPY_HW_SDCARD_DETECT_PIN (pin_B5)
|
||||
|
@ -84,9 +84,8 @@
|
||||
#define MICROPY_HW_LED4 (pin_B4) // blue
|
||||
#define MICROPY_HW_LED3_PWM { TIM2, 2, TIM_CHANNEL_1, GPIO_AF1_TIM2 }
|
||||
#define MICROPY_HW_LED4_PWM { TIM3, 3, TIM_CHANNEL_1, GPIO_AF2_TIM3 }
|
||||
#define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP)
|
||||
#define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRRL = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRRH = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin))
|
||||
#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin))
|
||||
|
||||
// SD card detect switch
|
||||
#define MICROPY_HW_SDCARD_DETECT_PIN (pin_A8)
|
||||
|
@ -84,9 +84,8 @@
|
||||
#define MICROPY_HW_LED4 (pin_B4) // blue
|
||||
#define MICROPY_HW_LED3_PWM { TIM2, 2, TIM_CHANNEL_1, GPIO_AF1_TIM2 }
|
||||
#define MICROPY_HW_LED4_PWM { TIM3, 3, TIM_CHANNEL_1, GPIO_AF2_TIM3 }
|
||||
#define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP)
|
||||
#define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRRL = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRRH = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin))
|
||||
#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin))
|
||||
|
||||
// SD card detect switch
|
||||
#define MICROPY_HW_SDCARD_DETECT_PIN (pin_A8)
|
||||
|
@ -73,9 +73,8 @@
|
||||
#define MICROPY_HW_LED4 (pin_C5) // G2 - green
|
||||
#define MICROPY_HW_LED1_PWM { TIM1, 1, TIM_CHANNEL_1, GPIO_AF1_TIM1 }
|
||||
#define MICROPY_HW_LED2_PWM { TIM1, 1, TIM_CHANNEL_3, GPIO_AF1_TIM1 }
|
||||
#define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP)
|
||||
#define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRRH = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRRL = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_low(pin))
|
||||
#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_high(pin))
|
||||
|
||||
// SD card detect switch
|
||||
#define MICROPY_HW_SDCARD_DETECT_PIN (pin_C13)
|
||||
|
@ -81,9 +81,8 @@
|
||||
#define MICROPY_HW_LED4 (pin_B4) // blue
|
||||
#define MICROPY_HW_LED3_PWM { TIM2, 2, TIM_CHANNEL_1, GPIO_AF1_TIM2 }
|
||||
#define MICROPY_HW_LED4_PWM { TIM3, 3, TIM_CHANNEL_1, GPIO_AF2_TIM3 }
|
||||
#define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP)
|
||||
#define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRRL = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRRH = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin))
|
||||
#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin))
|
||||
|
||||
// SD card detect switch
|
||||
#define MICROPY_HW_SDCARD_DETECT_PIN (pin_A8)
|
||||
|
@ -63,9 +63,8 @@
|
||||
#define MICROPY_HW_LED2 (pin_D12) // green
|
||||
#define MICROPY_HW_LED3 (pin_D13) // orange
|
||||
#define MICROPY_HW_LED4 (pin_D15) // blue
|
||||
#define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP)
|
||||
#define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRRL = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRRH = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin))
|
||||
#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin))
|
||||
|
||||
// USB config
|
||||
#define MICROPY_HW_USB_VBUS_DETECT_PIN (pin_A9)
|
||||
|
@ -67,9 +67,8 @@
|
||||
// LEDs
|
||||
#define MICROPY_HW_LED1 (pin_G14) // red
|
||||
#define MICROPY_HW_LED2 (pin_G13) // green
|
||||
#define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP)
|
||||
#define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRRL = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRRH = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin))
|
||||
#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin))
|
||||
|
||||
// USB config
|
||||
#define MICROPY_HW_USB_VBUS_DETECT_PIN (pin_B13)
|
||||
|
@ -82,9 +82,8 @@
|
||||
#define MICROPY_HW_LED2 (pin_D12) // green
|
||||
#define MICROPY_HW_LED3 (pin_D13) // orange
|
||||
#define MICROPY_HW_LED4 (pin_D15) // blue
|
||||
#define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP)
|
||||
#define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRRL = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRRH = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin))
|
||||
#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin))
|
||||
|
||||
// USB config
|
||||
#define MICROPY_HW_USB_VBUS_DETECT_PIN (pin_A9)
|
||||
|
@ -79,9 +79,8 @@ void STM32F7DISC_board_early_init(void);
|
||||
|
||||
// LEDs
|
||||
#define MICROPY_HW_LED1 (pin_I1) // green
|
||||
#define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP)
|
||||
#define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRR = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRR = (pin->pin_mask << 16))
|
||||
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin))
|
||||
#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin))
|
||||
|
||||
// SD card detect switch
|
||||
#define MICROPY_HW_SDCARD_DETECT_PIN (pin_C13)
|
||||
|
@ -61,9 +61,8 @@
|
||||
// LEDs
|
||||
#define MICROPY_HW_LED1 (pin_B2) // red
|
||||
#define MICROPY_HW_LED2 (pin_E8) // green
|
||||
#define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP)
|
||||
#define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRR = pin->pin_mask)
|
||||
#define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRR = pin->pin_mask<<16)
|
||||
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin))
|
||||
#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin))
|
||||
|
||||
// USB config
|
||||
// #define MICROPY_HW_USB_OTG_ID_PIN (pin_C12) // This is not the official ID Pin which should be PA10
|
||||
|
11
stmhal/led.c
11
stmhal/led.c
@ -67,21 +67,12 @@ STATIC const pyb_led_obj_t pyb_led_obj[] = {
|
||||
#define NUM_LEDS MP_ARRAY_SIZE(pyb_led_obj)
|
||||
|
||||
void led_init(void) {
|
||||
/* GPIO structure */
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
/* Configure I/O speed, mode, output type and pull */
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
|
||||
GPIO_InitStructure.Mode = MICROPY_HW_LED_OTYPE;
|
||||
GPIO_InitStructure.Pull = GPIO_NOPULL;
|
||||
|
||||
/* Turn off LEDs and initialize */
|
||||
for (int led = 0; led < NUM_LEDS; led++) {
|
||||
const pin_obj_t *led_pin = pyb_led_obj[led].led_pin;
|
||||
mp_hal_gpio_clock_enable(led_pin->gpio);
|
||||
MICROPY_HW_LED_OFF(led_pin);
|
||||
GPIO_InitStructure.Pin = led_pin->pin_mask;
|
||||
HAL_GPIO_Init(led_pin->gpio, &GPIO_InitStructure);
|
||||
mp_hal_pin_output(led_pin);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user