Skip to content

Commit

Permalink
add ARDUINO_ARCH_RTTHREAD to support RTduino
Browse files Browse the repository at this point in the history
  • Loading branch information
mysterywolf committed Jun 12, 2023
1 parent 2b3e458 commit 202fbb1
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions Adafruit_SPITFT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,15 @@ void Adafruit_SPITFT::writePixels(uint16_t *colors, uint32_t len, bool block,
spi_write_blocking(pi_spi, (uint8_t *)colors, len * 2);
}
return;
#elif defined(ARDUINO_ARCH_RTTHREAD)
if (!bigEndian) {
swapBytes(colors, len); // convert little-to-big endian for display
}
hwspi._spi->transfer(colors, 2 * len);
if (!bigEndian) {
swapBytes(colors, len); // big-to-little endian to restore pixel buffer
}
return;
#elif defined(USE_SPI_DMA) && \
(defined(__SAMD51__) || defined(ARDUINO_SAMD_ZERO))
if ((connection == TFT_HARD_SPI) || (connection == TFT_PARALLEL)) {
Expand Down Expand Up @@ -1244,6 +1253,46 @@ void Adafruit_SPITFT::writeColor(uint16_t color, uint32_t len) {
rtos_free(pixbuf);
return;
}
#elif defined(ARDUINO_ARCH_RTTHREAD)
uint16_t pixbufcount;
uint16_t *pixbuf;
int16_t lines = height() / 4;
#define QUICKPATH_MAX_LEN 16
uint16_t quickpath_buffer[QUICKPATH_MAX_LEN];

do {
pixbufcount = min(len, (lines * width()));
if (pixbufcount > QUICKPATH_MAX_LEN)
{
pixbuf = (uint16_t *)rt_malloc(2 * pixbufcount);
}
else
{
pixbuf = quickpath_buffer;
}
lines -= 2;
} while (!pixbuf && lines > 0);

if (pixbuf) {
uint16_t const swap_color = __builtin_bswap16(color);

while (len) {
uint16_t count = min(len, pixbufcount);
// fill buffer with color
for (uint16_t i = 0; i < count; i++) {
pixbuf[i] = swap_color;
}
// Don't need to swap color inside the function
// It has been done outside this function
writePixels(pixbuf, count, true, true);
len -= count;
}
if (pixbufcount > QUICKPATH_MAX_LEN)
{
rt_free(pixbuf);
}
return;
}
#else // !ESP32
#if defined(USE_SPI_DMA) && (defined(__SAMD51__) || defined(ARDUINO_SAMD_ZERO))
if (((connection == TFT_HARD_SPI) || (connection == TFT_PARALLEL)) &&
Expand Down Expand Up @@ -2426,6 +2475,8 @@ void Adafruit_SPITFT::SPI_WRITE16(uint16_t w) {
spi_inst_t *pi_spi = hwspi._spi == &SPI ? spi0 : spi1;
w = __builtin_bswap16(w);
spi_write_blocking(pi_spi, (uint8_t *)&w, 2);
#elif defined(ARDUINO_ARCH_RTTHREAD)
hwspi._spi->transfer16(w);
#else
// MSB, LSB because TFTs are generally big-endian
hwspi._spi->transfer(w >> 8);
Expand Down Expand Up @@ -2482,6 +2533,9 @@ void Adafruit_SPITFT::SPI_WRITE32(uint32_t l) {
spi_inst_t *pi_spi = hwspi._spi == &SPI ? spi0 : spi1;
l = __builtin_bswap32(l);
spi_write_blocking(pi_spi, (uint8_t *)&l, 4);
#elif defined(ARDUINO_ARCH_RTTHREAD)
hwspi._spi->transfer16(l >> 16);
hwspi._spi->transfer16(l);
#else
hwspi._spi->transfer(l >> 24);
hwspi._spi->transfer(l >> 16);
Expand Down

0 comments on commit 202fbb1

Please sign in to comment.