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 {
|
||||
compatible = "tactility,gpio-hog";
|
||||
pin = <&gpio0 14 GPIO_FLAG_NONE>;
|
||||
mode = <GPIO_HOG_MODE_OUTPUT_HIGH>;
|
||||
};
|
||||
|
||||
power_en {
|
||||
compatible = "tactility,gpio-hog";
|
||||
pin = <&gpio0 10 GPIO_FLAG_NONE>;
|
||||
mode = <GPIO_HOG_MODE_OUTPUT_HIGH>;
|
||||
};
|
||||
|
||||
adc0 {
|
||||
|
||||
@ -13,7 +13,9 @@ properties:
|
||||
type: phandles
|
||||
required: true
|
||||
description: The GPIO pin to hog
|
||||
output-high:
|
||||
type: boolean
|
||||
default: true
|
||||
description: Level to drive the pin to (true = high, false = low)
|
||||
mode:
|
||||
type: int
|
||||
default: 0
|
||||
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" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.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 GpioPinSpec pin;
|
||||
bool output_high;
|
||||
enum GpioHogMode mode;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -24,9 +24,26 @@ static error_t start(Device* device) {
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
if (gpio_descriptor_set_flags(descriptor, GPIO_FLAG_DIRECTION_OUTPUT) != ERROR_NONE ||
|
||||
gpio_descriptor_set_level(descriptor, config->output_high) != ERROR_NONE) {
|
||||
LOG_E(TAG, "Failed to configure hogged pin");
|
||||
bool ok;
|
||||
switch (config->mode) {
|
||||
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);
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user