Skip to content

Commit 22ad39d

Browse files
authored
add ARDUINO_ARCH_RTTHREAD to support RTduino (#460)
1 parent 0e32d7d commit 22ad39d

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

Adafruit_SPITFT.cpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,15 @@ void Adafruit_SPITFT::writePixels(uint16_t *colors, uint32_t len, bool block,
10381038
spi_write_blocking(pi_spi, (uint8_t *)colors, len * 2);
10391039
}
10401040
return;
1041+
#elif defined(ARDUINO_ARCH_RTTHREAD)
1042+
if (!bigEndian) {
1043+
swapBytes(colors, len); // convert little-to-big endian for display
1044+
}
1045+
hwspi._spi->transfer(colors, 2 * len);
1046+
if (!bigEndian) {
1047+
swapBytes(colors, len); // big-to-little endian to restore pixel buffer
1048+
}
1049+
return;
10411050
#elif defined(USE_SPI_DMA) && \
10421051
(defined(__SAMD51__) || defined(ARDUINO_SAMD_ZERO))
10431052
if ((connection == TFT_HARD_SPI) || (connection == TFT_PARALLEL)) {
@@ -1245,7 +1254,44 @@ void Adafruit_SPITFT::writeColor(uint16_t color, uint32_t len) {
12451254
rtos_free(pixbuf);
12461255
return;
12471256
}
1248-
#else // !ESP32
1257+
#elif defined(ARDUINO_ARCH_RTTHREAD)
1258+
uint16_t pixbufcount;
1259+
uint16_t *pixbuf;
1260+
int16_t lines = height() / 4;
1261+
#define QUICKPATH_MAX_LEN 16
1262+
uint16_t quickpath_buffer[QUICKPATH_MAX_LEN];
1263+
1264+
do {
1265+
pixbufcount = min(len, (lines * width()));
1266+
if (pixbufcount > QUICKPATH_MAX_LEN) {
1267+
pixbuf = (uint16_t *)rt_malloc(2 * pixbufcount);
1268+
} else {
1269+
pixbuf = quickpath_buffer;
1270+
}
1271+
lines -= 2;
1272+
} while (!pixbuf && lines > 0);
1273+
1274+
if (pixbuf) {
1275+
uint16_t const swap_color = __builtin_bswap16(color);
1276+
1277+
while (len) {
1278+
uint16_t count = min(len, pixbufcount);
1279+
// fill buffer with color
1280+
for (uint16_t i = 0; i < count; i++) {
1281+
pixbuf[i] = swap_color;
1282+
}
1283+
// Don't need to swap color inside the function
1284+
// It has been done outside this function
1285+
writePixels(pixbuf, count, true, true);
1286+
len -= count;
1287+
}
1288+
if (pixbufcount > QUICKPATH_MAX_LEN) {
1289+
rt_free(pixbuf);
1290+
}
1291+
#undef QUICKPATH_MAX_LEN
1292+
return;
1293+
}
1294+
#else // !ESP32
12491295
#if defined(USE_SPI_DMA) && (defined(__SAMD51__) || defined(ARDUINO_SAMD_ZERO))
12501296
if (((connection == TFT_HARD_SPI) || (connection == TFT_PARALLEL)) &&
12511297
(len >= 16)) { // Don't bother with DMA on short pixel runs
@@ -2403,6 +2449,8 @@ void Adafruit_SPITFT::SPI_WRITE16(uint16_t w) {
24032449
spi_inst_t *pi_spi = hwspi._spi == &SPI ? spi0 : spi1;
24042450
w = __builtin_bswap16(w);
24052451
spi_write_blocking(pi_spi, (uint8_t *)&w, 2);
2452+
#elif defined(ARDUINO_ARCH_RTTHREAD)
2453+
hwspi._spi->transfer16(w);
24062454
#else
24072455
// MSB, LSB because TFTs are generally big-endian
24082456
hwspi._spi->transfer(w >> 8);
@@ -2459,6 +2507,9 @@ void Adafruit_SPITFT::SPI_WRITE32(uint32_t l) {
24592507
spi_inst_t *pi_spi = hwspi._spi == &SPI ? spi0 : spi1;
24602508
l = __builtin_bswap32(l);
24612509
spi_write_blocking(pi_spi, (uint8_t *)&l, 4);
2510+
#elif defined(ARDUINO_ARCH_RTTHREAD)
2511+
hwspi._spi->transfer16(l >> 16);
2512+
hwspi._spi->transfer16(l);
24622513
#else
24632514
hwspi._spi->transfer(l >> 24);
24642515
hwspi._spi->transfer(l >> 16);

0 commit comments

Comments
 (0)