Skip to content

Commit d2ea7d5

Browse files
committed
Rotated the displayed image because camera is in the back of the TTGO
1 parent dd2f5f0 commit d2ea7d5

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

esp32/examples/ttgo_demo/main/app_screen.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,8 @@ static UINT tjd_output(
237237
}
238238
}
239239

240-
// ESP_LOGI(TAG, "x1:%d y1:%d x2:%d y2:%d\n", dleft, dtop, dright, dbottom);
241-
tft->transmitCmdData(LCD_CASET, MAKEWORD(dleft >> 8, dleft & 0xFF, dright >> 8, dright & 0xFF));
242-
tft->transmitCmdData(LCD_PASET, MAKEWORD(dtop >> 8, dtop & 0xFF, dbottom >> 8, dbottom & 0xFF));
243-
tft->transmitCmd(LCD_RAMWR); // write to RAM
240+
//ESP_LOGI(TAG, "x1:%d x2:%d y1:%d y2:%d\n", dleft, dright, dtop, dbottom);
241+
tft->setAddrWindow(dleft, dtop, dright, dbottom);
244242

245243
uint16_t *p = (uint16_t *)malloc(sizeof(uint16_t) * len);
246244
if (!p) {
@@ -250,7 +248,7 @@ static UINT tjd_output(
250248
for (uint32_t i = 0; i < len; i++) {
251249
p[i] = tft->color565(dev->linbuf[dev->linbuf_idx][i].r, dev->linbuf[dev->linbuf_idx][i].g, dev->linbuf[dev->linbuf_idx][i].b);
252250
}
253-
tft->_fastSendBuf(p, len);
251+
tft->_fastSendBuf(p, len, true); // TODO: Swapping bytes directly in the camera register could enhance display
254252
free(p);
255253

256254
dev->linbuf_idx = ((dev->linbuf_idx + 1) & 1);
@@ -450,7 +448,7 @@ void lvgl_lcd_hal_init()
450448

451449
/*screen initialize*/
452450
tft->invertDisplay(true);
453-
tft->setRotation(0);
451+
tft->setRotation(2); // rotation needed if camera is on the back of the device
454452
tft->fillScreen(COLOR_BLACK);
455453

456454
lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/

esp32/examples/ttgo_demo/main/main.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,20 @@ void demo_task(void *arg) {
4141
disp_infos();
4242

4343
while(true) {
44+
auto start = esp_timer_get_time();
4445

4546
camera_fb_t *fb = esp_camera_fb_get();
4647

4748
if (!fb) {
4849
ESP_LOGE(TAG, "Camera capture failed");
4950
} else {
50-
TFT_jpg_image(CENTER, 0, 0, -1, NULL, fb->buf, fb->len);
51+
TFT_jpg_image(CENTER, CENTER, 0, -1, NULL, fb->buf, fb->len);
5152
esp_camera_fb_return(fb);
5253
fb = NULL;
5354
}
5455

56+
ESP_LOGI(TAG, "time taken: %lld ms", (esp_timer_get_time() - start) / 1000);
57+
5558
#if 0 // TODO: next step..
5659
Mat inputImage(fb->height, fb->width, CV_8UC2, fb->buf); // rgb565 is 2 channels of 8-bit unsigned
5760
Mat outputImage;
@@ -103,6 +106,8 @@ void app_main()
103106
/* Display memory infos */
104107
disp_infos();
105108

109+
ESP_LOGI(TAG, "Display width = %d, height = %d", tft->width(), tft->height());
110+
106111
/* Start the tasks */
107112
xTaskCreatePinnedToCore(demo_task, "demo", 1024 * 9, nullptr, 24, nullptr, 0);
108113
}

0 commit comments

Comments
 (0)