acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
Arduino_ESP32RGBPanel.cpp (5380B)
1 #include "Arduino_ESP32RGBPanel.h" 2 3 #if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3) 4 5 Arduino_ESP32RGBPanel::Arduino_ESP32RGBPanel( 6 int8_t de, int8_t vsync, int8_t hsync, int8_t pclk, 7 int8_t r0, int8_t r1, int8_t r2, int8_t r3, int8_t r4, 8 int8_t g0, int8_t g1, int8_t g2, int8_t g3, int8_t g4, int8_t g5, 9 int8_t b0, int8_t b1, int8_t b2, int8_t b3, int8_t b4, 10 uint16_t hsync_polarity, uint16_t hsync_front_porch, uint16_t hsync_pulse_width, uint16_t hsync_back_porch, 11 uint16_t vsync_polarity, uint16_t vsync_front_porch, uint16_t vsync_pulse_width, uint16_t vsync_back_porch, 12 uint16_t pclk_active_neg, int32_t prefer_speed, bool useBigEndian, 13 uint16_t de_idle_high, uint16_t pclk_idle_high) 14 : _de(de), _vsync(vsync), _hsync(hsync), _pclk(pclk), 15 _r0(r0), _r1(r1), _r2(r2), _r3(r3), _r4(r4), 16 _g0(g0), _g1(g1), _g2(g2), _g3(g3), _g4(g4), _g5(g5), 17 _b0(b0), _b1(b1), _b2(b2), _b3(b3), _b4(b4), 18 _hsync_polarity(hsync_polarity), _hsync_front_porch(hsync_front_porch), _hsync_pulse_width(hsync_pulse_width), _hsync_back_porch(hsync_back_porch), 19 _vsync_polarity(vsync_polarity), _vsync_front_porch(vsync_front_porch), _vsync_pulse_width(vsync_pulse_width), _vsync_back_porch(vsync_back_porch), 20 _pclk_active_neg(pclk_active_neg), _prefer_speed(prefer_speed), _useBigEndian(useBigEndian), 21 _de_idle_high(de_idle_high), _pclk_idle_high(pclk_idle_high) 22 { 23 } 24 25 bool Arduino_ESP32RGBPanel::begin(int32_t speed) 26 { 27 if (speed == GFX_NOT_DEFINED) 28 { 29 #ifdef CONFIG_SPIRAM_MODE_QUAD 30 _speed = 6000000L; 31 #else 32 _speed = 12000000L; 33 #endif 34 } 35 else 36 { 37 _speed = speed; 38 } 39 40 return true; 41 } 42 43 uint16_t *Arduino_ESP32RGBPanel::getFrameBuffer(int16_t w, int16_t h) 44 { 45 esp_lcd_rgb_panel_config_t *_panel_config = (esp_lcd_rgb_panel_config_t *)heap_caps_calloc(1, sizeof(esp_lcd_rgb_panel_config_t), MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL); 46 47 _panel_config->clk_src = LCD_CLK_SRC_PLL160M; 48 49 _panel_config->timings.pclk_hz = (_prefer_speed == GFX_NOT_DEFINED) ? _speed : _prefer_speed; 50 _panel_config->timings.h_res = w; 51 _panel_config->timings.v_res = h; 52 // The following parameters should refer to LCD spec 53 _panel_config->timings.hsync_pulse_width = _hsync_pulse_width; 54 _panel_config->timings.hsync_back_porch = _hsync_back_porch; 55 _panel_config->timings.hsync_front_porch = _hsync_front_porch; 56 _panel_config->timings.vsync_pulse_width = _vsync_pulse_width; 57 _panel_config->timings.vsync_back_porch = _vsync_back_porch; 58 _panel_config->timings.vsync_front_porch = _vsync_front_porch; 59 _panel_config->timings.flags.hsync_idle_low = (_hsync_polarity == 0) ? 1 : 0; 60 _panel_config->timings.flags.vsync_idle_low = (_vsync_polarity == 0) ? 1 : 0; 61 _panel_config->timings.flags.de_idle_high = _de_idle_high; 62 _panel_config->timings.flags.pclk_active_neg = _pclk_active_neg; 63 _panel_config->timings.flags.pclk_idle_high = _pclk_idle_high; 64 65 _panel_config->data_width = 16; // RGB565 in parallel mode, thus 16bit in width 66 _panel_config->sram_trans_align = 8; 67 _panel_config->psram_trans_align = 64; 68 _panel_config->hsync_gpio_num = _hsync; 69 _panel_config->vsync_gpio_num = _vsync; 70 _panel_config->de_gpio_num = _de; 71 _panel_config->pclk_gpio_num = _pclk; 72 73 if (_useBigEndian) 74 { 75 _panel_config->data_gpio_nums[0] = _g3; 76 _panel_config->data_gpio_nums[1] = _g4; 77 _panel_config->data_gpio_nums[2] = _g5; 78 _panel_config->data_gpio_nums[3] = _r0; 79 _panel_config->data_gpio_nums[4] = _r1; 80 _panel_config->data_gpio_nums[5] = _r2; 81 _panel_config->data_gpio_nums[6] = _r3; 82 _panel_config->data_gpio_nums[7] = _r4; 83 _panel_config->data_gpio_nums[8] = _b0; 84 _panel_config->data_gpio_nums[9] = _b1; 85 _panel_config->data_gpio_nums[10] = _b2; 86 _panel_config->data_gpio_nums[11] = _b3; 87 _panel_config->data_gpio_nums[12] = _b4; 88 _panel_config->data_gpio_nums[13] = _g0; 89 _panel_config->data_gpio_nums[14] = _g1; 90 _panel_config->data_gpio_nums[15] = _g2; 91 } 92 else 93 { 94 _panel_config->data_gpio_nums[0] = _b0; 95 _panel_config->data_gpio_nums[1] = _b1; 96 _panel_config->data_gpio_nums[2] = _b2; 97 _panel_config->data_gpio_nums[3] = _b3; 98 _panel_config->data_gpio_nums[4] = _b4; 99 _panel_config->data_gpio_nums[5] = _g0; 100 _panel_config->data_gpio_nums[6] = _g1; 101 _panel_config->data_gpio_nums[7] = _g2; 102 _panel_config->data_gpio_nums[8] = _g3; 103 _panel_config->data_gpio_nums[9] = _g4; 104 _panel_config->data_gpio_nums[10] = _g5; 105 _panel_config->data_gpio_nums[11] = _r0; 106 _panel_config->data_gpio_nums[12] = _r1; 107 _panel_config->data_gpio_nums[13] = _r2; 108 _panel_config->data_gpio_nums[14] = _r3; 109 _panel_config->data_gpio_nums[15] = _r4; 110 } 111 112 _panel_config->disp_gpio_num = GPIO_NUM_NC; 113 114 _panel_config->flags.disp_active_low = 0; 115 _panel_config->flags.relax_on_idle = 0; 116 _panel_config->flags.fb_in_psram = 1; // allocate frame buffer in PSRAM 117 118 ESP_ERROR_CHECK(esp_lcd_new_rgb_panel(_panel_config, &_panel_handle)); 119 ESP_ERROR_CHECK(esp_lcd_panel_reset(_panel_handle)); 120 ESP_ERROR_CHECK(esp_lcd_panel_init(_panel_handle)); 121 122 uint16_t color = random(0xffff); 123 ESP_ERROR_CHECK(_panel_handle->draw_bitmap(_panel_handle, 0, 0, 1, 1, &color)); 124 125 _rgb_panel = __containerof(_panel_handle, esp_rgb_panel_t, base); 126 127 return (uint16_t *)_rgb_panel->fb; 128 } 129 #endif // #if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3)