123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- #ifndef __VOICE__H__
- #define __VOICE__H__
- #include "types.h"
- #include "gpio.h"
- #define MAX_VOICE_SAMPLE_SIZE 512
- #define MAX_VOICE_SAMPLE_ID (MAX_VOICE_SAMPLE_SIZE-1)
- #define HALF_VOICE_SAMPLE_SIZE 256
- #define HALF_VOICE_SAMPLE_ID (HALF_VOICE_SAMPLE_SIZE-1)
- #define MAX_VOICE_WORD_SIZE 256
- #define HALF_VOICE_WORD_SIZE 128
- #define VOICE_BASE (0x40050800UL)
- #define VOICE_MID_BASE (0x40050a00UL)
- #define VOICE_SAMPLE_AUTO 0
- #define VOICE_SAMPLE_MANNUAL 1
- #define VOICE_SAMPLE_MODE SAMPLE_MANNUAL
- #define ENABLE_VOICE_INT *(volatile unsigned int *)0x40050034 |= 0x00000300
- #define MASK_VOICE_INT *(volatile unsigned int *)0x40050034 &= 0xfffffcff
- #define CLEAR_VOICE_HALF_INT *(volatile unsigned int *)0x40050038 |= BIT(8)
- #define CLEAR_VOICE_FULL_INT *(volatile unsigned int *)0x40050038 |= BIT(9)
- #define IS_CLAER_VOICE_HALF_INT (*(volatile unsigned int *)0x4005003c) & BIT(8)
- #define IS_CLAER_VOICE_FULL_INT (*(volatile unsigned int *)0x4005003c) & BIT(9)
- #define GET_IRQ_STATUS ((*(volatile unsigned int *) 0x4005003c) & 0x3ff)
- #define ENABLE_ADC (*(volatile unsigned int *)0x4000f048 |= BIT(3))
- #define DISABLE_ADC (*(volatile unsigned int *)0x4000f048 &= ~BIT(3))
- #define ADC_CLOCK_ENABLE (*(volatile unsigned int *)0x4000f044 |= BIT(13))
- #define ADC_CLOCK_DISABLE (*(volatile unsigned int *)0x4000f044 &= ~BIT(13))
- #define ADC_DBLE_CLOCK_DISABLE (*(volatile unsigned int *)0x4000f044 &= ~BIT(21))
- #define POWER_DOWN_ADC (*(volatile unsigned int *)0x4000f048 &= ~BIT(3))
- #define POWER_UP_TEMPSENSOR (*(volatile unsigned int *)0x4000f048 |= BIT(29))
- #define REG_IO_CONTROL ((volatile unsigned int *)0x4000f020)
- #define ADCC_REG_BASE (0x4000F000)
- typedef enum {
- VOICE_ENCODE_PCMA = 0,
- VOICE_ENCODE_PCMU = 1,
- VOICE_ENCODE_CVSD = 2,
- VOICE_ENCODE_BYP = 3
- }VOICE_ENCODE_t;
- typedef enum {
- VOICE_RATE_64K = 0,
- VOICE_RATE_32K = 1,
- VOICE_RATE_16K = 2,
- VOICE_RATE_8K = 3
- }VOICE_RATE_t;
- typedef enum {
- VOICE_NOTCH_BYP = 0,
- VOICE_NOTCH_1 = 1,
- VOICE_NOTCH_2 = 2,
- VOICE_NOTCH_3 = 3
- }VOICE_NOTCH_t;
- typedef enum {
- VOICE_POLARITY_POS = 0,
- VOICE_POLARITY_NEG = 1
- }VOICE_POLARITY_t;
- enum{
- HAL_VOICE_EVT_DATA = 1,
- HAL_VOICE_EVT_FAIL = 0xff
- };
- typedef struct _voice_Cfg_t{
- bool voiceSelAmicDmic;
- GPIO_Pin_e dmicDataPin;
- GPIO_Pin_e dmicClkPin;
- uint8_t amicGain;
- uint8_t voiceGain;
- VOICE_ENCODE_t voiceEncodeMode;
- VOICE_RATE_t voiceRate;
- bool voiceAutoMuteOnOff;
- }voice_Cfg_t;
- typedef struct _voice_Evt_t{
- int type;
- uint32_t* data;
- uint32_t size;
- }voice_Evt_t;
- typedef void (*voice_Hdl_t)(voice_Evt_t* pev);
- typedef struct _voice_Contex_t{
- bool enable;
- voice_Cfg_t cfg;
- voice_Hdl_t evt_handler;
- }voice_Ctx_t;
- void hal_voice_enable(void);
- void hal_voice_disable(void);
- void hal_voice_dmic_mode(void);
- void hal_voice_amic_mode(void);
- void hal_voice_dmic_open(GPIO_Pin_e dmicDataPin, GPIO_Pin_e dmicClkPin);
- void hal_voice_amic_gain(uint8_t amicGain);
- void hal_voice_gain(uint8_t voiceGain);
- void hal_voice_encode(VOICE_ENCODE_t voiceEncodeMode);
- void hal_voice_rate(VOICE_RATE_t voiceRate);
- void hal_voice_amute_on(void);
- void hal_voice_amute_off(void);
- void __attribute__((weak)) hal_ADC_IRQHandler(void);
- void hal_voice_init(void);
- int hal_voice_config(voice_Cfg_t cfg, voice_Hdl_t evt_handler);
- int hal_voice_start(void);
- int hal_voice_stop(void);
- int hal_voice_clear(void);
- #endif
|