Use new Zephyr 2.2 GPIO driver API features
Enable and disable pins are now handled the same using _set function instead of _write and using ACTIVE_HIGH/LOW setting in dts.
This commit is contained in:
@@ -44,11 +44,11 @@
|
||||
|
||||
switches {
|
||||
compatible = "switch";
|
||||
load-en {
|
||||
gpios = <&gpiob 12 GPIO_ACTIVE_HIGH>;
|
||||
load {
|
||||
gpios = <&gpioc 13 GPIO_ACTIVE_HIGH>;
|
||||
label = "Load enable";
|
||||
};
|
||||
usb-en {
|
||||
usb-pwr {
|
||||
gpios = <&gpiob 12 GPIO_ACTIVE_HIGH>;
|
||||
label = "USB charging port enable";
|
||||
};
|
||||
|
||||
@@ -36,19 +36,19 @@
|
||||
|
||||
switches {
|
||||
compatible = "switch";
|
||||
load-en {
|
||||
load {
|
||||
gpios = <&gpioc 13 GPIO_ACTIVE_HIGH>;
|
||||
label = "Load enable";
|
||||
};
|
||||
usb-pwr-en {
|
||||
usb-pwr {
|
||||
gpios = <&gpiob 10 GPIO_ACTIVE_HIGH>;
|
||||
label = "USB charging port enable";
|
||||
};
|
||||
v-solar-en {
|
||||
v-solar {
|
||||
gpios = <&gpioc 14 GPIO_ACTIVE_HIGH>;
|
||||
label = "Solar voltage measurement enable";
|
||||
};
|
||||
boot0-en {
|
||||
boot0 {
|
||||
gpios = <&gpiob 12 GPIO_ACTIVE_HIGH>;
|
||||
label = "BOOT0 pin trigger";
|
||||
};
|
||||
|
||||
@@ -59,8 +59,8 @@
|
||||
|
||||
switches {
|
||||
compatible = "switch";
|
||||
load-dis {
|
||||
gpios = <&gpiob 15 GPIO_ACTIVE_HIGH>;
|
||||
load {
|
||||
gpios = <&gpiob 15 GPIO_ACTIVE_LOW>;
|
||||
label = "Load disable";
|
||||
};
|
||||
};
|
||||
|
||||
@@ -32,16 +32,16 @@
|
||||
|
||||
switches {
|
||||
compatible = "switch";
|
||||
load-dis {
|
||||
gpios = <&gpiob 2 GPIO_ACTIVE_HIGH>;
|
||||
load {
|
||||
gpios = <&gpiob 2 GPIO_ACTIVE_LOW>;
|
||||
label = "Load disable";
|
||||
};
|
||||
uext-dis {
|
||||
gpios = <&gpioc 14 GPIO_ACTIVE_HIGH>;
|
||||
uext {
|
||||
gpios = <&gpioc 14 GPIO_ACTIVE_LOW>;
|
||||
label = "UEXT disable";
|
||||
};
|
||||
can-dis {
|
||||
gpios = <&gpioa 15 GPIO_ACTIVE_HIGH>;
|
||||
can {
|
||||
gpios = <&gpioa 15 GPIO_ACTIVE_LOW>;
|
||||
label = "CAN disable / standby";
|
||||
};
|
||||
};
|
||||
|
||||
@@ -36,15 +36,15 @@
|
||||
|
||||
switches {
|
||||
compatible = "switch";
|
||||
load-dis {
|
||||
gpios = <&gpiob 2 GPIO_ACTIVE_HIGH>;
|
||||
load {
|
||||
gpios = <&gpiob 2 GPIO_ACTIVE_LOW>;
|
||||
label = "Load disable";
|
||||
};
|
||||
usb-pwr-dis {
|
||||
gpios = <&gpiob 5 GPIO_ACTIVE_HIGH>;
|
||||
usb-pwr {
|
||||
gpios = <&gpiob 5 GPIO_ACTIVE_LOW>;
|
||||
label = "USB charging port disable";
|
||||
};
|
||||
boot0-en {
|
||||
boot0 {
|
||||
gpios = <&gpiob 12 GPIO_ACTIVE_HIGH>;
|
||||
label = "BOOT0 pin trigger";
|
||||
};
|
||||
|
||||
+4
-4
@@ -98,10 +98,10 @@ static void dac_setup()
|
||||
|
||||
static void adc_setup()
|
||||
{
|
||||
#ifdef DT_SWITCH_V_SOLAR_EN_GPIOS_CONTROLLER
|
||||
struct device *dev = device_get_binding(DT_SWITCH_V_SOLAR_EN_GPIOS_CONTROLLER);
|
||||
gpio_pin_configure(dev, DT_SWITCH_V_SOLAR_EN_GPIOS_PIN, GPIO_DIR_OUT);
|
||||
gpio_pin_write(dev, DT_SWITCH_V_SOLAR_EN_GPIOS_PIN, 1);
|
||||
#ifdef DT_SWITCH_V_SOLAR_GPIOS_CONTROLLER
|
||||
struct device *dev = device_get_binding(DT_SWITCH_V_SOLAR_GPIOS_CONTROLLER);
|
||||
gpio_pin_configure(dev, DT_SWITCH_V_SOLAR_GPIOS_PIN,
|
||||
DT_SWITCH_V_SOLAR_GPIOS_FLAGS | GPIO_OUTPUT_ACTIVE);
|
||||
#endif
|
||||
|
||||
struct device *dev_adc = device_get_binding(DT_ADC_1_NAME);
|
||||
|
||||
+5
-6
@@ -79,7 +79,7 @@ private:
|
||||
DigitalOut can_disable;
|
||||
#elif defined(__ZEPHYR__)
|
||||
struct device *can_dev;
|
||||
struct device *gpio_stb_dev;
|
||||
struct device *can_en_dev;
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -130,17 +130,16 @@ ThingSetCAN::ThingSetCAN(uint8_t can_node_id, const unsigned int c):
|
||||
node_id(can_node_id),
|
||||
channel(c)
|
||||
{
|
||||
gpio_stb_dev = device_get_binding(DT_SWITCH_CAN_DIS_GPIOS_CONTROLLER);
|
||||
gpio_pin_configure(gpio_stb_dev, DT_SWITCH_CAN_DIS_GPIOS_PIN, GPIO_DIR_OUT);
|
||||
gpio_pin_write(gpio_stb_dev, DT_SWITCH_CAN_DIS_GPIOS_PIN, 1);
|
||||
can_en_dev = device_get_binding(DT_SWITCH_CAN_GPIOS_CONTROLLER);
|
||||
gpio_pin_configure(can_en_dev, DT_SWITCH_CAN_GPIOS_PIN,
|
||||
DT_SWITCH_CAN_GPIOS_FLAGS | GPIO_OUTPUT_INACTIVE);
|
||||
|
||||
can_dev = device_get_binding("CAN_1");
|
||||
}
|
||||
|
||||
void ThingSetCAN::enable()
|
||||
{
|
||||
// enable the transceiver (set STB pin low)
|
||||
gpio_pin_write(gpio_stb_dev, DT_SWITCH_CAN_DIS_GPIOS_PIN, 0);
|
||||
gpio_pin_write(gpio_stb_dev, DT_SWITCH_CAN_GPIOS_PIN, 1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+4
-5
@@ -71,11 +71,10 @@ void ExtOled::enable()
|
||||
uext_dis = 0;
|
||||
#endif
|
||||
|
||||
#if defined(DT_SWITCH_UEXT_DIS_GPIOS_CONTROLLER) && defined(__ZEPHYR__)
|
||||
struct device *dev_uext_dis =
|
||||
device_get_binding(DT_SWITCH_UEXT_DIS_GPIOS_CONTROLLER);
|
||||
gpio_pin_configure(dev_uext_dis, DT_SWITCH_UEXT_DIS_GPIOS_PIN, GPIO_DIR_OUT);
|
||||
gpio_pin_write(dev_uext_dis, DT_SWITCH_UEXT_DIS_GPIOS_PIN, 0);
|
||||
#ifdef DT_SWITCH_UEXT_GPIOS_CONTROLLER
|
||||
struct device *dev_uext_dis = device_get_binding(DT_SWITCH_UEXT_GPIOS_CONTROLLER);
|
||||
gpio_pin_configure(dev_uext_dis, DT_SWITCH_UEXT_GPIOS_PIN,
|
||||
DT_SWITCH_UEXT_GPIOS_FLAGS | GPIO_OUTPUT_ACTIVE);
|
||||
#endif
|
||||
|
||||
#ifdef OLED_BRIGHTNESS
|
||||
|
||||
+4
-4
@@ -224,11 +224,11 @@ void reset_device()
|
||||
|
||||
void start_stm32_bootloader()
|
||||
{
|
||||
#ifdef DT_SWITCH_BOOT0_EN_GPIOS_CONTROLLER
|
||||
#ifdef DT_SWITCH_BOOT0_GPIOS_CONTROLLER
|
||||
// pin is connected to BOOT0 via resistor and capacitor
|
||||
struct device *dev = device_get_binding(DT_SWITCH_BOOT0_EN_GPIOS_CONTROLLER);
|
||||
gpio_pin_configure(dev, DT_SWITCH_BOOT0_EN_GPIOS_PIN, GPIO_DIR_OUT);
|
||||
gpio_pin_write(dev, DT_SWITCH_BOOT0_EN_GPIOS_PIN, 1);
|
||||
struct device *dev = device_get_binding(DT_SWITCH_BOOT0_GPIOS_CONTROLLER);
|
||||
gpio_pin_configure(dev, DT_SWITCH_BOOT0_GPIOS_PIN,
|
||||
DT_SWITCH_BOOT0_GPIOS_FLAGS | GPIO_OUTPUT_ACTIVE);
|
||||
|
||||
k_sleep(100); // wait for capacitor at BOOT0 pin to charge up
|
||||
reset_device();
|
||||
|
||||
+6
-6
@@ -172,15 +172,15 @@ void leds_update_thread()
|
||||
for (int pin_number = 0; pin_number < NUM_LED_PINS; pin_number++) {
|
||||
switch (led_pin_setup[led_count][pin_number]) {
|
||||
case PIN_HIGH:
|
||||
gpio_pin_configure(led_devs[pin_number], led_pins[pin_number], GPIO_DIR_OUT);
|
||||
gpio_pin_write(led_devs[pin_number], led_pins[pin_number], 1);
|
||||
gpio_pin_configure(led_devs[pin_number], led_pins[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_DIR_OUT);
|
||||
gpio_pin_write(led_devs[pin_number], led_pins[pin_number], 0);
|
||||
gpio_pin_configure(led_devs[pin_number], led_pins[pin_number], GPIO_OUTPUT);
|
||||
gpio_pin_set(led_devs[pin_number], led_pins[pin_number], 0);
|
||||
break;
|
||||
case PIN_FLOAT:
|
||||
gpio_pin_configure(led_devs[pin_number], led_pins[pin_number], GPIO_DIR_IN);
|
||||
gpio_pin_configure(led_devs[pin_number], led_pins[pin_number], GPIO_INPUT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -188,7 +188,7 @@ void leds_update_thread()
|
||||
else {
|
||||
// all pins floating
|
||||
for (int pin_number = 0; pin_number < NUM_LED_PINS; pin_number++) {
|
||||
gpio_pin_configure(led_devs[pin_number], led_pins[pin_number], GPIO_DIR_IN);
|
||||
gpio_pin_configure(led_devs[pin_number], led_pins[pin_number], GPIO_INPUT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+17
-39
@@ -185,27 +185,18 @@ void LoadOutput::switch_set(bool status)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__ZEPHYR__) && defined(DT_SWITCH_LOAD_EN_GPIOS_CONTROLLER)
|
||||
gpio_pin_configure(dev_load, DT_SWITCH_LOAD_EN_GPIOS_PIN, GPIO_DIR_OUT);
|
||||
#ifdef DT_SWITCH_LOAD_GPIOS_CONTROLLER
|
||||
gpio_pin_configure(dev_load, DT_SWITCH_LOAD_GPIOS_PIN,
|
||||
DT_SWITCH_LOAD_GPIOS_FLAGS | GPIO_OUTPUT_INACTIVE);
|
||||
if (status == true) {
|
||||
gpio_pin_write(dev_load, DT_SWITCH_LOAD_EN_GPIOS_PIN, 1);
|
||||
}
|
||||
else {
|
||||
gpio_pin_write(dev_load, DT_SWITCH_LOAD_EN_GPIOS_PIN, 0);
|
||||
}
|
||||
#ifdef PIN_I_LOAD_COMP
|
||||
lptim_init();
|
||||
#else
|
||||
gpio_pin_set(dev_load, DT_SWITCH_LOAD_GPIOS_PIN, 1);
|
||||
#endif
|
||||
|
||||
#if defined(__ZEPHYR__) && defined(DT_SWITCH_LOAD_DIS_GPIOS_CONTROLLER)
|
||||
gpio_pin_configure(dev_load, DT_SWITCH_LOAD_DIS_GPIOS_PIN, GPIO_DIR_OUT);
|
||||
if (status == true) {
|
||||
#ifdef PIN_I_LOAD_COMP
|
||||
lptim_init();
|
||||
#else
|
||||
gpio_pin_write(dev_load, DT_SWITCH_LOAD_DIS_GPIOS_PIN, 0);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
gpio_pin_write(dev_load, DT_SWITCH_LOAD_DIS_GPIOS_PIN, 1);
|
||||
gpio_pin_set(dev_load, DT_SWITCH_LOAD_GPIOS_PIN, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -227,23 +218,14 @@ void LoadOutput::usb_set(bool status)
|
||||
else usb_pwr_dis = 1;
|
||||
#endif
|
||||
|
||||
#if defined(__ZEPHYR__) && defined(DT_SWITCH_USB_PWR_EN_GPIOS_CONTROLLER)
|
||||
gpio_pin_configure(dev_usb, DT_SWITCH_USB_PWR_EN_GPIOS_PIN, GPIO_DIR_OUT);
|
||||
#ifdef DT_SWITCH_USB_PWR_GPIOS_CONTROLLER
|
||||
gpio_pin_configure(dev_usb, DT_SWITCH_USB_PWR_GPIOS_PIN,
|
||||
DT_SWITCH_USB_PWR_GPIOS_FLAGS | GPIO_OUTPUT_INACTIVE);
|
||||
if (status == true) {
|
||||
gpio_pin_write(dev_usb, DT_SWITCH_USB_PWR_EN_GPIOS_PIN, 1);
|
||||
gpio_pin_set(dev_usb, DT_SWITCH_USB_PWR_GPIOS_PIN, 1);
|
||||
}
|
||||
else {
|
||||
gpio_pin_write(dev_usb, DT_SWITCH_USB_PWR_EN_GPIOS_PIN, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__ZEPHYR__) && defined(DT_SWITCH_USB_PWR_DIS_GPIOS_CONTROLLER)
|
||||
gpio_pin_configure(dev_usb, DT_SWITCH_USB_PWR_DIS_GPIOS_PIN, GPIO_DIR_OUT);
|
||||
if (status == true) {
|
||||
gpio_pin_write(dev_usb, DT_SWITCH_USB_PWR_DIS_GPIOS_PIN, 0);
|
||||
}
|
||||
else {
|
||||
gpio_pin_write(dev_usb, DT_SWITCH_USB_PWR_DIS_GPIOS_PIN, 1);
|
||||
gpio_pin_set(dev_usb, DT_SWITCH_USB_PWR_GPIOS_PIN, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -254,16 +236,12 @@ void LoadOutput::usb_set(bool status)
|
||||
|
||||
void LoadOutput::get_bindings()
|
||||
{
|
||||
#if defined(DT_SWITCH_USB_PWR_EN_GPIOS_CONTROLLER)
|
||||
dev_usb = device_get_binding(DT_SWITCH_USB_PWR_EN_GPIOS_CONTROLLER);
|
||||
#elif defined(DT_SWITCH_USB_PWR_DIS_GPIOS_CONTROLLER)
|
||||
dev_usb = device_get_binding(DT_SWITCH_USB_PWR_DIS_GPIOS_CONTROLLER);
|
||||
#ifdef DT_SWITCH_USB_PWR_GPIOS_CONTROLLER
|
||||
dev_usb = device_get_binding(DT_SWITCH_USB_PWR_GPIOS_CONTROLLER);
|
||||
#endif
|
||||
|
||||
#if defined(DT_SWITCH_LOAD_EN_GPIOS_CONTROLLER)
|
||||
dev_load = device_get_binding(DT_SWITCH_LOAD_EN_GPIOS_CONTROLLER);
|
||||
#elif defined(DT_SWITCH_LOAD_DIS_GPIOS_CONTROLLER)
|
||||
dev_load = device_get_binding(DT_SWITCH_LOAD_DIS_GPIOS_CONTROLLER);
|
||||
#ifdef DT_SWITCH_LOAD_GPIOS_CONTROLLER
|
||||
dev_load = device_get_binding(DT_SWITCH_LOAD_GPIOS_CONTROLLER);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user