Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 9821

Interfacing (DSI, CSI, I2C, etc.) • Re: Small TFT based on ILI9341 ST7789 - how to use

$
0
0
Also looks like a hack to me .
Considering the overlay name literally has 'hack' in it... But, it's sort of a working solution if anyone needs but......
Note: all this is untested! Just wrote this from the tablet while having my first cup of Coffee!
Oo, that's awesome, thanks. That's exactly what I was just working on pretty much already, I think I had mostly got it by the time I saw your post but it'll still be great to refer to as I try to piece this together.

I'm going to try and have a unified `backlight-gpio` setting that sets the pin across three modes and also add a unified `backlight-invert` option that will do ACTIVE_LOW/ACTIVE_HIGH for binary mode or (I think this would work?) invert the `brightness-modes` list. Then I'll have the three modes (binary, hard pwm, soft pwm) modes unmask based on the users config choice.

I would love to have the user set `backlight-pwm` to true/false if they want pwm and then otherwise have it automatically unmask software or hardware pwm depending on the GPIO provided - if they provide a pin that can use hardware pwm, do that, otherwise use software. I don't think this is possible though.

What I can perhaps do though is default to soft pwm regardless of pin and have a `backlight-enable-hw-pwm` option or something to unmask the hardware pwm, but still working out exactly how to do that.

Since this is unfamiliar territory for me, I've been working with an LLM a bit (not my first go-to but sometimes beats harassing real people with dumb questions, plus, google sucks so much these days I feel like you're almost forced to, maybe that's the trick, eh?), this is what it's just come up with based on those requirements, I'm just reviewing it now (I already see a bunch of issues LOL) to make sure it looks sane based on my limited knowledge of the syntaschemax, if so I'll try it out

Code:

/* * mipi-dbi-spi-ebl-overlay.dts * * Based off mipi-dbi-spi-overlay.dts, adds enhanced backlight ("ebl") control: * * - Unified backlight-gpio-pin for all control types * - Simple GPIO (on/off) backlight * - Hardware PWM backlight using SoC PWM controller (limited pins) * - Software/kernel PWM backlight using pwm-gpio on any GPIO * - Optional backlight-invert for active-low / inverted brightness * * Params: *   compatible: *     Override panel compatible (e.g. "panel-mipi-dbi-spi,st7789v") * *   spi0-0, spi0-1, spi1-0, spi1-1, spi1-2, spi2-0, spi2-1, spi2-2: *     Select which SPI bus/chip-select the panel is attached to. * *   speed: *     SPI max frequency (Hz), default 32000000. * *   cpha, cpol: *     Set SPI mode (CPHA/CPOL). * *   write-only: *     Set panel as write-only (no MISO). * *   width, height: *     Active resolution in pixels (hactive/vactive). * *   x-offset, y-offset: *     Horizontal/vertical back porch (offset). * *   clock-frequency: *     Panel clock frequency. * *   width-mm, height-mm: *     Physical panel size in millimeters. * *   reset-gpio: *     Panel reset GPIO. * *   dc-gpio: *     Panel data/command GPIO. * *   backlight-gpio-pin: *     GPIO used for backlight control in all modes. * *   backlight-gpio: *     Enable simple GPIO backlight (on/off). * *   backlight-pwm: *     Enable software PWM backlight using pwm-gpio (default PWM mode). * *   backlight-hw-pwm: *     Enable hardware PWM backlight using SoC PWM controller. *     NOTE: only valid on GPIO 12, 13, 18, or 19. * *   backlight-def-brightness: *     Default brightness level index for PWM backlights. * *   backlight-invert: *     Invert backlight polarity: *       - GPIO mode: ACTIVE_LOW instead of ACTIVE_HIGH *       - PWM modes: invert brightness curve (0=brightest, 255=darkest) */#include <dt-bindings/gpio/gpio.h>/dts-v1/;/plugin/;/ {compatible = "brcm,bcm2835";spidev_fragment: fragment@0 {target-path = "spi0/spidev@0";__overlay__ {status = "disabled";};};panel_fragment: fragment@1 {target = <&spi0>;__overlay__ {/* needed to avoid dtc warning */#address-cells = <1>;#size-cells = <0>;status = "okay";panel: panel@0 {compatible = "panel", "panel-mipi-dbi-spi";reg = <0>;spi-max-frequency = <32000000>;width-mm = <0>;height-mm = <0>;timing: panel-timing {hactive = <320>;vactive = <240>;hback-porch = <0>;vback-porch = <0>;clock-frequency = <0>;hfront-porch = <0>;hsync-len = <0>;vfront-porch = <0>;vsync-len = <0>;};};};};/* --------------------------------------------------------------------- *//* Mode 1: simple GPIO backlight                                         *//* --------------------------------------------------------------------- */fragment@10 {target = <&panel>;__dormant__ {backlight = <&backlight_gpio>;};};fragment@11 {target-path = "/";__dormant__ {backlight_gpio: backlight_gpio {compatible = "gpio-backlight";/* default: active high, GPIO set via backlight-gpio-pin */gpios = <&gpio 255 GPIO_ACTIVE_HIGH>;};};};/* --------------------------------------------------------------------- *//* Mode 2: hardware PWM backlight (SoC PWM controller)                   *//* --------------------------------------------------------------------- */fragment@20 {target = <&panel>;__dormant__ {backlight = <&backlight_pwm_hw>;};};fragment@21 {target-path = "/";__dormant__ {backlight_pwm_hw: backlight_pwm_hw {compatible = "pwm-backlight";brightness-levels = <0 6 8 12 16 24 32 40 48 64 96 128 160 192 224 255>;default-brightness-level = <15>;/* hw PWM controller &pwm, channel set via backlight-pwm-chan if needed */pwms = <&pwm 0 200000 0>;};};};fragment@22 {target = <&pwm>;__dormant__ {status = "okay";};};fragment@23 {target = <&gpio>;__dormant__ {/* default hw PWM pin: GPIO18 alt5 (PWM0) */pwm_pins: pwm_pins {brcm,pins = <18>;brcm,function = <2>; /* Alt5 */};};};fragment@24 {target = <&chosen>;__dormant__ {bootargs = "snd_bcm2835.enable_headphones=0";};};/* --------------------------------------------------------------------- *//* Mode 3: software PWM backlight via pwm-gpio                           *//* --------------------------------------------------------------------- */fragment@30 {target = <&panel>;__dormant__ {backlight = <&backlight_pwm_soft>;};};fragment@31 {target-path = "/";__dormant__ {backlight_pwm_soft: backlight_pwm_soft {compatible = "pwm-backlight";brightness-levels = <0 6 8 12 16 24 32 40 48 64 96 128 160 192 224 255>;default-brightness-level = <15>;/* software PWM provider (pwm-gpio) */pwms = <&pwm_gpio 0 200000 0>;};};};fragment@32 {target = <&gpio>;__overlay__ {pwm_gpio_pins: pwm_gpio_pins@4 {brcm,pins = <22>;       /* default gpio 22 */brcm,function = <1>;    /* output */brcm,pull = <0>;        /* pull-none */};};};fragment@33 {target-path = "/";__overlay__ {pwm_gpio: pwm_gpio@4 {compatible = "pwm-gpio";pinctrl-names = "default";pinctrl-0 = <&pwm_gpio_pins>;/* gpio set via backlight-gpio-pin */gpios = <&gpio 22 0>;};};};/* --------------------------------------------------------------------- *//* Overrides                                                             *//* --------------------------------------------------------------------- */__overrides__ {compatible    = <&panel>, "compatible";spi0-0        = <&panel_fragment>, "target:0=",<&spi0>,<&spidev_fragment>, "target-path=spi0/spidev@0",<&panel>, "reg:0=0";spi0-1        = <&panel_fragment>, "target:0=",<&spi0>,<&spidev_fragment>, "target-path=spi0/spidev@1",<&panel>, "reg:0=1";spi1-0        = <&panel_fragment>, "target:0=",<&spi1>,<&spidev_fragment>, "target-path=spi1/spidev@0",<&panel>, "reg:0=0";spi1-1        = <&panel_fragment>, "target:0=",<&spi1>,<&spidev_fragment>, "target-path=spi1/spidev@1",<&panel>, "reg:0=1";spi1-2        = <&panel_fragment>, "target:0=",<&spi1>,<&spidev_fragment>, "target-path=spi1/spidev@2",<&panel>, "reg:0=2";spi2-0        = <&panel_fragment>, "target:0=",<&spi2>,<&spidev_fragment>, "target-path=spi2/spidev@0",<&panel>, "reg:0=0";spi2-1        = <&panel_fragment>, "target:0=",<&spi2>,<&spidev_fragment>, "target-path=spi2/spidev@1",<&panel>, "reg:0=1";spi2-2        = <&panel_fragment>, "target:0=",<&spi2>,<&spidev_fragment>, "target-path=spi2/spidev@2",<&panel>, "reg:0=2";speed         = <&panel>, "spi-max-frequency:0";cpha          = <&panel>, "spi-cpha?";cpol          = <&panel>, "spi-cpol?";write-only    = <&panel>, "write-only?";width         = <&timing>, "hactive:0";height        = <&timing>, "vactive:0";x-offset      = <&timing>, "hback-porch:0";y-offset      = <&timing>, "vback-porch:0";clock-frequency = <&timing>, "clock-frequency:0";width-mm      = <&panel>, "width-mm:0";height-mm     = <&panel>, "height-mm:0";/* optional gpios */reset-gpio    = <&panel>, "reset-gpios:0=", <&gpio>,<&panel>, "reset-gpios:4",<&panel>, "reset-gpios:8=0"; /* GPIO_ACTIVE_HIGH */dc-gpio       = <&panel>, "dc-gpios:0=", <&gpio>,<&panel>, "dc-gpios:4",<&panel>, "dc-gpios:8=0"; /* GPIO_ACTIVE_HIGH *//* * Unified backlight pin: *   - backlight_gpio.gpios[1] *   - pwm_pins.brcm,pins[0] (hw PWM) *   - pwm_gpio_pins.brcm,pins[0] (soft PWM) *   - pwm_gpio.gpios[1] */backlight-gpio-pin =<&backlight_gpio>, "gpios:4",        /* GPIO index */<&pwm_pins>, "brcm,pins:0",          /* hw PWM pin */<&pwm_gpio_pins>, "brcm,pins:0",     /* soft PWM pin */<&pwm_gpio>, "gpios:4";              /* soft PWM gpios[1] *//* Mode 1: simple GPIO backlight */backlight-gpio        = <0>, "+10+11";/* Mode 2: hardware PWM backlight (SoC PWM) */backlight-hw-pwm      = <0>, "+20+21+22+23+24";backlight-pwm-chan    = <&backlight_pwm_hw>, "pwms:4";backlight-pwm-gpio    = <&pwm_pins>, "brcm,pins:0";backlight-pwm-func    = <&pwm_pins>, "brcm,function:0";/* Mode 3: software PWM backlight (pwm-gpio) */backlight-pwm         = <0>, "+30+31+32+33";/* Default brightness index applied to both PWM modes */backlight-def-brightness =<&backlight_pwm_hw>, "default-brightness-level:0",<&backlight_pwm_soft>, "default-brightness-level:0";/* * backlight-invert: *   - GPIO: ACTIVE_LOW instead of ACTIVE_HIGH *   - PWM: invert brightness-levels array */backlight-invert =/* gpio-backlight: flags cell (ACTIVE_LOW) */<&backlight_gpio>, "gpios:8=1",/* hw PWM: inverted brightness curve */<&backlight_pwm_hw>, "brightness-levels:0=",<255 224 192 160 128 96 64 48 40 32 24 16 12 8 6 0>,/* soft PWM: inverted brightness curve */<&backlight_pwm_soft>, "brightness-levels:0=",<255 224 192 160 128 96 64 48 40 32 24 16 12 8 6 0>;};};

Statistics: Posted by forbiddenera — Mon Jan 12, 2026 12:38 pm



Viewing all articles
Browse latest Browse all 9821

Trending Articles