Add first pass of SPI LCD logic
This commit is contained in:
+1
-1
@@ -1,3 +1,3 @@
|
||||
idf_component_register(SRCS "spincoat-plater-firmware.c" "dshot_esc_encoder.c"
|
||||
PRIV_REQUIRES esp_driver_rmt esp_driver_uart
|
||||
PRIV_REQUIRES esp_driver_rmt esp_driver_gpio esp_driver_uart esp_driver_spi esp_lcd
|
||||
INCLUDE_DIRS ".")
|
||||
|
||||
@@ -9,4 +9,45 @@ menu "Pin Mapping Configuration"
|
||||
default 27
|
||||
help
|
||||
This is the pin used for receiving UART telemetry from the ESC.
|
||||
config TFT_MISO_PIN
|
||||
int "SPI LCD MISO pin"
|
||||
default 12
|
||||
help
|
||||
This is the pin for MISO on the SPI LCD.
|
||||
config TFT_MOSI_PIN
|
||||
int "SPI LCD MOSI pin"
|
||||
default 13
|
||||
help
|
||||
This is the pin for MOSI on the SPI LCD.
|
||||
config TFT_SCKL_PIN
|
||||
int "SPI LCD SCKL pin"
|
||||
default 14
|
||||
help
|
||||
This is the pin for SCKL on the SPI LCD.
|
||||
config TFT_CS_PIN
|
||||
int "SPI LCD CS pin"
|
||||
default 15
|
||||
help
|
||||
This is the pin for CS on the SPI LCD.
|
||||
config TFT_DC_PIN
|
||||
int "SPI LCD DC pin"
|
||||
default 2
|
||||
help
|
||||
This is the pin for DC on the SPI LCD.
|
||||
config TFT_BL_PIN
|
||||
int "SPI LCD BL (backlight) pin"
|
||||
default 21
|
||||
help
|
||||
This is the pin for backlight control on the SPI LCD.
|
||||
config TFT_HRES
|
||||
int "The horizontal resolution of the TFT display"
|
||||
default 320
|
||||
help
|
||||
This is the horizontal resolution for the front-panel SPI LCD
|
||||
config TFT_VRES
|
||||
int "The vertical resolution of the TFT display"
|
||||
default 240
|
||||
help
|
||||
This is the vertical resolution for the front-panel SPI LCD
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
## IDF Component Manager Manifest File
|
||||
dependencies:
|
||||
## Required IDF version
|
||||
idf:
|
||||
version: '>=4.1.0'
|
||||
# # Put list of dependencies here
|
||||
# # For components maintained by Espressif:
|
||||
# component: "~1.0.0"
|
||||
# # For 3rd party components:
|
||||
# username/component: ">=1.0.0,<2.0.0"
|
||||
# username2/component2:
|
||||
# version: "~1.0.0"
|
||||
# # For transient dependencies `public` flag can be set.
|
||||
# # `public` flag doesn't have an effect dependencies of the `main` component.
|
||||
# # All dependencies of `main` are public by default.
|
||||
# public: true
|
||||
espressif/esp_lcd_ili9341: ^2.0.0
|
||||
@@ -8,9 +8,18 @@
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "driver/rmt_tx.h"
|
||||
#include "driver/uart.h"
|
||||
#include "driver/gpio.h"
|
||||
|
||||
#include "hal/spi_types.h"
|
||||
#include "esp_lcd_panel_ops.h"
|
||||
#include "driver/spi_common.h"
|
||||
#include "esp_lcd_panel_io.h"
|
||||
#include "esp_lcd_ili9341.h"
|
||||
|
||||
#include "dshot_esc_encoder.h"
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32H2
|
||||
@@ -18,9 +27,20 @@
|
||||
#else
|
||||
#define DSHOT_ESC_RESOLUTION_HZ 40000000 // 40MHz resolution, DSHot protocol needs a relative high resolution
|
||||
#endif
|
||||
|
||||
#define GPIO_ESC_CTRL CONFIG_ESC_CTRL_PIN
|
||||
#define GPIO_ESC_RX CONFIG_TELEMETRY_RX_PIN
|
||||
#define UART_NUM UART_NUM_2
|
||||
#define LCD_SPI_HOST SPI2_HOST
|
||||
|
||||
#define GPIO_TFT_MISO CONFIG_TFT_MISO_PIN
|
||||
#define GPIO_TFT_MOSI CONFIG_TFT_MOSI_PIN
|
||||
#define GPIO_TFT_SCKL CONFIG_TFT_SCKL_PIN
|
||||
#define GPIO_TFT_CS CONFIG_TFT_CS_PIN
|
||||
#define GPIO_TFT_DC CONFIG_TFT_DC_PIN
|
||||
#define GPIO_TFT_BL CONFIG_TFT_BL_PIN // Backlight
|
||||
#define TFT_HRES CONFIG_TFT_HRES
|
||||
#define TFT_VRES CONFIG_TFT_VRES
|
||||
|
||||
#define ESP_INTR_FLAG_DEFAULT 0
|
||||
|
||||
@@ -117,6 +137,58 @@ void init_telemetry_uart_rx(void) {
|
||||
ESP_ERROR_CHECK(uart_set_pin(UART_NUM, UART_PIN_NO_CHANGE, GPIO_ESC_RX, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
|
||||
}
|
||||
|
||||
void spi_lcd_transfer_done(void) {
|
||||
return;
|
||||
}
|
||||
|
||||
void init_spi_lcd(void) {
|
||||
ESP_LOGI(TAG, "Initialize SPI bus");
|
||||
// TODO might need to replace with another config var
|
||||
const spi_bus_config_t bus_config = ILI9341_PANEL_BUS_SPI_CONFIG(GPIO_TFT_SCKL,
|
||||
GPIO_TFT_MOSI,
|
||||
TFT_HRES * TFT_VRES * sizeof(uint16_t));
|
||||
ESP_ERROR_CHECK(spi_bus_initialize(LCD_SPI_HOST, &bus_config, SPI_DMA_CH_AUTO));
|
||||
|
||||
ESP_LOGI(TAG, "Install panel IO");
|
||||
esp_lcd_panel_io_handle_t io_handle = NULL;
|
||||
const esp_lcd_panel_io_spi_config_t io_config = ILI9341_PANEL_IO_SPI_CONFIG(GPIO_TFT_CS, GPIO_TFT_DC,
|
||||
NULL, NULL);
|
||||
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)LCD_SPI_HOST, &io_config, &io_handle));
|
||||
|
||||
ESP_LOGI(TAG, "Install ILI9341 panel driver");
|
||||
esp_lcd_panel_handle_t panel_handle = NULL;
|
||||
const esp_lcd_panel_dev_config_t panel_config = {
|
||||
.reset_gpio_num = -1,
|
||||
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,
|
||||
.bits_per_pixel = 16,
|
||||
};
|
||||
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_ili9341(io_handle, &panel_config, &panel_handle));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true));
|
||||
|
||||
ESP_LOGI(TAG, "Turning on backlight");
|
||||
printf("Configured pin is reported as %d\n", CONFIG_TFT_BL_PIN);
|
||||
// TODO: This pin isn't going high. Configure it properly.
|
||||
|
||||
gpio_config_t io_conf = {
|
||||
.pin_bit_mask = (1ULL << GPIO_TFT_BL),
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pull_up_en = GPIO_PULLUP_ENABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_DISABLE
|
||||
};
|
||||
|
||||
gpio_config(&io_conf);
|
||||
|
||||
//gpio_reset_pin(GPIO_TFT_BL);
|
||||
//gpio_set_direction(GPIO_TFT_BL, GPIO_MODE_OUTPUT);
|
||||
ESP_ERROR_CHECK(gpio_set_level(GPIO_TFT_BL, 1));
|
||||
ESP_LOGI(TAG, "Finished init of spi LCD.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a DSHOT packet via the RMT. Make sure the RMT channel has been initialized
|
||||
* by calling *init_rmt_esc_tx()*
|
||||
@@ -187,6 +259,8 @@ void parse_telemetry(void) {
|
||||
}
|
||||
|
||||
void app_main(void) {
|
||||
init_spi_lcd();
|
||||
|
||||
init_rmt_esc_tx();
|
||||
throttle.throttle = 300;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user