Zephyr: Custom DTS binding for GPIO switch
Previously, the LED binding was abused. DTS is now much cleaner.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
/ {
|
||||
model = "Libre Solar MPPT 1210 HUS v0.4";
|
||||
compatible = "st,stm32l073rz-nucleo", "st,stm32l073";
|
||||
compatible = "st,stm32l073";
|
||||
|
||||
chosen {
|
||||
zephyr,console = &usart1;
|
||||
@@ -20,39 +20,45 @@
|
||||
|
||||
leds {
|
||||
compatible = "gpio-leds";
|
||||
led_pin_gnd: led_gnd {
|
||||
gnd {
|
||||
gpios = <&gpiob 14 GPIO_INT_ACTIVE_LOW>;
|
||||
label = "LED GND";
|
||||
};
|
||||
led_pin_soc12: led_soc12 {
|
||||
soc12 {
|
||||
gpios = <&gpiob 13 GPIO_INT_ACTIVE_HIGH>;
|
||||
label = "LED SOC12";
|
||||
};
|
||||
led_pin_soc3: led_soc3 {
|
||||
soc3 {
|
||||
gpios = <&gpiob 2 GPIO_INT_ACTIVE_HIGH>;
|
||||
label = "LED SOC3";
|
||||
};
|
||||
led_pin_rxtx: led_rxtx {
|
||||
rxtx {
|
||||
gpios = <&gpiob 11 GPIO_INT_ACTIVE_HIGH>;
|
||||
label = "LED RXTX";
|
||||
};
|
||||
led_pin_load: led_load {
|
||||
load {
|
||||
gpios = <&gpiob 10 GPIO_INT_ACTIVE_HIGH>;
|
||||
label = "LED Load";
|
||||
};
|
||||
pin_usb_pwr_en: tmp_usb_pwr_en {
|
||||
gpios = <&gpiob 12 GPIO_INT_ACTIVE_HIGH>;
|
||||
label = "USB power enable";
|
||||
};
|
||||
|
||||
switches {
|
||||
compatible = "switch";
|
||||
load-en {
|
||||
gpios = <&gpiob 12 GPIO_DIR_IN>;
|
||||
label = "Load enable";
|
||||
};
|
||||
usb-en {
|
||||
gpios = <&gpiob 12 GPIO_DIR_IN>;
|
||||
label = "USB charging port enable";
|
||||
};
|
||||
};
|
||||
|
||||
aliases {
|
||||
led-a = &led_pin_gnd;
|
||||
led-b = &led_pin_soc12;
|
||||
led-c = &led_pin_soc3;
|
||||
led-d = &led_pin_rxtx;
|
||||
led-e = &led_pin_load;
|
||||
usb-pwr-en = &pin_usb_pwr_en;
|
||||
uart-dbg = &usart1;
|
||||
uext-uart = &usart2;
|
||||
spi-uext = &spi1;
|
||||
i2c-uext = &i2c1;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ CONFIG_GPIO=y
|
||||
CONFIG_CLOCK_CONTROL=y
|
||||
# SYSCLK selection
|
||||
CONFIG_CLOCK_STM32_SYSCLK_SRC_PLL=y
|
||||
|
||||
# PLL configuration
|
||||
CONFIG_CLOCK_STM32_PLL_SRC_HSI=y
|
||||
CONFIG_CLOCK_STM32_PLL_MULTIPLIER=4
|
||||
|
||||
@@ -38,13 +38,16 @@ static const struct pin_config pinconf[] = {
|
||||
{STM32_PIN_PB7, STM32L0_PINMUX_FUNC_PB7_I2C1_SDA},
|
||||
#endif /* CONFIG_I2C_1 */
|
||||
#ifdef CONFIG_SPI_1
|
||||
{STM32_PIN_PA5, STM32L0_PINMUX_FUNC_PA5_SPI1_SCK},
|
||||
{STM32_PIN_PA6, STM32L0_PINMUX_FUNC_PA6_SPI1_MISO},
|
||||
{STM32_PIN_PA7, STM32L0_PINMUX_FUNC_PA7_SPI1_MOSI},
|
||||
{STM32_PIN_PB3, STM32L0_PINMUX_FUNC_PB3_SPI1_SCK},
|
||||
{STM32_PIN_PB4, STM32L0_PINMUX_FUNC_PB4_SPI1_MISO},
|
||||
{STM32_PIN_PB5, STM32L0_PINMUX_FUNC_PB5_SPI1_MOSI},
|
||||
#endif /* CONFIG_SPI_1 */
|
||||
#ifdef CONFIG_ADC_1
|
||||
{STM32_PIN_PA0, STM32L0_PINMUX_FUNC_PA0_ADC_IN0},
|
||||
#endif /* CONFIG_ADC_1 */
|
||||
#ifdef CONFIG_DAC_1
|
||||
{STM32_PIN_PA4, STM32L0_PINMUX_FUNC_PA4_DAC_OUT1},
|
||||
#endif /* CONFIG_ADC_1 */
|
||||
};
|
||||
|
||||
static int pinmux_stm32_init(struct device *port)
|
||||
@@ -60,16 +63,16 @@ SYS_INIT(pinmux_stm32_init, PRE_KERNEL_1,
|
||||
CONFIG_PINMUX_STM32_DEVICE_INITIALIZATION_PRIORITY);
|
||||
|
||||
const char *led_ports[CONFIG_NUM_LED_PINS] = {
|
||||
DT_ALIAS_LED_A_GPIOS_CONTROLLER,
|
||||
DT_ALIAS_LED_B_GPIOS_CONTROLLER,
|
||||
DT_ALIAS_LED_C_GPIOS_CONTROLLER,
|
||||
DT_ALIAS_LED_D_GPIOS_CONTROLLER,
|
||||
DT_ALIAS_LED_E_GPIOS_CONTROLLER
|
||||
DT_GPIO_LEDS_GND_GPIOS_CONTROLLER,
|
||||
DT_GPIO_LEDS_SOC12_GPIOS_CONTROLLER,
|
||||
DT_GPIO_LEDS_SOC3_GPIOS_CONTROLLER,
|
||||
DT_GPIO_LEDS_RXTX_GPIOS_CONTROLLER,
|
||||
DT_GPIO_LEDS_LOAD_GPIOS_CONTROLLER
|
||||
};
|
||||
const int led_pins[CONFIG_NUM_LED_PINS] = {
|
||||
DT_ALIAS_LED_A_GPIOS_PIN, // GND
|
||||
DT_ALIAS_LED_B_GPIOS_PIN, // SOC12
|
||||
DT_ALIAS_LED_C_GPIOS_PIN, // SOC3
|
||||
DT_ALIAS_LED_D_GPIOS_PIN, // RXTX
|
||||
DT_ALIAS_LED_E_GPIOS_PIN // LOAD
|
||||
DT_GPIO_LEDS_GND_GPIOS_PIN,
|
||||
DT_GPIO_LEDS_SOC12_GPIOS_PIN,
|
||||
DT_GPIO_LEDS_SOC3_GPIOS_PIN,
|
||||
DT_GPIO_LEDS_RXTX_GPIOS_PIN,
|
||||
DT_GPIO_LEDS_LOAD_GPIOS_PIN
|
||||
};
|
||||
|
||||
@@ -56,12 +56,12 @@ SYS_INIT(pinmux_stm32_init, PRE_KERNEL_1,
|
||||
CONFIG_PINMUX_STM32_DEVICE_INITIALIZATION_PRIORITY);
|
||||
|
||||
const char *led_ports[CONFIG_NUM_LED_PINS] = {
|
||||
DT_ALIAS_LED_A_GPIOS_CONTROLLER,
|
||||
DT_ALIAS_LED_B_GPIOS_CONTROLLER,
|
||||
DT_ALIAS_LED_C_GPIOS_CONTROLLER,
|
||||
DT_GPIO_LEDS_A_GPIOS_CONTROLLER,
|
||||
DT_GPIO_LEDS_B_GPIOS_CONTROLLER,
|
||||
DT_GPIO_LEDS_C_GPIOS_CONTROLLER,
|
||||
};
|
||||
const int led_pins[CONFIG_NUM_LED_PINS] = {
|
||||
DT_ALIAS_LED_A_GPIOS_PIN,
|
||||
DT_ALIAS_LED_B_GPIOS_PIN,
|
||||
DT_ALIAS_LED_C_GPIOS_PIN,
|
||||
DT_GPIO_LEDS_A_GPIOS_PIN,
|
||||
DT_GPIO_LEDS_B_GPIOS_PIN,
|
||||
DT_GPIO_LEDS_C_GPIOS_PIN,
|
||||
};
|
||||
|
||||
@@ -20,39 +20,37 @@
|
||||
|
||||
leds {
|
||||
compatible = "gpio-leds";
|
||||
led_pin_a: led_pin_a {
|
||||
a {
|
||||
gpios = <&gpiob 13 GPIO_INT_ACTIVE_HIGH>;
|
||||
label = "LED pin A";
|
||||
};
|
||||
led_pin_b: led_pin_b {
|
||||
b {
|
||||
gpios = <&gpiob 14 GPIO_INT_ACTIVE_HIGH>;
|
||||
label = "LED pin B";
|
||||
};
|
||||
led_pin_c: led_pin_c {
|
||||
c {
|
||||
gpios = <&gpiob 15 GPIO_INT_ACTIVE_HIGH>;
|
||||
label = "LED pin C";
|
||||
};
|
||||
// normal GPIO pins also configured as LEDs to be
|
||||
// able to assign aliases
|
||||
pin_load_dis: pin_load_dis {
|
||||
gpios = <&gpiob 2 GPIO_INT_ACTIVE_HIGH>;
|
||||
};
|
||||
|
||||
switches {
|
||||
compatible = "switch";
|
||||
load-dis {
|
||||
gpios = <&gpiob 2 GPIO_DIR_IN>;
|
||||
label = "Load disable";
|
||||
};
|
||||
pin_usb_pwr_dis: pin_usb_pwr_dis {
|
||||
gpios = <&gpiob 5 GPIO_INT_ACTIVE_HIGH>;
|
||||
label = "USB power disable";
|
||||
usb-dis {
|
||||
gpios = <&gpiob 5 GPIO_DIR_IN>;
|
||||
label = "USB charging port disable";
|
||||
};
|
||||
};
|
||||
|
||||
aliases {
|
||||
led-a = &led_pin_a;
|
||||
led-b = &led_pin_b;
|
||||
led-c = &led_pin_c;
|
||||
|
||||
/* WARNING: this one is DISable and not ENable... change name
|
||||
and implement proper handling! */
|
||||
load-en = &pin_load_dis;
|
||||
usb-pwr-en = &pin_usb_pwr_dis;
|
||||
uart-dbg = &usart1;
|
||||
uext-uart = &usart2;
|
||||
spi-uext = &spi1;
|
||||
i2c-uext = &i2c1;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@ const unsigned char bmp_disconnected [] = {
|
||||
I2C i2c_dev(PIN_UEXT_SDA, PIN_UEXT_SCL);
|
||||
OledSSD1306 oled(i2c_dev);
|
||||
#elif defined(__ZEPHYR__)
|
||||
const char i2c_dev[] = "I2C_1";
|
||||
const char i2c_dev[] = DT_ALIAS_I2C_UEXT_LABEL;
|
||||
OledSSD1306 oled(i2c_dev);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ extern const char *led_ports[CONFIG_NUM_LED_PINS];
|
||||
extern const int led_pins[CONFIG_NUM_LED_PINS];
|
||||
#endif // MBED or ZEPHYR
|
||||
|
||||
const pin_state_t led_pin_setup[NUM_LEDS][NUM_LED_PINS] = {
|
||||
const enum pin_state_t led_pin_setup[NUM_LEDS][NUM_LED_PINS] = {
|
||||
{ PIN_HIGH, PIN_LOW, PIN_LOW, PIN_LOW, PIN_LOW }, // LED1
|
||||
{ PIN_LOW, PIN_HIGH, PIN_LOW, PIN_LOW, PIN_LOW }, // LED2
|
||||
{ PIN_LOW, PIN_LOW, PIN_HIGH, PIN_LOW, PIN_LOW }, // LED3
|
||||
@@ -101,10 +101,10 @@ enum {
|
||||
ADC_POS_TEMP_FETS, // ADC 5 (PA_5)
|
||||
ADC_POS_I_LOAD, // ADC 6 (PA_6)
|
||||
ADC_POS_I_DCDC, // ADC 7 (PA_7)
|
||||
#if defined(STM32F0)
|
||||
#if defined(STM32F0) || defined(CONFIG_SOC_SERIES_STM32F0X)
|
||||
ADC_POS_TEMP_MCU, // ADC 16
|
||||
ADC_POS_VREF_MCU, // ADC 17
|
||||
#elif defined(STM32L0)
|
||||
#elif defined(STM32L0) || defined(CONFIG_SOC_SERIES_STM32L0X)
|
||||
ADC_POS_VREF_MCU, // ADC 17
|
||||
ADC_POS_TEMP_MCU, // ADC 18
|
||||
#endif
|
||||
@@ -112,7 +112,7 @@ enum {
|
||||
};
|
||||
|
||||
// selected ADC channels (has to match with above enum)
|
||||
#if defined(STM32F0)
|
||||
#if defined(STM32F0) || defined(CONFIG_SOC_SERIES_STM32F0X)
|
||||
#define ADC_CHSEL ( \
|
||||
ADC_CHSELR_CHSEL0 | \
|
||||
ADC_CHSELR_CHSEL1 | \
|
||||
@@ -122,7 +122,7 @@ enum {
|
||||
ADC_CHSELR_CHSEL16 | \
|
||||
ADC_CHSELR_CHSEL17 \
|
||||
)
|
||||
#elif defined(STM32L0)
|
||||
#elif defined(STM32L0) || defined(CONFIG_SOC_SERIES_STM32L0X)
|
||||
#define ADC_CHSEL ( \
|
||||
ADC_CHSELR_CHSEL0 | \
|
||||
ADC_CHSELR_CHSEL1 | \
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
set(BOARD_ROOT ${CMAKE_SOURCE_DIR}/..)
|
||||
set(DTS_ROOT ${CMAKE_SOURCE_DIR})
|
||||
|
||||
cmake_minimum_required(VERSION 3.13.1)
|
||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||
@@ -23,6 +24,7 @@ target_sources(app PRIVATE ../src/hardware.cpp)
|
||||
target_sources(app PRIVATE ../src/helper.cpp)
|
||||
target_sources(app PRIVATE ../src/leds.cpp)
|
||||
target_sources(app PRIVATE ../src/load.cpp)
|
||||
target_sources(app PRIVATE ../src/load_drv.cpp)
|
||||
target_sources(app PRIVATE ../src/main_zephyr.cpp)
|
||||
target_sources(app PRIVATE ../src/power_port.cpp)
|
||||
target_sources(app PRIVATE ../src/pwm_switch.cpp)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
# Copyright (c) 2020 Martin Jäger / Libre Solar
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
title: GPIO switch parent node
|
||||
description: GPIO pins to switch something on or off
|
||||
|
||||
compatible: "switch"
|
||||
|
||||
child-binding:
|
||||
title: GPIO switch child node
|
||||
description: GPIO switch child node
|
||||
properties:
|
||||
gpios:
|
||||
type: phandle-array
|
||||
required: true
|
||||
label:
|
||||
type: string
|
||||
required: true
|
||||
description: Human readable string describing the device (used by Zephyr for API name)
|
||||
Reference in New Issue
Block a user