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,68 @@
/*!
* \file adc.h
*
* \brief The head file of adc.c
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
*
* _ __ _ ________ _
* | |/ /(_)___ / ____/ /_ (_)___
* | // / __ \/ / / __ \/ / __ \
* / |/ / / / / /___/ / / / / /_/ /
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
* /_/
* (C) 2022-2025 XinChip
*
* \endcode
*
* \author ( XinChip ) Alex-J
*
* \author ( XinChip )
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __ADC_H__
#define __ADC_H__
#ifdef __cplusplus
extern "C" {
#endif
/*-----------------------------------------------------------------------------------
INCLUDE HEADE FILES
------------------------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include <stdint.h>
/*------------------------------------------------------------------------------------
Macros
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
TypeDef
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Global Variables
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Exported Functions
-------------------------------------------------------------------------------------*/
void adc_demo(void);
void adc_channelswitch_sw_demo(void);
void adc_channelswitch_hw_demo(void);
void mic_pga_adc_demo(void);
void ADC_channelswitch_hw_Intr_Callback(void);
void ADC_channelswitch_sw_Intr_Callback(void);
#ifdef __cplusplus
}
#endif
#endif /* __ADC_H__ */
@@ -0,0 +1,63 @@
/*!
* \file clock.h
*
* \brief The head file of clock.c
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
*
* _ __ _ ________ _
* | |/ /(_)___ / ____/ /_ (_)___
* | // / __ \/ / / __ \/ / __ \
* / |/ / / / / /___/ / / / / /_/ /
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
* /_/
* (C) 2022-2025 XinChip
*
* \endcode
*
* \author ( XinChip ) Alex-J
*
* \author ( XinChip )
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __CLOCK_H__
#define __CLOCK_H__
#ifdef __cplusplus
extern "C" {
#endif
/*-----------------------------------------------------------------------------------
INCLUDE HEADE FILES
------------------------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include <stdint.h>
/*------------------------------------------------------------------------------------
Macros
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
TypeDef
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Global Variables
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Exported Functions
-------------------------------------------------------------------------------------*/
void clock_init(void);
#ifdef __cplusplus
}
#endif
#endif /* __CLOCK_H__ */
@@ -0,0 +1,84 @@
/*!
* \file key.h
*
* \brief The head file of key.c
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
*
* _ __ _ ________ _
* | |/ /(_)___ / ____/ /_ (_)___
* | // / __ \/ / / __ \/ / __ \
* / |/ / / / / /___/ / / / / /_/ /
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
* /_/
* (C) 2022-2025 XinChip
*
* \endcode
*
* \author ( XinChip ) Alex-J
*
* \author ( XinChip )
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __KEY_H__
#define __KEY_H__
#ifdef __cplusplus
extern "C"
{
#endif
/*-----------------------------------------------------------------------------------
INCLUDE HEADE FILES
------------------------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include <stdint.h>
/*------------------------------------------------------------------------------------
Macros
-------------------------------------------------------------------------------------*/
#define KEY_DOWN_TIMER 10
#define KEY_LONG_TIMER 20
#define KEY_LOH_TIMER 20
#define KEY_UP_TIMER 10
// KEY NUM 0- 255
#define KEY_NUM1 0X0001
#define KEY_NUM2 0X0002
#define KEY_SHORT_DOWN 0X0000
#define KEY_SHORT_UP 0X0100
#define KEY_LONG_DOWN 0X0200
#define KEY_LONG_UP 0X0400
#define NO_KEY 0
#define REC_KEY KEY_NUM1
#define REC_KEY_SHORT_DOWN (REC_KEY | KEY_SHORT_DOWN)
#define REC_KEY_SHORT_UP (REC_KEY | KEY_SHORT_UP)
#define REC_KEY_LONG_DOWN (REC_KEY | KEY_LONG_DOWN)
#define REC_KEY_LONG_UP (REC_KEY | KEY_LONG_UP)
/*------------------------------------------------------------------------------------
TypeDef
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Global Variables
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Exported Functions
-------------------------------------------------------------------------------------*/
void app_key_init(void);
void app_key_scan(void);
#ifdef __cplusplus
}
#endif
#endif /* __KEY_H__ */
@@ -0,0 +1,66 @@
/*!
* \file main.h
*
* \brief The head file of main.c
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
*
* _ __ _ ________ _
* | |/ /(_)___ / ____/ /_ (_)___
* | // / __ \/ / / __ \/ / __ \
* / |/ / / / / /___/ / / / / /_/ /
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
* /_/
* (C) 2022-2025 XinChip
*
* \endcode
*
* \author ( XinChip ) Alex-J
*
* \author ( XinChip )
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H__
#define __MAIN_H__
#ifdef __cplusplus
extern "C" {
#endif
/*-----------------------------------------------------------------------------------
INCLUDE HEADE FILES
------------------------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include "xc6xxx.h"
#include "clock.h"
#include "adc.h"
/*------------------------------------------------------------------------------------
Macros
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
TypeDef
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Global Variables
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Exported Functions
-------------------------------------------------------------------------------------*/
#ifdef __cplusplus
}
#endif
#endif /* __MAIN_H__ */
@@ -0,0 +1,64 @@
/*!
* \file key_message.h
*
* \brief The head file of key_message.c
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
*
* _ __ _ ________ _
* | |/ /(_)___ / ____/ /_ (_)___
* | // / __ \/ / / __ \/ / __ \
* / |/ / / / / /___/ / / / / /_/ /
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
* /_/
* (C) 2022-2025 XinChip
*
* \endcode
*
* \author ( XinChip )
*
* \author ( XinChip )
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __KEY_MESSAGE_H__
#define __KEY_MESSAGE_H__
#ifdef __cplusplus
extern "C"
{
#endif
/*-----------------------------------------------------------------------------------
INCLUDE HEADE FILES
------------------------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include <stdint.h>
/*------------------------------------------------------------------------------------
Macros
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
TypeDef
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Global Variables
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Exported Functions
-------------------------------------------------------------------------------------*/
void app_key_message_send(uint16_t msg);
uint16_t app_key_message_get(void);
void app_key_message_clr(void);
#ifdef __cplusplus
}
#endif
#endif /* __KEY_MESSAGE_H__ */
@@ -0,0 +1,156 @@
/*!
* \file pga_adc.h
*
* \brief The head file of pga_adc.h
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
*
* _ __ _ ________ _
* | |/ /(_)___ / ____/ /_ (_)___
* | // / __ \/ / / __ \/ / __ \
* / |/ / / / / /___/ / / / / /_/ /
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
* /_/
* (C) 2022-2025 XinChip
*
* \endcode
*
* \author ( XinChip ) Alex-J
*
* \author ( XinChip )
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __BSP_AUDIO_ADC_H_
#define __BSP_AUDIO_ADC_H_
/*-----------------------------------------------------------------------------------
INCLUDE HEADE FILES
------------------------------------------------------------------------------------*/
#include "stdint.h"
#include "xc60xx.h"
#include "xc_drv_adc.h"
#include "xc_drv_pga.h"
/*------------------------------------------------------------------------------------
Macros
-------------------------------------------------------------------------------------*/
#define PGA_MIC_RECORD_DEMO_EN 1
#define PGA_MIC_GET_VAL_DEMO_EN 1
#define DMA_ENABLE 1
#define DMA_MULTIPLE_TRANS_ENABLE 1
#define ADC_PWM_MODE 1
#define MIC_SAMPLING_DEBUG 0 ///
#define USER_KEY_EN 1// KEY
#define MIC_GAIN_1_EN 1 // The first-level gain is enabled 20DB
#define MIC_GAIN_2_LEVEN 0X08 // Second-stage gain 1.6DB * N( 0 - 0X0E )
#define ADC_CLK_DIV_0 (0x00UL)
#define ADC_CLK_DIV_2 (0x01UL)
#define ADC_CLK_DIV_4 (0x03UL)
#define ADC_CLK_DIV_8 (0x07UL)
#define ADC_CLK_DIV_16 (0x0fUL)
#define ADC_CLOCK_FREQ_8M ADC_CLK_DIV_0 // ADC_FREQ_8M
#define ADC_CLOCK_FREQ_4M ADC_CLK_DIV_2 // ADC_FREQ_4M
#define ADC_CLOCK_FREQ_2M ADC_CLK_DIV_4 // ADC_FREQ_2M
#define ADC_CLOCK_FREQ_1M ADC_CLK_DIV_8 // ADC_FREQ_1M
#define ADC_CLOCK_FREQ_500K ADC_CLK_DIV_16 // ADC_FREQ_500K
#define ADC_FREQ_CLOCK ADC_CLOCK_FREQ_2M // ADC CLOCK select (ADC_CLOCK_FREQ_1M - ADC_CLOCK_FREQ_4M )
#define MIC_SAMPLING_8K 0
#define MIC_SAMPLING_16K 1
#define SAMPLING_TYPE MIC_SAMPLING_16K
#define MIC_SAMPLING_MAX_LEN 480//Recording cache buff length
#define MIC_SAMPLING_BUFF_MAX 2//
#define PCM_DATA_DEBUG_EN 1 // uart DEBUG pcm data
/*------------------------------------------------------------------------------------
TypeDef
-------------------------------------------------------------------------------------*/
#if PGA_MIC_RECORD_DEMO_EN
typedef struct
{
int16_t data_buff[MIC_SAMPLING_BUFF_MAX][MIC_SAMPLING_MAX_LEN]; //audio data to the buff
uint16_t data_rx_index; //data_buff index
uint16_t data_rx_len; //data_buff len
uint8_t save_buf_index; //double mic buff 1 indexdata_buff[save_buf_index] []
uint8_t get_buf_index; //double mic buff 1 indexdata_buff[save_buf_index] []
uint8_t save_data_buff_count; // mic buff SAVE index CON
uint8_t buf_full_flag;
uint8_t sampling_wait_count; // Audio sampling data interval The sampling frequency is calculated based on the sampling speed of the ADC For example, 16K sampling
uint8_t sampling_count; // Calculate the audio sampling points
int16_t pga_offset_val;
} mic_audio_t;
typedef struct
{
#if (MIC_SAMPLING_DEBUG)
uint32_t audio_adc_rx_con;
uint8_t audio_rx_stop_flag;
#endif // MIC_SAMPLING_DEBUG
#if (MIC_SAMPLING_DEBUG)
uint16_t rec_time;
uint16_t rec_time_con;
#endif //( MIC_SAMPLING_DEBUG)
uint8_t state;
} mic_record_t;
enum
{
REC_INIT,
REC_START,
REC_STOP,
};
#if (ADC_PWM_MODE)
enum adc_fs {
adc_fs_8k = 0,
adc_fs_16k,
};
#endif
/*------------------------------------------------------------------------------------
Global Variables
-------------------------------------------------------------------------------------*/
extern mic_audio_t mic_audio;
extern mic_record_t record;
/*------------------------------------------------------------------------------------
Exported Functions
-------------------------------------------------------------------------------------*/
void audio_adc_rx_dma_event_handler(void);
void audio_adc_rx_event_handler(uint16_t pga_adc_val);
void audio_adc_start_get_value(ADC_ChannelTypeDef_t Channel, uint16_t *adc_val);
void app_audio_record_init(void);
void app_audio_record_start(void);
void app_audio_record_stop(void);
uint8_t app_get_record_state(void);
uint8_t app_get_record_buff_full_state(void);
void app_clr_record_buff_full_state(void);
void app_record_process(void);
void mic_pga_adc_demo(void);
#endif // PGA_MIC_RECORD_DEMO_EN
#if (PGA_MIC_GET_VAL_DEMO_EN)
void pga_mic_adc_get_val_demo(void);
#endif // (PGA_MIC_GET_VAL_DEMO_EN)
void app_pga_init(void);
#endif //__BSP_AUDIO_ADC_H_