diff --git a/components/keyboard b/components/keyboard index b2b2c11..76cf073 160000 --- a/components/keyboard +++ b/components/keyboard @@ -1 +1 @@ -Subproject commit b2b2c11a05ec056dc153b702fb8ccc35a795701d +Subproject commit 76cf073ad933a19c8e2c88d69a073e7555653a67 diff --git a/components/spi-st77xx/include/st77xx.h b/components/spi-st77xx/include/st77xx.h index d9d3aea..a8acb50 100644 --- a/components/spi-st77xx/include/st77xx.h +++ b/components/spi-st77xx/include/st77xx.h @@ -140,7 +140,6 @@ typedef struct ST77XX { ST77XX_cb_t callback; // Internal state spi_device_handle_t spi_device; - bool dc_level; // Mutex SemaphoreHandle_t mutex; SemaphoreHandle_t spi_semaphore; @@ -149,21 +148,11 @@ typedef struct ST77XX { esp_err_t st77xx_init(ST77XX* device); esp_err_t st77xx_deinit(ST77XX* device); -esp_err_t st77xx_set_sleep(ST77XX* device, const bool state); esp_err_t st77xx_set_display(ST77XX* device, const bool state); -esp_err_t st77xx_set_invert(ST77XX* device, const bool state); -esp_err_t st77xx_set_partial_scanning(ST77XX* device, const uint16_t start, const uint16_t end); -esp_err_t st77xx_set_tearing_effect_line(ST77XX* device, const bool state); -esp_err_t st77xx_set_idle_mode(ST77XX* device, const bool state); esp_err_t st77xx_set_cfg(ST77XX* device, uint8_t rotation, bool color_mode); esp_err_t st77xx_write(ST77XX* device, const uint8_t *data); esp_err_t st77xx_write_partial_direct(ST77XX* device, const uint8_t *buffer, uint16_t x, uint16_t y, uint16_t width, uint16_t height); -esp_err_t st77xx_write_partial(ST77XX* device, const uint8_t *buffer, uint16_t x, uint16_t y, uint16_t width, uint16_t height); - -esp_err_t st77xx_select(ST77XX* device, const bool mode); - -esp_err_t st77xx_power_en(ST77XX* device); #ifdef __cplusplus } diff --git a/components/spi-st77xx/st77xx.c b/components/spi-st77xx/st77xx.c index a6ef342..506d912 100644 --- a/components/spi-st77xx/st77xx.c +++ b/components/spi-st77xx/st77xx.c @@ -39,8 +39,8 @@ const uint8_t st77xx_init_data[] = { ST77XX_SLPOUT, 0, // MADCTL: memory data access control Old: 0x88 ST77XX_MADCTL, 1, 0xa8, /* Page address order RGB order */ - // COLMOD: Interface Pixel format (18-bits per pixel @ 262K colors) - ST77XX_COLMOD, 1, 0x55, /* 18 bits per pixel, 262k of RGB interface */ + // COLMOD: Interface Pixel format (16-bits per pixel) + ST77XX_COLMOD, 1, 0x55, /* 16 bits per pixel */ // PORCTRK: Porch setting ST77XX_PORCTRK, 5, 0x0C, 0x0C, 0x00, 0x33, 0x33, /* Back porch, Front Porch, Separate porch control, Back porch idle, Back porch partial */ // GCTRL: Gate Control @@ -72,11 +72,9 @@ const uint8_t st77xx_init_data[] = { 0x00, }; -esp_err_t ST7789VI_send(ST77XX* device, const uint8_t *data, const int len,const bool dc_level) { +esp_err_t st77xx_send(ST77XX* device, const uint8_t *data, const int len) { if (len == 0) return ESP_OK; if (device->spi_device == NULL) return ESP_FAIL; - - device->dc_level = dc_level; /* TODO: This is currently disabled, maybe put back?*/ spi_transaction_t transaction = { .length = len * 8, // transaction length is in bits .tx_buffer = data, @@ -93,7 +91,7 @@ esp_err_t st77xx_send_command(ST77XX* device, const uint8_t cmd) { esp_err_t err; gpio_set_level(device->pin_dcx, 0); - err = ST7789VI_send(device, &cmd, 1, false); + err = st77xx_send(device, &cmd, 1); return err; } @@ -101,66 +99,32 @@ esp_err_t st77xx_send_data(ST77XX* device, const uint8_t* data, const uint16_t l { esp_err_t err; gpio_set_level(device->pin_dcx, 1); - err = ST7789VI_send(device, data, length,true); + err = st77xx_send(device, data, length); return err; } -//esp_err_t st77xx_reset(ST77XX* device) { -// if (device->mutex != NULL) xSemaphoreTake(device->mutex, portMAX_DELAY); -// esp_err_t res; -// if (device->pin_reset >= 0) { -// ESP_LOGI(TAG, "reset"); -// if (device->reset_external_pullup) { -// res = gpio_set_level(device->pin_reset, false); /* Checked 24 */ -// if (res != ESP_OK) return res; -// res = gpio_set_direction(device->pin_reset, GPIO_MODE_OUTPUT); /* Checked 24 */ -// if (res != ESP_OK) return res; -// vTaskDelay(50 / portTICK_PERIOD_MS); /* Checked 24 */ -// res = gpio_set_direction(device->pin_reset, GPIO_MODE_INPUT); /* Checked 24 */ -// if (res != ESP_OK) return res; -// vTaskDelay(50 / portTICK_PERIOD_MS); -// } else { -// res = gpio_set_level(device->pin_reset, false); -// if (res != ESP_OK) return res; -// vTaskDelay(50 / portTICK_PERIOD_MS); -// ESP_LOGI(TAG, "setting reset line to high"); -// res = gpio_set_level(device->pin_reset, true); -// if (res != ESP_OK) return res; -// vTaskDelay(50 / portTICK_PERIOD_MS); -// } -// } else { -// ESP_LOGI(TAG, "(no reset pin available)"); -// vTaskDelay(100 / portTICK_PERIOD_MS); -// } -// -// if (device->mutex != NULL) xSemaphoreGive(device->mutex); -// return ESP_OK; -//} - -uint8_t temp_fb [240 * 3]; - -uint8_t colour_bars [5][3] = { - {0xFF, 0x00, 0x00}, - {0x00, 0xFF, 0x00}, - {0x00, 0x00, 0xFF}, - {0xFF, 0xFF, 0x00}, - {0xFF, 0x00, 0xFF} -}; - esp_err_t st77xx_reset(ST77XX* device) { + if (device->mutex != NULL) xSemaphoreTake(device->mutex, portMAX_DELAY); esp_err_t res; res = gpio_set_level(device->pin_reset, false); - if (res != ESP_OK) return res; + if (res != ESP_OK) { + if (device->mutex != NULL) xSemaphoreGive(device->mutex); + return res; + } vTaskDelay(50 / portTICK_PERIOD_MS); res = gpio_set_level(device->pin_reset, true); - if (res != ESP_OK) return res; + if (res != ESP_OK) { + if (device->mutex != NULL) xSemaphoreGive(device->mutex); + return res; + } vTaskDelay(120 / portTICK_PERIOD_MS); /* This could possibly be shorter if a problem. */ ESP_LOGD(TAG, "Reset done"); + if (device->mutex != NULL) xSemaphoreGive(device->mutex); return ESP_OK; } @@ -264,88 +228,20 @@ esp_err_t st77xx_init(ST77XX* device) { res = st77xx_write_init_data(device, st77xx_init_data); if (res != ESP_OK) return res; -// res = st77xx_set_cfg(device, device->rotation, device->color_mode); -// if (res != ESP_OK) return res; - - - -// st77xx_send_command(device, ST77XX_RAMWR); /* Ram Write*/ -// for (uint32_t j = 0; j < 240; j++) -// { -//// temp_fb[j * 3] = 0xff; //colour_bars[j/5][0]; -//// temp_fb[j * 3 + 1] = 0x00;// colour_bars[j/5][0]; -//// temp_fb[j * 3 + 2] = 0x00; //colour_bars[j/5][0]; -// temp_fb[j * 3] = colour_bars[j/48][0]; -// temp_fb[j * 3 + 1] = colour_bars[j/48][1]; -// temp_fb[j * 3 + 2] = colour_bars[j/48][2]; -//// ESP_LOGE(TAG, "%d ",j/5); -// } -// -// for (uint32_t i = 0; i < 320; i++) { -// st77xx_send_data(device, temp_fb, sizeof(temp_fb)); -// } - -// // -//// //Disable sleep mode -//// res = st77xx_set_sleep(device, false); -//// if (res != ESP_OK) return res; -//// -//// //Turn on the LCD -//// res = st77xx_send_command(device, ST77XX_DISPON); -//// if (res != ESP_OK) return res; -//// -//// //Configure orientation -//// res = st77xx_set_cfg(device, device->rotation, device->color_mode); -//// if (res != ESP_OK) return res; + res = st77xx_set_cfg(device, device->rotation, device->color_mode); + if (res != ESP_OK) return res; return ESP_OK; } esp_err_t st77xx_deinit(ST77XX* device) { -return 0; - // if (device->mutex != NULL) xSemaphoreTake(device->mutex, portMAX_DELAY); // Block access to the peripheral while deinitialized -// esp_err_t res; -// if (device->spi_device != NULL) { -// res = spi_bus_remove_device(device->spi_device); -// device->spi_device = NULL; -// if (res != ESP_OK) return res; -// } -// res = gpio_set_direction(device->pin_dcx, GPIO_MODE_INPUT); -// if (res != ESP_OK) return res; -// res = gpio_set_direction(device->pin_cs, GPIO_MODE_INPUT); -// if (res != ESP_OK) return res; -// if (device->callback != NULL) { -// device->callback(true); -// } -// res = st77xx_reset(device); -// if (res != ESP_OK) return res; -// return res; -} - -esp_err_t st77xx_select(ST77XX* device, const bool state) { - if (device->spi_device != NULL) return ESP_FAIL; - return gpio_set_level(device->pin_cs, !state); + return ESP_OK; } esp_err_t st77xx_write(ST77XX* device, const uint8_t *buffer) { return st77xx_write_partial_direct(device, buffer, 0, 0, ST77XX_WIDTH, ST77XX_HEIGHT); } -esp_err_t st77xx_send(ST77XX* device, const uint8_t *data, const int len, const bool dc_level) { - if (len == 0) return ESP_OK; - if (device->spi_device == NULL) return ESP_FAIL; - device->dc_level = dc_level; - spi_transaction_t transaction = { - .length = len * 8, // transaction length is in bits - .tx_buffer = data, - .user = (void*) device, - }; - if (device->spi_semaphore != NULL) xSemaphoreTake(device->spi_semaphore, portMAX_DELAY); - esp_err_t res = spi_device_transmit(device->spi_device, &transaction); - if (device->spi_semaphore != NULL) xSemaphoreGive(device->spi_semaphore); - return res; -} - #define MADCTL_MY 0x80 ///< Bottom to top #define MADCTL_MX 0x40 ///< Right to left #define MADCTL_MV 0x20 ///< Reverse Mode @@ -355,7 +251,7 @@ esp_err_t st77xx_send(ST77XX* device, const uint8_t *data, const int len, const #define MADCTL_MH 0x04 ///< LCD refresh right to left esp_err_t st77xx_set_cfg(ST77XX * device, uint8_t rotation, bool color_mode) { - rotation = rotation & 0x03; + rotation = rotation & 0x07; uint8_t m = 0; switch (rotation) { @@ -371,6 +267,9 @@ esp_err_t st77xx_set_cfg(ST77XX * device, uint8_t rotation, bool color_mode) { case 3: m |= (MADCTL_MX | MADCTL_MY | MADCTL_MV); break; + case 4: + m |= (MADCTL_MY | MADCTL_MV); + break; } if (color_mode) { @@ -378,6 +277,7 @@ esp_err_t st77xx_set_cfg(ST77XX * device, uint8_t rotation, bool color_mode) { } else { m |= MADCTL_RGB; } + ESP_LOGD(TAG, "MADCTL = 0x%x", m); uint8_t data[1] = {m}; esp_err_t res = st77xx_send_command(device, ST77XX_MADCTL); @@ -399,6 +299,7 @@ esp_err_t st77xx_set_addr_window(ST77XX* device, uint16_t x, uint16_t y, uint16_ uint32_t xa = ((uint32_t)x << 16) | (x+w-1); uint32_t ya = ((uint32_t)y << 16) | (y+h-1); esp_err_t res; + ESP_LOGD(TAG, "CASET %x, RASET %x", xa, ya); res = st77xx_send_command(device, ST77XX_CASET); if (res != ESP_OK) return res; res = st77xx_send_u32(device, xa); @@ -412,19 +313,10 @@ esp_err_t st77xx_set_addr_window(ST77XX* device, uint16_t x, uint16_t y, uint16_ } esp_err_t st77xx_write_partial_direct(ST77XX* device, const uint8_t *buffer, uint16_t x, uint16_t y, uint16_t width, uint16_t height) { - // return ESP_OK; - ESP_LOGD(TAG, "x = %d, y = %d, width = %d, height = %d", x, y, width, height); - for (int i = 0; i < 20; i++) { - ESP_LOGD(TAG, "buffer[%d] = %x", i, buffer[0]); - } if (device->spi_device == NULL) return ESP_FAIL; if (device->mutex != NULL) xSemaphoreTake(device->mutex, portMAX_DELAY); -// esp_err_t res = st77xx_set_addr_window(device, x, y, width, height); -// if (res != ESP_OK) { -// if (device->mutex != NULL) xSemaphoreGive(device->mutex); -// return res; -// } - esp_err_t res = res = st77xx_send_command(device, ST77XX_RAMWR); + esp_err_t res; + res = st77xx_set_addr_window(device, x, y, width, height); if (res != ESP_OK) { if (device->mutex != NULL) xSemaphoreGive(device->mutex); return res; @@ -446,81 +338,6 @@ esp_err_t st77xx_write_partial_direct(ST77XX* device, const uint8_t *buffer, uin return res; } -esp_err_t st77xx_write_partial(ST77XX* device, const uint8_t *frameBuffer, uint16_t x, uint16_t y, uint16_t width, uint16_t height) { // With conversion -return 0; -// if (device->mutex != NULL) xSemaphoreTake(device->mutex, portMAX_DELAY); -// -// if (device->spi_device == NULL) { -// if (device->mutex != NULL) xSemaphoreGive(device->mutex); -// return ESP_FAIL; -// } -// esp_err_t res = ESP_OK; -// -// uint8_t *buffer = heap_caps_malloc(device->spi_max_transfer_size, MALLOC_CAP_8BIT); -// if (buffer == NULL) { -// if (device->mutex != NULL) xSemaphoreGive(device->mutex); -// return ESP_FAIL; -// } -// -// while (width > 0) { -// uint16_t transactionWidth = width; -// if (transactionWidth*2 > device->spi_max_transfer_size) { -// transactionWidth = device->spi_max_transfer_size / 2; -// } -// res = st77xx_set_addr_window(device, x, y, transactionWidth, height); -// if (res != ESP_OK) { -// free(buffer); -// if (device->mutex != NULL) xSemaphoreGive(device->mutex); -// return res; -// } -// for (uint16_t currentLine = 0; currentLine < height; currentLine++) { -// for (uint16_t i = 0; imutex != NULL) xSemaphoreGive(device->mutex); -// return res; -// } -// } -// width -= transactionWidth; -// x += transactionWidth; -// } -// free(buffer); -// if (device->mutex != NULL) xSemaphoreGive(device->mutex); -// return res; -} - -esp_err_t st77xx_power_en(ST77XX* device) { -// if (device->pin_reset >= 0 && !device->reset_external_pullup) { -// ESP_LOGI(TAG, "keep state of pin %d", device->pin_reset); -// // If there is no external pullup, we need to keep the reset pin HIGH during sleep -// return gpio_hold_en(device->pin_reset); -// } - return ESP_OK; -} - - - - -// -//esp_err_t st77xx_set_sleep(ST77XX* device, const bool state) { -// esp_err_t res; -// ESP_LOGI(TAG, "sleep mode %s", state ? "on" : "off"); -// if (device->mutex != NULL) xSemaphoreTake(device->mutex, portMAX_DELAY); -// if (state) { -// res = st77xx_send_command(device, ST77XX_SLPIN); -// if (res != ESP_OK) return res; -// } else { -// res = st77xx_send_command(device, ST77XX_SLPOUT); -// if (res != ESP_OK) return res; -// } -// if (device->mutex != NULL) xSemaphoreGive(device->mutex); -// return res; -//} -// esp_err_t st77xx_set_display(ST77XX* device, const bool state) { esp_err_t res; ESP_LOGI(TAG, "sleep display %s", state ? "on" : "off"); @@ -536,94 +353,3 @@ esp_err_t st77xx_set_display(ST77XX* device, const bool state) { if (device->mutex != NULL) xSemaphoreGive(device->mutex); return res; } -// -//esp_err_t st77xx_set_invert(ST77XX* device, const bool state) { -// ESP_LOGI(TAG, "invert %s", state ? "on" : "off"); -// if (device->mutex != NULL) xSemaphoreTake(device->mutex, portMAX_DELAY); -// -// if (state) { -// return st77xx_send_command(device, ST77XX_INVON); -// } else { -// return st77xx_send_command(device, ST77XX_INVOFF); -// } -// if (device->mutex != NULL) xSemaphoreGive(device->mutex); -//} -// -//esp_err_t st77xx_set_partial_scanning(ST77XX* device, const uint16_t start, const uint16_t end) { -// if (device->mutex != NULL) xSemaphoreTake(device->mutex, portMAX_DELAY); -// if ((start == 0) && (end >= ST77XX_WIDTH - 1)) { -// ESP_LOGI(TAG, "partial scanning off"); -// return st77xx_send_command(device, ST77XX_NORON); -// } else { -// ESP_LOGI(TAG, "partial scanning on (%u to %u)", start, end); -// esp_err_t res = st77xx_send_command(device, ST77XX_PTLAR); -// if (res != ESP_OK) return res; -// res = st77xx_send_u32(device, (start << 16) | end); -// if (res != ESP_OK) return res; -// return st77xx_send_command(device, ST77XX_PTLON); -// } -// if (device->mutex != NULL) xSemaphoreGive(device->mutex); -//} -// -//esp_err_t st77xx_set_tearing_effect_line(ST77XX* device, const bool state) { -// ESP_LOGI(TAG, "tearing effect line %s", state ? "on" : "off"); -// if (device->mutex != NULL) xSemaphoreTake(device->mutex, portMAX_DELAY); -// if (state) { -// return st77xx_send_command(device, ST77XX_TEON); -// } else { -// return st77xx_send_command(device, ST77XX_TEOFF); -// } -// if (device->mutex != NULL) xSemaphoreGive(device->mutex); -//} -// -//esp_err_t st77xx_set_idle_mode(ST77XX* device, const bool state) { -// ESP_LOGI(TAG, "idle mode %s", state ? "on" : "off"); -// if (device->mutex != NULL) xSemaphoreTake(device->mutex, portMAX_DELAY); -// if (state) { -// return st77xx_send_command(device, ST77XX_IDMON); -// } else { -// return st77xx_send_command(device, ST77XX_IDMOFF); -// } -// if (device->mutex != NULL) xSemaphoreGive(device->mutex); -//} - -// -//#define MADCTL_MY 0x80 ///< Bottom to topp -//#define MADCTL_MX 0x40 ///< Right to left -//#define MADCTL_MV 0x20 ///< Reverse Mode -//#define MADCTL_ML 0x10 ///< LCD refresh Bottom to top -//#define MADCTL_RGB 0x00 ///< Red-Green-Blue pixel order -//#define MADCTL_BGR 0x08 ///< Blue-Green-Red pixel order -//#define MADCTL_MH 0x04 ///< LCD refresh right to left -// -//esp_err_t st77xx_set_cfg(ST77XX* device, uint8_t rotation, bool color_mode) { -// rotation = rotation & 0x03; -// uint8_t m = 0; -// -// switch (rotation) { -// case 0: -// m |= MADCTL_MX; -// break; -// case 1: -// m |= MADCTL_MV; -// break; -// case 2: -// m |= MADCTL_MY; -// break; -// case 3: -// m |= (MADCTL_MX | MADCTL_MY | MADCTL_MV); -// break; -// } -// -// if (color_mode) { -// m |= MADCTL_BGR; -// } else { -// m |= MADCTL_RGB; -// } -// -// uint8_t commands[2] = {ST77XX_MADCTL, m}; -// esp_err_t res = st77xx_send(device, commands, 1, false); -// if (res != ESP_OK) return res; -// res = st77xx_send(device, commands+1, 1, true); -// return res; -//} diff --git a/components/troopers24-bsp b/components/troopers24-bsp index 1a74b27..457a91a 160000 --- a/components/troopers24-bsp +++ b/components/troopers24-bsp @@ -1 +1 @@ -Subproject commit 1a74b2792be28ea8bc9d9815e9dc8b85b08f7a47 +Subproject commit 457a91a6345a22dffb8fd7685064631c3ff0b5ec diff --git a/main/main.c b/main/main.c index 1ccc6dc..3a3d7ee 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++) {