From e7311d170a53f89233d85f14dee350e10c24298c Mon Sep 17 00:00:00 2001 From: Shicheng Chu <1468559561@qq.com> Date: Mon, 1 Apr 2024 01:59:48 +0800 Subject: [PATCH] [bsp][rtduino] pico rtduino support spi --- .../.ci/attachconfig/rtduino.attach | 4 - .../arduino_pinout/pins_arduino.c | 33 +++++ .../arduino_pinout/pins_arduino.h | 6 + bsp/raspberry-pico/board/Kconfig | 140 +++++++++--------- bsp/raspberry-pico/drivers/drv_spi.c | 8 +- 5 files changed, 115 insertions(+), 76 deletions(-) diff --git a/bsp/raspberry-pico/.ci/attachconfig/rtduino.attach b/bsp/raspberry-pico/.ci/attachconfig/rtduino.attach index 55e991c802..c14014d5c7 100644 --- a/bsp/raspberry-pico/.ci/attachconfig/rtduino.attach +++ b/bsp/raspberry-pico/.ci/attachconfig/rtduino.attach @@ -1,6 +1,2 @@ # scons: --strict CONFIG_BSP_USING_ARDUINO=y - -# check some important arduino libraries -CONFIG_PKG_USING_ARDUINO_TENSORFLOW_LITE_MICRO=y -CONFIG_PKG_USING_ARDUINO_TENSORFLOW_LITE_MICRO_EXAMPLE_HELLO_WORLD=y diff --git a/bsp/raspberry-pico/applications/arduino_pinout/pins_arduino.c b/bsp/raspberry-pico/applications/arduino_pinout/pins_arduino.c index f497891722..30975e4239 100644 --- a/bsp/raspberry-pico/applications/arduino_pinout/pins_arduino.c +++ b/bsp/raspberry-pico/applications/arduino_pinout/pins_arduino.c @@ -11,6 +11,14 @@ #include #include #include "pins_arduino.h" +#include +#include +#include +#include + +#define DBG_TAG "RTduino.pins_arduino" +#define DBG_LVL DBG_INFO +#include /* * {Arduino Pin, RT-Thread Pin [, Device Name, Channel]} @@ -51,3 +59,28 @@ const pin_map_t pin_map_table[]= {A1, 27, "adc1", 1}, /* ADC */ {A2, 28, "adc2", 2}, /* ADC */ }; + +#ifdef RTDUINO_USING_SPI +void switchToSPI(const char *bus_name) +{ + if(!rt_strcmp(bus_name, "spi0")) + { + /**SPI0 GPIO Configuration + 18u ------> SPI0_SCK + 16u ------> SPI0_MISO + 19u ------> SPI0_MOSI + 17u ------> SPI0_CS + */ + gpio_set_function(BSP_SPI0_SCK_PIN, GPIO_FUNC_SPI); + gpio_set_function(BSP_SPI0_MISO_PIN, GPIO_FUNC_SPI); + gpio_set_function(BSP_SPI0_MOSI_PIN, GPIO_FUNC_SPI); + gpio_init(BSP_SPI0_CS_PIN); + // Make the SPI pins available to picotool + bi_decl(bi_3pins_with_func(BSP_SPI0_MISO_PIN, BSP_SPI0_MOSI_PIN, BSP_SPI0_SCK_PIN, GPIO_FUNC_SPI)); + // Make the CS pin available to picotool + bi_decl(bi_1pin_with_name(BSP_SPI0_CS_PIN, "SPI CS")); + + LOG_I("D16, D17, D18 and D19 will switch from PWM to SPI"); + } +} +#endif /* RTDUINO_USING_SPI */ diff --git a/bsp/raspberry-pico/applications/arduino_pinout/pins_arduino.h b/bsp/raspberry-pico/applications/arduino_pinout/pins_arduino.h index 4c1b8c1f6d..b48c0b0cfb 100644 --- a/bsp/raspberry-pico/applications/arduino_pinout/pins_arduino.h +++ b/bsp/raspberry-pico/applications/arduino_pinout/pins_arduino.h @@ -51,4 +51,10 @@ /* Serial2 : P-TX P-RX */ #define RTDUINO_SERIAL2_DEVICE_NAME "uart1" +#define SS D17 +#define RTDUINO_DEFAULT_SPI_BUS_NAME "spi0" + +/* i2c0 : D4-SDA D5-SCL */ +#define RTDUINO_DEFAULT_IIC_BUS_NAME "i2c0" + #endif /* Pins_Arduino_h */ diff --git a/bsp/raspberry-pico/board/Kconfig b/bsp/raspberry-pico/board/Kconfig index 53dac12035..a2d6677a98 100644 --- a/bsp/raspberry-pico/board/Kconfig +++ b/bsp/raspberry-pico/board/Kconfig @@ -22,6 +22,10 @@ menu "Onboard Peripheral Drivers" select BSP_USING_PWM7 select BSP_USING_I2C select BSP_USING_I2C0 + select BSP_USING_SPI + select BSP_USING_SPI0 + select RTDUINO_USING_WIRE + select RTDUINO_USING_SPI imply RTDUINO_USING_SERVO default n @@ -158,15 +162,15 @@ menu "On-chip Peripheral Drivers" default n if BSP_USING_SOFT_SPI0 config BSP_S_SPI0_SCK_PIN - int "spi0 sck pin number (GP)" + int "spi0 SCK pin number (GP)" range 0 28 default 6 config BSP_S_SPI0_MOSI_PIN - int "spi0 mosi pin number (GP)" + int "spi0 MOSI pin number (GP)" range 0 28 default 7 config BSP_S_SPI0_MISO_PIN - int "spi0 miso pin number (GP)" + int "spi0 MISO pin number (GP)" range 0 28 default 4 endif @@ -175,15 +179,15 @@ menu "On-chip Peripheral Drivers" default n if BSP_USING_SOFT_SPI1 config BSP_S_SPI1_SCK_PIN - int "spi1 sck pin number (GP)" + int "spi1 SCK pin number (GP)" range 0 28 default 10 config BSP_S_SPI1_MOSI_PIN - int "spi1 mosi pin number (GP)" + int "spi1 MOSI pin number (GP)" range 0 28 default 11 config BSP_S_SPI1_MISO_PIN - int "spi1 miso pin number (GP)" + int "spi1 MISO pin number (GP)" range 0 28 default 12 endif @@ -227,66 +231,66 @@ menu "On-chip Peripheral Drivers" default n if BSP_USING_SPI0 choice - prompt "spi0 tx pin number (GP)" + prompt "spi0 MOSI pin number (GP)" depends on BSP_USING_SPI0 - default BSP_SPI0_TX_PIN_3 - config BSP_SPI0_TX_PIN_3 - bool "3" - config BSP_SPI0_TX_PIN_7 - bool "7" - config BSP_SPI0_TX_PIN_19 + default BSP_SPI0_MOSI_PIN_19 if BSP_USING_ARDUINO + config BSP_SPI0_MOSI_PIN_19 bool "19" + config BSP_SPI0_MOSI_PIN_3 + bool "3" + config BSP_SPI0_MOSI_PIN_7 + bool "7" endchoice - config BSP_SPI0_TX_PIN + config BSP_SPI0_MOSI_PIN int - default 3 if BSP_SPI0_TX_PIN_3 - default 7 if BSP_SPI0_TX_PIN_7 - default 19 if BSP_SPI0_TX_PIN_19 + default 3 if BSP_SPI0_MOSI_PIN_3 + default 7 if BSP_SPI0_MOSI_PIN_7 + default 19 if BSP_SPI0_MOSI_PIN_19 choice - prompt "spi0 rx pin number (GP)" + prompt "spi0 MISO pin number (GP)" depends on BSP_USING_SPI0 - default BSP_SPI0_RX_PIN_4 - config BSP_SPI0_RX_PIN_0 - bool "0" - config BSP_SPI0_RX_PIN_4 - bool "4" - config BSP_SPI0_RX_PIN_16 + default BSP_SPI0_MISO_PIN_16 if BSP_USING_ARDUINO + config BSP_SPI0_MISO_PIN_16 bool "16" + config BSP_SPI0_MISO_PIN_0 + bool "0" + config BSP_SPI0_MISO_PIN_4 + bool "4" endchoice - config BSP_SPI0_RX_PIN + config BSP_SPI0_MISO_PIN int - default 0 if BSP_SPI0_RX_PIN_0 - default 4 if BSP_SPI0_RX_PIN_4 - default 16 if BSP_SPI0_RX_PIN_16 + default 0 if BSP_SPI0_MISO_PIN_0 + default 4 if BSP_SPI0_MISO_PIN_4 + default 16 if BSP_SPI0_MISO_PIN_16 choice - prompt "spi0 sck pin number (GP)" + prompt "spi0 SCK pin number (GP)" depends on BSP_USING_SPI0 - default BSP_SPI0_SCK_PIN_2 + default BSP_SPI0_SCK_PIN_18 if BSP_USING_ARDUINO + config BSP_SPI0_SCK_PIN_18 + bool "18" config BSP_SPI0_SCK_PIN_2 bool "2" config BSP_SPI0_SCK_PIN_6 bool "6" - config BSP_SPI0_SCK_PIN_8 - bool "8" endchoice config BSP_SPI0_SCK_PIN int default 2 if BSP_SPI0_SCK_PIN_2 default 6 if BSP_SPI0_SCK_PIN_6 - default 8 if BSP_SPI0_SCK_PIN_8 + default 18 if BSP_SPI0_SCK_PIN_18 choice - prompt "spi0 cs pin number (GP)" + prompt "spi0 CS pin number (GP)" depends on BSP_USING_SPI0 - default BSP_SPI0_CS_PIN_5 + default BSP_SPI0_CS_PIN_17 if BSP_USING_ARDUINO + config BSP_SPI0_CS_PIN_17 + bool "17" config BSP_SPI0_CS_PIN_1 bool "1" config BSP_SPI0_CS_PIN_5 bool "5" - config BSP_SPI0_CS_PIN_17 - bool "17" endchoice config BSP_SPI0_CS_PIN int @@ -300,41 +304,41 @@ menu "On-chip Peripheral Drivers" default n if BSP_USING_SPI1 choice - prompt "spi1 tx pin number (GP)" + prompt "spi1 MOSI pin number (GP)" depends on BSP_USING_SPI1 - default BSP_SPI1_TX_PIN_11 - config BSP_SPI1_TX_PIN_11 - bool "11" - config BSP_SPI1_TX_PIN_15 + default BSP_SPI1_MOSI_PIN_15 if BSP_USING_ARDUINO + config BSP_SPI1_MOSI_PIN_15 bool "15" + config BSP_SPI1_MOSI_PIN_11 + bool "11" endchoice - config BSP_SPI1_TX_PIN + config BSP_SPI1_MOSI_PIN int - default 11 if BSP_SPI1_TX_PIN_11 - default 15 if BSP_SPI1_TX_PIN_15 + default 11 if BSP_SPI1_MOSI_PIN_11 + default 15 if BSP_SPI1_MOSI_PIN_15 choice - prompt "spi1 rx pin number (GP)" + prompt "spi1 MISO pin number (GP)" depends on BSP_USING_SPI1 - default BSP_SPI1_RX_PIN_12 - config BSP_SPI1_RX_PIN_8 - bool "8" - config BSP_SPI1_RX_PIN_12 + default BSP_SPI1_MISO_PIN_12 if BSP_USING_ARDUINO + config BSP_SPI1_MISO_PIN_12 bool "12" + config BSP_SPI1_MISO_PIN_8 + bool "8" endchoice - config BSP_SPI1_RX_PIN + config BSP_SPI1_MISO_PIN int - default 8 if BSP_SPI1_RX_PIN_8 - default 12 if BSP_SPI1_RX_PIN_12 + default 8 if BSP_SPI0_MISO_PIN_8 + default 12 if BSP_SPI0_MISO_PIN_12 choice - prompt "spi1 sck pin number (GP)" - depends on BSP_USING_SPI0 - default BSP_SPI1_SCK_PIN_10 - config BSP_SPI1_SCK_PIN_10 - bool "10" + prompt "spi1 SCK pin number (GP)" + depends on BSP_USING_SPI1 + default BSP_SPI1_SCK_PIN_14 if BSP_USING_ARDUINO config BSP_SPI1_SCK_PIN_14 bool "14" + config BSP_SPI1_SCK_PIN_10 + bool "10" endchoice config BSP_SPI1_SCK_PIN int @@ -342,13 +346,13 @@ menu "On-chip Peripheral Drivers" default 14 if BSP_SPI1_SCK_PIN_14 choice - prompt "spi1 cs pin number (GP)" + prompt "spi1 CS pin number (GP)" depends on BSP_USING_SPI0 - default BSP_SPI1_CS_PIN_13 - config BSP_SPI1_CS_PIN_9 - bool "9" + default BSP_SPI1_CS_PIN_13 if BSP_USING_ARDUINO config BSP_SPI1_CS_PIN_13 bool "13" + config BSP_SPI1_CS_PIN_9 + bool "9" endchoice config BSP_SPI1_CS_PIN int @@ -692,11 +696,11 @@ menu "On-chip Peripheral Drivers" choice prompt "i2c0 scl pin number (GP)" depends on BSP_USING_I2C0 - default BSP_I2C0_SCL_PIN_21 - config BSP_I2C0_SCL_PIN_1 - bool "1" + default BSP_I2C0_SCL_PIN_5 if BSP_USING_ARDUINO config BSP_I2C0_SCL_PIN_5 bool "5" + config BSP_I2C0_SCL_PIN_1 + bool "1" config BSP_I2C0_SCL_PIN_9 bool "9" config BSP_I2C0_SCL_PIN_13 @@ -718,11 +722,11 @@ menu "On-chip Peripheral Drivers" choice prompt "i2c0 sda pin number (GP)" depends on BSP_USING_I2C0 - default BSP_I2C0_SDA_PIN_20 - config BSP_I2C0_SDA_PIN_0 - bool "0" + default BSP_I2C0_SDA_PIN_4 if BSP_USING_ARDUINO config BSP_I2C0_SDA_PIN_4 bool "4" + config BSP_I2C0_SDA_PIN_0 + bool "0" config BSP_I2C0_SDA_PIN_8 bool "8" config BSP_I2C0_SDA_PIN_12 diff --git a/bsp/raspberry-pico/drivers/drv_spi.c b/bsp/raspberry-pico/drivers/drv_spi.c index 86ce30cfbd..597a1b70a3 100644 --- a/bsp/raspberry-pico/drivers/drv_spi.c +++ b/bsp/raspberry-pico/drivers/drv_spi.c @@ -38,8 +38,8 @@ static struct pico_spi pico_spi_obj[] = #ifdef BSP_USING_SPI0 { .handle = spi0, - .spi_rx_pin = BSP_SPI0_RX_PIN, - .spi_tx_pin = BSP_SPI0_TX_PIN, + .spi_rx_pin = BSP_SPI0_MISO_PIN, + .spi_tx_pin = BSP_SPI0_MOSI_PIN, .spi_sck_pin = BSP_SPI0_SCK_PIN, .spi_cs_pin = BSP_SPI0_CS_PIN, .device_name = "spi0", @@ -48,8 +48,8 @@ static struct pico_spi pico_spi_obj[] = #ifdef BSP_USING_SPI1 { .handle = spi1, - .spi_rx_pin = BSP_SPI1_RX_PIN, - .spi_tx_pin = BSP_SPI1_TX_PIN, + .spi_rx_pin = BSP_SPI1_MISO_PIN, + .spi_tx_pin = BSP_SPI1_MOSI_PIN, .spi_sck_pin = BSP_SPI1_SCK_PIN, .spi_cs_pin = BSP_SPI1_CS_PIN, .device_name = "spi1",