One Framework 0.1.0
RoboMaster嵌入式框架“一键”解决方案,为你的“创意”服务。
载入中...
搜索中...
未找到
led_pixel.h
浏览该文件的文档.
1#ifndef OF_LED_PIXEL_H
2#define OF_LED_PIXEL_H
3
4#include <zephyr/device.h>
5#include <stdint.h>
6
7#define _HEX_C2I(c) ( \
8(c) >= '0' && (c) <= '9' ? (c) - '0' : \
9(c) >= 'a' && (c) <= 'f' ? (c) - 'a' + 10 : \
10(c) >= 'A' && (c) <= 'F' ? (c) - 'A' + 10 : 0 \
11)
12
13/* 2. 判断是否有 '#' 前缀,决定偏移量
14 * 如果 s[0] 是 '#', 偏移量为 1, 否则为 0
15 */
16#define _HEX_OFF(s) ((s)[0] == '#' ? 1 : 0)
17
18/* 3. 获取第 I 个字节的高位和低位字符,合成字节
19 * s: 字符串
20 * i: 第几个颜色分量 (0=R, 1=G, 2=B)
21 * off: 偏移量
22 */
23#define _HEX_BYTE(s, i, off) ( \
24(_HEX_C2I((s)[(off) + (i)*2]) << 4) | \
25(_HEX_C2I((s)[(off) + (i)*2 + 1])) \
26)
27
28#define COLOR_HEX(s) { \
29.r = _HEX_BYTE(s, 0, _HEX_OFF(s)), \
30.g = _HEX_BYTE(s, 1, _HEX_OFF(s)), \
31.b = _HEX_BYTE(s, 2, _HEX_OFF(s)) \
32}
33
34
36{
37 uint8_t r;
38 uint8_t g;
39 uint8_t b;
40};
41
42typedef int (*led_set_pixel_t)(const struct device* dev, struct led_color color, const uint8_t bright_percent);
43typedef int (*led_pixel_off_t)(const struct device* dev);
44typedef int (*led_pixel_on_t)(const struct device* dev);
45
52
61static inline int led_pixel_set(const struct device* dev, const struct led_color color, const uint8_t bright_percent)
62{
63 const struct led_pixel_api* api =
64 (const struct led_pixel_api*)dev->api;
65 return api->set_led_pixel(dev, color, bright_percent);
66}
67
68static inline int led_pixel_off(const struct device* dev)
69{
70 const struct led_pixel_api* api = (const struct led_pixel_api*)dev->api;
71 return api->close_led(dev);
72}
73
74static inline int led_pixel_on(const struct device* dev)
75{
76 const struct led_pixel_api* api = (const struct led_pixel_api*)dev->api;
77 return api->open_led(dev);
78}
79
80#endif //OF_LED_PIXEL_H
static int led_pixel_off(const struct device *dev)
定义 led_pixel.h:68
int(* led_set_pixel_t)(const struct device *dev, struct led_color color, const uint8_t bright_percent)
定义 led_pixel.h:42
int(* led_pixel_off_t)(const struct device *dev)
定义 led_pixel.h:43
static int led_pixel_set(const struct device *dev, const struct led_color color, const uint8_t bright_percent)
设置像素 LED 的颜色
定义 led_pixel.h:61
int(* led_pixel_on_t)(const struct device *dev)
定义 led_pixel.h:44
static int led_pixel_on(const struct device *dev)
定义 led_pixel.h:74
定义 led_pixel.h:36
uint8_t g
定义 led_pixel.h:38
uint8_t b
定义 led_pixel.h:39
uint8_t r
定义 led_pixel.h:37
定义 led_pixel.h:47
led_set_pixel_t set_led_pixel
定义 led_pixel.h:48
led_pixel_on_t open_led
定义 led_pixel.h:50
led_pixel_off_t close_led
定义 led_pixel.h:49