Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion components/drivers/graphic/Kconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
config RT_USING_LCD
bool "Using LCD graphic drivers"
bool "Using LCD graphic drivers" if !RT_USING_DM
default n

menuconfig RT_USING_GRAPHIC
bool "Using Graphics device drivers"
depends on RT_USING_DM
default n

if RT_USING_GRAPHIC
rsource "backlight/Kconfig"
rsource "framebuffer/Kconfig"
rsource "logo/Kconfig"
endif
23 changes: 23 additions & 0 deletions components/drivers/graphic/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from building import *

group = []
objs = []

if not GetDepend(['RT_USING_GRAPHIC']):
Return('group')

cwd = GetCurrentDir()
list = os.listdir(cwd)
CPPPATH = [cwd + '/../include']

src = ['graphic.c', 'graphic_primary.c', 'graphic_simple.c']

group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)

for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(d, 'SConscript'))
objs = objs + group

Return('objs')
22 changes: 22 additions & 0 deletions components/drivers/graphic/backlight/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
menuconfig RT_GRAPHIC_BACKLIGHT
bool "Backlight support"
default n

config RT_GRAPHIC_BACKLIGHT_GPIO
bool "Generic GPIO based backlight driver"
depends on RT_GRAPHIC_BACKLIGHT
depends on RT_USING_PIN
default n

config RT_GRAPHIC_BACKLIGHT_PWM
bool "Generic PWM based backlight driver"
depends on RT_GRAPHIC_BACKLIGHT
depends on RT_USING_OFW
depends on RT_USING_PIN
depends on RT_USING_PWM
depends on RT_USING_REGULATOR
default n

if RT_GRAPHIC_BACKLIGHT
osource "$(SOC_DM_GRAPHIC_BACKLIGHT_DIR)/Kconfig"
endif
20 changes: 20 additions & 0 deletions components/drivers/graphic/backlight/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from building import *

group = []

if not GetDepend(['RT_GRAPHIC_BACKLIGHT']):
Return('group')

cwd = GetCurrentDir()
CPPPATH = [cwd + '/../../include']

src = ['backlight.c']

if GetDepend(['RT_GRAPHIC_BACKLIGHT_GPIO']):
src += ['backlight-gpio.c']

if GetDepend(['RT_GRAPHIC_BACKLIGHT_PWM']):
src += ['backlight-pwm.c']

group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
135 changes: 135 additions & 0 deletions components/drivers/graphic/backlight/backlight-gpio.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-02-25 GuEe-GUI the first version
*/

#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>

#define DBG_TAG "backlight.gpio"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>

struct gpio_backlight
{
struct rt_backlight_device parent;

rt_base_t pin;
rt_uint8_t active_val;
};

#define raw_to_gpio_backlight(raw) rt_container_of(raw, struct gpio_backlight, parent)

static rt_err_t gpio_backlight_update_status(struct rt_backlight_device *bl)
{
rt_uint8_t brightness;
struct gpio_backlight *gbl = raw_to_gpio_backlight(bl);

rt_pin_mode(gbl->pin, PIN_MODE_OUTPUT);

brightness = rt_backlight_power_brightness(bl);

if (!gbl->active_val)
{
brightness = !brightness;
}

rt_pin_write(gbl->pin, brightness);

return RT_EOK;
}

static struct rt_backlight_ops gpio_backlight_ops =
{
.update_status = gpio_backlight_update_status,
};

static rt_err_t gpio_backlight_probe(struct rt_platform_device *pdev)
{
rt_err_t err;
rt_bool_t def_value;
struct rt_device *dev = &pdev->parent;
struct gpio_backlight *gbl = rt_calloc(1, sizeof(*gbl));

if (!gbl)
{
return -RT_ENOMEM;
}

def_value = rt_dm_dev_prop_read_bool(dev, "default-on");

gbl->pin = rt_pin_get_named_pin(dev, RT_NULL, 0, RT_NULL, &gbl->active_val);

if (gbl->pin < 0)
{
err = gbl->pin;

goto _fail;
}

/* Set the initial power state */
if (!dev->ofw_node || !rt_dm_dev_prop_read_bool(dev, "phandle"))
{
gbl->parent.props.power = def_value ?
RT_BACKLIGHT_POWER_UNBLANK : RT_BACKLIGHT_POWER_POWERDOWN;
}
else if (rt_pin_read(gbl->pin) != gbl->active_val)
{
gbl->parent.props.power = RT_BACKLIGHT_POWER_POWERDOWN;
}
else
{
gbl->parent.props.power = RT_BACKLIGHT_POWER_UNBLANK;
}

gbl->parent.props.max_brightness = 1;
gbl->parent.ops = &gpio_backlight_ops;

if ((err = rt_backlight_register(&gbl->parent)))
{
goto _fail;
}

rt_pin_mode(gbl->pin, PIN_MODE_OUTPUT);
rt_backlight_set_brightness(&gbl->parent, 1);

return RT_EOK;

_fail:
rt_free(gbl);

return err;
}

static rt_err_t gpio_backlight_remove(struct rt_platform_device *pdev)
{
struct gpio_backlight *gbl = pdev->parent.user_data;

rt_backlight_unregister(&gbl->parent);

rt_free(gbl);

return RT_EOK;
}

static const struct rt_ofw_node_id gpio_backlight_ofw_ids[] =
{
{ .compatible = "gpio-backlight" },
{ /* sentinel */ }
};

static struct rt_platform_driver gpio_backlight_driver =
{
.name = "gpio-backlight",
.ids = gpio_backlight_ofw_ids,

.probe = gpio_backlight_probe,
.remove = gpio_backlight_remove,
};
RT_PLATFORM_DRIVER_EXPORT(gpio_backlight_driver);
Loading