mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-08-17 23:55:04 +00:00
Devices and drivers
This commit is contained in:
parent
5160bcf2bf
commit
24aed54671
@ -6,7 +6,8 @@
|
||||
#include <tactility/bindings/esp32_gpio.h>
|
||||
#include <tactility/bindings/esp32_i2c.h>
|
||||
#include <tactility/bindings/esp32_usbhost.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
#include <bindings/rgb_display.h>
|
||||
#include <bindings/gt911.h>
|
||||
|
||||
@ -55,9 +56,17 @@
|
||||
pin-scl = <&gpio0 3 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 21 GPIO_FLAG_NONE>;
|
||||
period-ns = <33333>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
pin-backlight = <&gpio0 21 GPIO_FLAG_NONE>;
|
||||
compatible = "pwm-backlight";
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
display0 {
|
||||
|
||||
@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
REQUIRES TactilityKernel driver
|
||||
REQUIRES TactilityKernel
|
||||
)
|
||||
|
||||
@ -6,7 +6,9 @@
|
||||
#include <tactility/bindings/esp32_i2c.h>
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
#include <tactility/bindings/rgb_led_pwm.h>
|
||||
#include <bindings/ili9341.h>
|
||||
#include <bindings/cst816s.h>
|
||||
|
||||
@ -39,13 +41,57 @@
|
||||
};
|
||||
};
|
||||
|
||||
rgb_led_channel_red {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 4 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <1>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_channel_green {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 16 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <2>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_channel_blue {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 17 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <3>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_pwm {
|
||||
compatible = "rgb-led-pwm";
|
||||
pwm-red = <&rgb_led_channel_red>;
|
||||
pwm-green = <&rgb_led_channel_green>;
|
||||
pwm-blue = <&rgb_led_channel_blue>;
|
||||
// Default is red, and we want to reset it to off by default
|
||||
default-color = <0 0 0>;
|
||||
enabled;
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 27 GPIO_FLAG_NONE>;
|
||||
period-ns = <1953125>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
compatible = "pwm-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 27 GPIO_FLAG_NONE>;
|
||||
frequency-hz = <512>;
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -1,20 +1,8 @@
|
||||
#include <tactility/module.h>
|
||||
#include <tactility/error.h>
|
||||
|
||||
#include <driver/gpio.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
static error_t start() {
|
||||
// Set the RGB LED pins to output and turn them off (0 on, 1 off)
|
||||
gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT); // Red
|
||||
gpio_set_direction(GPIO_NUM_16, GPIO_MODE_OUTPUT); // Green
|
||||
gpio_set_direction(GPIO_NUM_17, GPIO_MODE_OUTPUT); // Blue
|
||||
|
||||
gpio_set_level(GPIO_NUM_4, 1); // Red
|
||||
gpio_set_level(GPIO_NUM_16, 1); // Green
|
||||
gpio_set_level(GPIO_NUM_17, 1); // Blue
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
REQUIRES TactilityKernel driver
|
||||
REQUIRES TactilityKernel
|
||||
)
|
||||
|
||||
@ -6,7 +6,9 @@
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
#include <tactility/bindings/rgb_led_pwm.h>
|
||||
#include <bindings/ili9341.h>
|
||||
#include <bindings/xpt2046.h>
|
||||
|
||||
@ -24,13 +26,57 @@
|
||||
gpio-count = <40>;
|
||||
};
|
||||
|
||||
rgb_led_channel_red {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 4 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <1>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_channel_green {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 16 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <2>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_channel_blue {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 17 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <3>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_pwm {
|
||||
compatible = "rgb-led-pwm";
|
||||
pwm-red = <&rgb_led_channel_red>;
|
||||
pwm-green = <&rgb_led_channel_green>;
|
||||
pwm-blue = <&rgb_led_channel_blue>;
|
||||
// Default is red, and we want to reset it to off by default
|
||||
default-color = <0 0 0>;
|
||||
enabled;
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 27 GPIO_FLAG_NONE>;
|
||||
period-ns = <1953125>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
compatible = "pwm-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 27 GPIO_FLAG_NONE>;
|
||||
frequency-hz = <512>;
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -3,12 +3,10 @@
|
||||
extern "C" {
|
||||
|
||||
static error_t start() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
REQUIRES TactilityKernel driver
|
||||
REQUIRES TactilityKernel
|
||||
)
|
||||
|
||||
@ -7,7 +7,9 @@
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
#include <tactility/bindings/rgb_led_pwm.h>
|
||||
#include <bindings/ili9341.h>
|
||||
#include <bindings/xpt2046_softspi.h>
|
||||
|
||||
@ -33,13 +35,57 @@
|
||||
pin-scl = <&gpio0 22 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
rgb_led_channel_red {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 4 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <1>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_channel_green {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 16 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <2>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_channel_blue {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 17 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <3>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 21 GPIO_FLAG_NONE>;
|
||||
period-ns = <1953125>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
rgb_led_pwm {
|
||||
compatible = "rgb-led-pwm";
|
||||
pwm-red = <&rgb_led_channel_red>;
|
||||
pwm-green = <&rgb_led_channel_green>;
|
||||
pwm-blue = <&rgb_led_channel_blue>;
|
||||
// Default is red, and we want to reset it to off by default
|
||||
default-color = <0 0 0>;
|
||||
enabled;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
compatible = "pwm-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 21 GPIO_FLAG_NONE>;
|
||||
frequency-hz = <512>;
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
touch {
|
||||
|
||||
@ -1,25 +1,12 @@
|
||||
#include <tactility/module.h>
|
||||
#include <tactility/error.h>
|
||||
|
||||
#include <driver/gpio.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
static error_t start() {
|
||||
// Set the RGB LED pins to output and turn them off (0 on, 1 off)
|
||||
gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT); // Red
|
||||
gpio_set_direction(GPIO_NUM_16, GPIO_MODE_OUTPUT); // Green
|
||||
gpio_set_direction(GPIO_NUM_17, GPIO_MODE_OUTPUT); // Blue
|
||||
|
||||
gpio_set_level(GPIO_NUM_4, 1); // Red
|
||||
gpio_set_level(GPIO_NUM_16, 1); // Green
|
||||
gpio_set_level(GPIO_NUM_17, 1); // Blue
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
REQUIRES TactilityKernel driver
|
||||
REQUIRES TactilityKernel
|
||||
)
|
||||
|
||||
@ -7,7 +7,9 @@
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
#include <tactility/bindings/rgb_led_pwm.h>
|
||||
#include <bindings/st7789.h>
|
||||
#include <bindings/xpt2046_softspi.h>
|
||||
|
||||
@ -33,13 +35,57 @@
|
||||
pin-scl = <&gpio0 22 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
rgb_led_channel_red {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 4 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <1>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_channel_green {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 16 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <2>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_channel_blue {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 17 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <3>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_pwm {
|
||||
compatible = "rgb-led-pwm";
|
||||
pwm-red = <&rgb_led_channel_red>;
|
||||
pwm-green = <&rgb_led_channel_green>;
|
||||
pwm-blue = <&rgb_led_channel_blue>;
|
||||
// Default is red, and we want to reset it to off by default
|
||||
default-color = <0 0 0>;
|
||||
enabled;
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 21 GPIO_FLAG_NONE>;
|
||||
period-ns = <1953125>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
compatible = "pwm-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 21 GPIO_FLAG_NONE>;
|
||||
frequency-hz = <512>;
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
touch {
|
||||
|
||||
@ -1,20 +1,8 @@
|
||||
#include <tactility/module.h>
|
||||
#include <tactility/error.h>
|
||||
|
||||
#include <driver/gpio.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
static error_t start() {
|
||||
// Set the RGB LED pins to output and turn them off (0 on, 1 off)
|
||||
gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT); // Red
|
||||
gpio_set_direction(GPIO_NUM_16, GPIO_MODE_OUTPUT); // Green
|
||||
gpio_set_direction(GPIO_NUM_17, GPIO_MODE_OUTPUT); // Blue
|
||||
|
||||
gpio_set_level(GPIO_NUM_4, 1); // Red
|
||||
gpio_set_level(GPIO_NUM_16, 1); // Green
|
||||
gpio_set_level(GPIO_NUM_17, 1); // Blue
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
REQUIRES TactilityKernel driver
|
||||
REQUIRES TactilityKernel
|
||||
)
|
||||
|
||||
@ -6,7 +6,9 @@
|
||||
#include <tactility/bindings/esp32_i2c.h>
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
#include <tactility/bindings/rgb_led_pwm.h>
|
||||
#include <bindings/ili9341.h>
|
||||
#include <bindings/gt911.h>
|
||||
|
||||
@ -39,12 +41,57 @@
|
||||
};
|
||||
};
|
||||
|
||||
rgb_led_channel_red {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 4 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <1>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_channel_green {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 16 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <2>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_channel_blue {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 17 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <3>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_pwm {
|
||||
compatible = "rgb-led-pwm";
|
||||
pwm-red = <&rgb_led_channel_red>;
|
||||
pwm-green = <&rgb_led_channel_green>;
|
||||
pwm-blue = <&rgb_led_channel_blue>;
|
||||
// Default is red, and we want to reset it to off by default
|
||||
default-color = <0 0 0>;
|
||||
enabled;
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 27 GPIO_FLAG_NONE>;
|
||||
period-ns = <33333>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
compatible = "pwm-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 27 GPIO_FLAG_NONE>;
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -3,12 +3,10 @@
|
||||
extern "C" {
|
||||
|
||||
static error_t start() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
REQUIRES TactilityKernel driver
|
||||
REQUIRES TactilityKernel
|
||||
)
|
||||
|
||||
@ -7,7 +7,9 @@
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
#include <tactility/bindings/rgb_led_pwm.h>
|
||||
#include <bindings/st7796.h>
|
||||
#include <bindings/gt911.h>
|
||||
|
||||
@ -49,12 +51,57 @@
|
||||
pin-scl = <&gpio0 22 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
rgb_led_channel_red {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 4 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <1>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_channel_green {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 16 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <2>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_channel_blue {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 17 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <3>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_pwm {
|
||||
compatible = "rgb-led-pwm";
|
||||
pwm-red = <&rgb_led_channel_red>;
|
||||
pwm-green = <&rgb_led_channel_green>;
|
||||
pwm-blue = <&rgb_led_channel_blue>;
|
||||
// Default is red, and we want to reset it to off by default
|
||||
default-color = <0 0 0>;
|
||||
enabled;
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 27 GPIO_FLAG_NONE>;
|
||||
period-ns = <33333>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
compatible = "pwm-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 27 GPIO_FLAG_NONE>;
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -1,25 +1,12 @@
|
||||
#include <tactility/module.h>
|
||||
#include <tactility/error.h>
|
||||
|
||||
#include <driver/gpio.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
static error_t start() {
|
||||
// Set the RGB LED pins to output and turn them off (0 on, 1 off)
|
||||
gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT); // Red
|
||||
gpio_set_direction(GPIO_NUM_16, GPIO_MODE_OUTPUT); // Green
|
||||
gpio_set_direction(GPIO_NUM_17, GPIO_MODE_OUTPUT); // Blue
|
||||
|
||||
gpio_set_level(GPIO_NUM_4, 1); // Red
|
||||
gpio_set_level(GPIO_NUM_16, 1); // Green
|
||||
gpio_set_level(GPIO_NUM_17, 1); // Blue
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
@ -8,7 +8,8 @@
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
#include <bindings/rgb_display.h>
|
||||
#include <bindings/gt911.h>
|
||||
|
||||
@ -71,9 +72,17 @@
|
||||
};
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 2 GPIO_FLAG_NONE>;
|
||||
period-ns = <33333>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
pin-backlight = <&gpio0 2 GPIO_FLAG_NONE>;
|
||||
compatible = "pwm-backlight";
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
display0 {
|
||||
|
||||
@ -3,12 +3,10 @@
|
||||
extern "C" {
|
||||
|
||||
static error_t start() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
REQUIRES TactilityKernel driver
|
||||
REQUIRES TactilityKernel
|
||||
)
|
||||
|
||||
@ -5,7 +5,9 @@
|
||||
#include <tactility/bindings/esp32_gpio.h>
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
#include <tactility/bindings/rgb_led_pwm.h>
|
||||
#include <bindings/ili9341.h>
|
||||
#include <bindings/xpt2046_softspi.h>
|
||||
|
||||
@ -23,13 +25,58 @@
|
||||
gpio-count = <40>;
|
||||
};
|
||||
|
||||
|
||||
rgb_led_channel_red {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 22 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <1>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_channel_green {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 16 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <2>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_channel_blue {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 17 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <3>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_pwm {
|
||||
compatible = "rgb-led-pwm";
|
||||
pwm-red = <&rgb_led_channel_red>;
|
||||
pwm-green = <&rgb_led_channel_green>;
|
||||
pwm-blue = <&rgb_led_channel_blue>;
|
||||
// Default is red, and we want to reset it to off by default
|
||||
default-color = <0 0 0>;
|
||||
enabled;
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 21 GPIO_FLAG_NONE>;
|
||||
period-ns = <1953125>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
compatible = "pwm-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 21 GPIO_FLAG_NONE>;
|
||||
frequency-hz = <512>;
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
touch {
|
||||
|
||||
@ -3,12 +3,10 @@
|
||||
extern "C" {
|
||||
|
||||
static error_t start() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
REQUIRES TactilityKernel driver
|
||||
REQUIRES TactilityKernel
|
||||
)
|
||||
|
||||
@ -8,7 +8,9 @@
|
||||
#include <tactility/bindings/esp32_i2c.h>
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
#include <tactility/bindings/rgb_led_pwm.h>
|
||||
#include <bindings/st7789.h>
|
||||
#include <bindings/xpt2046.h>
|
||||
|
||||
@ -40,6 +42,43 @@
|
||||
channels = <ADC_CHANNEL_6 ADC_ATTEN_DB_12 ADC_BITWIDTH_DEFAULT>;
|
||||
};
|
||||
|
||||
rgb_led_channel_red {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 22 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <1>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_channel_green {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 16 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <2>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_channel_blue {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 17 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <3>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_pwm {
|
||||
compatible = "rgb-led-pwm";
|
||||
pwm-red = <&rgb_led_channel_red>;
|
||||
pwm-green = <&rgb_led_channel_green>;
|
||||
pwm-blue = <&rgb_led_channel_blue>;
|
||||
// Default is red, and we want to reset it to off by default
|
||||
default-color = <0 0 0>;
|
||||
enabled;
|
||||
};
|
||||
|
||||
// Matches the deprecated HAL's old ChargeFromAdcVoltage config: adcMultiplier=2.11,
|
||||
// adcRefVoltage=3.3 (default), voltageMin/Max=3.2/4.2 (default, same as battery-sense's own
|
||||
// fixed curve - see TactilityKernel/source/drivers/battery_sense.cpp).
|
||||
@ -50,13 +89,20 @@
|
||||
multiplier = <2110>;
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 27 GPIO_FLAG_NONE>;
|
||||
period-ns = <25000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
compatible = "pwm-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 27 GPIO_FLAG_NONE>;
|
||||
frequency-hz = <40000>;
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -3,12 +3,10 @@
|
||||
extern "C" {
|
||||
|
||||
static error_t start() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
REQUIRES TactilityKernel driver
|
||||
REQUIRES TactilityKernel
|
||||
)
|
||||
|
||||
@ -8,7 +8,8 @@
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
#include <bindings/st7789.h>
|
||||
#include <bindings/ft5x06.h>
|
||||
|
||||
@ -46,9 +47,17 @@
|
||||
};
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 38 GPIO_FLAG_NONE>;
|
||||
period-ns = <33333>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
pin-backlight = <&gpio0 38 GPIO_FLAG_NONE>;
|
||||
compatible = "pwm-backlight";
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
REQUIRES TactilityKernel driver
|
||||
REQUIRES TactilityKernel
|
||||
)
|
||||
|
||||
@ -8,7 +8,8 @@
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
#include <bindings/ili9488.h>
|
||||
#include <bindings/gt911.h>
|
||||
|
||||
@ -46,13 +47,20 @@
|
||||
};
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 38 GPIO_FLAG_NONE>;
|
||||
period-ns = <1953125>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
compatible = "pwm-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 38 GPIO_FLAG_NONE>;
|
||||
frequency-hz = <512>;
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_gpio_backlight.h>
|
||||
#include <tactility/bindings/gpio_backlight.h>
|
||||
#include <bindings/rgb_display.h>
|
||||
#include <bindings/gt911.h>
|
||||
#include <bindings/tca9534.h>
|
||||
@ -70,8 +70,8 @@
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-gpio-backlight";
|
||||
pin-backlight = <&io_expander0 1 GPIO_FLAG_NONE>;
|
||||
compatible = "gpio-backlight";
|
||||
pin = <&io_expander0 1 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
display0 {
|
||||
|
||||
@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
REQUIRES TactilityKernel driver
|
||||
REQUIRES TactilityKernel
|
||||
)
|
||||
|
||||
@ -7,7 +7,8 @@
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
#include <bindings/ili9341.h>
|
||||
#include <bindings/xpt2046.h>
|
||||
|
||||
@ -33,13 +34,20 @@
|
||||
pin-scl = <&gpio0 21 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 27 GPIO_FLAG_NONE>;
|
||||
period-ns = <25000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
compatible = "pwm-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 27 GPIO_FLAG_NONE>;
|
||||
frequency-hz = <40000>;
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -3,12 +3,10 @@
|
||||
extern "C" {
|
||||
|
||||
static error_t start() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
REQUIRES TactilityKernel driver
|
||||
REQUIRES TactilityKernel
|
||||
)
|
||||
|
||||
@ -7,7 +7,8 @@
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
#include <bindings/ili9488.h>
|
||||
#include <bindings/xpt2046.h>
|
||||
|
||||
@ -33,13 +34,20 @@
|
||||
pin-scl = <&gpio0 21 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 27 GPIO_FLAG_NONE>;
|
||||
period-ns = <1953125>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
compatible = "pwm-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 27 GPIO_FLAG_NONE>;
|
||||
frequency-hz = <512>;
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -8,7 +8,8 @@
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
#include <bindings/rgb_display.h>
|
||||
#include <bindings/gt911.h>
|
||||
|
||||
@ -63,10 +64,17 @@
|
||||
};
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 2 GPIO_FLAG_NONE>;
|
||||
period-ns = <1953125>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
pin-backlight = <&gpio0 2 GPIO_FLAG_NONE>;
|
||||
frequency-hz = <512>;
|
||||
compatible = "pwm-backlight";
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
display0 {
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
#include "devices/Display.h"
|
||||
#include <driver/gpio.h>
|
||||
|
||||
#include <PwmBacklight.h>
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
@ -7,16 +6,6 @@
|
||||
using namespace tt::hal;
|
||||
|
||||
static bool initBoot() {
|
||||
//Set the RGB Led Pins to output and turn them off
|
||||
ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT)); //Red
|
||||
ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_16, GPIO_MODE_OUTPUT)); //Green
|
||||
ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_17, GPIO_MODE_OUTPUT)); //Blue
|
||||
|
||||
//0 on, 1 off... yep it's backwards.
|
||||
ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_4, 1)); //Red
|
||||
ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_16, 1)); //Green
|
||||
ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_17, 1)); //Blue
|
||||
|
||||
return driver::pwmbacklight::init(LCD_PIN_BACKLIGHT);
|
||||
}
|
||||
|
||||
|
||||
@ -3,12 +3,10 @@
|
||||
extern "C" {
|
||||
|
||||
static error_t start() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/display_placeholder.h>
|
||||
#include <tactility/bindings/rgb_led_pwm.h>
|
||||
|
||||
/ {
|
||||
compatible = "root";
|
||||
@ -74,4 +75,42 @@
|
||||
pin-tx = <&gpio0 22 GPIO_FLAG_NONE>;
|
||||
pin-rx = <&gpio0 21 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
|
||||
rgb_led_channel_red {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 4 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <1>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_channel_green {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 16 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <2>;
|
||||
inverted;
|
||||
};
|
||||
|
||||
rgb_led_channel_blue {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 17 GPIO_FLAG_NONE>;
|
||||
period-ns = <500000>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <3>;
|
||||
inverted;
|
||||
// Default is red, and we want to reset it to off by default
|
||||
default-color = <0 0 0>;
|
||||
enabled;
|
||||
};
|
||||
|
||||
rgb_led_pwm {
|
||||
compatible = "rgb-led-pwm";
|
||||
pwm-red = <&rgb_led_channel_red>;
|
||||
pwm-green = <&rgb_led_channel_green>;
|
||||
pwm-blue = <&rgb_led_channel_blue>;
|
||||
};
|
||||
};
|
||||
|
||||
@ -8,7 +8,8 @@
|
||||
#include <tactility/bindings/esp32_grove.h>
|
||||
#include <tactility/bindings/esp32_i2c.h>
|
||||
#include <tactility/bindings/esp32_i2s.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_wifi_pinned.h>
|
||||
@ -134,15 +135,22 @@
|
||||
};
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 42 GPIO_FLAG_NONE>;
|
||||
// 32 KHz and higher causes the screen to start dimming again above 80% brightness
|
||||
// when moving the brightness slider rapidly from a lower setting to 100% (debug-traced, not a slider bug).
|
||||
period-ns = <33333>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
compatible = "pwm-backlight";
|
||||
// Off by default so dispaly power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 42 GPIO_FLAG_NONE>;
|
||||
// 32 KHz and higher causes the screen to start dimming again above 80% brightness
|
||||
// when moving the brightness slider rapidly from a lower setting to 100% (debug-traced, not a slider bug).
|
||||
frequency-hz = <30000>;
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -8,7 +8,8 @@
|
||||
#include <tactility/bindings/esp32_grove.h>
|
||||
#include <tactility/bindings/esp32_i2c.h>
|
||||
#include <tactility/bindings/esp32_i2s.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_wifi_pinned.h>
|
||||
@ -134,15 +135,22 @@
|
||||
};
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 42 GPIO_FLAG_NONE>;
|
||||
// 32 KHz and higher causes the screen to start dimming again above 80% brightness
|
||||
// when moving the brightness slider rapidly from a lower setting to 100% (debug-traced, not a slider bug).
|
||||
period-ns = <33333>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
compatible = "pwm-backlight";
|
||||
// Off by default so dispaly power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 42 GPIO_FLAG_NONE>;
|
||||
// 32 KHz and higher causes the screen to start dimming again above 80% brightness
|
||||
// when moving the brightness slider rapidly from a lower setting to 100% (debug-traced, not a slider bug).
|
||||
frequency-hz = <30000>;
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -9,7 +9,8 @@
|
||||
#include <tactility/bindings/esp32_i2c.h>
|
||||
#include <tactility/bindings/esp32_sdmmc.h>
|
||||
#include <tactility/bindings/esp32_i8080.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
#include <tactility/bindings/gpio_hog.h>
|
||||
#include <bindings/button_control.h>
|
||||
#include <bindings/st7789_i8080.h>
|
||||
@ -39,13 +40,13 @@
|
||||
// HAL's initBoot() used to run. gpio-hog nodes run in declaration order, so they must stay
|
||||
// before the i8080 bus node.
|
||||
power_on {
|
||||
compatible = "tactility,gpio-hog";
|
||||
compatible = "gpio-hog";
|
||||
pin = <&gpio0 14 GPIO_FLAG_NONE>;
|
||||
mode = <GPIO_HOG_MODE_OUTPUT_HIGH>;
|
||||
};
|
||||
|
||||
power_en {
|
||||
compatible = "tactility,gpio-hog";
|
||||
compatible = "gpio-hog";
|
||||
pin = <&gpio0 10 GPIO_FLAG_NONE>;
|
||||
mode = <GPIO_HOG_MODE_OUTPUT_HIGH>;
|
||||
};
|
||||
@ -68,13 +69,20 @@
|
||||
multiplier = <2000>;
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 38 GPIO_FLAG_NONE>;
|
||||
period-ns = <33333>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
compatible = "pwm-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 38 GPIO_FLAG_NONE>;
|
||||
frequency-hz = <30000>;
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
i8080_0 {
|
||||
|
||||
@ -13,7 +13,8 @@
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <bindings/bmi270.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
|
||||
#include <bindings/st7789.h>
|
||||
#include <bindings/cardputer_adv_keyboard.h>
|
||||
@ -81,13 +82,20 @@
|
||||
i2cClockFrequency = <400000>;
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 38 GPIO_FLAG_NONE>;
|
||||
period-ns = <1953125>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
compatible = "pwm-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 38 GPIO_FLAG_NONE>;
|
||||
frequency-hz = <512>;
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -12,7 +12,8 @@
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
|
||||
#include <bindings/st7789.h>
|
||||
#include <bindings/cardputer_keyboard.h>
|
||||
@ -64,13 +65,20 @@
|
||||
i2cClockFrequency = <400000>;
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 38 GPIO_FLAG_NONE>;
|
||||
period-ns = <1953125>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
compatible = "pwm-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 38 GPIO_FLAG_NONE>;
|
||||
frequency-hz = <512>;
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -7,7 +7,8 @@
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <bindings/mpu6886.h>
|
||||
#include <bindings/bm8563.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
|
||||
#include <bindings/st7789.h>
|
||||
#include <bindings/button_control.h>
|
||||
@ -52,13 +53,20 @@
|
||||
pin-scl = <&gpio0 33 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 27 GPIO_FLAG_NONE>;
|
||||
period-ns = <1953125>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
compatible = "pwm-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 27 GPIO_FLAG_NONE>;
|
||||
frequency-hz = <512>;
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
#include <bindings/bq24295.h>
|
||||
#include <bindings/unphone_power_switch.h>
|
||||
#include <bindings/unphone_nav_buttons.h>
|
||||
#include <tactility/bindings/esp32_gpio_backlight.h>
|
||||
#include <tactility/bindings/gpio_backlight.h>
|
||||
#include <tactility/bindings/gpio_hog.h>
|
||||
|
||||
/ {
|
||||
@ -66,42 +66,42 @@
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-gpio-backlight";
|
||||
pin-backlight = <&tca9535 2 GPIO_FLAG_NONE>;
|
||||
compatible = "gpio-backlight";
|
||||
pin = <&tca9535 2 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
usb_vsense {
|
||||
compatible = "tactility,gpio-hog";
|
||||
compatible = "gpio-hog";
|
||||
pin = <&tca9535 14 GPIO_FLAG_NONE>;
|
||||
mode = <GPIO_HOG_MODE_INPUT>;
|
||||
};
|
||||
|
||||
vibration_motor {
|
||||
compatible = "tactility,gpio-hog";
|
||||
compatible = "gpio-hog";
|
||||
pin = <&tca9535 7 GPIO_FLAG_NONE>;
|
||||
mode = <GPIO_HOG_MODE_OUTPUT_LOW>;
|
||||
};
|
||||
|
||||
ir_leds {
|
||||
compatible = "tactility,gpio-hog";
|
||||
compatible = "gpio-hog";
|
||||
pin = <&gpio0 12 GPIO_FLAG_NONE>;
|
||||
mode = <GPIO_HOG_MODE_OUTPUT_LOW>;
|
||||
};
|
||||
|
||||
red_led {
|
||||
compatible = "tactility,gpio-hog";
|
||||
compatible = "gpio-hog";
|
||||
pin = <&gpio0 13 GPIO_FLAG_NONE>;
|
||||
mode = <GPIO_HOG_MODE_OUTPUT_LOW>;
|
||||
};
|
||||
|
||||
green_led {
|
||||
compatible = "tactility,gpio-hog";
|
||||
compatible = "gpio-hog";
|
||||
pin = <&tca9535 9 GPIO_FLAG_NONE>;
|
||||
mode = <GPIO_HOG_MODE_OUTPUT_LOW>;
|
||||
};
|
||||
|
||||
blue_led {
|
||||
compatible = "tactility,gpio-hog";
|
||||
compatible = "gpio-hog";
|
||||
pin = <&tca9535 13 GPIO_FLAG_NONE>;
|
||||
mode = <GPIO_HOG_MODE_OUTPUT_LOW>;
|
||||
};
|
||||
|
||||
@ -8,7 +8,8 @@
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <bindings/qmi8658.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
||||
#include <tactility/bindings/pwm_backlight.h>
|
||||
#include <bindings/st7789.h>
|
||||
|
||||
// Reference: https://www.waveshare.com/wiki/ESP32-S3-LCD-1.3
|
||||
@ -44,9 +45,17 @@
|
||||
};
|
||||
};
|
||||
|
||||
display_backlight_pwm {
|
||||
compatible = "espressif,esp32-pwm-ledc";
|
||||
pin = <&gpio0 20 GPIO_FLAG_NONE>;
|
||||
period-ns = <33333>;
|
||||
ledc-timer = <0>;
|
||||
ledc-channel = <0>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
pin-backlight = <&gpio0 20 GPIO_FLAG_NONE>;
|
||||
compatible = "pwm-backlight";
|
||||
pwm = <&display_backlight_pwm>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -1,29 +0,0 @@
|
||||
description: ESP32 LEDC-backed PWM backlight
|
||||
|
||||
compatible: "espressif,esp32-ledc-backlight"
|
||||
|
||||
properties:
|
||||
pin-backlight:
|
||||
type: phandles
|
||||
required: true
|
||||
description: Backlight PWM output pin
|
||||
frequency-hz:
|
||||
type: int
|
||||
default: 30000
|
||||
description: PWM frequency in Hz
|
||||
brightness-level-range:
|
||||
type: values
|
||||
default: [0, 255]
|
||||
description: Inclusive [min,max] brightness range. The minimum value turns the backlight off.
|
||||
brightness-default:
|
||||
type: int
|
||||
default: 200
|
||||
description: Default brightness level, applied by set_brightness_default(). Should fall within brightness-level-range.
|
||||
ledc-timer:
|
||||
type: int
|
||||
default: 0
|
||||
description: LEDC timer index, defined by ledc_timer_t
|
||||
ledc-channel:
|
||||
type: int
|
||||
default: 0
|
||||
description: LEDC channel index, defined by ledc_channel_t
|
||||
@ -0,0 +1,33 @@
|
||||
description: ESP32 LEDC-backed generic PWM output
|
||||
|
||||
compatible: "espressif,esp32-pwm-ledc"
|
||||
|
||||
properties:
|
||||
pin:
|
||||
type: phandles
|
||||
required: true
|
||||
description: PWM output pin
|
||||
period-ns:
|
||||
type: int
|
||||
required: true
|
||||
description: The PWM period, in nanoseconds
|
||||
duty-ns:
|
||||
type: int
|
||||
default: 0
|
||||
description: The PWM duty cycle (active time within one period), in nanoseconds
|
||||
inverted:
|
||||
type: boolean
|
||||
default: false
|
||||
description: Whether the output polarity is inverted
|
||||
duty-resolution:
|
||||
type: int
|
||||
default: 10
|
||||
description: LEDC duty resolution in bits, defined by ledc_timer_bit_t
|
||||
ledc-timer:
|
||||
type: int
|
||||
required: true
|
||||
description: LEDC timer index, defined by ledc_timer_t
|
||||
ledc-channel:
|
||||
type: int
|
||||
required: true
|
||||
description: LEDC channel index, defined by ledc_channel_t
|
||||
@ -1,15 +0,0 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#pragma once
|
||||
|
||||
#include <tactility/bindings/bindings.h>
|
||||
#include <tactility/drivers/esp32_gpio_backlight.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
DEFINE_DEVICETREE(esp32_gpio_backlight, struct Esp32GpioBacklightConfig)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -1,15 +0,0 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#pragma once
|
||||
|
||||
#include <tactility/bindings/bindings.h>
|
||||
#include <tactility/drivers/esp32_ledc_backlight.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
DEFINE_DEVICETREE(esp32_ledc_backlight, struct Esp32LedcBacklightConfig)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -2,13 +2,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <tactility/bindings/bindings.h>
|
||||
#include <tactility/drivers/spi_peripheral.h>
|
||||
#include <tactility/drivers/esp32_pwm_ledc.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
DEFINE_DEVICETREE(spi_peripheral, struct SpiPeripheralConfig)
|
||||
DEFINE_DEVICETREE(esp32_pwm_ledc, struct Esp32PwmLedcConfig)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#pragma once
|
||||
|
||||
#include <tactility/drivers/backlight.h>
|
||||
#include <tactility/drivers/gpio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Esp32GpioBacklightConfig {
|
||||
struct GpioPinSpec pin_backlight;
|
||||
bool default_on;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -2,18 +2,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <driver/ledc.h>
|
||||
#include <tactility/drivers/backlight.h>
|
||||
#include <tactility/drivers/gpio.h>
|
||||
#include <tactility/drivers/pwm.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Esp32LedcBacklightConfig {
|
||||
struct GpioPinSpec pin_backlight;
|
||||
uint32_t frequency_hz;
|
||||
struct BrightnessLevelRange brightness_range;
|
||||
uint8_t brightness_default;
|
||||
struct Esp32PwmLedcConfig {
|
||||
struct GpioPinSpec pin;
|
||||
uint32_t period_ns;
|
||||
uint32_t duty_ns;
|
||||
bool inverted;
|
||||
ledc_timer_bit_t duty_resolution;
|
||||
ledc_timer_t ledc_timer;
|
||||
ledc_channel_t ledc_channel;
|
||||
};
|
||||
@ -1,119 +0,0 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#include <tactility/drivers/esp32_gpio_backlight.h>
|
||||
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/driver.h>
|
||||
#include <tactility/drivers/backlight.h>
|
||||
#include <tactility/drivers/gpio_controller.h>
|
||||
#include <tactility/drivers/gpio_descriptor.h>
|
||||
#include <tactility/log.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#define TAG "Esp32GpioBacklight"
|
||||
#define GET_CONFIG(device) (static_cast<const Esp32GpioBacklightConfig*>((device)->config))
|
||||
|
||||
struct Esp32GpioBacklightInternal {
|
||||
GpioDescriptor* descriptor;
|
||||
uint8_t brightness;
|
||||
};
|
||||
|
||||
// region Driver lifecycle
|
||||
|
||||
static error_t start(Device* device) {
|
||||
const auto* config = GET_CONFIG(device);
|
||||
|
||||
auto* descriptor = gpio_descriptor_acquire(config->pin_backlight.gpio_controller, config->pin_backlight.pin, GPIO_OWNER_GPIO);
|
||||
if (descriptor == nullptr) {
|
||||
LOG_E(TAG, "Failed to acquire GPIO descriptor");
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
if (gpio_descriptor_set_flags(descriptor, config->pin_backlight.flags | GPIO_FLAG_DIRECTION_OUTPUT) != ERROR_NONE) {
|
||||
LOG_E(TAG, "Failed to configure backlight pin as output");
|
||||
gpio_descriptor_release(descriptor);
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
auto* internal = static_cast<Esp32GpioBacklightInternal*>(malloc(sizeof(Esp32GpioBacklightInternal)));
|
||||
if (internal == nullptr) {
|
||||
gpio_descriptor_release(descriptor);
|
||||
return ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
internal->descriptor = descriptor;
|
||||
internal->brightness = 0;
|
||||
|
||||
device_set_driver_data(device, internal);
|
||||
|
||||
backlight_set_brightness_default(device); // Allowed to fail, we don't care about the result
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop(Device* device) {
|
||||
backlight_set_brightness(device, 0); // Allowed to fail, we don't care about the result
|
||||
|
||||
auto* internal = static_cast<Esp32GpioBacklightInternal*>(device_get_driver_data(device));
|
||||
gpio_descriptor_release(internal->descriptor);
|
||||
free(internal);
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
// region BacklightApi
|
||||
|
||||
static error_t esp32_gpio_backlight_set_brightness(Device* device, uint8_t brightness) {
|
||||
auto* internal = static_cast<Esp32GpioBacklightInternal*>(device_get_driver_data(device));
|
||||
|
||||
error_t error = gpio_descriptor_set_level(internal->descriptor, brightness > 0);
|
||||
if (error != ERROR_NONE) {
|
||||
LOG_E(TAG, "Failed to set backlight level");
|
||||
return error;
|
||||
}
|
||||
|
||||
internal->brightness = brightness;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t esp32_gpio_backlight_set_brightness_default(Device* device) {
|
||||
return esp32_gpio_backlight_set_brightness(device, GET_CONFIG(device)->default_on ? 1 : 0);
|
||||
}
|
||||
|
||||
static error_t esp32_gpio_backlight_get_brightness(Device* device, uint8_t* out_brightness) {
|
||||
auto* internal = static_cast<Esp32GpioBacklightInternal*>(device_get_driver_data(device));
|
||||
*out_brightness = internal->brightness;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static uint8_t esp32_gpio_backlight_get_min_brightness(Device*) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t esp32_gpio_backlight_get_max_brightness(Device*) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
static const BacklightApi esp32_gpio_backlight_api = {
|
||||
.set_brightness = esp32_gpio_backlight_set_brightness,
|
||||
.set_brightness_default = esp32_gpio_backlight_set_brightness_default,
|
||||
.get_brightness = esp32_gpio_backlight_get_brightness,
|
||||
.get_min_brightness = esp32_gpio_backlight_get_min_brightness,
|
||||
.get_max_brightness = esp32_gpio_backlight_get_max_brightness,
|
||||
};
|
||||
|
||||
extern Module platform_esp32_module;
|
||||
|
||||
Driver esp32_gpio_backlight_driver = {
|
||||
.name = "esp32_gpio_backlight",
|
||||
.compatible = (const char*[]) { "espressif,esp32-gpio-backlight", nullptr },
|
||||
.start_device = start,
|
||||
.stop_device = stop,
|
||||
.api = &esp32_gpio_backlight_api,
|
||||
.device_type = &BACKLIGHT_TYPE,
|
||||
.owner = &platform_esp32_module,
|
||||
.internal = nullptr
|
||||
};
|
||||
@ -1,139 +0,0 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#include <tactility/drivers/esp32_ledc_backlight.h>
|
||||
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/driver.h>
|
||||
#include <tactility/drivers/backlight.h>
|
||||
#include <tactility/log.h>
|
||||
|
||||
#include <driver/ledc.h>
|
||||
#include <esp_err.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#define TAG "Esp32LedcBacklight"
|
||||
#define GET_CONFIG(device) (static_cast<const Esp32LedcBacklightConfig*>((device)->config))
|
||||
|
||||
struct Esp32LedcBacklightInternal {
|
||||
uint8_t brightness;
|
||||
};
|
||||
|
||||
// region Driver lifecycle
|
||||
|
||||
static error_t start(Device* device) {
|
||||
const auto* config = GET_CONFIG(device);
|
||||
|
||||
ledc_timer_config_t timer_config = {
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.duty_resolution = LEDC_TIMER_8_BIT,
|
||||
.timer_num = config->ledc_timer,
|
||||
.freq_hz = config->frequency_hz,
|
||||
.clk_cfg = LEDC_AUTO_CLK,
|
||||
.deconfigure = false,
|
||||
};
|
||||
if (ledc_timer_config(&timer_config) != ESP_OK) {
|
||||
LOG_E(TAG, "Failed to configure LEDC timer");
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
ledc_channel_config_t channel_config = {
|
||||
.gpio_num = (int)config->pin_backlight.pin,
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.channel = config->ledc_channel,
|
||||
.intr_type = LEDC_INTR_DISABLE,
|
||||
.timer_sel = config->ledc_timer,
|
||||
.duty = config->brightness_range.min,
|
||||
.hpoint = 0,
|
||||
.sleep_mode = LEDC_SLEEP_MODE_NO_ALIVE_NO_PD,
|
||||
.flags = {
|
||||
.output_invert = 0,
|
||||
},
|
||||
};
|
||||
if (ledc_channel_config(&channel_config) != ESP_OK) {
|
||||
LOG_E(TAG, "Failed to configure LEDC channel");
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
auto* internal = static_cast<Esp32LedcBacklightInternal*>(malloc(sizeof(Esp32LedcBacklightInternal)));
|
||||
if (internal == nullptr) {
|
||||
return ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
internal->brightness = config->brightness_range.min;
|
||||
|
||||
device_set_driver_data(device, internal);
|
||||
|
||||
backlight_set_brightness_default(device); // Allowed to fail, we don't care about the result
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop(Device* device) {
|
||||
backlight_set_brightness(device, 0); // Allowed to fail, we don't care about the result
|
||||
|
||||
auto* internal = static_cast<Esp32LedcBacklightInternal*>(device_get_driver_data(device));
|
||||
free(internal);
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
// region BacklightApi
|
||||
|
||||
static error_t esp32_ledc_backlight_set_brightness(Device* device, uint8_t brightness) {
|
||||
const auto* config = GET_CONFIG(device);
|
||||
auto* internal = static_cast<Esp32LedcBacklightInternal*>(device_get_driver_data(device));
|
||||
|
||||
esp_err_t ret = ledc_set_duty(LEDC_LOW_SPEED_MODE, config->ledc_channel, brightness);
|
||||
if (ret == ESP_OK) {
|
||||
ret = ledc_update_duty(LEDC_LOW_SPEED_MODE, config->ledc_channel);
|
||||
}
|
||||
if (ret != ESP_OK) {
|
||||
LOG_E(TAG, "Failed to set brightness: %s", esp_err_to_name(ret));
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
internal->brightness = brightness;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t esp32_ledc_backlight_set_brightness_default(Device* device) {
|
||||
return esp32_ledc_backlight_set_brightness(device, GET_CONFIG(device)->brightness_default);
|
||||
}
|
||||
|
||||
static error_t esp32_ledc_backlight_get_brightness(Device* device, uint8_t* out_brightness) {
|
||||
auto* internal = static_cast<Esp32LedcBacklightInternal*>(device_get_driver_data(device));
|
||||
*out_brightness = internal->brightness;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static uint8_t esp32_ledc_backlight_get_min_brightness(Device* device) {
|
||||
return GET_CONFIG(device)->brightness_range.min;
|
||||
}
|
||||
|
||||
static uint8_t esp32_ledc_backlight_get_max_brightness(Device* device) {
|
||||
return GET_CONFIG(device)->brightness_range.max;
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
static const BacklightApi esp32_ledc_backlight_api = {
|
||||
.set_brightness = esp32_ledc_backlight_set_brightness,
|
||||
.set_brightness_default = esp32_ledc_backlight_set_brightness_default,
|
||||
.get_brightness = esp32_ledc_backlight_get_brightness,
|
||||
.get_min_brightness = esp32_ledc_backlight_get_min_brightness,
|
||||
.get_max_brightness = esp32_ledc_backlight_get_max_brightness,
|
||||
};
|
||||
|
||||
extern Module platform_esp32_module;
|
||||
|
||||
Driver esp32_ledc_backlight_driver = {
|
||||
.name = "esp32_ledc_backlight",
|
||||
.compatible = (const char*[]) { "espressif,esp32-ledc-backlight", nullptr },
|
||||
.start_device = start,
|
||||
.stop_device = stop,
|
||||
.api = &esp32_ledc_backlight_api,
|
||||
.device_type = &BACKLIGHT_TYPE,
|
||||
.owner = &platform_esp32_module,
|
||||
.internal = nullptr
|
||||
};
|
||||
252
Platforms/platform-esp32/source/drivers/esp32_pwm_ledc.cpp
Normal file
252
Platforms/platform-esp32/source/drivers/esp32_pwm_ledc.cpp
Normal file
@ -0,0 +1,252 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#include <tactility/drivers/esp32_pwm_ledc.h>
|
||||
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/driver.h>
|
||||
#include <tactility/drivers/pwm.h>
|
||||
#include <tactility/log.h>
|
||||
|
||||
#include <driver/ledc.h>
|
||||
#include <esp_err.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#define TAG "Esp32PwmLedc"
|
||||
#define GET_CONFIG(device) (static_cast<const Esp32PwmLedcConfig*>((device)->config))
|
||||
#define GET_INTERNAL(device) (static_cast<Esp32PwmLedcInternal*>(device_get_driver_data(device)))
|
||||
|
||||
struct Esp32PwmLedcInternal {
|
||||
uint32_t period_ns;
|
||||
uint32_t duty_ns;
|
||||
bool inverted;
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
// region Helpers
|
||||
|
||||
static uint32_t compute_freq_hz(uint32_t period_ns) {
|
||||
return (uint32_t)(1000000000ULL / period_ns);
|
||||
}
|
||||
|
||||
static uint32_t compute_raw_duty(uint32_t duty_ns, uint32_t period_ns, ledc_timer_bit_t duty_resolution) {
|
||||
uint64_t max_duty = 1ULL << duty_resolution;
|
||||
uint64_t raw_duty = ((uint64_t)duty_ns * max_duty) / period_ns;
|
||||
return (uint32_t)(raw_duty > max_duty ? max_duty : raw_duty);
|
||||
}
|
||||
|
||||
// Reprograms the LEDC timer's frequency/resolution. Independent of the enabled state: it doesn't
|
||||
// touch the channel's signal-output-enable bit, so it's safe to call while output is stopped.
|
||||
static error_t apply_period(Device* device) {
|
||||
const auto* config = GET_CONFIG(device);
|
||||
const auto* internal = GET_INTERNAL(device);
|
||||
|
||||
ledc_timer_config_t timer_config = {
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.duty_resolution = config->duty_resolution,
|
||||
.timer_num = config->ledc_timer,
|
||||
.freq_hz = compute_freq_hz(internal->period_ns),
|
||||
.clk_cfg = LEDC_AUTO_CLK,
|
||||
.deconfigure = false,
|
||||
};
|
||||
if (ledc_timer_config(&timer_config) != ESP_OK) {
|
||||
LOG_E(TAG, "Failed to configure LEDC timer");
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
// ledc_update_duty() unconditionally re-enables the channel's signal output, so this only
|
||||
// touches hardware while the device is enabled; a pending duty/period change made while disabled
|
||||
// is picked up from internal state the next time enable() is called.
|
||||
static error_t apply_duty(Device* device) {
|
||||
const auto* config = GET_CONFIG(device);
|
||||
const auto* internal = GET_INTERNAL(device);
|
||||
if (!internal->enabled) {
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
uint32_t raw_duty = compute_raw_duty(internal->duty_ns, internal->period_ns, config->duty_resolution);
|
||||
esp_err_t ret = ledc_set_duty(LEDC_LOW_SPEED_MODE, config->ledc_channel, raw_duty);
|
||||
if (ret == ESP_OK) {
|
||||
ret = ledc_update_duty(LEDC_LOW_SPEED_MODE, config->ledc_channel);
|
||||
}
|
||||
if (ret != ESP_OK) {
|
||||
LOG_E(TAG, "Failed to set duty: %s", esp_err_to_name(ret));
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
// Rebuilds the LEDC channel (duty, output polarity, timer/pin binding) from current internal
|
||||
// state. Like ledc_update_duty(), this unconditionally re-enables the channel's signal output,
|
||||
// so callers must only invoke this while the device is meant to be enabled.
|
||||
static error_t apply_channel(Device* device) {
|
||||
const auto* config = GET_CONFIG(device);
|
||||
const auto* internal = GET_INTERNAL(device);
|
||||
|
||||
ledc_channel_config_t channel_config = {
|
||||
.gpio_num = (int)config->pin.pin,
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.channel = config->ledc_channel,
|
||||
.intr_type = LEDC_INTR_DISABLE,
|
||||
.timer_sel = config->ledc_timer,
|
||||
.duty = compute_raw_duty(internal->duty_ns, internal->period_ns, config->duty_resolution),
|
||||
.hpoint = 0,
|
||||
.sleep_mode = LEDC_SLEEP_MODE_NO_ALIVE_NO_PD,
|
||||
.flags = {
|
||||
.output_invert = internal->inverted ? 1u : 0u,
|
||||
},
|
||||
};
|
||||
if (ledc_channel_config(&channel_config) != ESP_OK) {
|
||||
LOG_E(TAG, "Failed to configure LEDC channel");
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
// region Driver lifecycle
|
||||
|
||||
// Nothing here touches LEDC hardware: period/duty/inverted may be overridden via the PwmApi
|
||||
// before the first enable() call, so construction only needs to seed tracked state from config.
|
||||
// enable() is what actually programs the timer and channel from that tracked state.
|
||||
static error_t start(Device* device) {
|
||||
const auto* config = GET_CONFIG(device);
|
||||
|
||||
auto* internal = static_cast<Esp32PwmLedcInternal*>(malloc(sizeof(Esp32PwmLedcInternal)));
|
||||
if (internal == nullptr) {
|
||||
return ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
internal->period_ns = config->period_ns;
|
||||
internal->duty_ns = config->duty_ns;
|
||||
internal->inverted = config->inverted;
|
||||
internal->enabled = false;
|
||||
|
||||
device_set_driver_data(device, internal);
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop(Device* device) {
|
||||
auto* internal = GET_INTERNAL(device);
|
||||
if (internal->enabled) {
|
||||
const auto* config = GET_CONFIG(device);
|
||||
ledc_stop(LEDC_LOW_SPEED_MODE, config->ledc_channel, 0); // Allowed to fail, we don't care about the result
|
||||
}
|
||||
|
||||
device_set_driver_data(device, nullptr);
|
||||
free(internal);
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
// region PwmApi
|
||||
|
||||
static error_t esp32_pwm_ledc_set_period(Device* device, uint32_t period_ns) {
|
||||
GET_INTERNAL(device)->period_ns = period_ns;
|
||||
error_t error = apply_period(device);
|
||||
if (error != ERROR_NONE) {
|
||||
return error;
|
||||
}
|
||||
return apply_duty(device);
|
||||
}
|
||||
|
||||
static error_t esp32_pwm_ledc_get_period(Device* device, uint32_t* period_ns) {
|
||||
*period_ns = GET_INTERNAL(device)->period_ns;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t esp32_pwm_ledc_set_duty(Device* device, uint32_t duty_ns) {
|
||||
GET_INTERNAL(device)->duty_ns = duty_ns;
|
||||
return apply_duty(device);
|
||||
}
|
||||
|
||||
static error_t esp32_pwm_ledc_get_duty(Device* device, uint32_t* duty_ns) {
|
||||
*duty_ns = GET_INTERNAL(device)->duty_ns;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t esp32_pwm_ledc_set_inverted(Device* device, bool inverted) {
|
||||
auto* internal = GET_INTERNAL(device);
|
||||
internal->inverted = inverted;
|
||||
|
||||
// While disabled, just track the override; apply_channel() rebuilds the channel with it
|
||||
// (and every other tracked setting) the next time enable() runs.
|
||||
if (!internal->enabled) {
|
||||
return ERROR_NONE;
|
||||
}
|
||||
return apply_channel(device);
|
||||
}
|
||||
|
||||
static error_t esp32_pwm_ledc_is_inverted(Device* device, bool* inverted) {
|
||||
*inverted = GET_INTERNAL(device)->inverted;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
// Applies the tracked period, duty and inverted settings (whether they came from the config
|
||||
// defaults or were overridden beforehand) and turns the output on.
|
||||
static error_t esp32_pwm_ledc_enable(Device* device) {
|
||||
error_t error = apply_period(device);
|
||||
if (error != ERROR_NONE) {
|
||||
return error;
|
||||
}
|
||||
|
||||
error = apply_channel(device);
|
||||
if (error != ERROR_NONE) {
|
||||
return error;
|
||||
}
|
||||
|
||||
GET_INTERNAL(device)->enabled = true;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t esp32_pwm_ledc_disable(Device* device) {
|
||||
auto* internal = GET_INTERNAL(device);
|
||||
if (!internal->enabled) {
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
const auto* config = GET_CONFIG(device);
|
||||
internal->enabled = false;
|
||||
|
||||
if (ledc_stop(LEDC_LOW_SPEED_MODE, config->ledc_channel, 0) != ESP_OK) {
|
||||
LOG_E(TAG, "Failed to stop LEDC channel");
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t esp32_pwm_ledc_is_enabled(Device* device, bool* enabled) {
|
||||
*enabled = GET_INTERNAL(device)->enabled;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
static const PwmApi esp32_pwm_ledc_api = {
|
||||
.set_period = esp32_pwm_ledc_set_period,
|
||||
.get_period = esp32_pwm_ledc_get_period,
|
||||
.set_duty = esp32_pwm_ledc_set_duty,
|
||||
.get_duty = esp32_pwm_ledc_get_duty,
|
||||
.set_inverted = esp32_pwm_ledc_set_inverted,
|
||||
.is_inverted = esp32_pwm_ledc_is_inverted,
|
||||
.enable = esp32_pwm_ledc_enable,
|
||||
.disable = esp32_pwm_ledc_disable,
|
||||
.is_enabled = esp32_pwm_ledc_is_enabled,
|
||||
};
|
||||
|
||||
extern Module platform_esp32_module;
|
||||
|
||||
Driver esp32_pwm_ledc_driver = {
|
||||
.name = "esp32_pwm_ledc",
|
||||
.compatible = (const char*[]) { "espressif,esp32-pwm-ledc", nullptr },
|
||||
.start_device = start,
|
||||
.stop_device = stop,
|
||||
.api = &esp32_pwm_ledc_api,
|
||||
.device_type = &PWM_TYPE,
|
||||
.owner = &platform_esp32_module,
|
||||
.internal = nullptr
|
||||
};
|
||||
@ -19,8 +19,7 @@ extern Driver esp32_i2s_driver;
|
||||
#if SOC_LCD_I80_SUPPORTED
|
||||
extern Driver esp32_i8080_driver;
|
||||
#endif
|
||||
extern Driver esp32_gpio_backlight_driver;
|
||||
extern Driver esp32_ledc_backlight_driver;
|
||||
extern Driver esp32_pwm_ledc_driver;
|
||||
#if SOC_SDMMC_HOST_SUPPORTED
|
||||
extern Driver esp32_sdmmc_driver;
|
||||
#endif
|
||||
@ -56,8 +55,7 @@ static error_t start() {
|
||||
#if SOC_LCD_I80_SUPPORTED
|
||||
check(driver_construct_add(&esp32_i8080_driver) == ERROR_NONE);
|
||||
#endif
|
||||
check(driver_construct_add(&esp32_gpio_backlight_driver) == ERROR_NONE);
|
||||
check(driver_construct_add(&esp32_ledc_backlight_driver) == ERROR_NONE);
|
||||
check(driver_construct_add(&esp32_pwm_ledc_driver) == ERROR_NONE);
|
||||
#if SOC_SDMMC_HOST_SUPPORTED
|
||||
check(driver_construct_add(&esp32_sdmmc_driver) == ERROR_NONE);
|
||||
#endif
|
||||
@ -111,8 +109,7 @@ static error_t stop() {
|
||||
#if SOC_LCD_I80_SUPPORTED
|
||||
check(driver_remove_destruct(&esp32_i8080_driver) == ERROR_NONE);
|
||||
#endif
|
||||
check(driver_remove_destruct(&esp32_ledc_backlight_driver) == ERROR_NONE);
|
||||
check(driver_remove_destruct(&esp32_gpio_backlight_driver) == ERROR_NONE);
|
||||
check(driver_remove_destruct(&esp32_pwm_ledc_driver) == ERROR_NONE);
|
||||
#if SOC_SDMMC_HOST_SUPPORTED
|
||||
check(driver_remove_destruct(&esp32_sdmmc_driver) == ERROR_NONE);
|
||||
#endif
|
||||
|
||||
@ -3,14 +3,14 @@ description: >
|
||||
enable pin rather than a PWM-dimmable one. Brightness is treated as boolean: any
|
||||
value greater than 0 turns the backlight on, 0 turns it off.
|
||||
|
||||
compatible: "espressif,esp32-gpio-backlight"
|
||||
compatible: "gpio-backlight"
|
||||
|
||||
properties:
|
||||
pin-backlight:
|
||||
pin:
|
||||
type: phandles
|
||||
required: true
|
||||
description: Backlight enable output pin
|
||||
default-on:
|
||||
enabled:
|
||||
type: boolean
|
||||
default: true
|
||||
default: false
|
||||
description: Whether the backlight is turned on by set_brightness_default()
|
||||
@ -6,7 +6,7 @@ description: >
|
||||
HAL's initBoot() hook. Declare a gpio-hog node before the dependent device(s) in the .dts
|
||||
source so it runs first.
|
||||
|
||||
compatible: "tactility,gpio-hog"
|
||||
compatible: "gpio-hog"
|
||||
|
||||
properties:
|
||||
pin:
|
||||
19
TactilityKernel/bindings/pwm-backlight.yaml
Normal file
19
TactilityKernel/bindings/pwm-backlight.yaml
Normal file
@ -0,0 +1,19 @@
|
||||
description: >
|
||||
PWM-driven display backlight. Wraps any PWM_TYPE device (e.g. espressif,esp32-pwm-ledc or
|
||||
pwm-generic) and maps the brightness-level-range onto its duty cycle.
|
||||
|
||||
compatible: "pwm-backlight"
|
||||
|
||||
properties:
|
||||
pwm:
|
||||
type: phandles
|
||||
required: true
|
||||
description: The PWM device driving the backlight
|
||||
brightness-level-range:
|
||||
type: values
|
||||
default: [0, 255]
|
||||
description: Inclusive [min,max] brightness range. The minimum value turns the backlight off.
|
||||
brightness-default:
|
||||
type: int
|
||||
default: 200
|
||||
description: Default brightness level, applied by set_brightness_default(). Should fall within brightness-level-range.
|
||||
20
TactilityKernel/bindings/pwm.yaml
Normal file
20
TactilityKernel/bindings/pwm.yaml
Normal file
@ -0,0 +1,20 @@
|
||||
description: >
|
||||
Generic PWM device that tracks period, duty cycle, polarity and enabled state in memory
|
||||
without driving real hardware. Useful as a placeholder on boards without a real PWM
|
||||
peripheral wired up yet, or in the POSIX simulator.
|
||||
|
||||
compatible: "pwm-generic"
|
||||
|
||||
properties:
|
||||
period-ns:
|
||||
type: int
|
||||
required: true
|
||||
description: The PWM period, in nanoseconds
|
||||
duty-ns:
|
||||
type: int
|
||||
default: 0
|
||||
description: The PWM duty cycle (active time within one period), in nanoseconds
|
||||
inverted:
|
||||
type: boolean
|
||||
default: false
|
||||
description: Whether the output polarity is inverted
|
||||
27
TactilityKernel/bindings/rgb-led-gpio.yaml
Normal file
27
TactilityKernel/bindings/rgb-led-gpio.yaml
Normal file
@ -0,0 +1,27 @@
|
||||
description: >
|
||||
RGB LED driven by 3 plain digital GPIO pins. Each channel is on/off only (no dimming):
|
||||
a color component greater than 0 turns that channel's pin on.
|
||||
|
||||
compatible: "rgb-led-gpio"
|
||||
|
||||
properties:
|
||||
pin-red:
|
||||
type: phandles
|
||||
required: true
|
||||
description: Red channel output pin
|
||||
pin-green:
|
||||
type: phandles
|
||||
required: true
|
||||
description: Green channel output pin
|
||||
pin-blue:
|
||||
type: phandles
|
||||
required: true
|
||||
description: Blue channel output pin
|
||||
enabled:
|
||||
type: boolean
|
||||
default: false
|
||||
description: Whether the LED is turned on by default
|
||||
default-color:
|
||||
type: values
|
||||
default: [255, 255, 255]
|
||||
description: Color applied when the LED is turned on by default
|
||||
27
TactilityKernel/bindings/rgb-led-pwm.yaml
Normal file
27
TactilityKernel/bindings/rgb-led-pwm.yaml
Normal file
@ -0,0 +1,27 @@
|
||||
description: >
|
||||
RGB LED driven by 3 PWM devices (e.g. espressif,esp32-pwm-ledc or pwm-generic),
|
||||
one per channel, giving each channel dimming via the wrapped device's duty cycle.
|
||||
|
||||
compatible: "rgb-led-pwm"
|
||||
|
||||
properties:
|
||||
pwm-red:
|
||||
type: phandle
|
||||
required: true
|
||||
description: PWM device driving the red channel
|
||||
pwm-green:
|
||||
type: phandle
|
||||
required: true
|
||||
description: PWM device driving the green channel
|
||||
pwm-blue:
|
||||
type: phandle
|
||||
required: true
|
||||
description: PWM device driving the blue channel
|
||||
enabled:
|
||||
type: boolean
|
||||
default: false
|
||||
description: Whether the LED is turned on by default
|
||||
default-color:
|
||||
type: values
|
||||
default: [255, 255, 255]
|
||||
description: Color applied when the LED is turned on by default
|
||||
@ -1,5 +0,0 @@
|
||||
description: SPI peripheral
|
||||
|
||||
compatible: "spi-peripheral"
|
||||
|
||||
properties: {}
|
||||
@ -0,0 +1,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#pragma once
|
||||
|
||||
#include <tactility/bindings/bindings.h>
|
||||
#include <tactility/drivers/gpio_backlight.h>
|
||||
|
||||
DEFINE_DEVICETREE(gpio_backlight, struct GpioBacklightConfig)
|
||||
@ -1,15 +0,0 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#pragma once
|
||||
|
||||
#include <tactility/bindings/bindings.h>
|
||||
#include <tactility/drivers/pointer_placeholder.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
DEFINE_DEVICETREE(pointer_placeholder, struct PointerPlaceholderConfig)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -0,0 +1,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#pragma once
|
||||
|
||||
#include <tactility/bindings/bindings.h>
|
||||
#include <tactility/drivers/pwm_backlight.h>
|
||||
|
||||
DEFINE_DEVICETREE(pwm_backlight, struct PwmBacklightConfig)
|
||||
@ -0,0 +1,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#pragma once
|
||||
|
||||
#include <tactility/bindings/bindings.h>
|
||||
#include <tactility/drivers/rgb_led_gpio.h>
|
||||
|
||||
DEFINE_DEVICETREE(rgb_led_gpio, struct RgbLedGpioConfig)
|
||||
7
TactilityKernel/include/tactility/bindings/rgb_led_pwm.h
Normal file
7
TactilityKernel/include/tactility/bindings/rgb_led_pwm.h
Normal file
@ -0,0 +1,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#pragma once
|
||||
|
||||
#include <tactility/bindings/bindings.h>
|
||||
#include <tactility/drivers/rgb_led_pwm.h>
|
||||
|
||||
DEFINE_DEVICETREE(rgb_led_pwm, struct RgbLedPwmConfig)
|
||||
24
TactilityKernel/include/tactility/drivers/gpio_backlight.h
Normal file
24
TactilityKernel/include/tactility/drivers/gpio_backlight.h
Normal file
@ -0,0 +1,24 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <tactility/drivers/gpio.h>
|
||||
|
||||
/**
|
||||
* @brief Devicetree configuration for a GPIO-driven on/off backlight.
|
||||
*/
|
||||
struct GpioBacklightConfig {
|
||||
/** Backlight enable output pin */
|
||||
struct GpioPinSpec pin;
|
||||
/** Whether the backlight is turned on by set_brightness_default() */
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -1,16 +0,0 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct PointerPlaceholderConfig {
|
||||
uint8_t _unused;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
150
TactilityKernel/include/tactility/drivers/pwm.h
Normal file
150
TactilityKernel/include/tactility/drivers/pwm.h
Normal file
@ -0,0 +1,150 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/error.h>
|
||||
|
||||
/**
|
||||
* @brief Devicetree configuration for a PWM device.
|
||||
*/
|
||||
struct PwmConfig {
|
||||
/** The PWM period, in nanoseconds */
|
||||
uint32_t period_ns;
|
||||
/** The PWM duty cycle (active time within one period), in nanoseconds */
|
||||
uint32_t duty_ns;
|
||||
/** Whether the output polarity is inverted */
|
||||
bool inverted;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief API for PWM drivers.
|
||||
*/
|
||||
struct PwmApi {
|
||||
/**
|
||||
* @brief Sets the PWM period.
|
||||
* @param[in] device the PWM device
|
||||
* @param[in] period_ns the period, in nanoseconds
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t (*set_period)(struct Device* device, uint32_t period_ns);
|
||||
|
||||
/**
|
||||
* @brief Gets the PWM period.
|
||||
* @param[in] device the PWM device
|
||||
* @param[out] period_ns the period, in nanoseconds
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t (*get_period)(struct Device* device, uint32_t* period_ns);
|
||||
|
||||
/**
|
||||
* @brief Sets the PWM duty cycle.
|
||||
* @param[in] device the PWM device
|
||||
* @param[in] duty_ns the active time within one period, in nanoseconds
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t (*set_duty)(struct Device* device, uint32_t duty_ns);
|
||||
|
||||
/**
|
||||
* @brief Gets the PWM duty cycle.
|
||||
* @param[in] device the PWM device
|
||||
* @param[out] duty_ns the active time within one period, in nanoseconds
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t (*get_duty)(struct Device* device, uint32_t* duty_ns);
|
||||
|
||||
/**
|
||||
* @brief Sets whether the output polarity is inverted.
|
||||
* @param[in] device the PWM device
|
||||
* @param[in] inverted true to invert the output polarity
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t (*set_inverted)(struct Device* device, bool inverted);
|
||||
|
||||
/**
|
||||
* @brief Gets whether the output polarity is inverted.
|
||||
* @param[in] device the PWM device
|
||||
* @param[out] inverted true when the output polarity is inverted
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t (*is_inverted)(struct Device* device, bool* inverted);
|
||||
|
||||
/**
|
||||
* @brief Enables the PWM output.
|
||||
* @param[in] device the PWM device
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t (*enable)(struct Device* device);
|
||||
|
||||
/**
|
||||
* @brief Disables the PWM output.
|
||||
* @param[in] device the PWM device
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t (*disable)(struct Device* device);
|
||||
|
||||
/**
|
||||
* @brief Gets whether the PWM output is enabled.
|
||||
* @param[in] device the PWM device
|
||||
* @param[out] enabled true when the output is enabled
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t (*is_enabled)(struct Device* device, bool* enabled);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Sets the PWM period using the specified PWM device.
|
||||
*/
|
||||
error_t pwm_set_period(struct Device* device, uint32_t period_ns);
|
||||
|
||||
/**
|
||||
* @brief Gets the PWM period using the specified PWM device.
|
||||
*/
|
||||
error_t pwm_get_period(struct Device* device, uint32_t* period_ns);
|
||||
|
||||
/**
|
||||
* @brief Sets the PWM duty cycle using the specified PWM device.
|
||||
*/
|
||||
error_t pwm_set_duty(struct Device* device, uint32_t duty_ns);
|
||||
|
||||
/**
|
||||
* @brief Gets the PWM duty cycle using the specified PWM device.
|
||||
*/
|
||||
error_t pwm_get_duty(struct Device* device, uint32_t* duty_ns);
|
||||
|
||||
/**
|
||||
* @brief Sets whether the output polarity is inverted using the specified PWM device.
|
||||
*/
|
||||
error_t pwm_set_inverted(struct Device* device, bool inverted);
|
||||
|
||||
/**
|
||||
* @brief Gets whether the output polarity is inverted using the specified PWM device.
|
||||
*/
|
||||
error_t pwm_is_inverted(struct Device* device, bool* inverted);
|
||||
|
||||
/**
|
||||
* @brief Enables the PWM output using the specified PWM device.
|
||||
*/
|
||||
error_t pwm_enable(struct Device* device);
|
||||
|
||||
/**
|
||||
* @brief Disables the PWM output using the specified PWM device.
|
||||
*/
|
||||
error_t pwm_disable(struct Device* device);
|
||||
|
||||
/**
|
||||
* @brief Gets whether the PWM output is enabled using the specified PWM device.
|
||||
*/
|
||||
error_t pwm_is_enabled(struct Device* device, bool* enabled);
|
||||
|
||||
extern const struct DeviceType PWM_TYPE;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
27
TactilityKernel/include/tactility/drivers/pwm_backlight.h
Normal file
27
TactilityKernel/include/tactility/drivers/pwm_backlight.h
Normal file
@ -0,0 +1,27 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/drivers/backlight.h>
|
||||
|
||||
/**
|
||||
* @brief Devicetree configuration for a PWM-driven backlight.
|
||||
*/
|
||||
struct PwmBacklightConfig {
|
||||
/** The PWM device driving the backlight */
|
||||
struct Device* pwm;
|
||||
/** Inclusive [min,max] brightness range. The minimum value turns the backlight off. */
|
||||
struct BrightnessLevelRange brightness_range;
|
||||
/** Default brightness level, applied by set_brightness_default() */
|
||||
uint8_t brightness_default;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
81
TactilityKernel/include/tactility/drivers/rgb_led.h
Normal file
81
TactilityKernel/include/tactility/drivers/rgb_led.h
Normal file
@ -0,0 +1,81 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/error.h>
|
||||
|
||||
/**
|
||||
* @brief An RGB color value.
|
||||
*/
|
||||
struct RgbLedColor {
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief API for RGB LED drivers.
|
||||
*/
|
||||
struct RgbLedApi {
|
||||
/**
|
||||
* @brief Sets the LED color.
|
||||
* @param[in] device the RGB LED device
|
||||
* @param[in] color the color to set
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t (*set_color)(struct Device* device, const struct RgbLedColor color);
|
||||
|
||||
/**
|
||||
* @brief Gets the LED color.
|
||||
* @param[in] device the RGB LED device
|
||||
* @param[out] out_color the current color
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t (*get_color)(struct Device* device, struct RgbLedColor* out_color);
|
||||
|
||||
/**
|
||||
* @brief Enables the LED output.
|
||||
* @param[in] device the RGB LED device
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t (*enable)(struct Device* device);
|
||||
|
||||
/**
|
||||
* @brief Disables the LED output.
|
||||
* @param[in] device the RGB LED device
|
||||
*/
|
||||
void (*disable)(struct Device* device);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Sets the LED color using the specified RGB LED device.
|
||||
*/
|
||||
error_t rgb_led_set_color(struct Device* device, struct RgbLedColor color);
|
||||
|
||||
/**
|
||||
* @brief Gets the LED color using the specified RGB LED device.
|
||||
*/
|
||||
error_t rgb_led_get_color(struct Device* device, struct RgbLedColor* out_color);
|
||||
|
||||
/**
|
||||
* @brief Enables the LED output using the specified RGB LED device.
|
||||
*/
|
||||
error_t rgb_led_enable(struct Device* device);
|
||||
|
||||
/**
|
||||
* @brief Disables the LED output using the specified RGB LED device.
|
||||
*/
|
||||
void rgb_led_disable(struct Device* device);
|
||||
|
||||
extern const struct DeviceType RGB_LED_TYPE;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
31
TactilityKernel/include/tactility/drivers/rgb_led_gpio.h
Normal file
31
TactilityKernel/include/tactility/drivers/rgb_led_gpio.h
Normal file
@ -0,0 +1,31 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <tactility/drivers/gpio.h>
|
||||
#include <tactility/drivers/rgb_led.h>
|
||||
|
||||
/**
|
||||
* @brief Devicetree configuration for the GPIO-driven RGB LED.
|
||||
*/
|
||||
struct RgbLedGpioConfig {
|
||||
/** Red channel output pin */
|
||||
struct GpioPinSpec pin_red;
|
||||
/** Green channel output pin */
|
||||
struct GpioPinSpec pin_green;
|
||||
/** Blue channel output pin */
|
||||
struct GpioPinSpec pin_blue;
|
||||
/** Whether the LED is turned on by default */
|
||||
bool enabled;
|
||||
/** Color applied when the LED is turned on by default */
|
||||
struct RgbLedColor default_color;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
31
TactilityKernel/include/tactility/drivers/rgb_led_pwm.h
Normal file
31
TactilityKernel/include/tactility/drivers/rgb_led_pwm.h
Normal file
@ -0,0 +1,31 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/drivers/rgb_led.h>
|
||||
|
||||
/**
|
||||
* @brief Devicetree configuration for the PWM-driven RGB LED.
|
||||
*/
|
||||
struct RgbLedPwmConfig {
|
||||
/** PWM device driving the red channel */
|
||||
struct Device* pwm_red;
|
||||
/** PWM device driving the green channel */
|
||||
struct Device* pwm_green;
|
||||
/** PWM device driving the blue channel */
|
||||
struct Device* pwm_blue;
|
||||
/** Whether the LED is turned on by default */
|
||||
bool enabled;
|
||||
/** Color applied when the LED is turned on by default */
|
||||
struct RgbLedColor default_color;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -1,19 +0,0 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <tactility/device.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct SpiPeripheralConfig {
|
||||
uint8_t _unused;
|
||||
};
|
||||
|
||||
extern const struct DeviceType SPI_PERIPHERAL_TYPE;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
144
TactilityKernel/source/drivers/gpio_backlight.cpp
Normal file
144
TactilityKernel/source/drivers/gpio_backlight.cpp
Normal file
@ -0,0 +1,144 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#include <tactility/drivers/gpio_backlight.h>
|
||||
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/driver.h>
|
||||
#include <tactility/drivers/backlight.h>
|
||||
#include <tactility/drivers/gpio_controller.h>
|
||||
#include <tactility/drivers/gpio_descriptor.h>
|
||||
#include <tactility/log.h>
|
||||
#include <tactility/module.h>
|
||||
|
||||
#include <new>
|
||||
|
||||
#define TAG "GpioBacklight"
|
||||
#define GET_CONFIG(device) (static_cast<const GpioBacklightConfig*>((device)->config))
|
||||
#define GET_INTERNAL(device) (static_cast<GpioBacklightInternal*>(device_get_driver_data(device)))
|
||||
|
||||
extern "C" {
|
||||
|
||||
struct GpioBacklightInternal {
|
||||
GpioDescriptor* descriptor;
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
// region GpioBacklightApi
|
||||
|
||||
static error_t enable(Device* device) {
|
||||
auto* internal = GET_INTERNAL(device);
|
||||
|
||||
error_t error = gpio_descriptor_set_level(internal->descriptor, true);
|
||||
if (error != ERROR_NONE) {
|
||||
LOG_E(TAG, "Failed to enable backlight");
|
||||
return error;
|
||||
}
|
||||
|
||||
internal->enabled = true;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t disable(Device* device) {
|
||||
auto* internal = GET_INTERNAL(device);
|
||||
|
||||
error_t error = gpio_descriptor_set_level(internal->descriptor, false);
|
||||
if (error != ERROR_NONE) {
|
||||
LOG_E(TAG, "Failed to disable backlight");
|
||||
return error;
|
||||
}
|
||||
|
||||
internal->enabled = false;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
// region BacklightApi
|
||||
|
||||
static error_t gpio_backlight_set_brightness(Device* device, uint8_t brightness) {
|
||||
return brightness > 0 ? enable(device) : disable(device);
|
||||
}
|
||||
|
||||
static error_t gpio_backlight_set_brightness_default(Device* device) {
|
||||
return GET_CONFIG(device)->enabled ? enable(device) : disable(device);
|
||||
}
|
||||
|
||||
static error_t gpio_backlight_get_brightness(Device* device, uint8_t* out_brightness) {
|
||||
*out_brightness = GET_INTERNAL(device)->enabled ? 1 : 0;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static uint8_t gpio_backlight_get_min_brightness(Device*) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t gpio_backlight_get_max_brightness(Device*) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
static constexpr BacklightApi GPIO_BACKLIGHT_API = {
|
||||
.set_brightness = gpio_backlight_set_brightness,
|
||||
.set_brightness_default = gpio_backlight_set_brightness_default,
|
||||
.get_brightness = gpio_backlight_get_brightness,
|
||||
.get_min_brightness = gpio_backlight_get_min_brightness,
|
||||
.get_max_brightness = gpio_backlight_get_max_brightness,
|
||||
};
|
||||
|
||||
// region Driver lifecycle
|
||||
|
||||
static error_t start(Device* device) {
|
||||
const auto* config = GET_CONFIG(device);
|
||||
|
||||
auto* descriptor = gpio_descriptor_acquire(config->pin.gpio_controller, config->pin.pin, GPIO_OWNER_GPIO);
|
||||
if (descriptor == nullptr) {
|
||||
LOG_E(TAG, "Failed to acquire GPIO descriptor");
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
if (gpio_descriptor_set_flags(descriptor, config->pin.flags | GPIO_FLAG_DIRECTION_OUTPUT) != ERROR_NONE) {
|
||||
LOG_E(TAG, "Failed to configure backlight pin as output");
|
||||
gpio_descriptor_release(descriptor);
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
auto* internal = new(std::nothrow) GpioBacklightInternal { .descriptor = descriptor, .enabled = false };
|
||||
if (internal == nullptr) {
|
||||
gpio_descriptor_release(descriptor);
|
||||
return ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
device_set_driver_data(device, internal);
|
||||
|
||||
gpio_backlight_set_brightness_default(device); // Allowed to fail, we don't care about the result
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop(Device* device) {
|
||||
disable(device); // Allowed to fail, we don't care about the result
|
||||
|
||||
auto* internal = GET_INTERNAL(device);
|
||||
gpio_descriptor_release(internal->descriptor);
|
||||
device_set_driver_data(device, nullptr);
|
||||
delete internal;
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
extern Module root_module;
|
||||
|
||||
Driver gpio_backlight_driver = {
|
||||
.name = "gpio_backlight",
|
||||
.compatible = (const char*[]) { "gpio-backlight", nullptr },
|
||||
.start_device = start,
|
||||
.stop_device = stop,
|
||||
.api = &GPIO_BACKLIGHT_API,
|
||||
.device_type = &BACKLIGHT_TYPE,
|
||||
.owner = &root_module,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
@ -62,7 +62,7 @@ extern Module root_module;
|
||||
|
||||
Driver gpio_hog_driver = {
|
||||
.name = "gpio_hog",
|
||||
.compatible = (const char*[]) { "tactility,gpio-hog", nullptr },
|
||||
.compatible = (const char*[]) { "gpio-hog", nullptr },
|
||||
.start_device = start,
|
||||
.stop_device = stop,
|
||||
.api = nullptr,
|
||||
|
||||
@ -1,26 +0,0 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#include <tactility/drivers/pointer_placeholder.h>
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/driver.h>
|
||||
#include <tactility/drivers/pointer.h>
|
||||
#include <tactility/module.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
static error_t start(Device*) { return ERROR_NONE; }
|
||||
static error_t stop(Device*) { return ERROR_NONE; }
|
||||
|
||||
extern Module root_module;
|
||||
|
||||
Driver pointer_placeholder_driver = {
|
||||
.name = "pointer_placeholder",
|
||||
.compatible = (const char*[]) { "pointer-placeholder", nullptr },
|
||||
.start_device = start,
|
||||
.stop_device = stop,
|
||||
.api = nullptr,
|
||||
.device_type = &POINTER_TYPE,
|
||||
.owner = &root_module,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
58
TactilityKernel/source/drivers/pwm.cpp
Normal file
58
TactilityKernel/source/drivers/pwm.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#include <tactility/drivers/pwm.h>
|
||||
#include <tactility/device.h>
|
||||
|
||||
#define PWM_DRIVER_API(driver) ((struct PwmApi*)driver->api)
|
||||
|
||||
extern "C" {
|
||||
|
||||
error_t pwm_set_period(Device* device, uint32_t period_ns) {
|
||||
const auto* driver = device_get_driver(device);
|
||||
return PWM_DRIVER_API(driver)->set_period(device, period_ns);
|
||||
}
|
||||
|
||||
error_t pwm_get_period(Device* device, uint32_t* period_ns) {
|
||||
const auto* driver = device_get_driver(device);
|
||||
return PWM_DRIVER_API(driver)->get_period(device, period_ns);
|
||||
}
|
||||
|
||||
error_t pwm_set_duty(Device* device, uint32_t duty_ns) {
|
||||
const auto* driver = device_get_driver(device);
|
||||
return PWM_DRIVER_API(driver)->set_duty(device, duty_ns);
|
||||
}
|
||||
|
||||
error_t pwm_get_duty(Device* device, uint32_t* duty_ns) {
|
||||
const auto* driver = device_get_driver(device);
|
||||
return PWM_DRIVER_API(driver)->get_duty(device, duty_ns);
|
||||
}
|
||||
|
||||
error_t pwm_set_inverted(Device* device, bool inverted) {
|
||||
const auto* driver = device_get_driver(device);
|
||||
return PWM_DRIVER_API(driver)->set_inverted(device, inverted);
|
||||
}
|
||||
|
||||
error_t pwm_is_inverted(Device* device, bool* inverted) {
|
||||
const auto* driver = device_get_driver(device);
|
||||
return PWM_DRIVER_API(driver)->is_inverted(device, inverted);
|
||||
}
|
||||
|
||||
error_t pwm_enable(Device* device) {
|
||||
const auto* driver = device_get_driver(device);
|
||||
return PWM_DRIVER_API(driver)->enable(device);
|
||||
}
|
||||
|
||||
error_t pwm_disable(Device* device) {
|
||||
const auto* driver = device_get_driver(device);
|
||||
return PWM_DRIVER_API(driver)->disable(device);
|
||||
}
|
||||
|
||||
error_t pwm_is_enabled(Device* device, bool* enabled) {
|
||||
const auto* driver = device_get_driver(device);
|
||||
return PWM_DRIVER_API(driver)->is_enabled(device, enabled);
|
||||
}
|
||||
|
||||
const DeviceType PWM_TYPE {
|
||||
.name = "pwm"
|
||||
};
|
||||
|
||||
}
|
||||
132
TactilityKernel/source/drivers/pwm_backlight.cpp
Normal file
132
TactilityKernel/source/drivers/pwm_backlight.cpp
Normal file
@ -0,0 +1,132 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#include <tactility/drivers/pwm_backlight.h>
|
||||
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/driver.h>
|
||||
#include <tactility/drivers/backlight.h>
|
||||
#include <tactility/drivers/pwm.h>
|
||||
#include <tactility/log.h>
|
||||
#include <tactility/module.h>
|
||||
|
||||
#include <new>
|
||||
|
||||
#define TAG "PwmBacklight"
|
||||
#define GET_CONFIG(device) (static_cast<const PwmBacklightConfig*>((device)->config))
|
||||
#define GET_INTERNAL(device) (static_cast<PwmBacklightInternal*>(device_get_driver_data(device)))
|
||||
|
||||
extern "C" {
|
||||
|
||||
struct PwmBacklightInternal {
|
||||
uint8_t brightness;
|
||||
};
|
||||
|
||||
// region BacklightApi
|
||||
|
||||
static error_t apply_brightness(Device* device, uint8_t brightness) {
|
||||
const auto* config = GET_CONFIG(device);
|
||||
|
||||
if (brightness <= config->brightness_range.min) {
|
||||
error_t error = pwm_disable(config->pwm);
|
||||
if (error != ERROR_NONE) {
|
||||
LOG_E(TAG, "Failed to disable PWM");
|
||||
return error;
|
||||
}
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
uint32_t period_ns;
|
||||
error_t error = pwm_get_period(config->pwm, &period_ns);
|
||||
if (error != ERROR_NONE) {
|
||||
LOG_E(TAG, "Failed to get PWM period");
|
||||
return error;
|
||||
}
|
||||
|
||||
uint8_t level = brightness - config->brightness_range.min;
|
||||
uint8_t range = config->brightness_range.max - config->brightness_range.min;
|
||||
uint32_t duty_ns = (uint32_t)(((uint64_t)level * period_ns) / range);
|
||||
|
||||
error = pwm_set_duty(config->pwm, duty_ns);
|
||||
if (error != ERROR_NONE) {
|
||||
LOG_E(TAG, "Failed to set PWM duty");
|
||||
return error;
|
||||
}
|
||||
|
||||
return pwm_enable(config->pwm);
|
||||
}
|
||||
|
||||
static error_t pwm_backlight_set_brightness(Device* device, uint8_t brightness) {
|
||||
error_t error = apply_brightness(device, brightness);
|
||||
if (error != ERROR_NONE) {
|
||||
return error;
|
||||
}
|
||||
GET_INTERNAL(device)->brightness = brightness;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t pwm_backlight_set_brightness_default(Device* device) {
|
||||
return pwm_backlight_set_brightness(device, GET_CONFIG(device)->brightness_default);
|
||||
}
|
||||
|
||||
static error_t pwm_backlight_get_brightness(Device* device, uint8_t* out_brightness) {
|
||||
*out_brightness = GET_INTERNAL(device)->brightness;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static uint8_t pwm_backlight_get_min_brightness(Device* device) {
|
||||
return GET_CONFIG(device)->brightness_range.min;
|
||||
}
|
||||
|
||||
static uint8_t pwm_backlight_get_max_brightness(Device* device) {
|
||||
return GET_CONFIG(device)->brightness_range.max;
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
static constexpr BacklightApi PWM_BACKLIGHT_API = {
|
||||
.set_brightness = pwm_backlight_set_brightness,
|
||||
.set_brightness_default = pwm_backlight_set_brightness_default,
|
||||
.get_brightness = pwm_backlight_get_brightness,
|
||||
.get_min_brightness = pwm_backlight_get_min_brightness,
|
||||
.get_max_brightness = pwm_backlight_get_max_brightness,
|
||||
};
|
||||
|
||||
// region Driver lifecycle
|
||||
|
||||
static error_t start(Device* device) {
|
||||
auto* internal = new(std::nothrow) PwmBacklightInternal { .brightness = GET_CONFIG(device)->brightness_range.min };
|
||||
if (internal == nullptr) {
|
||||
return ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
device_set_driver_data(device, internal);
|
||||
|
||||
pwm_backlight_set_brightness_default(device); // Allowed to fail, we don't care about the result
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop(Device* device) {
|
||||
pwm_backlight_set_brightness(device, GET_CONFIG(device)->brightness_range.min); // Allowed to fail, we don't care about the result
|
||||
|
||||
auto* internal = GET_INTERNAL(device);
|
||||
device_set_driver_data(device, nullptr);
|
||||
delete internal;
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
extern Module root_module;
|
||||
|
||||
Driver pwm_backlight_driver = {
|
||||
.name = "pwm_backlight",
|
||||
.compatible = (const char*[]) { "pwm-backlight", nullptr },
|
||||
.start_device = start,
|
||||
.stop_device = stop,
|
||||
.api = &PWM_BACKLIGHT_API,
|
||||
.device_type = &BACKLIGHT_TYPE,
|
||||
.owner = &root_module,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
33
TactilityKernel/source/drivers/rgb_led.cpp
Normal file
33
TactilityKernel/source/drivers/rgb_led.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#include <tactility/drivers/rgb_led.h>
|
||||
#include <tactility/device.h>
|
||||
|
||||
#define RGB_LED_DRIVER_API(driver) ((struct RgbLedApi*)driver->api)
|
||||
|
||||
extern "C" {
|
||||
|
||||
error_t rgb_led_set_color(Device* device, RgbLedColor color) {
|
||||
const auto* driver = device_get_driver(device);
|
||||
return RGB_LED_DRIVER_API(driver)->set_color(device, color);
|
||||
}
|
||||
|
||||
error_t rgb_led_get_color(Device* device, RgbLedColor* out_color) {
|
||||
const auto* driver = device_get_driver(device);
|
||||
return RGB_LED_DRIVER_API(driver)->get_color(device, out_color);
|
||||
}
|
||||
|
||||
error_t rgb_led_enable(Device* device) {
|
||||
const auto* driver = device_get_driver(device);
|
||||
return RGB_LED_DRIVER_API(driver)->enable(device);
|
||||
}
|
||||
|
||||
void rgb_led_disable(Device* device) {
|
||||
const auto* driver = device_get_driver(device);
|
||||
RGB_LED_DRIVER_API(driver)->disable(device);
|
||||
}
|
||||
|
||||
const DeviceType RGB_LED_TYPE {
|
||||
.name = "rgb_led"
|
||||
};
|
||||
|
||||
}
|
||||
165
TactilityKernel/source/drivers/rgb_led_gpio.cpp
Normal file
165
TactilityKernel/source/drivers/rgb_led_gpio.cpp
Normal file
@ -0,0 +1,165 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#include <tactility/drivers/rgb_led_gpio.h>
|
||||
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/driver.h>
|
||||
#include <tactility/drivers/gpio_controller.h>
|
||||
#include <tactility/drivers/gpio_descriptor.h>
|
||||
#include <tactility/log.h>
|
||||
#include <tactility/module.h>
|
||||
|
||||
#include <new>
|
||||
|
||||
#define TAG "RgbLedGpio"
|
||||
#define GET_CONFIG(device) (static_cast<const RgbLedGpioConfig*>((device)->config))
|
||||
#define GET_INTERNAL(device) (static_cast<RgbLedGpioInternal*>(device_get_driver_data(device)))
|
||||
|
||||
extern "C" {
|
||||
|
||||
struct RgbLedGpioInternal {
|
||||
GpioDescriptor* descriptor_red;
|
||||
GpioDescriptor* descriptor_green;
|
||||
GpioDescriptor* descriptor_blue;
|
||||
RgbLedColor color;
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
// region RgbLedApi
|
||||
|
||||
static error_t apply_levels(Device* device) {
|
||||
auto* internal = GET_INTERNAL(device);
|
||||
bool on = internal->enabled;
|
||||
|
||||
error_t error = gpio_descriptor_set_level(internal->descriptor_red, on && internal->color.r > 0);
|
||||
if (error == ERROR_NONE) {
|
||||
error = gpio_descriptor_set_level(internal->descriptor_green, on && internal->color.g > 0);
|
||||
}
|
||||
if (error == ERROR_NONE) {
|
||||
error = gpio_descriptor_set_level(internal->descriptor_blue, on && internal->color.b > 0);
|
||||
}
|
||||
if (error != ERROR_NONE) {
|
||||
LOG_E(TAG, "Failed to apply LED levels");
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
static error_t rgb_led_gpio_set_color(Device* device, RgbLedColor color) {
|
||||
GET_INTERNAL(device)->color = color;
|
||||
return apply_levels(device);
|
||||
}
|
||||
|
||||
static error_t rgb_led_gpio_get_color(Device* device, RgbLedColor* out_color) {
|
||||
*out_color = GET_INTERNAL(device)->color;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t rgb_led_gpio_enable(Device* device) {
|
||||
GET_INTERNAL(device)->enabled = true;
|
||||
return apply_levels(device);
|
||||
}
|
||||
|
||||
static void rgb_led_gpio_disable(Device* device) {
|
||||
GET_INTERNAL(device)->enabled = false;
|
||||
apply_levels(device); // Allowed to fail, we don't care about the result
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
static constexpr RgbLedApi RGB_LED_GPIO_API = {
|
||||
.set_color = rgb_led_gpio_set_color,
|
||||
.get_color = rgb_led_gpio_get_color,
|
||||
.enable = rgb_led_gpio_enable,
|
||||
.disable = rgb_led_gpio_disable,
|
||||
};
|
||||
|
||||
// region Driver lifecycle
|
||||
|
||||
static error_t start(Device* device) {
|
||||
const auto* config = GET_CONFIG(device);
|
||||
|
||||
auto* descriptor_red = gpio_descriptor_acquire(config->pin_red.gpio_controller, config->pin_red.pin, GPIO_OWNER_GPIO);
|
||||
if (descriptor_red == nullptr) {
|
||||
LOG_E(TAG, "Failed to acquire red GPIO descriptor");
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
auto* descriptor_green = gpio_descriptor_acquire(config->pin_green.gpio_controller, config->pin_green.pin, GPIO_OWNER_GPIO);
|
||||
if (descriptor_green == nullptr) {
|
||||
LOG_E(TAG, "Failed to acquire green GPIO descriptor");
|
||||
gpio_descriptor_release(descriptor_red);
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
auto* descriptor_blue = gpio_descriptor_acquire(config->pin_blue.gpio_controller, config->pin_blue.pin, GPIO_OWNER_GPIO);
|
||||
if (descriptor_blue == nullptr) {
|
||||
LOG_E(TAG, "Failed to acquire blue GPIO descriptor");
|
||||
gpio_descriptor_release(descriptor_red);
|
||||
gpio_descriptor_release(descriptor_green);
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
bool ok = gpio_descriptor_set_flags(descriptor_red, config->pin_red.flags | GPIO_FLAG_DIRECTION_OUTPUT) == ERROR_NONE &&
|
||||
gpio_descriptor_set_flags(descriptor_green, config->pin_green.flags | GPIO_FLAG_DIRECTION_OUTPUT) == ERROR_NONE &&
|
||||
gpio_descriptor_set_flags(descriptor_blue, config->pin_blue.flags | GPIO_FLAG_DIRECTION_OUTPUT) == ERROR_NONE;
|
||||
if (!ok) {
|
||||
LOG_E(TAG, "Failed to configure LED pins as outputs");
|
||||
gpio_descriptor_release(descriptor_red);
|
||||
gpio_descriptor_release(descriptor_green);
|
||||
gpio_descriptor_release(descriptor_blue);
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
auto* internal = new(std::nothrow) RgbLedGpioInternal {
|
||||
.descriptor_red = descriptor_red,
|
||||
.descriptor_green = descriptor_green,
|
||||
.descriptor_blue = descriptor_blue,
|
||||
.color = config->default_color,
|
||||
.enabled = false
|
||||
};
|
||||
if (internal == nullptr) {
|
||||
gpio_descriptor_release(descriptor_red);
|
||||
gpio_descriptor_release(descriptor_green);
|
||||
gpio_descriptor_release(descriptor_blue);
|
||||
return ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
device_set_driver_data(device, internal);
|
||||
|
||||
if (config->enabled) {
|
||||
rgb_led_gpio_enable(device); // Allowed to fail, we don't care about the result
|
||||
} else {
|
||||
apply_levels(device); // Allowed to fail, we don't care about the result
|
||||
}
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop(Device* device) {
|
||||
rgb_led_gpio_disable(device);
|
||||
|
||||
auto* internal = GET_INTERNAL(device);
|
||||
gpio_descriptor_release(internal->descriptor_red);
|
||||
gpio_descriptor_release(internal->descriptor_green);
|
||||
gpio_descriptor_release(internal->descriptor_blue);
|
||||
device_set_driver_data(device, nullptr);
|
||||
delete internal;
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
extern Module root_module;
|
||||
|
||||
Driver rgb_led_gpio_driver = {
|
||||
.name = "rgb_led_gpio",
|
||||
.compatible = (const char*[]) { "rgb-led-gpio", nullptr },
|
||||
.start_device = start,
|
||||
.stop_device = stop,
|
||||
.api = &RGB_LED_GPIO_API,
|
||||
.device_type = &RGB_LED_TYPE,
|
||||
.owner = &root_module,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
152
TactilityKernel/source/drivers/rgb_led_pwm.cpp
Normal file
152
TactilityKernel/source/drivers/rgb_led_pwm.cpp
Normal file
@ -0,0 +1,152 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#include <tactility/drivers/rgb_led_pwm.h>
|
||||
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/driver.h>
|
||||
#include <tactility/drivers/pwm.h>
|
||||
#include <tactility/log.h>
|
||||
#include <tactility/module.h>
|
||||
|
||||
#include <new>
|
||||
|
||||
#define TAG "RgbLedPwm"
|
||||
#define GET_CONFIG(device) (static_cast<const RgbLedPwmConfig*>((device)->config))
|
||||
#define GET_INTERNAL(device) (static_cast<RgbLedPwmInternal*>(device_get_driver_data(device)))
|
||||
|
||||
extern "C" {
|
||||
|
||||
struct RgbLedPwmInternal {
|
||||
RgbLedColor color;
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
// region RgbLedApi
|
||||
|
||||
static error_t apply_channel(Device* pwm_device, uint8_t component) {
|
||||
uint32_t period_ns;
|
||||
error_t error = pwm_get_period(pwm_device, &period_ns);
|
||||
if (error != ERROR_NONE) {
|
||||
return error;
|
||||
}
|
||||
|
||||
uint32_t duty_ns = (uint32_t)(((uint64_t)component * period_ns) / 255);
|
||||
return pwm_set_duty(pwm_device, duty_ns);
|
||||
}
|
||||
|
||||
static error_t apply_color(Device* device) {
|
||||
const auto* config = GET_CONFIG(device);
|
||||
const auto* internal = GET_INTERNAL(device);
|
||||
|
||||
error_t error = apply_channel(config->pwm_red, internal->color.r);
|
||||
if (error == ERROR_NONE) {
|
||||
error = apply_channel(config->pwm_green, internal->color.g);
|
||||
}
|
||||
if (error == ERROR_NONE) {
|
||||
error = apply_channel(config->pwm_blue, internal->color.b);
|
||||
}
|
||||
if (error != ERROR_NONE) {
|
||||
LOG_E(TAG, "Failed to apply LED color");
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
static error_t rgb_led_pwm_set_color(Device* device, RgbLedColor color) {
|
||||
GET_INTERNAL(device)->color = color;
|
||||
return apply_color(device);
|
||||
}
|
||||
|
||||
static error_t rgb_led_pwm_get_color(Device* device, RgbLedColor* out_color) {
|
||||
*out_color = GET_INTERNAL(device)->color;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t rgb_led_pwm_enable(Device* device) {
|
||||
const auto* config = GET_CONFIG(device);
|
||||
GET_INTERNAL(device)->enabled = true;
|
||||
|
||||
error_t error = pwm_enable(config->pwm_red);
|
||||
if (error == ERROR_NONE) {
|
||||
error = pwm_enable(config->pwm_green);
|
||||
}
|
||||
if (error == ERROR_NONE) {
|
||||
error = pwm_enable(config->pwm_blue);
|
||||
}
|
||||
if (error != ERROR_NONE) {
|
||||
LOG_E(TAG, "Failed to enable LED");
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
static void rgb_led_pwm_disable(Device* device) {
|
||||
const auto* config = GET_CONFIG(device);
|
||||
GET_INTERNAL(device)->enabled = false;
|
||||
|
||||
pwm_disable(config->pwm_red);
|
||||
pwm_disable(config->pwm_green);
|
||||
pwm_disable(config->pwm_blue);
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
static constexpr RgbLedApi RGB_LED_PWM_API = {
|
||||
.set_color = rgb_led_pwm_set_color,
|
||||
.get_color = rgb_led_pwm_get_color,
|
||||
.enable = rgb_led_pwm_enable,
|
||||
.disable = rgb_led_pwm_disable,
|
||||
};
|
||||
|
||||
// region Driver lifecycle
|
||||
|
||||
static error_t start(Device* device) {
|
||||
const auto* config = GET_CONFIG(device);
|
||||
|
||||
auto* internal = new(std::nothrow) RgbLedPwmInternal {
|
||||
.color = config->default_color,
|
||||
.enabled = false
|
||||
};
|
||||
if (internal == nullptr) {
|
||||
return ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
device_set_driver_data(device, internal);
|
||||
|
||||
error_t error = apply_color(device);
|
||||
if (error != ERROR_NONE) {
|
||||
device_set_driver_data(device, nullptr);
|
||||
delete internal;
|
||||
return error;
|
||||
}
|
||||
|
||||
if (config->enabled) {
|
||||
rgb_led_pwm_enable(device); // Allowed to fail, we don't care about the result
|
||||
}
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop(Device* device) {
|
||||
rgb_led_pwm_disable(device);
|
||||
|
||||
auto* internal = GET_INTERNAL(device);
|
||||
device_set_driver_data(device, nullptr);
|
||||
delete internal;
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
extern Module root_module;
|
||||
|
||||
Driver rgb_led_pwm_driver = {
|
||||
.name = "rgb_led_pwm",
|
||||
.compatible = (const char*[]) { "rgb-led-pwm", nullptr },
|
||||
.start_device = start,
|
||||
.stop_device = stop,
|
||||
.api = &RGB_LED_PWM_API,
|
||||
.device_type = &RGB_LED_TYPE,
|
||||
.owner = &root_module,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#include <tactility/drivers/spi_peripheral.h>
|
||||
#include <tactility/driver.h>
|
||||
#include <tactility/module.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
static error_t start(Device*) { return ERROR_NONE; }
|
||||
static error_t stop(Device*) { return ERROR_NONE; }
|
||||
|
||||
const DeviceType SPI_PERIPHERAL_TYPE = {
|
||||
.name = "spi_peripheral"
|
||||
};
|
||||
|
||||
extern Module root_module;
|
||||
|
||||
Driver spi_peripheral_driver = {
|
||||
.name = "spi_peripheral",
|
||||
.compatible = (const char*[]) { "spi-peripheral", nullptr },
|
||||
.start_device = start,
|
||||
.stop_device = stop,
|
||||
.api = nullptr,
|
||||
.device_type = &SPI_PERIPHERAL_TYPE,
|
||||
.owner = &root_module,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
@ -16,16 +16,20 @@ static error_t start() {
|
||||
if (driver_construct_add(&root_driver) != ERROR_NONE) return ERROR_RESOURCE;
|
||||
extern Driver display_placeholder_driver;
|
||||
if (driver_construct_add(&display_placeholder_driver) != ERROR_NONE) return ERROR_RESOURCE;
|
||||
extern Driver pointer_placeholder_driver;
|
||||
if (driver_construct_add(&pointer_placeholder_driver) != ERROR_NONE) return ERROR_RESOURCE;
|
||||
extern Driver spi_peripheral_driver;
|
||||
if (driver_construct_add(&spi_peripheral_driver) != ERROR_NONE) return ERROR_RESOURCE;
|
||||
extern Driver battery_sense_driver;
|
||||
if (driver_construct_add(&battery_sense_driver) != ERROR_NONE) return ERROR_RESOURCE;
|
||||
extern Driver battery_sense_power_supply_driver;
|
||||
if (driver_construct_add(&battery_sense_power_supply_driver) != ERROR_NONE) return ERROR_RESOURCE;
|
||||
extern Driver gpio_hog_driver;
|
||||
if (driver_construct_add(&gpio_hog_driver) != ERROR_NONE) return ERROR_RESOURCE;
|
||||
extern Driver pwm_backlight_driver;
|
||||
if (driver_construct_add(&pwm_backlight_driver) != ERROR_NONE) return ERROR_RESOURCE;
|
||||
extern Driver gpio_backlight_driver;
|
||||
if (driver_construct_add(&gpio_backlight_driver) != ERROR_NONE) return ERROR_RESOURCE;
|
||||
extern Driver rgb_led_gpio_driver;
|
||||
if (driver_construct_add(&rgb_led_gpio_driver) != ERROR_NONE) return ERROR_RESOURCE;
|
||||
extern Driver rgb_led_pwm_driver;
|
||||
if (driver_construct_add(&rgb_led_pwm_driver) != ERROR_NONE) return ERROR_RESOURCE;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
@ -29,7 +29,6 @@
|
||||
#include <tactility/drivers/rtc.h>
|
||||
#include <tactility/drivers/sdcard.h>
|
||||
#include <tactility/drivers/spi_controller.h>
|
||||
#include <tactility/drivers/spi_peripheral.h>
|
||||
#include <tactility/drivers/uart_controller.h>
|
||||
#include <tactility/drivers/wifi.h>
|
||||
#include <tactility/error.h>
|
||||
@ -243,8 +242,6 @@ const struct ModuleSymbol KERNEL_SYMBOLS[] = {
|
||||
DEFINE_MODULE_SYMBOL(spi_controller_try_lock),
|
||||
DEFINE_MODULE_SYMBOL(spi_controller_unlock),
|
||||
DEFINE_MODULE_SYMBOL(SPI_CONTROLLER_TYPE),
|
||||
// drivers/spi_peripheral
|
||||
DEFINE_MODULE_SYMBOL(SPI_PERIPHERAL_TYPE),
|
||||
// drivers/uart_controller
|
||||
DEFINE_MODULE_SYMBOL(uart_controller_open),
|
||||
DEFINE_MODULE_SYMBOL(uart_controller_close),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user