Browse Source

add: 添加i2s实现,未测试,当前参数固定

Wendal Chen 3 years ago
parent
commit
da4d79efe3
3 changed files with 68 additions and 3 deletions
  1. 6 3
      app/port/luat_base_air101.c
  2. 2 0
      app/port/luat_conf_bsp.h
  3. 60 0
      app/port/luat_i2s_air101.c

+ 6 - 3
app/port/luat_base_air101.c

@@ -138,9 +138,9 @@ static const luaL_Reg loadedlibs[] = {
 #endif
 
 #ifdef LUAT_USE_LVGL
-#ifndef LUAT_USE_LCD
-#define LUAT_USE_LCD
-#endif
+// #ifndef LUAT_USE_LCD
+// #define LUAT_USE_LCD
+// #endif
   {"lvgl",   luaopen_lvgl},
 #endif
 
@@ -182,6 +182,9 @@ static const luaL_Reg loadedlibs[] = {
 #endif
 #ifdef LUAT_USE_YMODEM
   {"ymodem", luaopen_ymodem},
+#endif
+#ifdef LUAT_USE_I2S
+  {"i2s", luaopen_i2s},
 #endif
   {NULL, NULL}
 };

+ 2 - 0
app/port/luat_conf_bsp.h

@@ -45,6 +45,8 @@
 // OTP
 #define LUAT_USE_OTP 1
 #define LUAT_USE_TOUCHKEY 1
+// i2s
+//#define LUAt_USE_I2S 1
 
 //----------------------------
 // 常用工具库, 按需启用, cjson和pack是强烈推荐启用的

+ 60 - 0
app/port/luat_i2s_air101.c

@@ -0,0 +1,60 @@
+#include "luat_base.h"
+#include "luat_i2s.h"
+
+#include "wm_include.h"
+#include "wm_i2s.h"
+
+#define LUAT_LOG_TAG "i2s"
+#include "luat_log.h"
+
+int tls_i2s_io_init(void)
+{
+    wm_i2s_ck_config(WM_IO_PB_08);
+    wm_i2s_ws_config(WM_IO_PB_09);
+    wm_i2s_di_config(WM_IO_PB_10);
+    wm_i2s_do_config(WM_IO_PB_11);
+    LLOGD("ck--PB08, ws--PB09, di--PB10, do--PB11");
+    return WM_SUCCESS;
+}
+
+int luat_i2s_setup(luat_i2s_conf_t *conf) {
+    // 首先, 配置io复用
+    tls_i2s_io_init();
+
+    // 然后转本地i2s配置
+    I2S_InitDef opts = { I2S_MODE_MASTER, I2S_CTRL_STEREO, I2S_RIGHT_CHANNEL, I2S_Standard, I2S_DataFormat_16, 8000, 5000000 };
+
+    int mode = I2S_MODE_MASTER; // 当前强制master
+    int stereo = 0;
+    int format = 0; // i2s
+    int datawidth = 16;
+    int freq = 44100;
+
+    opts.I2S_Mode_MS = mode;
+    opts.I2S_Mode_SS = (stereo<<22);
+    opts.I2S_Mode_LR = I2S_LEFT_CHANNEL;
+    opts.I2S_Trans_STD = (format*0x1000000);
+    opts.I2S_DataFormat = (datawidth/8 - 1)*0x10;
+    opts.I2S_AudioFreq = freq;
+    opts.I2S_MclkFreq = 80000000;
+
+    wm_i2s_port_init(&opts);
+    wm_i2s_register_callback(NULL);
+
+    return 0;
+}
+
+int luat_i2s_send(uint8_t id, char* buff, size_t len) {
+    wm_i2s_tx_int((int16_t *)buff, len / 2, NULL);
+    return len;
+}
+
+int luat_i2s_recv(uint8_t id, char* buff, size_t len) {
+    wm_i2s_rx_int((int16_t *)buff, len / 2);
+    return len;
+}
+
+int luat_i2s_close(uint8_t id) {
+    wm_i2s_tx_rx_stop();
+    return 0;
+}