main.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include <stdarg.h>
  2. #include "yc11xx.h"
  3. #include "yc11xx_uart.h"
  4. #include "yc11xx_gpio.h"
  5. #include "Drv_mic.h"
  6. #include "system.h"
  7. #define LED_GPIO 4
  8. extern MIC_CUR_VARIABLE sMicCurVariable;
  9. void LED_Run(void)
  10. {
  11. static uint32_t times = 0;
  12. times++;
  13. if(times>0x100)
  14. {
  15. times = 0;
  16. GPIO_CONFIG(LED_GPIO) = (GPIO_CONFIG(LED_GPIO)==GPCFG_OUTPUT_HIGH)? GPCFG_OUTPUT_LOW: GPCFG_OUTPUT_HIGH;
  17. }
  18. }
  19. /*
  20. * @method Audio_sampling_init
  21. * @brief mic adc init
  22. * @retval None
  23. */
  24. void Audio_sampling_init()
  25. {
  26. DRV_Mic_Init();
  27. DRV_Mic_Enable();
  28. }
  29. /*
  30. * @method Audio_get_buffer_len
  31. * @brief Get adc dma buf unread data length.
  32. * @retval None
  33. */
  34. int Audio_get_buffer_len()
  35. {
  36. int audioWPtr = HREADW(CORE_ADCD_ADDR) ;
  37. int audioRPtr = TO_16BIT_ADDR(sMicCurVariable.mReadPtr) ;
  38. int audioBufferLen = (int)(sMicCurVariable.mEndPtr - sMicCurVariable.mReadBufPtr);
  39. if(audioRPtr <= audioWPtr)
  40. {
  41. return (audioWPtr - audioRPtr);
  42. }
  43. else
  44. {
  45. return (audioBufferLen - (audioRPtr - audioWPtr));
  46. }
  47. }
  48. /*
  49. * @method Audio_to_uart_start
  50. * @brief read mic adc data for adc_dma_buf, and send mic adc data by uart.
  51. * @retval None
  52. */
  53. void Audio_to_uart_start()
  54. {
  55. if (sMicCurVariable.mMicEnable == MIC_DISABLE)
  56. return;
  57. int audioWPtr = HREADW(CORE_ADCD_ADDR) ;
  58. int bufferLen = Audio_get_buffer_len();
  59. if (bufferLen != 0 && bufferLen >= ENCODE_INPUT_LEN)
  60. {
  61. //Original sound sampling(pcm)
  62. for(int indexL = 0; indexL < ENCODE_INPUT_LEN; indexL++)
  63. MyPrintf("%c",*(sMicCurVariable.mReadPtr + indexL));
  64. sMicCurVariable.mReadPtr += ENCODE_INPUT_LEN;
  65. if (sMicCurVariable.mReadPtr == sMicCurVariable.mEndPtr)
  66. sMicCurVariable.mReadPtr = sMicCurVariable.mReadBufPtr;
  67. }
  68. }
  69. int main(void)
  70. {
  71. printport_init();
  72. GPIO_CONFIG(LED_GPIO)= GPCFG_OUTPUT_LOW;
  73. Audio_sampling_init();
  74. while(1)
  75. {
  76. LED_Run();
  77. Audio_to_uart_start();
  78. }
  79. }