diff --git a/Devices/btt-panda-touch/bigtreetech,panda-touch.dts b/Devices/btt-panda-touch/bigtreetech,panda-touch.dts index 6f56d6a7a..d106f1ce4 100644 --- a/Devices/btt-panda-touch/bigtreetech,panda-touch.dts +++ b/Devices/btt-panda-touch/bigtreetech,panda-touch.dts @@ -6,7 +6,8 @@ #include #include #include -#include +#include +#include #include #include @@ -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 { diff --git a/Devices/cyd-2432s024c/CMakeLists.txt b/Devices/cyd-2432s024c/CMakeLists.txt index a832a83a2..a7d3e6712 100644 --- a/Devices/cyd-2432s024c/CMakeLists.txt +++ b/Devices/cyd-2432s024c/CMakeLists.txt @@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*) idf_component_register( SRCS ${SOURCE_FILES} - REQUIRES TactilityKernel driver + REQUIRES TactilityKernel ) diff --git a/Devices/cyd-2432s024c/cyd,2432s024c.dts b/Devices/cyd-2432s024c/cyd,2432s024c.dts index ee3049995..3db349493 100644 --- a/Devices/cyd-2432s024c/cyd,2432s024c.dts +++ b/Devices/cyd-2432s024c/cyd,2432s024c.dts @@ -6,7 +6,9 @@ #include #include #include -#include +#include +#include +#include #include #include @@ -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 { diff --git a/Devices/cyd-2432s024c/source/module.cpp b/Devices/cyd-2432s024c/source/module.cpp index 47010a742..e05e61583 100644 --- a/Devices/cyd-2432s024c/source/module.cpp +++ b/Devices/cyd-2432s024c/source/module.cpp @@ -1,20 +1,8 @@ #include -#include - -#include 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; } diff --git a/Devices/cyd-2432s024r/CMakeLists.txt b/Devices/cyd-2432s024r/CMakeLists.txt index a832a83a2..a7d3e6712 100644 --- a/Devices/cyd-2432s024r/CMakeLists.txt +++ b/Devices/cyd-2432s024r/CMakeLists.txt @@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*) idf_component_register( SRCS ${SOURCE_FILES} - REQUIRES TactilityKernel driver + REQUIRES TactilityKernel ) diff --git a/Devices/cyd-2432s024r/cyd,2432s024r.dts b/Devices/cyd-2432s024r/cyd,2432s024r.dts index 928fb9a14..8ea0b9996 100644 --- a/Devices/cyd-2432s024r/cyd,2432s024r.dts +++ b/Devices/cyd-2432s024r/cyd,2432s024r.dts @@ -6,7 +6,9 @@ #include #include #include -#include +#include +#include +#include #include #include @@ -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 { diff --git a/Devices/cyd-2432s024r/source/module.cpp b/Devices/cyd-2432s024r/source/module.cpp index 2cd4c7385..3b2590086 100644 --- a/Devices/cyd-2432s024r/source/module.cpp +++ b/Devices/cyd-2432s024r/source/module.cpp @@ -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; } diff --git a/Devices/cyd-2432s028r/CMakeLists.txt b/Devices/cyd-2432s028r/CMakeLists.txt index a832a83a2..a7d3e6712 100644 --- a/Devices/cyd-2432s028r/CMakeLists.txt +++ b/Devices/cyd-2432s028r/CMakeLists.txt @@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*) idf_component_register( SRCS ${SOURCE_FILES} - REQUIRES TactilityKernel driver + REQUIRES TactilityKernel ) diff --git a/Devices/cyd-2432s028r/cyd,2432s028r.dts b/Devices/cyd-2432s028r/cyd,2432s028r.dts index 4a4378ea2..bbce1f5e0 100644 --- a/Devices/cyd-2432s028r/cyd,2432s028r.dts +++ b/Devices/cyd-2432s028r/cyd,2432s028r.dts @@ -7,7 +7,9 @@ #include #include #include -#include +#include +#include +#include #include #include @@ -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 { diff --git a/Devices/cyd-2432s028r/source/module.cpp b/Devices/cyd-2432s028r/source/module.cpp index 83bd0960d..26ff57688 100644 --- a/Devices/cyd-2432s028r/source/module.cpp +++ b/Devices/cyd-2432s028r/source/module.cpp @@ -1,25 +1,12 @@ #include -#include - -#include 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; } diff --git a/Devices/cyd-2432s028rv3/CMakeLists.txt b/Devices/cyd-2432s028rv3/CMakeLists.txt index a832a83a2..a7d3e6712 100644 --- a/Devices/cyd-2432s028rv3/CMakeLists.txt +++ b/Devices/cyd-2432s028rv3/CMakeLists.txt @@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*) idf_component_register( SRCS ${SOURCE_FILES} - REQUIRES TactilityKernel driver + REQUIRES TactilityKernel ) diff --git a/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts b/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts index 48c105288..55a5973fd 100644 --- a/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts +++ b/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts @@ -7,7 +7,9 @@ #include #include #include -#include +#include +#include +#include #include #include @@ -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 { diff --git a/Devices/cyd-2432s028rv3/source/module.cpp b/Devices/cyd-2432s028rv3/source/module.cpp index 3f7e4f1cc..ed7f9255e 100644 --- a/Devices/cyd-2432s028rv3/source/module.cpp +++ b/Devices/cyd-2432s028rv3/source/module.cpp @@ -1,20 +1,8 @@ #include -#include - -#include 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; } diff --git a/Devices/cyd-2432s032c/CMakeLists.txt b/Devices/cyd-2432s032c/CMakeLists.txt index a832a83a2..a7d3e6712 100644 --- a/Devices/cyd-2432s032c/CMakeLists.txt +++ b/Devices/cyd-2432s032c/CMakeLists.txt @@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*) idf_component_register( SRCS ${SOURCE_FILES} - REQUIRES TactilityKernel driver + REQUIRES TactilityKernel ) diff --git a/Devices/cyd-2432s032c/cyd,2432s032c.dts b/Devices/cyd-2432s032c/cyd,2432s032c.dts index c04a13fe0..f50992cb2 100644 --- a/Devices/cyd-2432s032c/cyd,2432s032c.dts +++ b/Devices/cyd-2432s032c/cyd,2432s032c.dts @@ -6,7 +6,9 @@ #include #include #include -#include +#include +#include +#include #include #include @@ -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 { diff --git a/Devices/cyd-2432s032c/source/module.cpp b/Devices/cyd-2432s032c/source/module.cpp index 348f0204d..ee8c6422b 100644 --- a/Devices/cyd-2432s032c/source/module.cpp +++ b/Devices/cyd-2432s032c/source/module.cpp @@ -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; } diff --git a/Devices/cyd-3248s035c/CMakeLists.txt b/Devices/cyd-3248s035c/CMakeLists.txt index ac88a91d8..731e5e601 100644 --- a/Devices/cyd-3248s035c/CMakeLists.txt +++ b/Devices/cyd-3248s035c/CMakeLists.txt @@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*) idf_component_register( SRCS ${SOURCE_FILES} - REQUIRES TactilityKernel driver + REQUIRES TactilityKernel ) diff --git a/Devices/cyd-3248s035c/cyd,3248s035c.dts b/Devices/cyd-3248s035c/cyd,3248s035c.dts index d5924ff2b..ed28ca40c 100644 --- a/Devices/cyd-3248s035c/cyd,3248s035c.dts +++ b/Devices/cyd-3248s035c/cyd,3248s035c.dts @@ -7,7 +7,9 @@ #include #include #include -#include +#include +#include +#include #include #include @@ -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 { diff --git a/Devices/cyd-3248s035c/source/module.cpp b/Devices/cyd-3248s035c/source/module.cpp index e694b6f1a..6c5b2cd9c 100644 --- a/Devices/cyd-3248s035c/source/module.cpp +++ b/Devices/cyd-3248s035c/source/module.cpp @@ -1,25 +1,12 @@ #include -#include - -#include 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; } diff --git a/Devices/cyd-8048s043c/cyd,8048s043c.dts b/Devices/cyd-8048s043c/cyd,8048s043c.dts index 0d82c1d20..71b477695 100644 --- a/Devices/cyd-8048s043c/cyd,8048s043c.dts +++ b/Devices/cyd-8048s043c/cyd,8048s043c.dts @@ -8,7 +8,8 @@ #include #include #include -#include +#include +#include #include #include @@ -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 { diff --git a/Devices/cyd-8048s043c/source/module.cpp b/Devices/cyd-8048s043c/source/module.cpp index acb29a758..d638238dc 100644 --- a/Devices/cyd-8048s043c/source/module.cpp +++ b/Devices/cyd-8048s043c/source/module.cpp @@ -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; } diff --git a/Devices/cyd-e32r28t/CMakeLists.txt b/Devices/cyd-e32r28t/CMakeLists.txt index a832a83a2..a7d3e6712 100644 --- a/Devices/cyd-e32r28t/CMakeLists.txt +++ b/Devices/cyd-e32r28t/CMakeLists.txt @@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*) idf_component_register( SRCS ${SOURCE_FILES} - REQUIRES TactilityKernel driver + REQUIRES TactilityKernel ) diff --git a/Devices/cyd-e32r28t/cyd,e32r28t.dts b/Devices/cyd-e32r28t/cyd,e32r28t.dts index 2ae405d13..3d90c8483 100644 --- a/Devices/cyd-e32r28t/cyd,e32r28t.dts +++ b/Devices/cyd-e32r28t/cyd,e32r28t.dts @@ -5,7 +5,9 @@ #include #include #include -#include +#include +#include +#include #include #include @@ -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 { diff --git a/Devices/cyd-e32r28t/source/module.cpp b/Devices/cyd-e32r28t/source/module.cpp index 7806af3d0..3ee0556ca 100644 --- a/Devices/cyd-e32r28t/source/module.cpp +++ b/Devices/cyd-e32r28t/source/module.cpp @@ -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; } diff --git a/Devices/cyd-e32r32p/CMakeLists.txt b/Devices/cyd-e32r32p/CMakeLists.txt index a832a83a2..a7d3e6712 100644 --- a/Devices/cyd-e32r32p/CMakeLists.txt +++ b/Devices/cyd-e32r32p/CMakeLists.txt @@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*) idf_component_register( SRCS ${SOURCE_FILES} - REQUIRES TactilityKernel driver + REQUIRES TactilityKernel ) diff --git a/Devices/cyd-e32r32p/cyd,e32r32p.dts b/Devices/cyd-e32r32p/cyd,e32r32p.dts index bdbc379d7..e7e5c92d8 100644 --- a/Devices/cyd-e32r32p/cyd,e32r32p.dts +++ b/Devices/cyd-e32r32p/cyd,e32r32p.dts @@ -8,7 +8,9 @@ #include #include #include -#include +#include +#include +#include #include #include @@ -40,6 +42,43 @@ channels = ; }; + 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 { diff --git a/Devices/cyd-e32r32p/source/module.cpp b/Devices/cyd-e32r32p/source/module.cpp index 65488c2b9..1a3df3034 100644 --- a/Devices/cyd-e32r32p/source/module.cpp +++ b/Devices/cyd-e32r32p/source/module.cpp @@ -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; } diff --git a/Devices/elecrow-crowpanel-advance-28/CMakeLists.txt b/Devices/elecrow-crowpanel-advance-28/CMakeLists.txt index a832a83a2..a7d3e6712 100644 --- a/Devices/elecrow-crowpanel-advance-28/CMakeLists.txt +++ b/Devices/elecrow-crowpanel-advance-28/CMakeLists.txt @@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*) idf_component_register( SRCS ${SOURCE_FILES} - REQUIRES TactilityKernel driver + REQUIRES TactilityKernel ) diff --git a/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts b/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts index c6a088f72..fe6881c60 100644 --- a/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts +++ b/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts @@ -8,7 +8,8 @@ #include #include #include -#include +#include +#include #include #include @@ -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 { diff --git a/Devices/elecrow-crowpanel-advance-35/CMakeLists.txt b/Devices/elecrow-crowpanel-advance-35/CMakeLists.txt index a832a83a2..a7d3e6712 100644 --- a/Devices/elecrow-crowpanel-advance-35/CMakeLists.txt +++ b/Devices/elecrow-crowpanel-advance-35/CMakeLists.txt @@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*) idf_component_register( SRCS ${SOURCE_FILES} - REQUIRES TactilityKernel driver + REQUIRES TactilityKernel ) diff --git a/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts b/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts index e6f6cf168..173c9cd40 100644 --- a/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts +++ b/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts @@ -8,7 +8,8 @@ #include #include #include -#include +#include +#include #include #include @@ -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 { diff --git a/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts b/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts index 0be96a1ea..4cffd6041 100644 --- a/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts +++ b/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include @@ -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 { diff --git a/Devices/elecrow-crowpanel-basic-28/CMakeLists.txt b/Devices/elecrow-crowpanel-basic-28/CMakeLists.txt index a832a83a2..a7d3e6712 100644 --- a/Devices/elecrow-crowpanel-basic-28/CMakeLists.txt +++ b/Devices/elecrow-crowpanel-basic-28/CMakeLists.txt @@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*) idf_component_register( SRCS ${SOURCE_FILES} - REQUIRES TactilityKernel driver + REQUIRES TactilityKernel ) diff --git a/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts b/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts index 58945c75a..5c04fcab3 100644 --- a/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts +++ b/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts @@ -7,7 +7,8 @@ #include #include #include -#include +#include +#include #include #include @@ -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 { diff --git a/Devices/elecrow-crowpanel-basic-28/source/module.cpp b/Devices/elecrow-crowpanel-basic-28/source/module.cpp index e9cdd36d4..4f792da31 100644 --- a/Devices/elecrow-crowpanel-basic-28/source/module.cpp +++ b/Devices/elecrow-crowpanel-basic-28/source/module.cpp @@ -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; } diff --git a/Devices/elecrow-crowpanel-basic-35/CMakeLists.txt b/Devices/elecrow-crowpanel-basic-35/CMakeLists.txt index a832a83a2..a7d3e6712 100644 --- a/Devices/elecrow-crowpanel-basic-35/CMakeLists.txt +++ b/Devices/elecrow-crowpanel-basic-35/CMakeLists.txt @@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*) idf_component_register( SRCS ${SOURCE_FILES} - REQUIRES TactilityKernel driver + REQUIRES TactilityKernel ) diff --git a/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts b/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts index e7f888b5e..de27790aa 100644 --- a/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts +++ b/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts @@ -7,7 +7,8 @@ #include #include #include -#include +#include +#include #include #include @@ -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 { diff --git a/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts b/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts index 8477a403e..1bf9d0bfb 100644 --- a/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts +++ b/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts @@ -8,7 +8,8 @@ #include #include #include -#include +#include +#include #include #include @@ -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 { diff --git a/Devices/guition-jc2432w328c/Source/Configuration.cpp b/Devices/guition-jc2432w328c/Source/Configuration.cpp index 9734b668f..8324dcffe 100644 --- a/Devices/guition-jc2432w328c/Source/Configuration.cpp +++ b/Devices/guition-jc2432w328c/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include #include #include @@ -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); } diff --git a/Devices/guition-jc2432w328c/Source/module.cpp b/Devices/guition-jc2432w328c/Source/module.cpp index 0abd3887e..d1e1fe373 100644 --- a/Devices/guition-jc2432w328c/Source/module.cpp +++ b/Devices/guition-jc2432w328c/Source/module.cpp @@ -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; } diff --git a/Devices/guition-jc2432w328c/guition,jc2432w328c.dts b/Devices/guition-jc2432w328c/guition,jc2432w328c.dts index 0a76eaff6..1f70b9681 100644 --- a/Devices/guition-jc2432w328c/guition,jc2432w328c.dts +++ b/Devices/guition-jc2432w328c/guition,jc2432w328c.dts @@ -8,6 +8,7 @@ #include #include #include +#include / { 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>; + }; }; diff --git a/Devices/lilygo-tdeck-plus/lilygo,tdeck-plus.dts b/Devices/lilygo-tdeck-plus/lilygo,tdeck-plus.dts index 6e7b737f8..1cfc2c93d 100644 --- a/Devices/lilygo-tdeck-plus/lilygo,tdeck-plus.dts +++ b/Devices/lilygo-tdeck-plus/lilygo,tdeck-plus.dts @@ -8,7 +8,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -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 { diff --git a/Devices/lilygo-tdeck/lilygo,tdeck.dts b/Devices/lilygo-tdeck/lilygo,tdeck.dts index da408c310..62ede4f77 100644 --- a/Devices/lilygo-tdeck/lilygo,tdeck.dts +++ b/Devices/lilygo-tdeck/lilygo,tdeck.dts @@ -8,7 +8,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -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 { diff --git a/Devices/lilygo-thmi/lilygo,thmi.dts b/Devices/lilygo-thmi/lilygo,thmi.dts index 33f023cec..d724d9a3a 100644 --- a/Devices/lilygo-thmi/lilygo,thmi.dts +++ b/Devices/lilygo-thmi/lilygo,thmi.dts @@ -9,7 +9,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -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 = ; }; power_en { - compatible = "tactility,gpio-hog"; + compatible = "gpio-hog"; pin = <&gpio0 10 GPIO_FLAG_NONE>; mode = ; }; @@ -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 { diff --git a/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts b/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts index a00145083..e47a2cd7c 100644 --- a/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts +++ b/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts @@ -13,7 +13,8 @@ #include #include #include -#include +#include +#include #include #include @@ -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 { diff --git a/Devices/m5stack-cardputer/m5stack,cardputer.dts b/Devices/m5stack-cardputer/m5stack,cardputer.dts index cc34fca94..bd802d2f4 100644 --- a/Devices/m5stack-cardputer/m5stack,cardputer.dts +++ b/Devices/m5stack-cardputer/m5stack,cardputer.dts @@ -12,7 +12,8 @@ #include #include #include -#include +#include +#include #include #include @@ -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 { diff --git a/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts b/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts index 47a5dac7a..701040f98 100644 --- a/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts +++ b/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts @@ -7,7 +7,8 @@ #include #include #include -#include +#include +#include #include #include @@ -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 { diff --git a/Devices/unphone/unphone.dts b/Devices/unphone/unphone.dts index 323ef0532..f0c3c3999 100644 --- a/Devices/unphone/unphone.dts +++ b/Devices/unphone/unphone.dts @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include / { @@ -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 = ; }; vibration_motor { - compatible = "tactility,gpio-hog"; + compatible = "gpio-hog"; pin = <&tca9535 7 GPIO_FLAG_NONE>; mode = ; }; ir_leds { - compatible = "tactility,gpio-hog"; + compatible = "gpio-hog"; pin = <&gpio0 12 GPIO_FLAG_NONE>; mode = ; }; red_led { - compatible = "tactility,gpio-hog"; + compatible = "gpio-hog"; pin = <&gpio0 13 GPIO_FLAG_NONE>; mode = ; }; green_led { - compatible = "tactility,gpio-hog"; + compatible = "gpio-hog"; pin = <&tca9535 9 GPIO_FLAG_NONE>; mode = ; }; blue_led { - compatible = "tactility,gpio-hog"; + compatible = "gpio-hog"; pin = <&tca9535 13 GPIO_FLAG_NONE>; mode = ; }; diff --git a/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts b/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts index 2748b30b9..eadabedee 100644 --- a/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts +++ b/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts @@ -8,7 +8,8 @@ #include #include #include -#include +#include +#include #include // 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 { diff --git a/Platforms/platform-esp32/bindings/espressif,esp32-ledc-backlight.yaml b/Platforms/platform-esp32/bindings/espressif,esp32-ledc-backlight.yaml deleted file mode 100644 index d91066e30..000000000 --- a/Platforms/platform-esp32/bindings/espressif,esp32-ledc-backlight.yaml +++ /dev/null @@ -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 diff --git a/Platforms/platform-esp32/bindings/espressif,esp32-pwm-ledc.yaml b/Platforms/platform-esp32/bindings/espressif,esp32-pwm-ledc.yaml new file mode 100644 index 000000000..073ec3855 --- /dev/null +++ b/Platforms/platform-esp32/bindings/espressif,esp32-pwm-ledc.yaml @@ -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 diff --git a/Platforms/platform-esp32/include/tactility/bindings/esp32_gpio_backlight.h b/Platforms/platform-esp32/include/tactility/bindings/esp32_gpio_backlight.h deleted file mode 100644 index e91550339..000000000 --- a/Platforms/platform-esp32/include/tactility/bindings/esp32_gpio_backlight.h +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -#pragma once - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -DEFINE_DEVICETREE(esp32_gpio_backlight, struct Esp32GpioBacklightConfig) - -#ifdef __cplusplus -} -#endif diff --git a/Platforms/platform-esp32/include/tactility/bindings/esp32_ledc_backlight.h b/Platforms/platform-esp32/include/tactility/bindings/esp32_ledc_backlight.h deleted file mode 100644 index 625872d89..000000000 --- a/Platforms/platform-esp32/include/tactility/bindings/esp32_ledc_backlight.h +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -#pragma once - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -DEFINE_DEVICETREE(esp32_ledc_backlight, struct Esp32LedcBacklightConfig) - -#ifdef __cplusplus -} -#endif diff --git a/TactilityKernel/include/tactility/bindings/spi_peripheral.h b/Platforms/platform-esp32/include/tactility/bindings/esp32_pwm_ledc.h similarity index 60% rename from TactilityKernel/include/tactility/bindings/spi_peripheral.h rename to Platforms/platform-esp32/include/tactility/bindings/esp32_pwm_ledc.h index 30cccd85f..9a2813d2c 100644 --- a/TactilityKernel/include/tactility/bindings/spi_peripheral.h +++ b/Platforms/platform-esp32/include/tactility/bindings/esp32_pwm_ledc.h @@ -2,13 +2,13 @@ #pragma once #include -#include +#include #ifdef __cplusplus extern "C" { #endif -DEFINE_DEVICETREE(spi_peripheral, struct SpiPeripheralConfig) +DEFINE_DEVICETREE(esp32_pwm_ledc, struct Esp32PwmLedcConfig) #ifdef __cplusplus } diff --git a/Platforms/platform-esp32/include/tactility/drivers/esp32_gpio_backlight.h b/Platforms/platform-esp32/include/tactility/drivers/esp32_gpio_backlight.h deleted file mode 100644 index c64547428..000000000 --- a/Platforms/platform-esp32/include/tactility/drivers/esp32_gpio_backlight.h +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -#pragma once - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct Esp32GpioBacklightConfig { - struct GpioPinSpec pin_backlight; - bool default_on; -}; - -#ifdef __cplusplus -} -#endif diff --git a/Platforms/platform-esp32/include/tactility/drivers/esp32_ledc_backlight.h b/Platforms/platform-esp32/include/tactility/drivers/esp32_pwm_ledc.h similarity index 52% rename from Platforms/platform-esp32/include/tactility/drivers/esp32_ledc_backlight.h rename to Platforms/platform-esp32/include/tactility/drivers/esp32_pwm_ledc.h index 3b75ccf59..021b81a81 100644 --- a/Platforms/platform-esp32/include/tactility/drivers/esp32_ledc_backlight.h +++ b/Platforms/platform-esp32/include/tactility/drivers/esp32_pwm_ledc.h @@ -2,18 +2,19 @@ #pragma once #include -#include #include +#include #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; }; diff --git a/Platforms/platform-esp32/source/drivers/esp32_gpio_backlight.cpp b/Platforms/platform-esp32/source/drivers/esp32_gpio_backlight.cpp deleted file mode 100644 index 64fcb32d9..000000000 --- a/Platforms/platform-esp32/source/drivers/esp32_gpio_backlight.cpp +++ /dev/null @@ -1,119 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -#include - -#include -#include -#include -#include -#include -#include - -#include - -#define TAG "Esp32GpioBacklight" -#define GET_CONFIG(device) (static_cast((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(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(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(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(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 -}; diff --git a/Platforms/platform-esp32/source/drivers/esp32_ledc_backlight.cpp b/Platforms/platform-esp32/source/drivers/esp32_ledc_backlight.cpp deleted file mode 100644 index f1d075e26..000000000 --- a/Platforms/platform-esp32/source/drivers/esp32_ledc_backlight.cpp +++ /dev/null @@ -1,139 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -#include - -#include -#include -#include -#include - -#include -#include - -#include - -#define TAG "Esp32LedcBacklight" -#define GET_CONFIG(device) (static_cast((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(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(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(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(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 -}; diff --git a/Platforms/platform-esp32/source/drivers/esp32_pwm_ledc.cpp b/Platforms/platform-esp32/source/drivers/esp32_pwm_ledc.cpp new file mode 100644 index 000000000..41af027d8 --- /dev/null +++ b/Platforms/platform-esp32/source/drivers/esp32_pwm_ledc.cpp @@ -0,0 +1,252 @@ +// SPDX-License-Identifier: Apache-2.0 +#include + +#include +#include +#include +#include + +#include +#include + +#include + +#define TAG "Esp32PwmLedc" +#define GET_CONFIG(device) (static_cast((device)->config)) +#define GET_INTERNAL(device) (static_cast(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(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 +}; diff --git a/Platforms/platform-esp32/source/module.cpp b/Platforms/platform-esp32/source/module.cpp index 833be4c73..02614d245 100644 --- a/Platforms/platform-esp32/source/module.cpp +++ b/Platforms/platform-esp32/source/module.cpp @@ -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 diff --git a/Platforms/platform-esp32/bindings/espressif,esp32-gpio-backlight.yaml b/TactilityKernel/bindings/gpio-backlight.yaml similarity index 82% rename from Platforms/platform-esp32/bindings/espressif,esp32-gpio-backlight.yaml rename to TactilityKernel/bindings/gpio-backlight.yaml index e60cdc12b..1e785d182 100644 --- a/Platforms/platform-esp32/bindings/espressif,esp32-gpio-backlight.yaml +++ b/TactilityKernel/bindings/gpio-backlight.yaml @@ -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() diff --git a/TactilityKernel/bindings/tactility,gpio-hog.yaml b/TactilityKernel/bindings/gpio-hog.yaml similarity index 96% rename from TactilityKernel/bindings/tactility,gpio-hog.yaml rename to TactilityKernel/bindings/gpio-hog.yaml index 1cd39f002..b8de224e6 100644 --- a/TactilityKernel/bindings/tactility,gpio-hog.yaml +++ b/TactilityKernel/bindings/gpio-hog.yaml @@ -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: diff --git a/TactilityKernel/bindings/pwm-backlight.yaml b/TactilityKernel/bindings/pwm-backlight.yaml new file mode 100644 index 000000000..0632c1a38 --- /dev/null +++ b/TactilityKernel/bindings/pwm-backlight.yaml @@ -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. diff --git a/TactilityKernel/bindings/pwm.yaml b/TactilityKernel/bindings/pwm.yaml new file mode 100644 index 000000000..386fcfc0c --- /dev/null +++ b/TactilityKernel/bindings/pwm.yaml @@ -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 diff --git a/TactilityKernel/bindings/rgb-led-gpio.yaml b/TactilityKernel/bindings/rgb-led-gpio.yaml new file mode 100644 index 000000000..b4692bd73 --- /dev/null +++ b/TactilityKernel/bindings/rgb-led-gpio.yaml @@ -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 diff --git a/TactilityKernel/bindings/rgb-led-pwm.yaml b/TactilityKernel/bindings/rgb-led-pwm.yaml new file mode 100644 index 000000000..0b6582e08 --- /dev/null +++ b/TactilityKernel/bindings/rgb-led-pwm.yaml @@ -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 diff --git a/TactilityKernel/bindings/spi-peripheral.yaml b/TactilityKernel/bindings/spi-peripheral.yaml deleted file mode 100644 index 623c671d8..000000000 --- a/TactilityKernel/bindings/spi-peripheral.yaml +++ /dev/null @@ -1,5 +0,0 @@ -description: SPI peripheral - -compatible: "spi-peripheral" - -properties: {} diff --git a/TactilityKernel/include/tactility/bindings/gpio_backlight.h b/TactilityKernel/include/tactility/bindings/gpio_backlight.h new file mode 100644 index 000000000..8bd58cc1b --- /dev/null +++ b/TactilityKernel/include/tactility/bindings/gpio_backlight.h @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include +#include + +DEFINE_DEVICETREE(gpio_backlight, struct GpioBacklightConfig) diff --git a/TactilityKernel/include/tactility/bindings/pointer_placeholder.h b/TactilityKernel/include/tactility/bindings/pointer_placeholder.h deleted file mode 100644 index d5d026f49..000000000 --- a/TactilityKernel/include/tactility/bindings/pointer_placeholder.h +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -#pragma once - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -DEFINE_DEVICETREE(pointer_placeholder, struct PointerPlaceholderConfig) - -#ifdef __cplusplus -} -#endif diff --git a/TactilityKernel/include/tactility/bindings/pwm_backlight.h b/TactilityKernel/include/tactility/bindings/pwm_backlight.h new file mode 100644 index 000000000..bd3e6a4b7 --- /dev/null +++ b/TactilityKernel/include/tactility/bindings/pwm_backlight.h @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include +#include + +DEFINE_DEVICETREE(pwm_backlight, struct PwmBacklightConfig) diff --git a/TactilityKernel/include/tactility/bindings/rgb_led_gpio.h b/TactilityKernel/include/tactility/bindings/rgb_led_gpio.h new file mode 100644 index 000000000..4f363f3cd --- /dev/null +++ b/TactilityKernel/include/tactility/bindings/rgb_led_gpio.h @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include +#include + +DEFINE_DEVICETREE(rgb_led_gpio, struct RgbLedGpioConfig) diff --git a/TactilityKernel/include/tactility/bindings/rgb_led_pwm.h b/TactilityKernel/include/tactility/bindings/rgb_led_pwm.h new file mode 100644 index 000000000..3c007ac11 --- /dev/null +++ b/TactilityKernel/include/tactility/bindings/rgb_led_pwm.h @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include +#include + +DEFINE_DEVICETREE(rgb_led_pwm, struct RgbLedPwmConfig) diff --git a/TactilityKernel/include/tactility/drivers/gpio_backlight.h b/TactilityKernel/include/tactility/drivers/gpio_backlight.h new file mode 100644 index 000000000..00b1d3b4a --- /dev/null +++ b/TactilityKernel/include/tactility/drivers/gpio_backlight.h @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include + +/** + * @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 diff --git a/TactilityKernel/include/tactility/drivers/pointer_placeholder.h b/TactilityKernel/include/tactility/drivers/pointer_placeholder.h deleted file mode 100644 index e8b1553a5..000000000 --- a/TactilityKernel/include/tactility/drivers/pointer_placeholder.h +++ /dev/null @@ -1,16 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -#pragma once - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct PointerPlaceholderConfig { - uint8_t _unused; -}; - -#ifdef __cplusplus -} -#endif diff --git a/TactilityKernel/include/tactility/drivers/pwm.h b/TactilityKernel/include/tactility/drivers/pwm.h new file mode 100644 index 000000000..4b59be0a7 --- /dev/null +++ b/TactilityKernel/include/tactility/drivers/pwm.h @@ -0,0 +1,150 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#include +#include + +/** + * @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 diff --git a/TactilityKernel/include/tactility/drivers/pwm_backlight.h b/TactilityKernel/include/tactility/drivers/pwm_backlight.h new file mode 100644 index 000000000..a13a59cb1 --- /dev/null +++ b/TactilityKernel/include/tactility/drivers/pwm_backlight.h @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include +#include + +/** + * @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 diff --git a/TactilityKernel/include/tactility/drivers/rgb_led.h b/TactilityKernel/include/tactility/drivers/rgb_led.h new file mode 100644 index 000000000..d3333f319 --- /dev/null +++ b/TactilityKernel/include/tactility/drivers/rgb_led.h @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#include +#include + +/** + * @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 diff --git a/TactilityKernel/include/tactility/drivers/rgb_led_gpio.h b/TactilityKernel/include/tactility/drivers/rgb_led_gpio.h new file mode 100644 index 000000000..a1861fe92 --- /dev/null +++ b/TactilityKernel/include/tactility/drivers/rgb_led_gpio.h @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include +#include + +/** + * @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 diff --git a/TactilityKernel/include/tactility/drivers/rgb_led_pwm.h b/TactilityKernel/include/tactility/drivers/rgb_led_pwm.h new file mode 100644 index 000000000..85076f51e --- /dev/null +++ b/TactilityKernel/include/tactility/drivers/rgb_led_pwm.h @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include +#include + +/** + * @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 diff --git a/TactilityKernel/include/tactility/drivers/spi_peripheral.h b/TactilityKernel/include/tactility/drivers/spi_peripheral.h deleted file mode 100644 index fa725569c..000000000 --- a/TactilityKernel/include/tactility/drivers/spi_peripheral.h +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -#pragma once - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct SpiPeripheralConfig { - uint8_t _unused; -}; - -extern const struct DeviceType SPI_PERIPHERAL_TYPE; - -#ifdef __cplusplus -} -#endif diff --git a/TactilityKernel/source/drivers/gpio_backlight.cpp b/TactilityKernel/source/drivers/gpio_backlight.cpp new file mode 100644 index 000000000..fdfb89b1e --- /dev/null +++ b/TactilityKernel/source/drivers/gpio_backlight.cpp @@ -0,0 +1,144 @@ +// SPDX-License-Identifier: Apache-2.0 +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#define TAG "GpioBacklight" +#define GET_CONFIG(device) (static_cast((device)->config)) +#define GET_INTERNAL(device) (static_cast(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 +}; + +} diff --git a/TactilityKernel/source/drivers/gpio_hog.cpp b/TactilityKernel/source/drivers/gpio_hog.cpp index d3f08cab0..c331588ff 100644 --- a/TactilityKernel/source/drivers/gpio_hog.cpp +++ b/TactilityKernel/source/drivers/gpio_hog.cpp @@ -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, diff --git a/TactilityKernel/source/drivers/pointer_placeholder.cpp b/TactilityKernel/source/drivers/pointer_placeholder.cpp deleted file mode 100644 index b3d329af9..000000000 --- a/TactilityKernel/source/drivers/pointer_placeholder.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -#include -#include -#include -#include -#include - -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 -}; - -} diff --git a/TactilityKernel/source/drivers/pwm.cpp b/TactilityKernel/source/drivers/pwm.cpp new file mode 100644 index 000000000..bd67cb106 --- /dev/null +++ b/TactilityKernel/source/drivers/pwm.cpp @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: Apache-2.0 +#include +#include + +#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" +}; + +} diff --git a/TactilityKernel/source/drivers/pwm_backlight.cpp b/TactilityKernel/source/drivers/pwm_backlight.cpp new file mode 100644 index 000000000..dfb6b5ca2 --- /dev/null +++ b/TactilityKernel/source/drivers/pwm_backlight.cpp @@ -0,0 +1,132 @@ +// SPDX-License-Identifier: Apache-2.0 +#include + +#include +#include +#include +#include +#include +#include + +#include + +#define TAG "PwmBacklight" +#define GET_CONFIG(device) (static_cast((device)->config)) +#define GET_INTERNAL(device) (static_cast(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 +}; + +} diff --git a/TactilityKernel/source/drivers/rgb_led.cpp b/TactilityKernel/source/drivers/rgb_led.cpp new file mode 100644 index 000000000..8f4b90e79 --- /dev/null +++ b/TactilityKernel/source/drivers/rgb_led.cpp @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: Apache-2.0 +#include +#include + +#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" +}; + +} diff --git a/TactilityKernel/source/drivers/rgb_led_gpio.cpp b/TactilityKernel/source/drivers/rgb_led_gpio.cpp new file mode 100644 index 000000000..a9ff58ca9 --- /dev/null +++ b/TactilityKernel/source/drivers/rgb_led_gpio.cpp @@ -0,0 +1,165 @@ +// SPDX-License-Identifier: Apache-2.0 +#include + +#include +#include +#include +#include +#include +#include + +#include + +#define TAG "RgbLedGpio" +#define GET_CONFIG(device) (static_cast((device)->config)) +#define GET_INTERNAL(device) (static_cast(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 +}; + +} diff --git a/TactilityKernel/source/drivers/rgb_led_pwm.cpp b/TactilityKernel/source/drivers/rgb_led_pwm.cpp new file mode 100644 index 000000000..1bb8de7a9 --- /dev/null +++ b/TactilityKernel/source/drivers/rgb_led_pwm.cpp @@ -0,0 +1,152 @@ +// SPDX-License-Identifier: Apache-2.0 +#include + +#include +#include +#include +#include +#include + +#include + +#define TAG "RgbLedPwm" +#define GET_CONFIG(device) (static_cast((device)->config)) +#define GET_INTERNAL(device) (static_cast(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 +}; + +} diff --git a/TactilityKernel/source/drivers/spi_peripheral.cpp b/TactilityKernel/source/drivers/spi_peripheral.cpp deleted file mode 100644 index 8e9a3956b..000000000 --- a/TactilityKernel/source/drivers/spi_peripheral.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -#include -#include -#include - -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 -}; - -} diff --git a/TactilityKernel/source/kernel_init.cpp b/TactilityKernel/source/kernel_init.cpp index d02cad9bf..0aad44468 100644 --- a/TactilityKernel/source/kernel_init.cpp +++ b/TactilityKernel/source/kernel_init.cpp @@ -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; } diff --git a/TactilityKernel/source/kernel_symbols.c b/TactilityKernel/source/kernel_symbols.c index 0d4945da2..42ff02a2a 100644 --- a/TactilityKernel/source/kernel_symbols.c +++ b/TactilityKernel/source/kernel_symbols.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -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),