You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

150 lines
3.8 KiB

/******************************************************************************
版权所有 (C), 2018-2099, Radkil_Std
******************************************************************************
文 件 名 : peripheral.c
版 本 号 : 初稿
作 者 : Radkil
生成日期 : 2023年2月13日
最近修改 :
功能描述 : 外设集中管理
修改历史 :
1.日 期 : 2023年2月13日
作 者 : Radkil
修改内容 : 创建文件
******************************************************************************/
#include <unistd.h>
#include "led.h"
#include "button.h"
#include "common.h"
#include "rd_time.h"
/*----------------------------------------------*
* 外部变量说明 *
*----------------------------------------------*/
/*----------------------------------------------*
* 外部函数原型说明 *
*----------------------------------------------*/
/*----------------------------------------------*
* 内部函数原型说明 *
*----------------------------------------------*/
/*----------------------------------------------*
* 全局变量 *
*----------------------------------------------*/
/*----------------------------------------------*
* 模块级变量 *
*----------------------------------------------*/
/*----------------------------------------------*
* 常量定义 *
*----------------------------------------------*/
/*----------------------------------------------*
* 宏定义 *
*----------------------------------------------*/
#ifdef BUILD_PERIPHERAL_STANDALONE
#include "rd_thread.h"
static void *rd_Led_Proc(void *arg)
{
while (1)
{
rd_LedProcess();
Rd_Delay(100);
}
return (void *)0;
}
int rd_Led_init(void)
{
return Rd_ThreadCreate(rd_Led_Proc, NULL, NULL);
}
void Test_led(l_led_t *pLed, int _iState)
{
log_i("lzd = %d", _iState);
}
void Test_led0(l_led_t *pLed, int _iState)
{
log_i("======= = %d", _iState);
}
void Btn15cbk(rd_btn_t *pBtn)
{
printf("Radkil 15 EVENT_PRESS_DOWN !\r\n");
}
void Btn14cbk(rd_btn_t *pBtn)
{
printf("Radkil 14 EVENT_HOLD !\r\n");
}
void Btn13cbk(rd_btn_t *pBtn)
{
printf("Radkil 13 EVENT_PRESS_UP !\r\n");
}
void Btn12cbk(rd_btn_t *pBtn)
{
printf("Radkil 12 EVENT_CLICK !\r\n");
}
int Btn15(void)
{
if (0 == HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_15)) return 0;
else return 1;
}
int Btn14(void)
{
if (0 == HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_14)) return 0;
else return 1;
}
int Btn13(void)
{
if (0 == HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_13)) return 0;
else return 1;
}
int Btn12(void)
{
if (0 == HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_12)) return 0;
else return 1;
}
int main(int argc, const char *argv[])
{
RD_INIT();
rd_btn_t *pBtn15 = rd_BtnCreate(0, Btn15, 0);
rd_btn_t *pBtn14 = rd_BtnCreate(0, Btn14, 0);
rd_btn_t *pBtn13 = rd_BtnCreate(0, Btn13, 0);
rd_btn_t *pBtn12 = rd_BtnCreate(0, Btn12, 0);
rd_BtnSetEventCbk(pBtn15, EVENT_PRESS_DOWN, Btn15cbk);
rd_BtnSetEventCbk(pBtn14, EVENT_HOLD, Btn14cbk);
rd_BtnSetEventCbk(pBtn13, EVENT_PRESS_UP, Btn13cbk);
rd_BtnSetEventCbk(pBtn12, EVENT_CLICK, Btn12cbk);
rd_BtnStart(pBtn15);
rd_BtnStart(pBtn14);
rd_BtnStart(pBtn13);
rd_BtnStart(pBtn12);
rd_led_t *dled0 = rd_LedCreate(0, "500,500", 1, Test_led, NULL);
rd_led_t *dled1 = rd_LedCreate(0, "1000,1000", 1, Test_led0, NULL);
rd_LedDynamicChangeLightMode(dled0, "1000,1000", 1);
rd_LedDynamicChangeLightMode(dled1, "1000,1000", 1);
rd_LedStart(dled0);
rd_LedStart(dled1);
while(1)
{
rd_LedProcess();
rd_BtnProcess();
}
return 0;
}
#endif