spi_example: fix the example to pass in esp32s2beta

This commit is contained in:
Michael (XIAO Xufeng) 2019-06-13 14:21:35 +08:00
parent 17378fd4c2
commit fcf4502c6b
5 changed files with 74 additions and 13 deletions

View File

@ -1,6 +1,11 @@
set(COMPONENT_SRCS "decode_image.c"
"pretty_effect.c"
set(COMPONENT_SRCS "pretty_effect.c"
"spi_master_example_main.c")
#only esp32 has enough memory to do jpeg decoding
if (CONFIG_IDF_TARGET_ESP32)
list(APPEND COMPONENT_SRCS "decode_image.c")
endif()
set(COMPONENT_ADD_INCLUDEDIRS ".")

View File

@ -11,6 +11,9 @@
#include <math.h>
#include "pretty_effect.h"
#include "sdkconfig.h"
#ifdef CONFIG_IDF_TARGET_ESP32
#include "decode_image.h"
uint16_t **pixels;
@ -23,6 +26,13 @@ static inline uint16_t get_bgnd_pixel(int x, int y)
y+=8;
return pixels[y][x];
}
#elif defined CONFIG_IDF_TARGET_ESP32S2BETA
//esp32s2beta doesn't have enough memory to hold the decoded image, calculate instead
static inline uint16_t get_bgnd_pixel(int x, int y)
{
return ((x<<3)^(y<<3)^(x*y));
}
#endif
//This variable is used to detect the next frame.
@ -57,5 +67,10 @@ void pretty_effect_calc_lines(uint16_t *dest, int line, int frame, int linect)
esp_err_t pretty_effect_init()
{
#ifdef CONFIG_IDF_TARGET_ESP32
return decode_image(&pixels);
#elif defined CONFIG_IDF_TARGET_ESP32S2BETA
//esp32s2beta doesn't have enough memory to hold the decoded image, calculate instead
return ESP_OK;
#endif
}

View File

@ -28,6 +28,10 @@
before the transaction is sent, the callback will set this line to the correct state.
*/
#ifdef CONFIG_IDF_TARGET_ESP32
#define LCD_HOST HSPI_HOST
#define DMA_CHAN 2
#define PIN_NUM_MISO 25
#define PIN_NUM_MOSI 23
#define PIN_NUM_CLK 19
@ -36,6 +40,19 @@
#define PIN_NUM_DC 21
#define PIN_NUM_RST 18
#define PIN_NUM_BCKL 5
#elif defined CONFIG_IDF_TARGET_ESP32S2BETA
#define LCD_HOST SPI2_HOST
#define DMA_CHAN LCD_HOST
#define PIN_NUM_MISO 37
#define PIN_NUM_MOSI 35
#define PIN_NUM_CLK 36
#define PIN_NUM_CS 34
#define PIN_NUM_DC 4
#define PIN_NUM_RST 5
#define PIN_NUM_BCKL 6
#endif
//To speed up transfers, every SPI transfer sends a bunch of lines. This define specifies how many. More means more memory use,
//but less overhead for setting up / finishing transfers. Make sure 240 is dividable by this.
@ -410,10 +427,10 @@ void app_main()
.pre_cb=lcd_spi_pre_transfer_callback, //Specify pre-transfer callback to handle D/C line
};
//Initialize the SPI bus
ret=spi_bus_initialize(HSPI_HOST, &buscfg, 1);
ret=spi_bus_initialize(LCD_HOST, &buscfg, DMA_CHAN);
ESP_ERROR_CHECK(ret);
//Attach the LCD to the SPI bus
ret=spi_bus_add_device(HSPI_HOST, &devcfg, &spi);
ret=spi_bus_add_device(LCD_HOST, &devcfg, &spi);
ESP_ERROR_CHECK(ret);
//Initialize the LCD
lcd_init(spi);

View File

@ -57,6 +57,17 @@ Pins in use. The SPI Master can use the GPIO mux, so feel free to change these i
#define GPIO_SCLK 15
#define GPIO_CS 14
#ifdef CONFIG_IDF_TARGET_ESP32
#define RCV_HOST HSPI_HOST
#define DMA_CHAN 2
#elif defined CONFIG_IDF_TARGET_ESP32S2BETA
#define RCV_HOST SPI2_HOST
#define DMA_CHAN RCV_HOST
#endif
//Called after a transaction is queued and ready for pickup by master. We use this to set the handshake line high.
void my_post_setup_cb(spi_slave_transaction_t *trans) {
@ -78,7 +89,9 @@ void app_main()
spi_bus_config_t buscfg={
.mosi_io_num=GPIO_MOSI,
.miso_io_num=GPIO_MISO,
.sclk_io_num=GPIO_SCLK
.sclk_io_num=GPIO_SCLK,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
};
//Configuration for the SPI slave interface
@ -106,7 +119,7 @@ void app_main()
gpio_set_pull_mode(GPIO_CS, GPIO_PULLUP_ONLY);
//Initialize SPI slave interface
ret=spi_slave_initialize(HSPI_HOST, &buscfg, &slvcfg, 1);
ret=spi_slave_initialize(RCV_HOST, &buscfg, &slvcfg, DMA_CHAN);
assert(ret==ESP_OK);
WORD_ALIGNED_ATTR char sendbuf[129]="";
@ -130,7 +143,7 @@ void app_main()
.post_setup_cb callback that is called as soon as a transaction is ready, to let the master know it is free to transfer
data.
*/
ret=spi_slave_transmit(HSPI_HOST, &t, portMAX_DELAY);
ret=spi_slave_transmit(RCV_HOST, &t, portMAX_DELAY);
//spi_slave_transmit does not return until the master has done a transmission, so by here we have sent our data and
//received data from the master. Print it.

View File

@ -58,6 +58,17 @@ Pins in use. The SPI Master can use the GPIO mux, so feel free to change these i
#define GPIO_SCLK 15
#define GPIO_CS 14
#ifdef CONFIG_IDF_TARGET_ESP32
#define SENDER_HOST HSPI_HOST
#define DMA_CHAN 2
#elif defined CONFIG_IDF_TARGET_ESP32S2BETA
#define SENDER_HOST SPI2_HOST
#define DMA_CHAN SENDER_HOST
#endif
//The semaphore indicating the slave is ready to receive stuff.
static xQueueHandle rdySem;
@ -132,9 +143,9 @@ void app_main()
gpio_isr_handler_add(GPIO_HANDSHAKE, gpio_handshake_isr_handler, NULL);
//Initialize the SPI bus and add the device we want to send stuff to.
ret=spi_bus_initialize(HSPI_HOST, &buscfg, 1);
ret=spi_bus_initialize(SENDER_HOST, &buscfg, DMA_CHAN);
assert(ret==ESP_OK);
ret=spi_bus_add_device(HSPI_HOST, &devcfg, &handle);
ret=spi_bus_add_device(SENDER_HOST, &devcfg, &handle);
assert(ret==ESP_OK);
//Assume the slave is ready for the first transmission: if the slave started up before us, we will not detect