Skip to content

Commit 7fa5cc0

Browse files
authored
fix: Update BSP components to have proper sizing for the max transfer size of their SPI buses (#515)
* fix: Update BSP components to have proper sizing for the max transfer size of their SPI buses * fix display driver example missing include
1 parent 9703269 commit 7fa5cc0

File tree

22 files changed

+80
-14
lines changed

22 files changed

+80
-14
lines changed

components/byte90/include/byte90.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <driver/gpio.h>
88
#include <driver/spi_master.h>
9+
#include <hal/spi_ll.h>
910
#include <hal/spi_types.h>
1011

1112
#include "adxl345.hpp"
@@ -60,6 +61,10 @@ class Byte90 : public BaseComponent {
6061
/// Alias for the pixel type used by the Byte90 display
6162
using Pixel = lv_color16_t;
6263

64+
/// Maximum number of bytes that can be transferred in a single SPI
65+
/// transaction to the Display. 32k on the ESP32-S3.
66+
static constexpr size_t SPI_MAX_TRANSFER_BYTES = SPI_LL_DMA_MAX_BIT_LEN / 8;
67+
6368
/// Alias for the display driver used by the Byte90 display
6469
using DisplayDriver = espp::Ssd1351;
6570

components/byte90/src/byte90.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ bool Byte90::init_spi_bus() {
2121
bus_cfg.sclk_io_num = spi_sclk_io;
2222
bus_cfg.quadwp_io_num = -1;
2323
bus_cfg.quadhd_io_num = -1;
24-
bus_cfg.max_transfer_sz = frame_buffer_size * sizeof(lv_color_t) + 100;
24+
bus_cfg.max_transfer_sz = SPI_MAX_TRANSFER_BYTES;
2525
auto ret = spi_bus_initialize(spi_num, &bus_cfg, SPI_DMA_CH_AUTO);
2626
if (ret != ESP_OK) {
2727
logger_.error("Failed to initialize bus.");

components/display_drivers/example/main/display_drivers_example.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
#include <memory>
33
#include <vector>
44

5+
#include <driver/spi_master.h>
6+
#include <hal/spi_ll.h>
7+
#include <hal/spi_types.h>
8+
59
#include "display.hpp"
6-
#include "driver/spi_master.h"
7-
#include "hal/spi_types.h"
810

911
// default, most displays use 16-bit coordinates
1012
#define DISPLAY_COORDINATES_16BIT 1
@@ -506,6 +508,11 @@ extern "C" void app_main(void) {
506508
//! [byte90_config example]
507509
#endif
508510

511+
/// Maximum number of bytes that can be transferred in a single SPI
512+
/// transaction to the Display. 2MB on ESP32, 1MB on ESP32-S2, 32k on the
513+
/// ESP32-S3.
514+
static constexpr size_t SPI_MAX_TRANSFER_BYTES = SPI_LL_DMA_MAX_BIT_LEN / 8;
515+
509516
fmt::print("Starting display_drivers example for {}\n", dev_kit);
510517
{
511518
#ifdef CONFIG_T_ENCODER_PRO
@@ -534,7 +541,7 @@ extern "C" void app_main(void) {
534541
buscfg.quadhd_io_num = -1;
535542
#endif
536543
buscfg.sclk_io_num = sclk;
537-
buscfg.max_transfer_sz = (int)(pixel_buffer_size * sizeof(lv_color_t));
544+
buscfg.max_transfer_sz = SPI_MAX_TRANSFER_BYTES;
538545
// create the spi device
539546
spi_device_interface_config_t devcfg;
540547
memset(&devcfg, 0, sizeof(devcfg));

components/esp-box/include/esp-box.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <driver/gpio.h>
88
#include <driver/i2s_std.h>
99
#include <driver/spi_master.h>
10+
#include <hal/spi_ll.h>
1011
#include <hal/spi_types.h>
1112

1213
#include <freertos/FreeRTOS.h>
@@ -62,6 +63,10 @@ class EspBox : public BaseComponent {
6263
/// Alias for the touch callback when touch events are received
6364
using touch_callback_t = std::function<void(const TouchpadData &)>;
6465

66+
/// Maximum number of bytes that can be transferred in a single SPI
67+
/// transaction to the Display. 32k on the ESP32-S3.
68+
static constexpr size_t SPI_MAX_TRANSFER_BYTES = SPI_LL_DMA_MAX_BIT_LEN / 8;
69+
6570
/// The type of the box
6671
enum class BoxType {
6772
UNKNOWN, ///< unknown box

components/esp-box/src/video.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ bool EspBox::initialize_lcd() {
6565
lcd_spi_bus_config_.sclk_io_num = lcd_sclk_io;
6666
lcd_spi_bus_config_.quadwp_io_num = -1;
6767
lcd_spi_bus_config_.quadhd_io_num = -1;
68-
lcd_spi_bus_config_.max_transfer_sz = frame_buffer_size * sizeof(lv_color_t) + 100;
68+
// 32k on s3; we can use this because we enable DMA below
69+
lcd_spi_bus_config_.max_transfer_sz = SPI_MAX_TRANSFER_BYTES;
6970

7071
memset(&lcd_config_, 0, sizeof(lcd_config_));
7172
lcd_config_.mode = 0;

components/matouch-rotary-display/include/matouch-rotary-display.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <driver/gpio.h>
88
#include <driver/spi_master.h>
9+
#include <hal/spi_ll.h>
910
#include <hal/spi_types.h>
1011

1112
#include "abi_encoder.hpp"
@@ -38,11 +39,23 @@ class MatouchRotaryDisplay : public BaseComponent {
3839
/// Alias for the pixel type used by the Matouch display
3940
using Pixel = lv_color16_t;
4041

42+
/// Maximum number of bytes that can be transferred in a single SPI
43+
/// transaction to the Display. 32k on the ESP32-S3.
44+
static constexpr size_t SPI_MAX_TRANSFER_BYTES = SPI_LL_DMA_MAX_BIT_LEN / 8;
45+
4146
/// Alias for the display driver used by the Matouch display
4247
using DisplayDriver = espp::Gc9a01;
48+
49+
/// Alias for the touchpad driver used by the Matouch display
4350
using TouchpadData = espp::TouchpadData;
51+
52+
/// Alias for the Encoder used by the Matouch display
4453
using Encoder = espp::AbiEncoder<espp::EncoderType::ROTATIONAL>;
54+
55+
/// Alias for the button callback function type
4556
using button_callback_t = espp::Interrupt::event_callback_fn;
57+
58+
/// Alias for the touch callback function type
4659
using touch_callback_t = std::function<void(const TouchpadData &)>;
4760

4861
/// @brief Access the singleton instance of the MatouchRotaryDisplay class

components/matouch-rotary-display/src/matouch-rotary-display.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ bool MatouchRotaryDisplay::initialize_lcd() {
236236
lcd_spi_bus_config_.sclk_io_num = lcd_sclk_io;
237237
lcd_spi_bus_config_.quadwp_io_num = -1;
238238
lcd_spi_bus_config_.quadhd_io_num = -1;
239-
lcd_spi_bus_config_.max_transfer_sz = frame_buffer_size * sizeof(lv_color_t) + 100;
239+
lcd_spi_bus_config_.max_transfer_sz = SPI_MAX_TRANSFER_BYTES;
240240

241241
memset(&lcd_config_, 0, sizeof(lcd_config_));
242242
lcd_config_.mode = 0;

components/seeed-studio-round-display/include/seeed-studio-round-display.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <driver/gpio.h>
66
#include <driver/spi_master.h>
7+
#include <hal/spi_ll.h>
78
#include <hal/spi_types.h>
89

910
#include "chsc6x.hpp"
@@ -37,6 +38,10 @@ class SsRoundDisplay : public espp::BaseComponent {
3738
using TouchDriver = espp::Chsc6x; ///< Alias for the touch driver.
3839
using TouchpadData = espp::TouchpadData; ///< Alias for the touchpad data.
3940

41+
/// Maximum number of bytes that can be transferred in a single SPI
42+
/// transaction to the Display. 32k on the ESP32-S3.
43+
static constexpr size_t SPI_MAX_TRANSFER_BYTES = SPI_LL_DMA_MAX_BIT_LEN / 8;
44+
4045
/// The touch callback function type
4146
/// \param data The touchpad data
4247
using touch_callback_t = std::function<void(const TouchpadData &)>;

components/seeed-studio-round-display/src/seeed-studio-round-display.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ bool SsRoundDisplay::initialize_lcd() {
195195
lcd_spi_bus_config_.sclk_io_num = pin_config_.sck;
196196
lcd_spi_bus_config_.quadwp_io_num = -1;
197197
lcd_spi_bus_config_.quadhd_io_num = -1;
198-
lcd_spi_bus_config_.max_transfer_sz = frame_buffer_size * sizeof(lv_color_t) + 100;
198+
lcd_spi_bus_config_.max_transfer_sz = SPI_MAX_TRANSFER_BYTES;
199199

200200
memset(&lcd_config_, 0, sizeof(lcd_config_));
201201
lcd_config_.mode = 0;

components/t-deck/include/t-deck.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <driver/gpio.h>
1313
#include <driver/i2s_std.h>
1414
#include <driver/spi_master.h>
15+
#include <hal/spi_ll.h>
1516
#include <hal/spi_types.h>
1617

1718
#include <freertos/FreeRTOS.h>
@@ -61,6 +62,10 @@ class TDeck : public BaseComponent {
6162
/// Alias for the pixel type used by the TDeck display
6263
using Pixel = lv_color16_t;
6364

65+
/// Maximum number of bytes that can be transferred in a single SPI
66+
/// transaction to the Display. 32k on the ESP32-S3.
67+
static constexpr size_t SPI_MAX_TRANSFER_BYTES = SPI_LL_DMA_MAX_BIT_LEN / 8;
68+
6469
/// Alias for the keypress callback for keyboard keypresses.
6570
using keypress_callback_t = TKeyboard::key_cb_fn;
6671

0 commit comments

Comments
 (0)