Files
chrg/apps/chrg/applications/tmr_pin.h
T
2025-08-23 11:54:16 +08:00

76 lines
2.1 KiB
C

#ifndef __PIN_TMR_H__
#define __PIN_TMR_H__
#include <rttypes.h>
#include <rtdef.h>
#include "drv_gpio.h"
#define PIN_NAME_LED1 "led1"
#define PIN_NAME_LED2 "led2"
#define PIN_NAME_LED3 "led3"
#define TMR_NAME_LED1 "tmr_led1"
#define TMR_NAME_LED2 "tmr_led2"
#define TMR_NAME_LED3 "tmr_led3"
#define PIN_LED1 GET_PIN(A, 8) //GET_PIN(C, 13)
#define PIN_LED2 GET_PIN(C, 14)
#define PIN_LED3 GET_PIN(C, 15)
#define TIMES_ALWAYS (0) // 无限周期
#define TIMES_ONE (1) // 单个周期
#define HOLD_ZERO (0) // 屏蔽参数
#define HOLD_ON (1) // 保持亮,on!=0,off=0
#define HOLD_OFF (1) // 保持灭,on=0, off!=0
#define PULSE_OFF (0) // 脉宽低
#define PULSE_ON (1) // 脉宽高
#define PULSE_TIME (25) // 脉冲动作持续时间,单位 ms
typedef enum {
IDX_PIN_LED1 = 0, // LED1
// IDX_PIN_LED2 = 1, // LED2
// IDX_PIN_LED3 = 2, // LED3
TOTAL_PINS
} ePIN_IDX;
typedef enum {
PIN_STAGE_IDLE = (0x00), // 空闲
PIN_STAGE_ON = (0x01), // 保持高
PIN_STAGE_OFF = (0x02), // 保持低
PIN_STAGE_END
} ePIN_STAGE;
struct tmr_pin_t {
rt_uint8_t index; // 引脚索引
char *pin_name; // 引脚名
rt_int32_t pin_base; // 引脚映射值
rt_int32_t pin_value; // 引脚值
rt_uint8_t pin_mode; // 引脚控制方向 0:out 1:in
const char *tmr_name; // 定时器名
rt_timer_t tmr_fd; // 定时器对象
ePIN_STAGE tmr_stage; // 定时器状态机
rt_uint32_t tmr_millis_on; // 定时器单次高持续时间 ms=ticks (基于 1000 ticks/s)
rt_uint32_t tmr_millis_off; // 定时器单次低持续时间 ms=ticks (基于 1000 ticks/s)
rt_uint32_t tmr_times; // 定时器执行周期总次数
rt_uint32_t tmr_cnt; // 定时器已执行周期次数
};
extern struct tmr_pin_t tmrpins[TOTAL_PINS];
extern rt_int32_t tmr_pin_set (struct tmr_pin_t *pPIN, rt_uint8_t value);
extern rt_int32_t tmr_pin_toggle (ePIN_IDX index);
extern rt_int32_t tmr_pin_pulsing (struct tmr_pin_t *pPIN, rt_uint8_t state);
extern rt_int32_t tmr_led_flashing (ePIN_IDX index, rt_uint32_t times, rt_uint32_t on, rt_uint32_t off);
#endif