Repository navigation
Expand file tree
/
Copy pathmain.c
More file actions
58 lines (49 loc) · 1.85 KB
/
Copy pathmain.c
File metadata and controls
58 lines (49 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "ZepLED_api.h"
#include "other_includes.h" /* 其他必要的头文件 */
zep_led_t led1, led2;
uint32_t led1cnt = 0;
/* 主示例 */
void main(void)
{
/*省略其他初始化*/
/* 注册两个LED对象 */
ZepLED_init(&led1, // LED1
led1_write, // 翻转亮灭的回调函数
&led1cnt, // 用户数据指针,比如这里传入一个int变量以作计数
true);
ZepLED_init(&led2, led2_write, NULL, false);
/* 所有api操作的示例 */
ZepLED_on(&led1); // LED1常灭
ZepLED_on(&led1); // LED1常亮
ZepLED_blink(&led2, 1000, 200); // LED2闪烁,周期1000ms,亮200ms
const zep_led_step_t pat[] = {
{500, 1}, // LED1先亮500ms
{300, 0}, // 再灭300ms
{200, 1},
{100, 0}
};
ZepLED_set_pattern(&led1, // 给LED1设置自定义行为
pat, // 行为列表
sizeof(pat) / sizeof(pat[0]),
true); // LED1按pat模式循环,若非循环,结束时回归常灭
/* 主循环 */
while(1)
{
/* 这里示例一下时间片更新,实际使用中可以放在定时器中断里 */
ZepLED_tick(&led1, 100); // 更新LED1状态,时间片100ms
ZepLED_tick(&led2, 100); // 更新LED2状态,时间片100ms
/* 其他业务逻辑 */
delay_ms(100); /* 模拟等待100ms ,在 RTOS中可替换为任务周期*/
}
}
/**** 供绑定的写GPIO回调 ****/
static void led1_write(void *user, int level)
{
(*(uint32_t *)user)++; /* 这里示例一下操作用户数据 */
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_10, level ? GPIO_PIN_SET : GPIO_PIN_RESET);
}
static void led2_write(void *user, int level)
{
(void)user;
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_11, level ? GPIO_PIN_SET : GPIO_PIN_RESET);
}