From 1514265f483e0a66618372297f5db7bfa0787f4f Mon Sep 17 00:00:00 2001 From: Malte Heinzelmann Date: Wed, 5 Jun 2024 12:13:35 +0200 Subject: [PATCH] Working on the driver --- components/spi-st77xx/include/st77xx.h | 1 - components/spi-st77xx/st77xx.c | 21 ++++++++------------- main/audio.c | 2 +- main/main.c | 6 +++++- main/nametag.c | 2 +- sdkconfig | 9 ++++----- 6 files changed, 19 insertions(+), 22 deletions(-) diff --git a/components/spi-st77xx/include/st77xx.h b/components/spi-st77xx/include/st77xx.h index b02f206..6abe3da 100644 --- a/components/spi-st77xx/include/st77xx.h +++ b/components/spi-st77xx/include/st77xx.h @@ -135,7 +135,6 @@ typedef struct ST77XX { // Configuration uint8_t rotation; bool color_mode; - bool reset_external_pullup; uint32_t spi_speed; uint32_t spi_max_transfer_size; ST77XX_cb_t callback; diff --git a/components/spi-st77xx/st77xx.c b/components/spi-st77xx/st77xx.c index 45adf4d..1a4a2a2 100644 --- a/components/spi-st77xx/st77xx.c +++ b/components/spi-st77xx/st77xx.c @@ -69,7 +69,6 @@ const uint8_t st77xx_init_data[] = { ST77XX_RASET, 4, 0x00, 0x00, 0x01, 0x3F, // Display on ST77XX_DISPON, 0, - 0x00 }; esp_err_t ST7789VI_send(ST77XX* device, const uint8_t *data, const int len,const bool dc_level) { @@ -164,17 +163,18 @@ esp_err_t st77xx_reset(ST77XX* device) { return ESP_OK; } -esp_err_t st77xx_write_init_data(ST77XX* device, const uint8_t * data) { +esp_err_t st77xx_write_init_data(ST77XX* device, const uint8_t * data, size_t size) { if (device->spi_device == NULL) return ESP_FAIL; esp_err_t res; uint8_t cmd, len; - while(true) { + for (int i = 0; i < size; i++) { cmd = *data++; - if (!cmd) return ESP_OK; //END len = *data++; + ESP_LOGD(TAG, "Sending command %x", cmd); res = st77xx_send_command(device, cmd); if (res != ESP_OK) break; if (len > 0) { + ESP_LOGD(TAG, "Sending %d bytes of data", len); res = st77xx_send_data(device, data, len); if (res != ESP_OK) break; } @@ -189,6 +189,7 @@ esp_err_t st77xx_init(ST77XX* device) { if (device->pin_dcx < 0) return ESP_FAIL; if (device->pin_cs < 0) return ESP_FAIL; + if (device->pin_reset < 0) return ESP_FAIL; /*if (device->mutex == NULL) { device->mutex = xSemaphoreCreateMutex(); @@ -199,13 +200,8 @@ esp_err_t st77xx_init(ST77XX* device) { res = gpio_set_direction(device->pin_dcx, GPIO_MODE_OUTPUT); if (res != ESP_OK) return res; - if (!device->reset_external_pullup && device->pin_reset >= 0) { - res = gpio_hold_dis(device->pin_reset); - if (res != ESP_OK) return res; - - res = gpio_set_direction(device->pin_reset, GPIO_MODE_OUTPUT); - if (res != ESP_OK) return res; - } + res = gpio_set_direction(device->pin_reset, GPIO_MODE_OUTPUT); + if (res != ESP_OK) return res; res = gpio_set_level(device->pin_dcx, true); if (res != ESP_OK) return res; @@ -236,7 +232,6 @@ esp_err_t st77xx_init(ST77XX* device) { device->callback(false); } - ESP_LOGE(TAG, "IO Setup complete "); //Reset the LCD display @@ -246,7 +241,7 @@ esp_err_t st77xx_init(ST77XX* device) { ESP_LOGE(TAG, "DC pin %d", device->pin_dcx); //Send the initialization data to the LCD display - res = st77xx_write_init_data(device, st77xx_init_data); + res = st77xx_write_init_data(device, st77xx_init_data, sizeof(st77xx_init_data) / sizeof(st77xx_init_data[0])); if (res != ESP_OK) return res; diff --git a/main/audio.c b/main/audio.c index 8926d36..a10b780 100644 --- a/main/audio.c +++ b/main/audio.c @@ -24,7 +24,7 @@ void _audio_init(int i2s_num) { i2s_driver_install(i2s_num, &i2s_config, 0, NULL); - i2s_pin_config_t pin_config = {.bck_io_num = GPIO_I2S_BCLK, .ws_io_num = GPIO_I2S_WS, .data_out_num = GPIO_I2S_DATA, .data_in_num = I2S_PIN_NO_CHANGE}; + i2s_pin_config_t pin_config = {.mck_io_num = -1, .bck_io_num = GPIO_I2S_BCLK, .ws_io_num = GPIO_I2S_WS, .data_out_num = GPIO_I2S_DATA, .data_in_num = I2S_PIN_NO_CHANGE}; i2s_set_pin(i2s_num, &pin_config); } diff --git a/main/main.c b/main/main.c index fca48e3..73369d9 100644 --- a/main/main.c +++ b/main/main.c @@ -100,7 +100,7 @@ static void ntp_sync_task(void* pvParameters) { static void audio_player_task(void* pvParameters) { vTaskDelay(pdMS_TO_TICKS(500)); - play_bootsound(); +// play_bootsound(); uint8_t leds[AMOUNT_OF_LEDS * 3] = {0}; for (uint8_t led = 0; led < AMOUNT_OF_LEDS; led++) { for (uint8_t part = 0; part <= 50; part++) { @@ -187,6 +187,7 @@ _Noreturn void app_main(void) { pca9555_set_gpio_value(io_expander, IO_AMP_GAIN1, 1); /* Turning the backlight on */ +#ifdef TR23 gpio_config_t io_conf = { .intr_type = GPIO_INTR_DISABLE, .mode = GPIO_MODE_OUTPUT, @@ -207,6 +208,9 @@ _Noreturn void app_main(void) { display_fatal_error(fatal_error_str, "Failed to turn on LCD backlight", "Flash may be corrupted", reset_board_str); stop(); } +#else + st77xx_backlight(true); +#endif /* Initialize LCD screen */ pax_buf_t* pax_buffer = get_pax_buffer(); diff --git a/main/nametag.c b/main/nametag.c index 23bdbbb..a77fcbb 100644 --- a/main/nametag.c +++ b/main/nametag.c @@ -131,8 +131,8 @@ static void place_in_sleep(xQueueHandle button_queue) { fflush(stdout); fflush(stderr); vTaskDelay(pdMS_TO_TICKS(100)); - gpio_hold_en(GPIO_LCD_BL); #ifdef TR23 + gpio_hold_en(GPIO_LCD_BL); ili9341_power_en(get_ili9341()); #endif gpio_deep_sleep_hold_en(); diff --git a/sdkconfig b/sdkconfig index 040b98d..78ecefc 100644 --- a/sdkconfig +++ b/sdkconfig @@ -834,14 +834,13 @@ CONFIG_HEAP_TRACING_OFF=y # CONFIG_LOG_DEFAULT_LEVEL_NONE is not set # CONFIG_LOG_DEFAULT_LEVEL_ERROR is not set # CONFIG_LOG_DEFAULT_LEVEL_WARN is not set -CONFIG_LOG_DEFAULT_LEVEL_INFO=y -# CONFIG_LOG_DEFAULT_LEVEL_DEBUG is not set +# CONFIG_LOG_DEFAULT_LEVEL_INFO is not set +CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y # CONFIG_LOG_DEFAULT_LEVEL_VERBOSE is not set -CONFIG_LOG_DEFAULT_LEVEL=3 +CONFIG_LOG_DEFAULT_LEVEL=4 CONFIG_LOG_MAXIMUM_EQUALS_DEFAULT=y -# CONFIG_LOG_MAXIMUM_LEVEL_DEBUG is not set # CONFIG_LOG_MAXIMUM_LEVEL_VERBOSE is not set -CONFIG_LOG_MAXIMUM_LEVEL=3 +CONFIG_LOG_MAXIMUM_LEVEL=4 CONFIG_LOG_COLORS=y CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y # CONFIG_LOG_TIMESTAMP_SOURCE_SYSTEM is not set