luat_i2s_air101.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "luat_base.h"
  2. #include "luat_i2s.h"
  3. #include "wm_include.h"
  4. #include "wm_i2s.h"
  5. #define LUAT_LOG_TAG "i2s"
  6. #include "luat_log.h"
  7. int tls_i2s_io_init(void)
  8. {
  9. wm_i2s_ck_config(WM_IO_PB_08);
  10. wm_i2s_ws_config(WM_IO_PB_09);
  11. wm_i2s_di_config(WM_IO_PB_10);
  12. wm_i2s_do_config(WM_IO_PB_11);
  13. LLOGD("ck--PB08, ws--PB09, di--PB10, do--PB11");
  14. return WM_SUCCESS;
  15. }
  16. int luat_i2s_setup(luat_i2s_conf_t *conf) {
  17. // 首先, 配置io复用
  18. tls_i2s_io_init();
  19. // 然后转本地i2s配置
  20. I2S_InitDef opts = { I2S_MODE_MASTER, I2S_CTRL_STEREO, I2S_RIGHT_CHANNEL, I2S_Standard, I2S_DataFormat_16, 8000, 5000000 };
  21. int mode = I2S_MODE_MASTER; // 当前强制master
  22. int stereo = 0;
  23. int format = 0; // i2s
  24. int datawidth = 16;
  25. int freq = 44100;
  26. opts.I2S_Mode_MS = mode;
  27. opts.I2S_Mode_SS = (stereo<<22);
  28. opts.I2S_Mode_LR = I2S_LEFT_CHANNEL;
  29. opts.I2S_Trans_STD = (format*0x1000000);
  30. opts.I2S_DataFormat = (datawidth/8 - 1)*0x10;
  31. opts.I2S_AudioFreq = freq;
  32. opts.I2S_MclkFreq = 80000000;
  33. wm_i2s_port_init(&opts);
  34. wm_i2s_register_callback(NULL);
  35. return 0;
  36. }
  37. int luat_i2s_send(uint8_t id, char* buff, size_t len) {
  38. wm_i2s_tx_int((int16_t *)buff, len / 2, NULL);
  39. return len;
  40. }
  41. int luat_i2s_recv(uint8_t id, char* buff, size_t len) {
  42. wm_i2s_rx_int((int16_t *)buff, len / 2);
  43. return len;
  44. }
  45. int luat_i2s_close(uint8_t id) {
  46. wm_i2s_tx_rx_stop();
  47. return 0;
  48. }