Adafruit_dvhstx.h
1 #pragma once 2 3 #include "Adafruit_GFX.h" 4 5 #include "drivers/dvhstx/dvhstx.hpp" 6 7 enum DVHSTXResolution { 8 /* well supported, square pixels on a 16:9 display, actual resolution 1280x720@50Hz */ 9 DVHSTX_RESOLUTION_320x180, 10 DVHSTX_RESOLUTION_640x360, 11 12 /* sometimes supported, square pixels on a 16:9 display, actual resolution 960x540@60Hz */ 13 DVHSTX_RESOLUTION_480x270, 14 15 /* sometimes supported, square pixels on a 16:9 display, actual resolution 800x450@60Hz */ 16 DVHSTX_RESOLUTION_400x225, 17 18 /* well supported, but pixels aren't square on a 16:9 display */ 19 DVHSTX_RESOLUTION_320x240, /* 4:3, actual resolution 640x480@60Hz */ 20 DVHSTX_RESOLUTION_360x240, /* 3:2, actual resolution 720x480@60Hz */ 21 DVHSTX_RESOLUTION_360x200, /* 18:10, actual resolution 720x400@70Hz */ 22 DVHSTX_RESOLUTION_360x288, /* 5:4, actual resolution 720x576@60Hz */ 23 DVHSTX_RESOLUTION_400x300, /* 4:3, actual resolution 800x600@60Hz */ 24 DVHSTX_RESOLUTION_512x384, /* 4:3, actual resolution 1024x768@60Hz */ 25 26 /* sometimes supported, but pixels aren't square on a 16:9 display */ 27 DVHSTX_RESOLUTION_400x240, /* 5:3, actual resolution 800x480@60Hz */ 28 }; 29 30 using pimoroni::DVHSTXPinout; 31 32 #define DVHSTX_PINOUT_METRO_RP2350 ((DVHSTXPinout){14, 18, 16, 12}) 33 // TODO: check and enable these pinouts 34 #define DVHSTX_PINOUT_FEATHER_RP2350 ((DVHSTXPinout){14, 18, 16, 12}) 35 #define DVHSTX_PINOUT_FRUITJAM_RP2350 ((DVHSTXPinout){14, 18, 16, 12}) 36 37 int16_t dvhstx_width(DVHSTXResolution r); 38 int16_t dvhstx_height(DVHSTXResolution r); 39 40 class DVHSTX16 : public Adafruit_GFX { 41 public: 42 /**************************************************************************/ 43 /*! 44 @brief Instatiate a DVHSTX 16-bit canvas context for graphics 45 @param res Display resolution 46 @param double_buffered Whether to allocate two buffers 47 */ 48 /**************************************************************************/ 49 DVHSTX16(DVHSTXPinout pinout, DVHSTXResolution res, bool double_buffered=false) : Adafruit_GFX(dvhstx_width(res), dvhstx_height(res)), pinout(pinout), res{res}, double_buffered{double_buffered} {} 50 ~DVHSTX16() { end(); } 51 52 bool begin() { 53 return hstx.init(dvhstx_width(res), dvhstx_height(res), pimoroni::DVHSTX::MODE_RGB565, double_buffered, pinout); 54 } 55 void end() { hstx.reset(); } 56 57 void drawPixel(int16_t x, int16_t y, uint16_t color); 58 void fillScreen(uint16_t color); 59 void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); 60 void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); 61 uint16_t getPixel(int16_t x, int16_t y) const; 62 /**********************************************************************/ 63 /*! 64 @brief Get a pointer to the internal buffer memory (current back buffer) 65 @returns A pointer to the allocated buffer 66 */ 67 /**********************************************************************/ 68 uint16_t *getBuffer(void) const { return hstx.get_back_buffer<uint16_t>(); } 69 70 /**********************************************************************/ 71 /*! 72 @brief If double-buffered, wait for retrace and swap buffers. Otherwise, do nothing (returns immediately) 73 @param copy_framebuffer if true, copy the new screen to the new back buffer. Otherwise, the content is undefined. 74 */ 75 /**********************************************************************/ 76 void swap(bool copy_framebuffer = false); 77 78 protected: 79 uint16_t getRawPixel(int16_t x, int16_t y) const; 80 void drawFastRawVLine(int16_t x, int16_t y, int16_t h, uint16_t color); 81 void drawFastRawHLine(int16_t x, int16_t y, int16_t w, uint16_t color); 82 83 private: 84 DVHSTXPinout pinout; 85 DVHSTXResolution res; 86 bool double_buffered; 87 mutable pimoroni::DVHSTX hstx; 88 }; 89 90 #if 0 91 class DVHSTX8 : GFXcanvas8 { 92 /**************************************************************************/ 93 /*! 94 @brief Instatiate a DVHSTX 8-bit canvas context for graphics 95 @param res Display resolution 96 @param double_buffered Whether to allocate two buffers 97 */ 98 /**************************************************************************/ 99 DVHSTX8(DVHSTXResolution res, bool double_buffered=false); 100 ~DVHSTX8() { end(); } 101 bool begin() { 102 return hstx.init(width, height, MODE_PALETTE, double_buffered); 103 } 104 void end() { hstx.reset(); } 105 106 void drawPixel(int16_t x, int16_t y, uint16_t color); 107 void fillScreen(uint16_t color); 108 void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); 109 void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); 110 bool getPixel(int16_t x, int16_t y) const; 111 /**********************************************************************/ 112 /*! 113 @brief Get a pointer to the internal buffer memory (current back buffer) 114 @returns A pointer to the allocated buffer 115 */ 116 /**********************************************************************/ 117 uint8_t *getBuffer(void) const { return hstx.get_back_buffer<uint8_t>(); } 118 119 120 /**********************************************************************/ 121 /*! 122 @brief If double-buffered, wait for retrace and swap buffers. Otherwise, do nothing (returns immediately) 123 @param copy_framebuffer if true, copy the new screen to the new back buffer. Otherwise, the content is undefined. 124 */ 125 /**********************************************************************/ 126 void swap(bool copy_framebuffer = false); 127 protected: 128 bool getRawPixel(int16_t x, int16_t y) const; 129 void drawFastRawVLine(int16_t x, int16_t y, int16_t h, uint16_t color); 130 void drawFastRawHLine(int16_t x, int16_t y, int16_t w, uint16_t color); 131 132 }; 133 134 class DVHSTXTEXT1 : GFXcanvas16 { 135 DVHSTX16(); 136 bool begin() { 137 return hstx.init(1280, 720, MODE_TEXT_MONO, true); 138 } 139 using TextColor = pimoroni::DVHSTX::TextColour; 140 void end() { hstx.reset(); } 141 }; 142 143 class DVHSTXTEXT3 : GFXcanvas16 { 144 DVHSTX16(); 145 bool begin() { 146 return hstx.init(1280, 720, MODE_TEXT_RGB111, true); 147 } 148 void end() { hstx.reset(); } 149 }; 150 #endif