LEDs: Use GPIO flags from dts properly
The flags were always assumed to be ACTIVE_HIGH, which is now fixed.
This commit is contained in:
+25
-4
@@ -67,7 +67,7 @@ static const int led_pin_states[NUM_LEDS][NUM_LED_PINS] = {
|
||||
/*
|
||||
* GPIO pin numbers (for up to 5 LED pins)
|
||||
*/
|
||||
static const int led_pins[] = {
|
||||
static const gpio_pin_t led_pins[] = {
|
||||
DT_PHA_BY_IDX(DT_PATH(leds), gpios, 0, pin),
|
||||
#if NUM_LED_PINS >= 2
|
||||
DT_PHA_BY_IDX(DT_PATH(leds), gpios, 1, pin),
|
||||
@@ -102,6 +102,25 @@ static const char *const led_ports[] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
* GPIO pin flags (for up to 5 LED pins)
|
||||
*/
|
||||
static const gpio_flags_t led_flags[] = {
|
||||
DT_PHA_BY_IDX(DT_PATH(leds), gpios, 0, flags),
|
||||
#if NUM_LED_PINS >= 2
|
||||
DT_PHA_BY_IDX(DT_PATH(leds), gpios, 1, flags),
|
||||
#endif
|
||||
#if NUM_LED_PINS >= 3
|
||||
DT_PHA_BY_IDX(DT_PATH(leds), gpios, 2, flags),
|
||||
#endif
|
||||
#if NUM_LED_PINS >= 4
|
||||
DT_PHA_BY_IDX(DT_PATH(leds), gpios, 3, flags),
|
||||
#endif
|
||||
#if NUM_LED_PINS >= 5
|
||||
DT_PHA_BY_IDX(DT_PATH(leds), gpios, 4, flags),
|
||||
#endif
|
||||
};
|
||||
|
||||
static int led_states[NUM_LEDS]; // must be one of enum LedState
|
||||
static int trigger_timeout[NUM_LEDS]; // seconds until trigger should end
|
||||
|
||||
@@ -148,11 +167,13 @@ void leds_update_thread()
|
||||
for (unsigned int pin_number = 0; pin_number < NUM_LED_PINS; pin_number++) {
|
||||
switch (led_pin_states[led_count][pin_number]) {
|
||||
case PIN_HIGH:
|
||||
gpio_pin_configure(led_devs[pin_number], led_pins[pin_number], GPIO_OUTPUT);
|
||||
gpio_pin_configure(led_devs[pin_number], led_pins[pin_number],
|
||||
led_flags[pin_number] | GPIO_OUTPUT);
|
||||
gpio_pin_set(led_devs[pin_number], led_pins[pin_number], 1);
|
||||
break;
|
||||
case PIN_LOW:
|
||||
gpio_pin_configure(led_devs[pin_number], led_pins[pin_number], GPIO_OUTPUT);
|
||||
gpio_pin_configure(led_devs[pin_number], led_pins[pin_number],
|
||||
led_flags[pin_number] | GPIO_OUTPUT);
|
||||
gpio_pin_set(led_devs[pin_number], led_pins[pin_number], 0);
|
||||
break;
|
||||
case PIN_FLOAT:
|
||||
@@ -181,7 +202,7 @@ void leds_init(bool enabled)
|
||||
for (unsigned int led = 0; led < NUM_LEDS; led++) {
|
||||
if (enabled) {
|
||||
led_states[led] = LED_STATE_ON;
|
||||
trigger_timeout[led] = 0; // switched off the first time the main loop is called
|
||||
trigger_timeout[led] = 0; // switched off the first time the main loop is called
|
||||
}
|
||||
else {
|
||||
led_states[led] = LED_STATE_OFF;
|
||||
|
||||
@@ -89,6 +89,7 @@
|
||||
|
||||
#define DT_N_S_leds_P_gpios_IDX_0_PH DT_N_S_soc_S_pin_controller_48000000_S_gpio_48000800
|
||||
#define DT_N_S_leds_P_gpios_IDX_0_VAL_pin 15
|
||||
#define DT_N_S_leds_P_gpios_IDX_0_VAL_flags 0
|
||||
#define DT_N_S_leds_P_gpios_LEN 1
|
||||
|
||||
#define DT_N_S_soc_S_pin_controller_48000000_S_gpio_48000800_P_label "GPIOC"
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "devicetree.h"
|
||||
#include "devicetree_unfixed.h"
|
||||
#include "autoconf.h"
|
||||
#include "stdint.h"
|
||||
|
||||
#ifndef __deprecated
|
||||
#define __deprecated __attribute__((deprecated))
|
||||
@@ -42,6 +43,13 @@
|
||||
#define LOG_MODULE_REGISTER(a, b)
|
||||
|
||||
|
||||
/* from gpio.h */
|
||||
|
||||
typedef uint8_t gpio_pin_t;
|
||||
|
||||
typedef uint32_t gpio_flags_t;
|
||||
|
||||
|
||||
/* crazy functions from Zephyr's util.h */
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user