TinyGPU
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
ILI9341Driver< RGB_T > Class Template Reference

Driver for ILI9341 SPI display controller. More...

#include <DisplayDriverSPI.h>

Inheritance diagram for ILI9341Driver< RGB_T >:
Inheritance graph
[legend]
Collaboration diagram for ILI9341Driver< RGB_T >:
Collaboration graph
[legend]

Public Types

using Rotation = tinygpu::DisplayRotation
 

Public Member Functions

 ILI9341Driver (SPIClass &spi, int8_t cs, int8_t dc, int8_t rst=-1, Rotation rotation=Rotation::kNone, uint32_t frequencyHz=40000000, size_t nativeWidth=240, size_t nativeHeight=320)
 
size_t width () const override
 
size_t height () const override
 
bool begin () override
 
void setRotation (Rotation rotation) override
 
Rotation rotation () const
 
void setInvertColor (bool invert)
 Toggles the ILI9341's display inversion (DINVON/DINVOFF, 0x21/ 0x20). Some cheap ILI9341-compatible clone panels' color filter needs this set, or every color renders as its photographic negative (RED shows as cyan, GREEN as magenta, BLUE as yellow) - confirmed on real hardware. Safe to call any time after begin() - and safe to call before a later begin() too: begin() sends SWRESET (0x01), a real hardware reset that puts the panel's own inversion register back to its power-on default regardless of what this method last told it (no explicit invert command appears anywhere in begin() itself, so this is easy to miss), so begin() re-sends whatever this last requested (via invertColor_) as its final step - a call to this method always sticks no matter how many further begin() calls follow (e.g. a caller's own redundant DeviceOutput::begin()).
 
- Public Member Functions inherited from DisplayDriverSPI< RGB_T >
 DisplayDriverSPI (SPIClass &spi, int8_t cs, int8_t dc, int8_t rst=-1, size_t xOffset=0, size_t yOffset=0, uint32_t frequencyHz=40000000, uint32_t readFrequencyHz=15000000, size_t width=240, size_t height=320)
 
size_t width () const override
 
size_t height () const override
 
bool writeData (ISurface< RGB_T > &surface) override
 
void setSwapOutputBytes (bool swap)
 
bool writeData (ISurface< RGB_T > &surface, size_t x, size_t y) override
 
bool readData (ISurface< RGB_T > &surface, size_t x, size_t y)
 
- Public Member Functions inherited from DisplayDriver< RGB_T >
virtual ~DisplayDriver ()=default
 
virtual bool begin ()=0
 
virtual void end ()
 
virtual bool writeData (ISurface< RGB_T > &surface)=0
 
virtual bool writeData (ISurface< RGB_T > &surface, size_t x, size_t y)=0
 
virtual void setRotation (DisplayRotation rotation)
 
virtual size_t width () const =0
 
virtual size_t height () const =0
 
void writeColor (size_t width, size_t height, RGB_T color)
 

Static Protected Member Functions

static uint8_t madctlForRotation (Rotation rotation)
 

Protected Attributes

Rotation rotation_
 
size_t nativeWidth_
 
size_t nativeHeight_
 
bool invertColor_ = false
 
- Protected Attributes inherited from DisplayDriverSPI< RGB_T >
SPIClass & spi_
 
int8_t cs_
 
int8_t dc_
 
int8_t rst_
 
size_t xOffset_
 
size_t yOffset_
 
uint32_t frequencyHz_
 
uint32_t readFrequencyHz_
 
size_t width_
 
size_t height_
 
bool swapOutputBytes_ = false
 
- Protected Attributes inherited from DisplayDriver< RGB_T >
Font5x7< RGB_T > defaultFont
 

Additional Inherited Members

- Protected Member Functions inherited from DisplayDriverSPI< RGB_T >
void setColumnRowAddress (size_t x, size_t y, size_t w, size_t h)
 
bool setAddressWindow (size_t x, size_t y, size_t w, size_t h) override
 
void setupPinsAndReset ()
 
void writeCommand (uint8_t cmd)
 
void writeData16 (uint16_t d1, uint16_t d2)
 
void writeData8 (uint8_t data)
 
void writeDataN (std::initializer_list< uint8_t > bytes)
 
virtual bool setAddressWindow (size_t x, size_t y, size_t w, size_t h)=0
 

Detailed Description

template<typename RGB_T = RGB565>
class tinygpu::ILI9341Driver< RGB_T >

Driver for ILI9341 SPI display controller.

This init sequence (power control, VCOM, gamma correction, and the leading 0xEF unlock command some clone panels need) and the MADCTL/BGR rotation table are ported from the widely-used, independently maintained Bodmer/TFT_eSPI library's ILI9341 driver - confirmed on real hardware to render standard RGB565 colors correctly (no field compensation needed) on a panel where this library's earlier minimal init (reset/sleep-out/pixel-format/MADCTL/display-on only, with a guessed non-BGR MADCTL) did not, no matter which MADCTL value was tried - the missing piece was the full power/gamma programming, not just the MADCTL bit.

Member Typedef Documentation

◆ Rotation

Alias for the shared tinygpu::DisplayRotation (see DisplayDriver.h) - kept so existing code written against ILI9341Driver<RGB_T>::Rotation still compiles unchanged now that the enum lives on the base class.

Constructor & Destructor Documentation

◆ ILI9341Driver()

ILI9341Driver ( SPIClass &  spi,
int8_t  cs,
int8_t  dc,
int8_t  rst = -1,
Rotation  rotation = Rotation::kNone,
uint32_t  frequencyHz = 40000000,
size_t  nativeWidth = 240,
size_t  nativeHeight = 320 
)
inline
Parameters
nativeWidth/nativeHeightthe panel's physical resolution in its native (portrait, MV bit clear) orientation - 240x320 is the common ILI9341 module size and the default; pass your panel's real values if it differs. width()/height() report these swapped or not depending on rotation (and any later setRotation() call) - see isLandscapeFamily().

Member Function Documentation

◆ begin()

bool begin ( )
inlineoverridevirtual

◆ height()

size_t height ( ) const
inlineoverridevirtual

Reimplemented from DisplayDriverSPI< RGB_T >.

◆ madctlForRotation()

static uint8_t madctlForRotation ( Rotation  rotation)
inlinestaticprotected

◆ rotation()

Rotation rotation ( ) const
inline

◆ setInvertColor()

void setInvertColor ( bool  invert)
inline

Toggles the ILI9341's display inversion (DINVON/DINVOFF, 0x21/ 0x20). Some cheap ILI9341-compatible clone panels' color filter needs this set, or every color renders as its photographic negative (RED shows as cyan, GREEN as magenta, BLUE as yellow) - confirmed on real hardware. Safe to call any time after begin() - and safe to call before a later begin() too: begin() sends SWRESET (0x01), a real hardware reset that puts the panel's own inversion register back to its power-on default regardless of what this method last told it (no explicit invert command appears anywhere in begin() itself, so this is easy to miss), so begin() re-sends whatever this last requested (via invertColor_) as its final step - a call to this method always sticks no matter how many further begin() calls follow (e.g. a caller's own redundant DeviceOutput::begin()).

◆ setRotation()

void setRotation ( Rotation  rotation)
inlineoverridevirtual

Changes the panel's rotation after begin(). Default no-op, for drivers with no such concept (e.g. a fixed-orientation panel, or a desktop/SDL backend) - concrete SPI drivers (ILI9341Driver, ILI9342Driver) override this to reprogram MADCTL.

Reimplemented from DisplayDriver< RGB_T >.

◆ width()

size_t width ( ) const
inlineoverridevirtual

Current addressable panel width/height in pixels - for a driver that supports setRotation(), these reflect the current rotation (landscape vs portrait swaps them; see isLandscapeFamily()), not necessarily the panel's native/physical orientation. Callers that need to lay out content (e.g. OutputTinyGPU's scale_to_fit target, or clearScreen()'s band loop) should read these fresh rather than caching their own copy, so a setRotation() call is picked up automatically without needing separate bookkeeping.

Reimplemented from DisplayDriverSPI< RGB_T >.

Member Data Documentation

◆ invertColor_

bool invertColor_ = false
protected

◆ nativeHeight_

size_t nativeHeight_
protected

◆ nativeWidth_

size_t nativeWidth_
protected

◆ rotation_

Rotation rotation_
protected

The documentation for this class was generated from the following file: