Skip to content

Commit 27eb7c4

Browse files
GuEe-GUIRbb666
authored andcommitted
[dm][graphic] add new drivers and logo
1. Generic GPIO based backlight driver 2. Generic PWM based backlight driver 3. Simple framebuffer support 4. Standard 224-color RT-Thread logo 5. Standard 224-color RT-Thread white logo Signed-off-by: GuEe-GUI <[email protected]>
1 parent 5abecc1 commit 27eb7c4

File tree

11 files changed

+4321
-0
lines changed

11 files changed

+4321
-0
lines changed

components/drivers/graphic/backlight/Kconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@ menuconfig RT_GRAPHIC_BACKLIGHT
22
bool "Backlight support"
33
default n
44

5+
config RT_GRAPHIC_BACKLIGHT_GPIO
6+
bool "Generic GPIO based backlight driver"
7+
depends on RT_GRAPHIC_BACKLIGHT
8+
depends on RT_USING_PIN
9+
default n
10+
11+
config RT_GRAPHIC_BACKLIGHT_PWM
12+
bool "Generic PWM based backlight driver"
13+
depends on RT_GRAPHIC_BACKLIGHT
14+
depends on RT_USING_OFW
15+
depends on RT_USING_PIN
16+
depends on RT_USING_PWM
17+
depends on RT_USING_REGULATOR
18+
default n
19+
520
if RT_GRAPHIC_BACKLIGHT
621
osource "$(SOC_DM_GRAPHIC_BACKLIGHT_DIR)/Kconfig"
722
endif

components/drivers/graphic/backlight/SConscript

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@ CPPPATH = [cwd + '/../../include']
1010

1111
src = ['backlight.c']
1212

13+
if GetDepend(['RT_GRAPHIC_BACKLIGHT_GPIO']):
14+
src += ['backlight-gpio.c']
15+
16+
if GetDepend(['RT_GRAPHIC_BACKLIGHT_PWM']):
17+
src += ['backlight-pwm.c']
18+
1319
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
1420
Return('group')
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
* Copyright (c) 2006-2023, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2023-02-25 GuEe-GUI the first version
9+
*/
10+
11+
#include <rthw.h>
12+
#include <rtthread.h>
13+
#include <rtdevice.h>
14+
15+
#define DBG_TAG "backlight.gpio"
16+
#define DBG_LVL DBG_INFO
17+
#include <rtdbg.h>
18+
19+
struct gpio_backlight
20+
{
21+
struct rt_backlight_device parent;
22+
23+
rt_base_t pin;
24+
rt_uint8_t active_val;
25+
};
26+
27+
#define raw_to_gpio_backlight(raw) rt_container_of(raw, struct gpio_backlight, parent)
28+
29+
static rt_err_t gpio_backlight_update_status(struct rt_backlight_device *bl)
30+
{
31+
rt_uint8_t brightness;
32+
struct gpio_backlight *gbl = raw_to_gpio_backlight(bl);
33+
34+
rt_pin_mode(gbl->pin, PIN_MODE_OUTPUT);
35+
36+
brightness = rt_backlight_power_brightness(bl);
37+
38+
if (!gbl->active_val)
39+
{
40+
brightness = !brightness;
41+
}
42+
43+
rt_pin_write(gbl->pin, brightness);
44+
45+
return RT_EOK;
46+
}
47+
48+
static struct rt_backlight_ops gpio_backlight_ops =
49+
{
50+
.update_status = gpio_backlight_update_status,
51+
};
52+
53+
static rt_err_t gpio_backlight_probe(struct rt_platform_device *pdev)
54+
{
55+
rt_err_t err;
56+
rt_bool_t def_value;
57+
struct rt_device *dev = &pdev->parent;
58+
struct gpio_backlight *gbl = rt_calloc(1, sizeof(*gbl));
59+
60+
if (!gbl)
61+
{
62+
return -RT_ENOMEM;
63+
}
64+
65+
def_value = rt_dm_dev_prop_read_bool(dev, "default-on");
66+
67+
gbl->pin = rt_pin_get_named_pin(dev, RT_NULL, 0, RT_NULL, &gbl->active_val);
68+
69+
if (gbl->pin < 0)
70+
{
71+
err = gbl->pin;
72+
73+
goto _fail;
74+
}
75+
76+
/* Set the initial power state */
77+
if (!dev->ofw_node || !rt_dm_dev_prop_read_bool(dev, "phandle"))
78+
{
79+
gbl->parent.props.power = def_value ?
80+
RT_BACKLIGHT_POWER_UNBLANK : RT_BACKLIGHT_POWER_POWERDOWN;
81+
}
82+
else if (rt_pin_read(gbl->pin) != gbl->active_val)
83+
{
84+
gbl->parent.props.power = RT_BACKLIGHT_POWER_POWERDOWN;
85+
}
86+
else
87+
{
88+
gbl->parent.props.power = RT_BACKLIGHT_POWER_UNBLANK;
89+
}
90+
91+
gbl->parent.props.max_brightness = 1;
92+
gbl->parent.ops = &gpio_backlight_ops;
93+
94+
if ((err = rt_backlight_register(&gbl->parent)))
95+
{
96+
goto _fail;
97+
}
98+
99+
rt_pin_mode(gbl->pin, PIN_MODE_OUTPUT);
100+
rt_backlight_set_brightness(&gbl->parent, 1);
101+
102+
return RT_EOK;
103+
104+
_fail:
105+
rt_free(gbl);
106+
107+
return err;
108+
}
109+
110+
static rt_err_t gpio_backlight_remove(struct rt_platform_device *pdev)
111+
{
112+
struct gpio_backlight *gbl = pdev->parent.user_data;
113+
114+
rt_backlight_unregister(&gbl->parent);
115+
116+
rt_free(gbl);
117+
118+
return RT_EOK;
119+
}
120+
121+
static const struct rt_ofw_node_id gpio_backlight_ofw_ids[] =
122+
{
123+
{ .compatible = "gpio-backlight" },
124+
{ /* sentinel */ }
125+
};
126+
127+
static struct rt_platform_driver gpio_backlight_driver =
128+
{
129+
.name = "gpio-backlight",
130+
.ids = gpio_backlight_ofw_ids,
131+
132+
.probe = gpio_backlight_probe,
133+
.remove = gpio_backlight_remove,
134+
};
135+
RT_PLATFORM_DRIVER_EXPORT(gpio_backlight_driver);

0 commit comments

Comments
 (0)