Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ARDUINO_ARCH_RTTHREAD to support RTduino #425

Closed
wants to merge 3 commits into from
Closed
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
52 changes: 52 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,44 @@ 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);
}
#undef QUICKPATH_MAX_LEN
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 @@ -2402,6 +2449,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 @@ -2458,6 +2507,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
Loading