mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-08-20 17:05:06 +00:00
Improve gpio-hog driver
This commit is contained in:
parent
49af1d42f8
commit
1069032148
@ -41,11 +41,13 @@
|
|||||||
power_on {
|
power_on {
|
||||||
compatible = "tactility,gpio-hog";
|
compatible = "tactility,gpio-hog";
|
||||||
pin = <&gpio0 14 GPIO_FLAG_NONE>;
|
pin = <&gpio0 14 GPIO_FLAG_NONE>;
|
||||||
|
mode = <GPIO_HOG_MODE_OUTPUT_HIGH>;
|
||||||
};
|
};
|
||||||
|
|
||||||
power_en {
|
power_en {
|
||||||
compatible = "tactility,gpio-hog";
|
compatible = "tactility,gpio-hog";
|
||||||
pin = <&gpio0 10 GPIO_FLAG_NONE>;
|
pin = <&gpio0 10 GPIO_FLAG_NONE>;
|
||||||
|
mode = <GPIO_HOG_MODE_OUTPUT_HIGH>;
|
||||||
};
|
};
|
||||||
|
|
||||||
adc0 {
|
adc0 {
|
||||||
|
|||||||
@ -13,7 +13,9 @@ properties:
|
|||||||
type: phandles
|
type: phandles
|
||||||
required: true
|
required: true
|
||||||
description: The GPIO pin to hog
|
description: The GPIO pin to hog
|
||||||
output-high:
|
mode:
|
||||||
type: boolean
|
type: int
|
||||||
default: true
|
default: 0
|
||||||
description: Level to drive the pin to (true = high, false = low)
|
description: |
|
||||||
|
Pin mode, see enum GpioHogMode in tactility/drivers/gpio_hog.h:
|
||||||
|
0 = GPIO_HOG_MODE_OUTPUT_HIGH, 1 = GPIO_HOG_MODE_OUTPUT_LOW, 2 = GPIO_HOG_MODE_INPUT.
|
||||||
|
|||||||
@ -5,13 +5,17 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include <tactility/drivers/gpio.h>
|
#include <tactility/drivers/gpio.h>
|
||||||
|
|
||||||
|
enum GpioHogMode {
|
||||||
|
GPIO_HOG_MODE_OUTPUT_HIGH,
|
||||||
|
GPIO_HOG_MODE_OUTPUT_LOW,
|
||||||
|
GPIO_HOG_MODE_INPUT,
|
||||||
|
};
|
||||||
|
|
||||||
struct GpioHogConfig {
|
struct GpioHogConfig {
|
||||||
struct GpioPinSpec pin;
|
struct GpioPinSpec pin;
|
||||||
bool output_high;
|
enum GpioHogMode mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@ -24,9 +24,26 @@ static error_t start(Device* device) {
|
|||||||
return ERROR_RESOURCE;
|
return ERROR_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gpio_descriptor_set_flags(descriptor, GPIO_FLAG_DIRECTION_OUTPUT) != ERROR_NONE ||
|
bool ok;
|
||||||
gpio_descriptor_set_level(descriptor, config->output_high) != ERROR_NONE) {
|
switch (config->mode) {
|
||||||
LOG_E(TAG, "Failed to configure hogged pin");
|
case GPIO_HOG_MODE_OUTPUT_HIGH:
|
||||||
|
ok = gpio_descriptor_set_flags(descriptor, GPIO_FLAG_DIRECTION_OUTPUT) == ERROR_NONE &&
|
||||||
|
gpio_descriptor_set_level(descriptor, true) == ERROR_NONE;
|
||||||
|
break;
|
||||||
|
case GPIO_HOG_MODE_OUTPUT_LOW:
|
||||||
|
ok = gpio_descriptor_set_flags(descriptor, GPIO_FLAG_DIRECTION_OUTPUT) == ERROR_NONE &&
|
||||||
|
gpio_descriptor_set_level(descriptor, false) == ERROR_NONE;
|
||||||
|
break;
|
||||||
|
case GPIO_HOG_MODE_INPUT:
|
||||||
|
ok = gpio_descriptor_set_flags(descriptor, GPIO_FLAG_DIRECTION_INPUT) == ERROR_NONE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ok = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ok) {
|
||||||
|
LOG_E(TAG, "Failed to configure hogged pin %u", config->pin.pin);
|
||||||
gpio_descriptor_release(descriptor);
|
gpio_descriptor_release(descriptor);
|
||||||
return ERROR_RESOURCE;
|
return ERROR_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user