drv_mic.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /**
  2. * Copyright 2016, yichip Semiconductor(shenzhen office)
  3. * All Rights Reserved.
  4. *
  5. * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Yichip Semiconductor;
  6. * the contents of this file may not be disclosed to third parties, copied
  7. * or duplicated in any form, in whole or in part, without the prior
  8. * written permission of Yichip Semiconductor.
  9. */
  10. /**
  11. *@file drv_mic.h
  12. *@brief mic support for application.
  13. */
  14. #ifndef _DRV_MIC_H_
  15. #define _DRV_MIC_H_
  16. #include "ipc.h"
  17. #include <stdbool.h>
  18. #include <stdio.h>
  19. /**
  20. *@brief ADC configure.
  21. */
  22. #define DRV_ADC_M0RAM_ENABLE 0x40
  23. #define DRV_ADC_FILTER_DISABLE 0x20
  24. #define DRV_ADC_ENABLE 0x80
  25. #define DRV_ADC_8K_FILTer 0x10
  26. #define DRV_ADC_16K_FILTer 0x00
  27. #define DRV_ADC_CLEAR_RSSI 0x08
  28. #define DRV_ADC_AVG_TIMER_RSSI 0x06
  29. #define DRV_ADC_RSSI_CLOCK 0x01
  30. /**
  31. *@brief ADC gpio.
  32. */
  33. #define DRV_ADC_CHANNEL_SIG_GPIO6 0x0001
  34. #define DRV_ADC_CHANNEL_SIG_GPIO7 0x0002
  35. #define DRV_ADC_CHANNEL_SIG_GPIO8 0x0004
  36. #define DRV_ADC_CHANNEL_SIG_GPIO9 0x0008
  37. #define DRV_ADC_CHANNEL_SIG_GPIO10 0x0010
  38. #define DRV_ADC_CHANNEL_SIG_GPIO11 0x0020
  39. #define DRV_ADC_CHANNEL_SIG_GPIO12 0x0040
  40. #define DRV_ADC_CHANNEL_SIG_GPIO13 0x0080
  41. #define DRV_ADC_CHANNEL_DIFF_GPIO67 0x0100
  42. #define DRV_ADC_CHANNEL_DIFF_GPIO89 0x0200
  43. #define DRV_ADC_CHANNEL_DIFF_GPIO1011 0x0400
  44. #define DRV_ADC_CHANNEL_DIFF_GPIO1213 0x0800
  45. #define ENCODE_INPUT_LEN 80
  46. #define ENCODE_OUTPUT_LEN 20
  47. #define ENCODE_PACKET_NUM 6
  48. #define MIC_QUEUE_MAX 100
  49. #define MIC_ADPCM_PACKET_LEN 24
  50. #define ENCODE_PACKETS_LEN (ENCODE_INPUT_LEN*ENCODE_PACKET_NUM)
  51. #define RECORE_BUFFER_SIZE 2400
  52. typedef unsigned int uint;
  53. typedef signed short s16;
  54. /**
  55. *@brief ADC driver Configure definition.
  56. */
  57. typedef struct
  58. {
  59. unsigned char *mDmaBuf; /*!< adc DMA start address */
  60. int16_t mDmaBufLen; /*!< adc DMA buffer length */
  61. uint16_t mSampleDelay; /*!< adc channel switch delay counter, based on 3M */
  62. uint16_t mChannelCfg; /*!< adc channel switch */
  63. uint8_t mAdcConfig; /*!< adc ctrl byte */
  64. } DRV_ADC_CONFIG;
  65. /**
  66. *@brief Microphone state enum.
  67. */
  68. typedef enum
  69. {
  70. MIC_DISABLE,
  71. MIC_ENABLE
  72. }MIC_STATUS_ENUM;
  73. /**
  74. *@brief Microphone current variable.
  75. */
  76. typedef struct
  77. {
  78. unsigned char *mReadBufPtr; /*!< the pointer of microphone read buffer start */
  79. unsigned char *mReadPtr; /*!< Microphone read pointer*/
  80. unsigned char *mEndPtr; /*!< the pointer of microphone read buffer ending*/
  81. MIC_STATUS_ENUM mMicEnable; /*!< microphone enable */
  82. MIC_STATUS_ENUM mMicBleEnable;/*!< microphone ble enable*/
  83. }MIC_CUR_VARIABLE;
  84. /**
  85. *@brief Queue header.
  86. */
  87. typedef struct
  88. {
  89. void *pHead; /*!< Header pointer*/
  90. void *pWrite; /*!< Writing queue pointer*/
  91. void *pRead; /*!< Reading queue pointer*/
  92. uint8_t unit_Len; /*!< size of element */
  93. uint8_t array_Len; /*!< the length of array */
  94. uint8_t current_queue_len;/*!< Entire queue length */
  95. }QUEUE_HEADER;
  96. typedef void (*tMicCallback)(IPC_DATA_FORMAT *,int);
  97. bool queue_init(QUEUE_HEADER *pQheader, void *pMem, uint8_t unitLen, uint8_t len);
  98. bool queue_clear(QUEUE_HEADER *pQheader);
  99. void * Delete_Queue(QUEUE_HEADER *pQheader);
  100. bool queue_is_empty(QUEUE_HEADER *pQheader);
  101. bool queue_is_full(QUEUE_HEADER *pQheader);
  102. bool Insert_Queue(QUEUE_HEADER *pQheader,void *pEle);
  103. void Drv_micQueueInit();
  104. bool Drv_micQueueEmpty(QUEUE_HEADER *pQheader);
  105. void Drv_micClearQueue();
  106. void Drv_adcdma_init(DRV_ADC_CONFIG *pAdcConfig);
  107. void Drv_adc_enable(void);
  108. unsigned short Drv_adc_getWptr(void);
  109. void Drv_adc_disable(void);
  110. void DRV_Mic_Init(void);
  111. void DRV_Mic_DeInit(void);
  112. void DRV_Mic_sendEnable();
  113. void DRV_Mic_sendDisable();
  114. void DRV_Mic_Enable(void);
  115. void DRV_Mic_Disable(void);
  116. MIC_STATUS_ENUM DRV_Mic_State(void);
  117. void Drv_micQueueInit();
  118. bool Drv_micQueueEmpty(QUEUE_HEADER *pQheader);
  119. void Drv_micClearQueue();
  120. bool Drv_micInsertQueue(QUEUE_HEADER *pQheader,void *pEle);
  121. void Drv_voiceDecodeDataSend();
  122. void DRV_Mic_multiply_2(s16 *data,int datalen);
  123. int DRV_Mic_Get_Buffer_Len();
  124. void DRV_Mic_Encode_ADC();
  125. #endif