mirror of
https://gitee.com/moluo-tech/CodeBrick.git
synced 2025-01-30 04:42:53 +08:00
增加blink(通用LED/马达/蜂鸣器)控制器.
This commit is contained in:
parent
b4cadbb5b7
commit
f6dfd4fa00
80
framework/blink.c
Normal file
80
framework/blink.c
Normal file
@ -0,0 +1,80 @@
|
||||
/*******************************************************************************
|
||||
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˸<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(dev, motor, buzzer)<EFBFBD><EFBFBD><EFBFBD>豸(dev, motor, buzzer)<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2019-04-01 Morro Initial version.
|
||||
*******************************************************************************/
|
||||
#include "public.h"
|
||||
#include "blink.h" /*get_tick()*/
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __CC_ARM /* ARM Compiler */
|
||||
extern blink_dev_t __section_blink_dev$$Base;
|
||||
extern blink_dev_t __section_blink_dev$$Limit;
|
||||
#define blink_tbl_start &__section_blink_dev$$Base
|
||||
#define blink_tbl_end &__section_blink_dev$$Limit
|
||||
#elif defined (__ICCARM__) /* for IAR Compiler */
|
||||
#pragma section="__section_blink_dev"
|
||||
#define blink_tbl_start __section_begin("__section_blink_dev")
|
||||
#define blink_tbl_end __section_end("__section_blink_dev")
|
||||
#endif
|
||||
|
||||
/*
|
||||
* @brief
|
||||
* @param[in] name - <EFBFBD>豸<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param[in] ontime - <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵΪ0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ùر<EFBFBD>)
|
||||
* @param[in] offtime- <EFBFBD>ر<EFBFBD>ʱ<EFBFBD><EFBFBD>
|
||||
* @param[in] repeats- <EFBFBD>ظ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(0<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><EFBFBD>)
|
||||
* @return none
|
||||
*/
|
||||
void blink_dev_ctrl(blink_dev_t *dev, int ontime, int offtime, int repeats)
|
||||
{
|
||||
dev->ontime = ontime;
|
||||
dev->offtime = offtime + ontime;
|
||||
dev->repeats = repeats;
|
||||
dev->tick = get_tick();
|
||||
dev->count = 0;
|
||||
if (ontime == 0) {
|
||||
dev->ioctrl(false);
|
||||
dev->enable = false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief <EFBFBD>豸<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param[in] none
|
||||
* @return none
|
||||
*/
|
||||
void blink_dev_process(void)
|
||||
{
|
||||
blink_dev_t *s, *e;
|
||||
s = (blink_dev_t *)blink_tbl_start;
|
||||
e = (blink_dev_t *)blink_tbl_end;
|
||||
|
||||
for (; s < e; s++) {
|
||||
if (s->ontime == 0) {
|
||||
continue;
|
||||
} else if (get_tick() - s->tick < s->ontime) {
|
||||
if (!s->enable) {
|
||||
s->enable = true;
|
||||
s->ioctrl(true);
|
||||
}
|
||||
} else if(get_tick() - s->tick < s->offtime) {
|
||||
if (s->enable) {
|
||||
s->enable = false;
|
||||
s->ioctrl(false);
|
||||
}
|
||||
} else {
|
||||
s->tick = get_tick();
|
||||
if (s->repeats) {
|
||||
if (++s->count >= s->repeats) {
|
||||
s->ontime = 0;
|
||||
s->ioctrl(false);
|
||||
s->enable = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
40
framework/blink.h
Normal file
40
framework/blink.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*******************************************************************************
|
||||
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˸<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(led, motor, buzzer)<EFBFBD><EFBFBD><EFBFBD>豸(led, motor, buzzer)<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2019-04-01 Morro Initial version.
|
||||
*******************************************************************************/
|
||||
#ifndef _BLINK_H_
|
||||
#define _BLINK_H_
|
||||
|
||||
#include "framework.h"
|
||||
#include <stdbool.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*Blink <20>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>*/
|
||||
typedef struct {
|
||||
unsigned short ontime;
|
||||
unsigned short offtime;
|
||||
unsigned short repeats;
|
||||
unsigned char count;
|
||||
unsigned char enable;
|
||||
unsigned int tick;
|
||||
void (*ioctrl)(bool enable);
|
||||
}blink_dev_t;
|
||||
|
||||
#define blink_dev_register(name, ioctrl) \
|
||||
(blink_dev_t name) \
|
||||
SECTION("__section_blink_dev") UNUSED = \
|
||||
{0,0,0,0,ioctrl}
|
||||
|
||||
void blink_dev_ctrl(blink_dev_t *dev, int ontime, int offtime, int repeat);
|
||||
void blink_dev_process(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user