Add ILI9341 driver
This commit is contained in:
parent
88bbf0609e
commit
80a7369f89
6 changed files with 12873 additions and 16 deletions
4
.gitmodules
vendored
4
.gitmodules
vendored
|
@ -14,3 +14,7 @@
|
|||
path = factory_test/components/i2c-bno055
|
||||
url = git@github.com:Nicolai-Electronics/esp32-component-i2c-bno055.git
|
||||
branch = master
|
||||
[submodule "factory_test/components/spi-ili9341"]
|
||||
path = factory_test/components/spi-ili9341
|
||||
url = git@github.com:Nicolai-Electronics/esp32-component-spi-ili9341.git
|
||||
branch = master
|
||||
|
|
1
factory_test/components/spi-ili9341
Submodule
1
factory_test/components/spi-ili9341
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 39948a19d2e7df58abb5f993e3bac661601722cb
|
|
@ -3,11 +3,13 @@
|
|||
#include <esp_log.h>
|
||||
#include <driver/gpio.h>
|
||||
#include "managed_i2c.h"
|
||||
#include "logo.h"
|
||||
|
||||
static const char *TAG = "hardware";
|
||||
|
||||
PCA9555 pca9555;
|
||||
BNO055 bno055;
|
||||
PCA9555 dev_pca9555 = {0};
|
||||
BNO055 dev_bno055 = {0};
|
||||
ILI9341 dev_ili9341 = {0};
|
||||
|
||||
esp_err_t hardware_init() {
|
||||
esp_err_t res;
|
||||
|
@ -32,6 +34,30 @@ esp_err_t hardware_init() {
|
|||
ESP_LOGE(TAG, "Initializing SPI bus failed");
|
||||
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 = -1;
|
||||
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 = NULL; // Callback for changing LCD mode between ESP32 and FPGA
|
||||
|
||||
res = ili9341_init(&dev_ili9341);
|
||||
if (res != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Initializing LCD failed");
|
||||
return res;
|
||||
}
|
||||
|
||||
// Hack: show logo while the other hardware components initialize
|
||||
res = ili9341_write(&dev_ili9341, logo);
|
||||
if (res != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to write logo to LCD");
|
||||
return res;
|
||||
}
|
||||
|
||||
// System I2C bus
|
||||
res = i2c_init(I2C_BUS_SYS, GPIO_I2C_SYS_SDA, GPIO_I2C_SYS_SCL, I2C_SPEED_SYS, false, false);
|
||||
|
@ -41,7 +67,7 @@ esp_err_t hardware_init() {
|
|||
}
|
||||
|
||||
// PCA9555 IO expander on system I2C bus
|
||||
res = pca9555_init(&pca9555, I2C_BUS_SYS, PCA9555_ADDR, GPIO_INT_PCA9555);
|
||||
res = pca9555_init(&dev_pca9555, I2C_BUS_SYS, PCA9555_ADDR, GPIO_INT_PCA9555);
|
||||
if (res != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Initializing PCA9555 failed");
|
||||
return res;
|
||||
|
@ -49,7 +75,7 @@ esp_err_t hardware_init() {
|
|||
|
||||
// BNO055 sensor on system I2C bus
|
||||
|
||||
res = bno055_init(&bno055, I2C_BUS_SYS, BNO055_ADDR, GPIO_INT_BNO055, true);
|
||||
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;
|
||||
|
@ -66,9 +92,13 @@ esp_err_t hardware_init() {
|
|||
}
|
||||
|
||||
PCA9555* get_pca9555() {
|
||||
return &pca9555;
|
||||
return &dev_pca9555;
|
||||
}
|
||||
|
||||
BNO055* get_bno055() {
|
||||
return &bno055;
|
||||
return &dev_bno055;
|
||||
}
|
||||
|
||||
ILI9341* get_ili9341() {
|
||||
return &dev_ili9341;
|
||||
}
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
#include <driver/spi_master.h>
|
||||
#include "pca9555.h"
|
||||
#include "bno055.h"
|
||||
#include "ili9341.h"
|
||||
|
||||
esp_err_t hardware_init();
|
||||
PCA9555* get_pca9555();
|
||||
BNO055* get_bno055();
|
||||
ILI9341* get_ili9341();
|
||||
|
||||
// Interrupts
|
||||
#define GPIO_INT_STM32 0
|
||||
|
|
12807
factory_test/main/logo.h
Normal file
12807
factory_test/main/logo.h
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,4 +1,5 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sdkconfig.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
|
@ -7,11 +8,12 @@
|
|||
#include <esp_err.h>
|
||||
#include <esp_log.h>
|
||||
#include "hardware.h"
|
||||
#include "pca9555.h"
|
||||
|
||||
static const char *TAG = "main";
|
||||
|
||||
bool calibrate = true;
|
||||
ILI9341* ili9341 = NULL;
|
||||
uint8_t* framebuffer = NULL;
|
||||
|
||||
void button_handler(uint8_t pin, bool value) {
|
||||
switch(pin) {
|
||||
|
@ -117,6 +119,21 @@ void app_main(void) {
|
|||
printf("Failed to initialize hardware!\n");
|
||||
restart();
|
||||
}
|
||||
|
||||
ili9341 = get_ili9341();
|
||||
|
||||
framebuffer = heap_caps_malloc(ILI9341_BUFFER_SIZE, MALLOC_CAP_8BIT);
|
||||
if (framebuffer == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to allocate framebuffer");
|
||||
restart();
|
||||
}
|
||||
|
||||
/*memset(framebuffer, 0, ILI9341_BUFFER_SIZE); // Clear framebuffer
|
||||
res = ili9341_write(ili9341, framebuffer);
|
||||
if (res != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to write framebuffer to LCD");
|
||||
restart();
|
||||
}*/
|
||||
|
||||
/* Print chip information */
|
||||
esp_chip_info_t chip_info;
|
||||
|
@ -145,18 +162,12 @@ void app_main(void) {
|
|||
rotation_offset.z = 0;
|
||||
|
||||
while (1) {
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
/*res = bno055_test(bno055);
|
||||
if (res != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Testing BNO055 failed");
|
||||
continue;
|
||||
}*/
|
||||
|
||||
res = bno055_workaround(bno055);
|
||||
//vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
/*res = bno055_workaround(bno055);
|
||||
if (res != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Workaround failed %d\n", res);
|
||||
continue;
|
||||
}
|
||||
}*/
|
||||
|
||||
/*res = bno055_get_vector(bno055, BNO055_VECTOR_ACCELEROMETER, &acceleration);
|
||||
if (res != ESP_OK) {
|
||||
|
@ -215,4 +226,6 @@ void app_main(void) {
|
|||
|
||||
printf("Magnetic (uT) x: %5.4f y: %5.4f z: %5.4f Rotation (deg): x: %5.4f y: %5.4f z: %5.4f \n", magnetism.x, magnetism.y, magnetism.z, rotation.x, rotation.y, rotation.z);
|
||||
}
|
||||
|
||||
free(framebuffer);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue