Skip to content

Commit 175a7d2

Browse files
GuEe-GUIRbb666
authored andcommitted
[DM/FEATURE] Support LED
Provides general LED control API and drivers. It can work on PWM, GPIO and Syscon... Signed-off-by: GuEe-GUI <[email protected]>
1 parent d3820ed commit 175a7d2

File tree

6 files changed

+434
-0
lines changed

6 files changed

+434
-0
lines changed

components/drivers/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ rsource "touch/Kconfig"
2121
rsource "graphic/Kconfig"
2222
rsource "hwcrypto/Kconfig"
2323
rsource "wlan/Kconfig"
24+
rsource "led/Kconfig"
2425
rsource "mailbox/Kconfig"
2526
rsource "phye/Kconfig"
2627
rsource "ata/Kconfig"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2006-2022, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2022-3-08 GuEe-GUI the first version
9+
*/
10+
11+
#ifndef __LED_H__
12+
#define __LED_H__
13+
14+
#include <rthw.h>
15+
#include <rtdef.h>
16+
17+
struct rt_led_ops;
18+
19+
enum rt_led_state
20+
{
21+
RT_LED_S_OFF,
22+
RT_LED_S_ON,
23+
RT_LED_S_TOGGLE,
24+
RT_LED_S_BLINK,
25+
26+
RT_LED_STATE_NR,
27+
};
28+
29+
struct rt_led_device
30+
{
31+
struct rt_device parent;
32+
33+
const struct rt_led_ops *ops;
34+
35+
struct rt_spinlock spinlock;
36+
37+
void *sysdata;
38+
void *priv;
39+
};
40+
41+
struct rt_led_ops
42+
{
43+
rt_err_t (*set_state)(struct rt_led_device *led, enum rt_led_state state);
44+
rt_err_t (*get_state)(struct rt_led_device *led, enum rt_led_state *out_state);
45+
rt_err_t (*set_period)(struct rt_led_device *led, rt_uint32_t period_ms);
46+
rt_err_t (*set_brightness)(struct rt_led_device *led, rt_uint32_t brightness);
47+
};
48+
49+
rt_err_t rt_hw_led_register(struct rt_led_device *led);
50+
rt_err_t rt_hw_led_unregister(struct rt_led_device *led);
51+
52+
rt_err_t rt_led_set_state(struct rt_led_device *led, enum rt_led_state state);
53+
rt_err_t rt_led_get_state(struct rt_led_device *led, enum rt_led_state *out_state);
54+
rt_err_t rt_led_set_period(struct rt_led_device *led, rt_uint32_t period_ms);
55+
rt_err_t rt_led_set_brightness(struct rt_led_device *led, rt_uint32_t brightness);
56+
57+
#endif /* __LED_H__ */

components/drivers/include/rtdevice.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ extern "C" {
5151
#endif /* RT_ATA_AHCI */
5252
#endif /* RT_USING_ATA */
5353

54+
#ifdef RT_USING_LED
55+
#include "drivers/led.h"
56+
#endif
57+
5458
#ifdef RT_USING_MBOX
5559
#include "drivers/mailbox.h"
5660
#endif /* RT_USING_MBOX */

components/drivers/led/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
menuconfig RT_USING_LED
2+
bool "Using Light Emitting Diode (LED) device drivers"
3+
depends on RT_USING_DM
4+
default n
5+
6+
if RT_USING_LED
7+
osource "$(SOC_DM_LED_DIR)/Kconfig"
8+
endif

components/drivers/led/SConscript

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from building import *
2+
3+
group = []
4+
5+
if not GetDepend(['RT_USING_DM', 'RT_USING_LED']):
6+
Return('group')
7+
8+
cwd = GetCurrentDir()
9+
CPPPATH = [cwd + '/../include']
10+
11+
src = ['led.c']
12+
13+
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
14+
15+
Return('group')

0 commit comments

Comments
 (0)