This commit is contained in:
moyuhai
2026-06-09 16:39:17 +08:00
commit 41a602f89c
3057 changed files with 771495 additions and 0 deletions
@@ -0,0 +1,212 @@
/*!
* \file key.c
*
* \brief Target key implementation
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
*
* _ __ _ ________ _
* | |/ /(_)___ / ____/ /_ (_)___
* | // / __ \/ / / __ \/ / __ \
* / |/ / / / / /___/ / / / / /_/ /
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
* /_/
* (C) 2022-2025 XinChip
*
* \endcode
*
* \author ( XinChip ) Alex-J
*
* \author ( XinChip )
*/
/*-----------------------------------------------------------------------------------
INCLUDE HEADE FILES
------------------------------------------------------------------------------------*/
#include "xc_drv_gpio.h"
#include "xc60xx.h"
#include "key.h"
#include "message.h"
/*------------------------------------------------------------------------------------
Macros
-------------------------------------------------------------------------------------*/
#define IS_KEY_DOWN(n) (!(xc_gpio_read_pin(n)))
#define KEY_GPIO GPIO_10
/*------------------------------------------------------------------------------------
Global Variables
-------------------------------------------------------------------------------------*/
static uint16_t last_key_val = NO_KEY;
static uint16_t key_down_count = 0;
static uint16_t key_up_count = 0;
/*------------------------------------------------------------------------------------
Func Prototype
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Functions
-------------------------------------------------------------------------------------*/
/**
* @brief app_key_hold_detection
* @details
* @param curren_key_val
* @retval key_num
*/
__RAM_CODE uint16_t app_key_hold_detection(uint16_t curren_key_val)
{
uint16_t key_num = NO_KEY;
if (key_down_count < 0xff)
key_down_count++;
if (key_down_count == KEY_DOWN_TIMER)
{
key_num = (curren_key_val | KEY_SHORT_DOWN); // shor key
}
else if(key_down_count == KEY_LONG_TIMER)
{
key_num = (curren_key_val | KEY_LONG_DOWN); // loog key
}
key_up_count = 0;
return key_num;
}
/**
* @brief app_new_key_detection
* @details key up or new key detection
* @param curren_key_val
* @retval key_num
*/
__RAM_CODE uint16_t app_new_key_detection(uint16_t curren_key_val)
{
uint16_t key_num = NO_KEY;
key_up_count++;
if (key_up_count >= KEY_UP_TIMER)
{
if (key_down_count >= KEY_LONG_TIMER)
{
key_num = (last_key_val | KEY_LONG_UP); // long key up
last_key_val = 0;
}
else if (key_down_count >= KEY_DOWN_TIMER && key_down_count < KEY_LONG_TIMER)
{
key_num = (last_key_val | KEY_SHORT_UP); // shor key up
last_key_val = 0;
}
key_down_count = 0;
key_up_count = 0;
}
if ((curren_key_val && curren_key_val != last_key_val))
{
if (key_down_count >= KEY_LONG_TIMER)
{
key_num = (last_key_val | KEY_LONG_UP); // long key up
}
else if (key_down_count >= KEY_DOWN_TIMER && key_down_count < KEY_LONG_TIMER)
{
key_num = (last_key_val | KEY_SHORT_UP); // shor key up
}
last_key_val = curren_key_val;
key_down_count = 0;
key_up_count = 0;
}
return key_num;
}
/**
* @brief key_check_process
* @details
* @param curren_key_val
* @retval key_num
*/
__RAM_CODE uint16_t key_check_process(uint16_t curren_key_val)
{
uint16_t key_num = NO_KEY;
if ( curren_key_val == last_key_val && last_key_val != NO_KEY )
{
key_num = app_key_hold_detection(curren_key_val);
}
else
{
key_num = app_new_key_detection(curren_key_val);
}
return key_num;
}
/**
* @brief gpio_key_check
* @details
* @param void
* @retval key_num
*/
uint16_t gpio_key_check(void)
{
uint16_t key_val = NO_KEY;
if ( IS_KEY_DOWN(KEY_GPIO) )
{
key_val = REC_KEY;
}
return key_val;
}
/**
* @brief key_check_process
* @details key scan and send
* @param void
* @retval void
*/
void app_key_scan(void)
{
uint16_t key_num = NO_KEY;
uint16_t key_val = NO_KEY;
key_val = gpio_key_check();
key_num = key_check_process(key_val);
if (key_num != NO_KEY)
{
app_key_message_send( key_num );
}
}
/**
* @brief app_key_init
* @details key init
* @param void
* @retval void
*/
void app_key_init(void)
{
GPIO_InitCfg_t GPIO_InitCfg = {0};
GPIO_InitCfg.Mux = GPIO_Mux0;
GPIO_InitCfg.FunSel = GPIO_Dx;
GPIO_InitCfg.Pull = GPIO_PULLUP;
GPIO_InitCfg.Dir = GPIO_DIR_INPUT;
GPIO_InitCfg.Int = NOT_INT;
GPIO_InitCfg.Pin = KEY_GPIO;
xc_gpio_init(&GPIO_InitCfg);
}
@@ -0,0 +1,145 @@
/*!
* \file main.c
*
* \brief Target main implementation
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
*
* _ __ _ ________ _
* | |/ /(_)___ / ____/ /_ (_)___
* | // / __ \/ / / __ \/ / __ \
* / |/ / / / / /___/ / / / / /_/ /
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
* /_/
* (C) 2022-2025 XinChip
*
* \endcode
*
* \author ( XinChip ) Alex-J
*
* \author ( XinChip )
*/
/*-----------------------------------------------------------------------------------
INCLUDE HEADE FILES
------------------------------------------------------------------------------------*/
#include "main.h"
#include "pga_adc.h"
/*------------------------------------------------------------------------------------
Macros
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Global Variables
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Func Prototype
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Functions
-------------------------------------------------------------------------------------*/
void app_uart_init(void)
{
GPIO_InitCfg_t gpio_cfg = {0};
gpio_cfg.Mux = GPIO_Mux0;
gpio_cfg.Pull = GPIO_PULLUP;
gpio_cfg.Int = NOT_INT;
gpio_cfg.FunSel = UART0_TX;
gpio_cfg.Pin = GPIO_3;
gpio_cfg.Dir = GPIO_DIR_OUTPUT;
xc_gpio_init(&gpio_cfg);
gpio_cfg.FunSel = UART0_RX;
gpio_cfg.Pin = GPIO_19;
gpio_cfg.Dir = GPIO_DIR_INPUT;
xc_gpio_init(&gpio_cfg);
UART_InitCfg_t uart_cfg = {0};
uart_cfg.Parity = UART_PARITY_DISABLE;
uart_cfg.StopBits = UART_STOP_1_BITS;
uart_cfg.WordLength = UART_DATA_8_BITS;
uart_cfg.BaudRate = UART_BAUDRATE_115200;
uart_cfg.HardwareFlowControl = UART_HWFC_DISABLE;
xc_uart_init(UART0_IDX, &uart_cfg);
}
int app_io_simulate_time_period(void)
{
GPIO_InitCfg_t GPIO_InitCfg = { 0 };
GPIO_InitCfg.Mux = GPIO_Mux0;
GPIO_InitCfg.FunSel = GPIO_Dx;
GPIO_InitCfg.Pull = GPIO_PULLUP;
GPIO_InitCfg.Dir = GPIO_DIR_OUTPUT;
GPIO_InitCfg.Int = NOT_INT;
GPIO_InitCfg.Pin = 17;
xc_gpio_init(&GPIO_InitCfg);
GPIO_InitCfg.Pin = 20;
xc_gpio_init(&GPIO_InitCfg);
GPIO_InitCfg.Pin = 1;
xc_gpio_init(&GPIO_InitCfg);
xc_gpio_write_pin(GPIO_17, GPIO_PIN_RESET);
xc_gpio_write_pin(GPIO_20, GPIO_PIN_RESET);
xc_gpio_write_pin(GPIO_1, GPIO_PIN_RESET);
return 0;
}
void clock_init(void)
{
CLOCK_InitCfg_t clock_cfg;
clock_cfg.hfclk_src = CLOCK_HFCLK_SRC_XTAL;
clock_cfg.hfclk_in = CLOCK_HFCLK_IN_32M;
clock_cfg.lfclk_src = CLOCK_LFCLK_SRC_RC;
if (clock_cfg.lfclk_src == CLOCK_LFCLK_SRC_XTAL) {
clock_cfg.lfclk_in = CLOCK_LFCLK_IN_32768;
} else if (clock_cfg.lfclk_src == CLOCK_LFCLK_SRC_RC) {
clock_cfg.lfclk_in = CLOCK_LFCLK_IN_32K;
}
xc_clock_init_cfg(&clock_cfg);
SysTick_Config(xc_clock_hfclk_in_get() / 100);
SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
}
int main(void)
{
// Clock Initialization
clock_init();
app_uart_init();
app_io_simulate_time_period();
app_pga_init();
delay_ms(1);//Wait for the pga to stabilize
DEBUG("__START__\n");
#if (PGA_MIC_RECORD_DEMO_EN)
/*----- mic pga adc demo ----- */
mic_pga_adc_demo();
#endif //(PGA_MIC_RECORD_DEMO_EN)
#if (PGA_MIC_GET_VAL_DEMO_EN)
/*----- mic pga get adc value demo ----- */
pga_mic_adc_get_val_demo();
#endif //(PGA_MIC_GET_VAL_DEMO_EN)
while(1)
{
/* main loop */
;
}
}
@@ -0,0 +1,123 @@
/*!
* \file key.c
*
* \brief Target key implementation
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
*
* _ __ _ ________ _
* | |/ /(_)___ / ____/ /_ (_)___
* | // / __ \/ / / __ \/ / __ \
* / |/ / / / / /___/ / / / / /_/ /
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
* /_/
* (C) 2022-2025 XinChip
*
* \endcode
*
* \author ( XinChip ) Alex-J
*
* \author ( XinChip )
*/
/*-----------------------------------------------------------------------------------
INCLUDE HEADE FILES
------------------------------------------------------------------------------------*/
#include "message.h"
#include "xc6xxx.h"
/*------------------------------------------------------------------------------------
Macros
-------------------------------------------------------------------------------------*/
#define MESSAGE_MAX 40
#define MSG_ADD_MAX(msg) (msg >= MESSAGE_MAX) ? (MESSAGE_MAX) : (msg+1)
#define MSG_REDUCE_MIN(msg) (msg) ? (msg - 1) : 0
#define MSG_LOOP_MAX_MIN(msg) (msg >= MESSAGE_MAX) ? (0) : (msg)
/*------------------------------------------------------------------------------------
Global Variables
-------------------------------------------------------------------------------------*/
uint16_t message_buff[MESSAGE_MAX] = {0};
volatile uint16_t message_in_count = 0;
volatile uint16_t message_out_index = 0;
/*------------------------------------------------------------------------------------
Func Prototype
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Functions
-------------------------------------------------------------------------------------*/
/**
* @brief app_key_message_send
* @details key msg send
* @param void
* @retval void
*/
void app_key_message_send(uint16_t msg)
{
if (message_in_count >= MESSAGE_MAX )
{
return;
}
for(uint8_t i = 0; i < MESSAGE_MAX ; i++)
{
if (message_buff[i] == 0)
{
message_buff[i] = msg;
message_in_count++;
break;
}
}
}
/**
* @brief app_key_message_get
* @details get key msg
* @param void
* @retval void
*/
uint16_t app_key_message_get(void)
{
uint16_t msg = 0;
if (!message_in_count)
{
message_out_index = 0;
return msg;
}
for(uint8_t i = 0; i < MESSAGE_MAX ; i++)
{
if (message_buff[message_out_index])
{
msg = message_buff[message_out_index];
message_buff[message_out_index] = 0;
message_out_index = MSG_ADD_MAX(message_out_index);
message_out_index = MSG_LOOP_MAX_MIN(message_out_index);
message_in_count = MSG_REDUCE_MIN(message_in_count);
break;
}
message_out_index = MSG_ADD_MAX(message_out_index);
message_out_index = MSG_LOOP_MAX_MIN(message_out_index);
}
return msg;
}
/**
* @brief app_key_message_clr
* @details clear key msg
* @param void
* @retval void
*/
void app_key_message_clr(void)
{
memset(message_buff,0x00,MESSAGE_MAX);
message_in_count = 0;
}
File diff suppressed because it is too large Load Diff