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.h (4823B)

      1 #include "Arduino_DataBus.h"
      2 
      3 #if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3)
      4 
      5 #ifndef _ARDUINO_ESP32RGBPANEL_H_
      6 #define _ARDUINO_ESP32RGBPANEL_H_
      7 
      8 #include "esp_lcd_panel_io.h"
      9 #include "esp_lcd_panel_rgb.h"
     10 #include "esp_lcd_panel_vendor.h"
     11 #include "esp_lcd_panel_ops.h"
     12 #include "esp_lcd_panel_interface.h"
     13 #include "esp_private/gdma.h"
     14 #include "esp_pm.h"
     15 #include "hal/dma_types.h"
     16 
     17 #include "hal/lcd_hal.h"
     18 #include "hal/lcd_ll.h"
     19 
     20 #include "esp32s3/rom/cache.h"
     21 // This function is located in ROM (also see esp_rom/${target}/ld/${target}.rom.ld)
     22 extern int Cache_WriteBack_Addr(uint32_t addr, uint32_t size);
     23 
     24 // extract from esp-idf esp_lcd_rgb_panel.c
     25 struct esp_rgb_panel_t
     26 {
     27   esp_lcd_panel_t base;                                        // Base class of generic lcd panel
     28   int panel_id;                                                // LCD panel ID
     29   lcd_hal_context_t hal;                                       // Hal layer object
     30   size_t data_width;                                           // Number of data lines (e.g. for RGB565, the data width is 16)
     31   size_t sram_trans_align;                                     // Alignment for framebuffer that allocated in SRAM
     32   size_t psram_trans_align;                                    // Alignment for framebuffer that allocated in PSRAM
     33   int disp_gpio_num;                                           // Display control GPIO, which is used to perform action like "disp_off"
     34   intr_handle_t intr;                                          // LCD peripheral interrupt handle
     35   esp_pm_lock_handle_t pm_lock;                                // Power management lock
     36   size_t num_dma_nodes;                                        // Number of DMA descriptors that used to carry the frame buffer
     37   uint8_t *fb;                                                 // Frame buffer
     38   size_t fb_size;                                              // Size of frame buffer
     39   int data_gpio_nums[SOC_LCD_RGB_DATA_WIDTH];                  // GPIOs used for data lines, we keep these GPIOs for action like "invert_color"
     40   size_t resolution_hz;                                        // Peripheral clock resolution
     41   esp_lcd_rgb_timing_t timings;                                // RGB timing parameters (e.g. pclk, sync pulse, porch width)
     42   gdma_channel_handle_t dma_chan;                              // DMA channel handle
     43   esp_lcd_rgb_panel_frame_trans_done_cb_t on_frame_trans_done; // Callback, invoked after frame trans done
     44   void *user_ctx;                                              // Reserved user's data of callback functions
     45   int x_gap;                                                   // Extra gap in x coordinate, it's used when calculate the flush window
     46   int y_gap;                                                   // Extra gap in y coordinate, it's used when calculate the flush window
     47   struct
     48   {
     49     unsigned int disp_en_level : 1; // The level which can turn on the screen by `disp_gpio_num`
     50     unsigned int stream_mode : 1;   // If set, the LCD transfers data continuously, otherwise, it stops refreshing the LCD when transaction done
     51     unsigned int fb_in_psram : 1;   // Whether the frame buffer is in PSRAM
     52   } flags;
     53   dma_descriptor_t dma_nodes[]; // DMA descriptor pool of size `num_dma_nodes`
     54 };
     55 
     56 class Arduino_ESP32RGBPanel
     57 {
     58 public:
     59   Arduino_ESP32RGBPanel(
     60       int8_t de, int8_t vsync, int8_t hsync, int8_t pclk,
     61       int8_t r0, int8_t r1, int8_t r2, int8_t r3, int8_t r4,
     62       int8_t g0, int8_t g1, int8_t g2, int8_t g3, int8_t g4, int8_t g5,
     63       int8_t b0, int8_t b1, int8_t b2, int8_t b3, int8_t b4,
     64       uint16_t hsync_polarity, uint16_t hsync_front_porch, uint16_t hsync_pulse_width, uint16_t hsync_back_porch,
     65       uint16_t vsync_polarity, uint16_t vsync_front_porch, uint16_t vsync_pulse_width, uint16_t vsync_back_porch,
     66       uint16_t pclk_active_neg = 0, int32_t prefer_speed = GFX_NOT_DEFINED, bool useBigEndian = false,
     67       uint16_t de_idle_high = 0, uint16_t pclk_idle_high = 0);
     68 
     69   bool begin(int32_t speed = GFX_NOT_DEFINED);
     70 
     71   uint16_t *getFrameBuffer(int16_t w, int16_t h);
     72 
     73 protected:
     74 private:
     75   int32_t _speed;
     76   int8_t _de, _vsync, _hsync, _pclk;
     77   int8_t _r0, _r1, _r2, _r3, _r4;
     78   int8_t _g0, _g1, _g2, _g3, _g4, _g5;
     79   int8_t _b0, _b1, _b2, _b3, _b4;
     80   uint16_t _hsync_polarity;
     81   uint16_t _hsync_front_porch;
     82   uint16_t _hsync_pulse_width;
     83   uint16_t _hsync_back_porch;
     84   uint16_t _vsync_polarity;
     85   uint16_t _vsync_front_porch;
     86   uint16_t _vsync_pulse_width;
     87   uint16_t _vsync_back_porch;
     88   uint16_t _pclk_active_neg;
     89   int32_t _prefer_speed;
     90   bool _useBigEndian;
     91   uint16_t _de_idle_high;
     92   uint16_t _pclk_idle_high;
     93 
     94   esp_lcd_panel_handle_t _panel_handle = NULL;
     95   esp_rgb_panel_t *_rgb_panel;
     96 };
     97 
     98 #endif // _ARDUINO_ESP32RGBPANEL_H_
     99 
    100 #endif // #if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3)