luat_i2s_air101.c 1.5 KB

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