From 5ec8d0b912321eb1ec6d6a3b184e74472031e33b Mon Sep 17 00:00:00 2001 From: Renze Nicolai Date: Sun, 15 May 2022 02:51:51 +0200 Subject: [PATCH 1/4] Remove board support component --- components/mch2022-bsp/CMakeLists.txt | 13 -- components/mch2022-bsp/hardware.c | 229 -------------------------- components/mch2022-bsp/hardware.h | 66 -------- 3 files changed, 308 deletions(-) delete mode 100644 components/mch2022-bsp/CMakeLists.txt delete mode 100644 components/mch2022-bsp/hardware.c delete mode 100644 components/mch2022-bsp/hardware.h diff --git a/components/mch2022-bsp/CMakeLists.txt b/components/mch2022-bsp/CMakeLists.txt deleted file mode 100644 index 4fc355c..0000000 --- a/components/mch2022-bsp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -idf_component_register( - SRCS "hardware.c" - INCLUDE_DIRS "." - REQUIRES - "appfs" - "bus-i2c" - "i2c-bno055" - "pax-graphics" - "sdcard" - "spi-ice40" - "spi-ili9341" - "mch2022-rp2040" -) diff --git a/components/mch2022-bsp/hardware.c b/components/mch2022-bsp/hardware.c deleted file mode 100644 index 3bb672a..0000000 --- a/components/mch2022-bsp/hardware.c +++ /dev/null @@ -1,229 +0,0 @@ -#include "hardware.h" -#include -#include -#include -#include "managed_i2c.h" -#include "sdcard.h" -#include "rp2040.h" - -static const char *TAG = "hardware"; - -static BNO055 dev_bno055 = {0}; -static ILI9341 dev_ili9341 = {0}; -static ICE40 dev_ice40 = {0}; -static RP2040 dev_rp2040 = {0}; - -static uint8_t rp2040_fw_version = 0; - -static bool bsp_ready = false; -static bool rp2040_ready = false; -static bool ice40_ready = false; -static bool bno055_ready = false; - -esp_err_t ice40_get_done_wrapper(bool* done) { - uint16_t buttons; - esp_err_t res = rp2040_read_buttons(&dev_rp2040, &buttons); - if (res != ESP_OK) return res; - *done = !((buttons >> 5) & 0x01); - printf("FPGA done is %u\n", *done); - return ESP_OK; -} - -esp_err_t ice40_set_reset_wrapper(bool reset) { - printf("FPGA reset set to %u\n", reset); - esp_err_t res = rp2040_set_fpga(&dev_rp2040, reset); - vTaskDelay(100 / portTICK_PERIOD_MS); - return res; -} - -void ili9341_set_lcd_mode(bool mode) { - ESP_LOGI(TAG, "LCD mode switch to %s", mode ? "FPGA" : "ESP32"); - esp_err_t res = gpio_set_level(GPIO_LCD_MODE, mode); - if (res != ESP_OK) { - ESP_LOGE(TAG, "Setting LCD mode failed"); - } -} - -static esp_err_t _bus_init() { - esp_err_t res; - - // I2C bus - res = i2c_init(I2C_BUS_SYS, GPIO_I2C_SYS_SDA, GPIO_I2C_SYS_SCL, I2C_SPEED_SYS, false, false); - if (res != ESP_OK) { - ESP_LOGE(TAG, "Initializing system I2C bus failed"); - return res; - } - - // SPI bus - spi_bus_config_t busConfiguration = {0}; - busConfiguration.mosi_io_num = GPIO_SPI_MOSI; - busConfiguration.miso_io_num = GPIO_SPI_MISO; - busConfiguration.sclk_io_num = GPIO_SPI_CLK; - busConfiguration.quadwp_io_num = -1; - busConfiguration.quadhd_io_num = -1; - busConfiguration.max_transfer_sz = SPI_MAX_TRANSFER_SIZE; - res = spi_bus_initialize(SPI_BUS, &busConfiguration, SPI_DMA_CHANNEL); - if (res != ESP_OK) { - ESP_LOGE(TAG, "Initializing SPI bus failed"); - return res; - } - - return ESP_OK; -} - -/* BSP init - * - * This function initializes the interrupt handling service, the SPI and I2C busses and the LCD display. - * After running this function information can be displayed to the user via the display. - * - */ - -esp_err_t bsp_init() { - if (bsp_ready) return ESP_OK; - - esp_err_t res; - - // Interrupts - res = gpio_install_isr_service(0); - if (res != ESP_OK) { - ESP_LOGE(TAG, "Initializing ISR service failed"); - return res; - } - - // Communication busses - res = _bus_init(); - if (res != ESP_OK) return res; - - // LCD display - dev_ili9341.spi_bus = SPI_BUS; - dev_ili9341.pin_cs = GPIO_SPI_CS_LCD; - dev_ili9341.pin_dcx = GPIO_SPI_DC_LCD; - dev_ili9341.pin_reset = GPIO_LCD_RESET; - dev_ili9341.rotation = 1; - dev_ili9341.color_mode = true; // Blue and red channels are swapped - dev_ili9341.spi_speed = 60000000; // 60MHz - dev_ili9341.spi_max_transfer_size = SPI_MAX_TRANSFER_SIZE; - dev_ili9341.callback = ili9341_set_lcd_mode; // Callback for changing LCD mode between ESP32 and FPGA - - res = gpio_set_direction(GPIO_LCD_MODE, GPIO_MODE_OUTPUT); - if (res != ESP_OK) { - ESP_LOGE(TAG, "Initializing LCD mode GPIO failed"); - return res; - } - - res = ili9341_init(&dev_ili9341); - if (res != ESP_OK) { - ESP_LOGE(TAG, "Initializing LCD failed"); - return res; - } - - bsp_ready = true; - return ESP_OK; -} - -/* RP2040 init - * - * This function initializes communication with the RP2040 co-processor. - * After running this function the buttons, backlight control and FPGA management functions will be available for use. - * - */ - -esp_err_t bsp_rp2040_init() { - if (!bsp_ready) return ESP_FAIL; - if (rp2040_ready) return ESP_OK; - - // RP2040 co-processor - dev_rp2040.i2c_bus = I2C_BUS_SYS; - dev_rp2040.i2c_address = RP2040_ADDR; - dev_rp2040.pin_interrupt = GPIO_INT_RP2040; - dev_rp2040.queue = xQueueCreate(8, sizeof(rp2040_input_message_t)); - - esp_err_t res = rp2040_init(&dev_rp2040); - if (res != ESP_OK) { - ESP_LOGE(TAG, "Initializing RP2040 failed"); - return res; - } - - if (rp2040_get_firmware_version(&dev_rp2040, &rp2040_fw_version) != ESP_OK) { - ESP_LOGE(TAG, "Initializing RP2040 failed to read firmware version"); - return ESP_FAIL; - } - - rp2040_ready = true; - return ESP_OK; -} - -/* RP2040 init - * - * This function initializes the ICE40 FPGA - * After running this function the FPGA will be kept in reset state until a bitstream is loaded - * - */ - -esp_err_t bsp_ice40_init() { - if (!bsp_ready) return ESP_FAIL; - if (!rp2040_ready) return ESP_FAIL; - if (rp2040_fw_version == 0xFF) return ESP_FAIL; // The ICE40 FPGA can only be controlled when the RP2040 is not in bootloader mode - if (ice40_ready) return ESP_OK; - - dev_ice40.spi_bus = SPI_BUS; - dev_ice40.pin_cs = GPIO_SPI_CS_FPGA; - dev_ice40.pin_done = -1; - dev_ice40.pin_reset = -1; - dev_ice40.pin_int = GPIO_INT_FPGA; - dev_ice40.spi_speed_full_duplex = 26700000; - dev_ice40.spi_speed_half_duplex = 40000000; - dev_ice40.spi_max_transfer_size = SPI_MAX_TRANSFER_SIZE; - dev_ice40.get_done = ice40_get_done_wrapper; - dev_ice40.set_reset = ice40_set_reset_wrapper; - - esp_err_t res = ice40_init(&dev_ice40); - if (res != ESP_OK) { - ESP_LOGE(TAG, "Initializing FPGA failed"); - return res; - } - - ice40_ready = true; - return ESP_OK; -} - -/* BNO055 init - * - * This function initializes the BNO055 position sensor - * After running this function the position sensor can be used - * - */ - -esp_err_t bsp_bno055_init() { - if (!bsp_ready) return ESP_FAIL; - if (bno055_ready) return ESP_OK; - - esp_err_t res = bno055_init(&dev_bno055, I2C_BUS_SYS, BNO055_ADDR, GPIO_INT_BNO055, true); - if (res != ESP_OK) { - ESP_LOGE(TAG, "Initializing BNO055 failed"); - return res; - } - - bno055_ready = true; - return ESP_OK; -} - -ILI9341* get_ili9341() { - if (!bsp_ready) return NULL; - return &dev_ili9341; -} - -RP2040* get_rp2040() { - if (!rp2040_ready) return NULL; - return &dev_rp2040; -} - -ICE40* get_ice40() { - if (!ice40_ready) return NULL; - return &dev_ice40; -} - -BNO055* get_bno055() { - if (!bno055_ready) return NULL; - return &dev_bno055; -} diff --git a/components/mch2022-bsp/hardware.h b/components/mch2022-bsp/hardware.h deleted file mode 100644 index e74706c..0000000 --- a/components/mch2022-bsp/hardware.h +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once - -#include -#include -#include -#include "bno055.h" -#include "ili9341.h" -#include "ice40.h" -#include "rp2040.h" - -// Interrupts -#define GPIO_INT_RP2040 34 -#define GPIO_INT_BNO055 36 -#define GPIO_INT_FPGA 39 - -// SD card -#define SD_PWR 19 // Also LED power -#define SD_D0 2 -#define SD_CLK 14 -#define SD_CMD 15 - -// LEDs -#define GPIO_LED_DATA 5 - -// I2S audio -#define GPIO_I2S_CLK 14 -#define GPIO_I2S_DATA 13 -#define GPIO_I2S_LR 4 - -// I2C bus -#define GPIO_I2C_SYS_SCL 21 -#define GPIO_I2C_SYS_SDA 22 -#define I2C_BUS_SYS 0 -#define I2C_SPEED_SYS 8000 // 8 kHz //20000 // 20 kHz - -// RP2040 co-processor -#define RP2040_ADDR 0x17 - -// BNO055 sensor -#define BNO055_ADDR 0x28 - -// SPI bus -#define GPIO_SPI_CLK 18 -#define GPIO_SPI_MOSI 23 -#define GPIO_SPI_MISO 35 -#define GPIO_SPI_CS_RP2040 19 -#define GPIO_SPI_CS_FPGA 27 -#define SPI_BUS VSPI_HOST -#define SPI_MAX_TRANSFER_SIZE 4094 -#define SPI_DMA_CHANNEL 2 - -// LCD display -#define GPIO_LCD_RESET 25 -#define GPIO_LCD_MODE 26 -#define GPIO_SPI_CS_LCD 32 -#define GPIO_SPI_DC_LCD 33 - -esp_err_t bsp_init(); -esp_err_t bsp_rp2040_init(); -esp_err_t bsp_ice40_init(); -esp_err_t bsp_bno055_init(); - -ILI9341* get_ili9341(); -RP2040* get_rp2040(); -ICE40* get_ice40(); -BNO055* get_bno055(); From 7d49cee64819895edef8d838b31376c1f9a60bd0 Mon Sep 17 00:00:00 2001 From: Renze Nicolai Date: Sun, 15 May 2022 02:52:09 +0200 Subject: [PATCH 2/4] Add board support component submodule --- .gitmodules | 3 +++ components/mch2022-bsp | 1 + 2 files changed, 4 insertions(+) create mode 160000 components/mch2022-bsp diff --git a/.gitmodules b/.gitmodules index d632ee0..9801f03 100644 --- a/.gitmodules +++ b/.gitmodules @@ -31,3 +31,6 @@ [submodule "components/mch2022-efuse"] path = components/mch2022-efuse url = https://github.com/badgeteam/esp32-component-mch2022-efuse.git +[submodule "components/mch2022-bsp"] + path = components/mch2022-bsp + url = https://github.com/badgeteam/esp32-component-mch2022-bsp.git diff --git a/components/mch2022-bsp b/components/mch2022-bsp new file mode 160000 index 0000000..a9249a4 --- /dev/null +++ b/components/mch2022-bsp @@ -0,0 +1 @@ +Subproject commit a9249a495ff988c40ee45bfd324a9ed16e0eed80 From f25278d3d962353be3242836d4eea76ef6c482e7 Mon Sep 17 00:00:00 2001 From: Renze Nicolai Date: Sun, 15 May 2022 02:59:35 +0200 Subject: [PATCH 3/4] Update bsp submodule --- components/mch2022-bsp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/mch2022-bsp b/components/mch2022-bsp index a9249a4..bfe0cc2 160000 --- a/components/mch2022-bsp +++ b/components/mch2022-bsp @@ -1 +1 @@ -Subproject commit a9249a495ff988c40ee45bfd324a9ed16e0eed80 +Subproject commit bfe0cc2bdbebcd7af82dbb58151b6c112e97efce From 247b0a269de0dc00097153a6d651b27f0ca7fa29 Mon Sep 17 00:00:00 2001 From: Renze Nicolai Date: Sun, 15 May 2022 03:02:49 +0200 Subject: [PATCH 4/4] Update names of SD card GPIO pins --- main/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/main.c b/main/main.c index 0987068..3e71a42 100644 --- a/main/main.c +++ b/main/main.c @@ -708,7 +708,7 @@ void app_main(void) { } /* Start SD card filesystem */ - res = mount_sd(SD_CMD, SD_CLK, SD_D0, SD_PWR, "/sd", false, 5); + res = mount_sd(GPIO_SD_CMD, GPIO_SD_CLK, GPIO_SD_D0, GPIO_SD_PWR, "/sd", false, 5); bool sdcard_ready = (res == ESP_OK); if (sdcard_ready) { ESP_LOGI(TAG, "SD card filesystem mounted");