Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 125 additions & 7 deletions Adafruit_ILI9341.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,53 @@ void Adafruit_ILI9341::setScrollMargins(uint16_t top, uint16_t bottom) {
void Adafruit_ILI9341::setAddrWindow(uint16_t x1, uint16_t y1, uint16_t w,
uint16_t h) {
uint16_t x2 = (x1 + w - 1), y2 = (y1 + h - 1);
writeCommand(ILI9341_CASET); // Column address set
SPI_WRITE16(x1);
SPI_WRITE16(x2);
writeCommand(ILI9341_PASET); // Row address set
SPI_WRITE16(y1);
SPI_WRITE16(y2);
writeCommand(ILI9341_RAMWR); // Write to RAM
#if defined(ARDUINO_ARCH_RP2040)
// Use optimised code if it is HARDWARE SPI
if (connection == 0) {
// Since the SPI functions do not terminate until transmission is complete
// a busy check is not needed.
// while (spi_get_hw(spi0)->sr & SPI_SSPSR_BSY_BITS) {};
SPI_DC_LOW(); // Command mode
spi_set_format(spi0, 8, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST);
spi_get_hw(spi0)->dr = (uint32_t)ILI9341_CASET;

while (spi_get_hw(spi0)->sr & SPI_SSPSR_BSY_BITS) {};
SPI_DC_HIGH(); // Data mode
spi_get_hw(spi0)->dr = (uint32_t)x1>>8;
spi_get_hw(spi0)->dr = (uint32_t)x1;
spi_get_hw(spi0)->dr = (uint32_t)x2>>8;
spi_get_hw(spi0)->dr = (uint32_t)x2;

while (spi_get_hw(spi0)->sr & SPI_SSPSR_BSY_BITS) {};
SPI_DC_LOW(); // Command mode
spi_get_hw(spi0)->dr = (uint32_t)ILI9341_PASET;

while (spi_get_hw(spi0)->sr & SPI_SSPSR_BSY_BITS) {};
SPI_DC_HIGH(); // Data mode
spi_get_hw(spi0)->dr = (uint32_t)y1>>8;
spi_get_hw(spi0)->dr = (uint32_t)y1;
spi_get_hw(spi0)->dr = (uint32_t)y2>>8;
spi_get_hw(spi0)->dr = (uint32_t)y2;

while (spi_get_hw(spi0)->sr & SPI_SSPSR_BSY_BITS) {};
SPI_DC_LOW(); // Command mode
spi_get_hw(spi0)->dr = (uint32_t)ILI9341_RAMWR;

while (spi_get_hw(spi0)->sr & SPI_SSPSR_BSY_BITS) {};
spi_set_format(spi0, 16, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST);
SPI_DC_HIGH(); // Data mode
}
else
#endif
{
writeCommand(ILI9341_CASET); // Column address set
SPI_WRITE16(x1);
SPI_WRITE16(x2);
writeCommand(ILI9341_PASET); // Row address set
SPI_WRITE16(y1);
SPI_WRITE16(y2);
writeCommand(ILI9341_RAMWR); // Write to RAM
}
}

/**************************************************************************/
Expand All @@ -327,3 +367,81 @@ uint8_t Adafruit_ILI9341::readcommand8(uint8_t commandByte, uint8_t index) {
sendCommand(0xD9, &data, 1); // Set Index Register
return Adafruit_SPITFT::readcommand8(commandByte);
}


// Override Adafruit_GFX writePixel() for RP2040
/*!
@brief Draw a single pixel to the display at requested coordinates.
Not self-contained; should follow a startWrite() call.
@param x Horizontal position (0 = left).
@param y Vertical position (0 = top).
@param color 16-bit pixel color in '565' RGB format.
*/
#if defined(ARDUINO_ARCH_RP2040)
void Adafruit_ILI9341::writePixel(int16_t x, int16_t y, uint16_t color) {

// If it is a TFT_HARD_SPI interface then use RP2040 optimised code
// otherwise use original code
if (connection == 0) {
if ((x >= 0) && (x < _width) && (y >= 0) && (y < _height)) {
// Since the SPI functions do not terminate until transmission is complete
// a busy check is not needed.
// while (spi_get_hw(spi0)->sr & SPI_SSPSR_BSY_BITS) {};
SPI_DC_LOW(); // Command mode
spi_set_format(spi0, 8, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST);
spi_get_hw(spi0)->dr = (uint32_t)ILI9341_CASET;

while (spi_get_hw(spi0)->sr & SPI_SSPSR_BSY_BITS) {};
SPI_DC_HIGH();
spi_get_hw(spi0)->dr = (uint32_t)x>>8;
spi_get_hw(spi0)->dr = (uint32_t)x;
spi_get_hw(spi0)->dr = (uint32_t)x>>8;
spi_get_hw(spi0)->dr = (uint32_t)x;

while (spi_get_hw(spi0)->sr & SPI_SSPSR_BSY_BITS) {};
SPI_DC_LOW(); // Command mode
spi_get_hw(spi0)->dr = (uint32_t)ILI9341_PASET;

while (spi_get_hw(spi0)->sr & SPI_SSPSR_BSY_BITS) {};
SPI_DC_HIGH();
spi_get_hw(spi0)->dr = (uint32_t)y>>8;
spi_get_hw(spi0)->dr = (uint32_t)y;
spi_get_hw(spi0)->dr = (uint32_t)y>>8;
spi_get_hw(spi0)->dr = (uint32_t)y;

while (spi_get_hw(spi0)->sr & SPI_SSPSR_BSY_BITS) {};
SPI_DC_LOW(); // Command mode
spi_get_hw(spi0)->dr = (uint32_t)ILI9341_RAMWR;

while (spi_get_hw(spi0)->sr & SPI_SSPSR_BSY_BITS) {};
SPI_DC_HIGH();
spi_get_hw(spi0)->dr = (uint32_t)color>>8;
spi_get_hw(spi0)->dr = (uint32_t)color;

/*
// Subsequent pixel reads work OK without draining the FIFO...
// Drain RX FIFO, then wait for shifting to finish (which may be *after*
// TX FIFO drains), then drain RX FIFO again
while (spi_is_readable(spi0))
(void)spi_get_hw(spi0)->dr;
while (spi_get_hw(spi0)->sr & SPI_SSPSR_BSY_BITS)
tight_loop_contents();
while (spi_is_readable(spi0))
(void)spi_get_hw(spi0)->dr;
//*/

// Subsequent pixel reads work without this
// spi_get_hw(spi0)->icr = SPI_SSPICR_RORIC_BITS;

while (spi_get_hw(spi0)->sr & SPI_SSPSR_BSY_BITS) {};

// Next call will start with 8 bit command so changing to 16 bit not needed here
//spi_set_format(spi0, 16, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST);
}
}
else {
Adafruit_SPITFT::writePixel(x, y, color);
return;
}
}
#endif
5 changes: 5 additions & 0 deletions Adafruit_ILI9341.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ class Adafruit_ILI9341 : public Adafruit_SPITFT {
void scrollTo(uint16_t y);
void setScrollMargins(uint16_t top, uint16_t bottom);

#if defined(ARDUINO_ARCH_RP2040)
// Override GFX for RP2040
void writePixel(int16_t x, int16_t y, uint16_t color);
#endif

// Transaction API not used by GFX
void setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h);

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Raspberry PI Pico (RP2040) optimised to work with Earle Philhower's Arduino board package and my optimised fork of Adafruit_GFX here:

https://github.com/Bodmer/Adafruit-GFX-Library





# Adafruit ILI9341 Arduino Library [![Build Status](https://github.com/adafruit/Adafruit_ILI9341/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit_ILI9341/actions)[![Documentation](https://github.com/adafruit/ci-arduino/blob/master/assets/doxygen_badge.svg)](http://adafruit.github.io/Adafruit_ILI9341/html/index.html)

This is a library for the Adafruit ILI9341 display products
Expand Down
19 changes: 14 additions & 5 deletions examples/graphicstest/graphicstest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,28 @@
#include "Adafruit_ILI9341.h"

// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10
//#define TFT_DC 9
//#define TFT_CS 10

// For Raspberry Pi Pico (RP2040)
// TFT MISO/SDO connects to Pico pin D0 (GPIO 0)
// TFT MOSI/SDI connects to Pico pin D3 (GPIO 3)
// TFT CLK/SCK/SCLK connects to Pico pin D2 (GPIO 2)
#define TFT_CS 20 // Chip select control pin (GPIO 20)
#define TFT_DC 18 // Data Command control pin (GPIO 18)
#define TFT_RST 19 // Reset pin (GPIO 19)

// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// If using the breakout, change pins as desired
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
// If using Raspberry Pi Pico (RP2040)
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

void setup() {
Serial.begin(9600);
Serial.println("ILI9341 Test!");

tft.begin();
tft.begin(64000000); // Can set SPI clock rate

// read diagnostics (optional but can help debug problems)
uint8_t x = tft.readcommand8(ILI9341_RDMODE);
Expand Down
18 changes: 14 additions & 4 deletions examples/pictureEmbed/pictureEmbed.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,30 @@
//#define TFT_CS 10

// Feather 32u4 or M0 with TFT FeatherWing:
#define TFT_DC 10
#define TFT_CS 9
//#define TFT_DC 10
//#define TFT_CS 9
// ESP8266:
//#define TFT_DC 15
//#define TFT_CS 0
// Raspberry Pi Pico (RP2040)
// TFT MISO/SDO connects to Pico pin D0 (GPIO 0)
// TFT MOSI/SDI connects to Pico pin D3 (GPIO 3)
// TFT CLK/SCK/SCLK connects to Pico pin D2 (GPIO 2)
#define TFT_CS 20 // Chip select control pin (GPIO 20)
#define TFT_DC 18 // Data Command control pin (GPIO 18)
#define TFT_RST 19 // Reset pin (GPIO 19)

// Other boards (including Feather boards) may have other pinouts;
// see learn.adafruit.com/adafruit-2-4-tft-touch-screen-featherwing/pinouts

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// If using the breakout, change pins as desired
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
// If using Raspberry Pi Pico (RP2040)
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

void setup() {
tft.begin();
tft.begin(64000000); // Can set SPI clock rate
}

void loop(void) {
Expand Down