|
|
@@ -15,23 +15,11 @@
|
|
|
#define LUAT_LOG_TAG "airlink"
|
|
|
#include "luat_log.h"
|
|
|
|
|
|
-#ifdef CHIP_EC718
|
|
|
-
|
|
|
-#define TEST_SPI_ID 0
|
|
|
-#define TEST_BUFF_SIZE (1600)
|
|
|
-#define TEST_CS_PIN 8
|
|
|
-#define TEST_RDY_PIN 22
|
|
|
-#define TEST_BTN_PIN 0
|
|
|
-
|
|
|
-#else
|
|
|
-
|
|
|
-#define TEST_SPI_ID 0
|
|
|
+#define MASTER_SPI_ID g_airlink_spi_conf.spi_id
|
|
|
#define TEST_BUFF_SIZE (1600)
|
|
|
-#define TEST_CS_PIN 15
|
|
|
-#define TEST_RDY_PIN 22
|
|
|
-#define TEST_BTN_PIN 2
|
|
|
-
|
|
|
-#endif
|
|
|
+#define TEST_CS_PIN g_airlink_spi_conf.cs_pin
|
|
|
+#define TEST_RDY_PIN g_airlink_spi_conf.rdy_pin
|
|
|
+#define TEST_IRQ_PIN g_airlink_spi_conf.irq_pin
|
|
|
|
|
|
#ifdef TYPE_EC718M
|
|
|
#include "platform_def.h"
|
|
|
@@ -54,16 +42,16 @@ static uint32_t is_waiting_queue = 0;
|
|
|
|
|
|
static luat_rtos_queue_t evt_queue;
|
|
|
|
|
|
-__USER_FUNC_IN_RAM__ static int slave_rdy_irq(void *data, void* args) {
|
|
|
- // uint32_t len = 0;
|
|
|
+__USER_FUNC_IN_RAM__ static int slave_irq_cb(void *data, void* args) {
|
|
|
+ uint32_t len = 0;
|
|
|
// if (is_waiting_queue) {
|
|
|
// is_waiting_queue = 0;
|
|
|
- // luat_rtos_queue_get_cnt(evt_queue, &len);
|
|
|
- // // luat_rtos_event_send(spi_task_handle, 2, 2, 3, 4, 100);
|
|
|
- // luat_event_t evt = {.id=2};
|
|
|
- // if (len < 24) {
|
|
|
- // luat_rtos_queue_send(evt_queue, &evt, sizeof(evt), 0);
|
|
|
- // }
|
|
|
+ luat_rtos_queue_get_cnt(evt_queue, &len);
|
|
|
+ // luat_rtos_event_send(spi_task_handle, 2, 2, 3, 4, 100);
|
|
|
+ luat_event_t evt = {.id=2};
|
|
|
+ if (len < 24) {
|
|
|
+ luat_rtos_queue_send(evt_queue, &evt, sizeof(evt), 0);
|
|
|
+ }
|
|
|
// }
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -79,8 +67,27 @@ __USER_FUNC_IN_RAM__ static void on_newdata_notify(void) {
|
|
|
}
|
|
|
|
|
|
static void spi_gpio_setup(void) {
|
|
|
+ if (g_airlink_spi_conf.cs_pin == 0) {
|
|
|
+ // if (g_airlink_spi_conf.spi_id == 0) {
|
|
|
+ g_airlink_spi_conf.cs_pin = 8;
|
|
|
+ // }
|
|
|
+ // else {
|
|
|
+ // g_airlink_spi_conf.cs_pin = 8;
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ if (g_airlink_spi_conf.rdy_pin == 0) {
|
|
|
+ // if (g_airlink_spi_conf.spi_id == 0) {
|
|
|
+ g_airlink_spi_conf.rdy_pin = 22;
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ if (g_airlink_spi_conf.irq_pin == 0) {
|
|
|
+ g_airlink_spi_conf.irq_pin = 255; // 默认禁用irq脚
|
|
|
+ }
|
|
|
+
|
|
|
+ LLOGI("spi master id %d cs %d rdy %d irq %d", MASTER_SPI_ID, g_airlink_spi_conf.cs_pin, g_airlink_spi_conf.rdy_pin, g_airlink_spi_conf.irq_pin);
|
|
|
+
|
|
|
luat_spi_t spi_conf = {
|
|
|
- .id = TEST_SPI_ID,
|
|
|
+ .id = MASTER_SPI_ID,
|
|
|
.CPHA = 1,
|
|
|
.CPOL = 1,
|
|
|
.dataw = 8,
|
|
|
@@ -91,18 +98,17 @@ static void spi_gpio_setup(void) {
|
|
|
.cs = 255
|
|
|
};
|
|
|
luat_pm_iovolt_ctrl(0, 3300);
|
|
|
+
|
|
|
luat_spi_setup(&spi_conf);
|
|
|
luat_gpio_cfg_t gpio_cfg = {0};
|
|
|
|
|
|
// 从机准备好脚
|
|
|
luat_gpio_set_default_cfg(&gpio_cfg);
|
|
|
gpio_cfg.pin = TEST_RDY_PIN;
|
|
|
- gpio_cfg.mode = LUAT_GPIO_IRQ;
|
|
|
+ gpio_cfg.mode = LUAT_GPIO_INPUT;
|
|
|
gpio_cfg.irq_type = LUAT_GPIO_FALLING_IRQ;
|
|
|
gpio_cfg.pull = 0;
|
|
|
- gpio_cfg.irq_cb = slave_rdy_irq;
|
|
|
luat_gpio_open(&gpio_cfg);
|
|
|
- LLOGD("gpio rdy setup done %d", TEST_RDY_PIN);
|
|
|
|
|
|
// CS片选脚
|
|
|
luat_gpio_set_default_cfg(&gpio_cfg);
|
|
|
@@ -111,6 +117,16 @@ static void spi_gpio_setup(void) {
|
|
|
gpio_cfg.pull = LUAT_GPIO_PULLUP;
|
|
|
gpio_cfg.output_level = 1;
|
|
|
luat_gpio_open(&gpio_cfg);
|
|
|
+
|
|
|
+ if (g_airlink_spi_conf.irq_pin != 255) {
|
|
|
+ luat_gpio_set_default_cfg(&gpio_cfg);
|
|
|
+ gpio_cfg.pin = TEST_RDY_PIN;
|
|
|
+ gpio_cfg.mode = LUAT_GPIO_IRQ;
|
|
|
+ gpio_cfg.irq_type = LUAT_GPIO_FALLING_IRQ;
|
|
|
+ gpio_cfg.pull = LUAT_GPIO_PULLUP;
|
|
|
+ gpio_cfg.irq_cb = slave_irq_cb;
|
|
|
+ luat_gpio_open(&gpio_cfg);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -198,7 +214,7 @@ __USER_FUNC_IN_RAM__ static void spi_master_task(void *param)
|
|
|
link = NULL;
|
|
|
|
|
|
g_airlink_statistic.tx_pkg.total ++;
|
|
|
- luat_spi_transfer(TEST_SPI_ID, (const char*)txbuff, TEST_BUFF_SIZE, (char*)rxbuff, TEST_BUFF_SIZE);
|
|
|
+ luat_spi_transfer(MASTER_SPI_ID, (const char*)txbuff, TEST_BUFF_SIZE, (char*)rxbuff, TEST_BUFF_SIZE);
|
|
|
luat_gpio_set(TEST_CS_PIN, 1);
|
|
|
// luat_airlink_print_buff("RX", rxbuff, 32);
|
|
|
// 对接收到的数据进行解析
|
|
|
@@ -225,6 +241,7 @@ void luat_airlink_start_master(void)
|
|
|
LLOGE("SPI主机任务已经启动过了!!!");
|
|
|
return;
|
|
|
}
|
|
|
- luat_rtos_queue_create(&evt_queue, 2048, sizeof(luat_event_t));
|
|
|
+
|
|
|
+ luat_rtos_queue_create(&evt_queue, 4*1024, sizeof(luat_event_t));
|
|
|
luat_rtos_task_create(&spi_task_handle, 4 * 1024, 95, "spi", spi_master_task, NULL, 0);
|
|
|
}
|