Skip to content

Commit 71cedbc

Browse files
committed
improved driver::ili9341 using Spi::transfer<16>
1 parent 19e740a commit 71cedbc

File tree

2 files changed

+23
-31
lines changed

2 files changed

+23
-31
lines changed

src/modm/driver/display/ili9341_impl.hpp

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,9 @@ void
202202
Ili9341<Interface, Reset, Backlight, BufferSize>::drawHorizontalLine(
203203
glcd::Point start, uint16_t length)
204204
{
205-
uint16_t const pixelValue { modm::toBigEndian(foregroundColor.color) };
206205
auto minLength { std::min(std::size_t(length), BufferSize) };
207206
uint16_t *buffer16 { reinterpret_cast<uint16_t *>(buffer) };
208-
std::fill(buffer16, buffer16+minLength, pixelValue);
207+
std::fill(buffer16, buffer16+minLength, foregroundColor.color);
209208

210209
BatchHandle h(*this);
211210

@@ -223,10 +222,9 @@ void
223222
Ili9341<Interface, Reset, Backlight, BufferSize>::drawVerticalLine(
224223
glcd::Point start, uint16_t length)
225224
{
226-
uint16_t const pixelValue { modm::toBigEndian(foregroundColor.color) };
227225
auto minLength { std::min(std::size_t(length), BufferSize) };
228226
uint16_t *buffer16 { reinterpret_cast<uint16_t *>(buffer) };
229-
std::fill(buffer16, buffer16+minLength, pixelValue);
227+
std::fill(buffer16, buffer16+minLength, foregroundColor.color);
230228

231229
BatchHandle h(*this);
232230

@@ -248,10 +246,9 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::fillRectangle(
248246
auto const y { upperLeft.getY() };
249247
std::size_t pixelCount { std::size_t(width) * std::size_t(height) };
250248

251-
uint16_t const pixelValue { modm::toBigEndian(foregroundColor.color) };
252249
auto minLength { std::min(std::size_t(pixelCount), BufferSize) };
253250
uint16_t *buffer16 { reinterpret_cast<uint16_t *>(buffer) };
254-
std::fill(buffer16, buffer16+minLength, pixelValue);
251+
std::fill(buffer16, buffer16+minLength, foregroundColor.color);
255252

256253
BatchHandle h(*this);
257254

@@ -270,9 +267,6 @@ void
270267
Ili9341<Interface, Reset, Backlight, BufferSize>::fillCircle(
271268
glcd::Point center, uint16_t radius)
272269
{
273-
uint8_t const setColor[] { uint8_t((foregroundColor.color >> 8) & 0xff),
274-
uint8_t(foregroundColor.color & 0xff) };
275-
276270
int16_t f = 1 - radius;
277271
int16_t ddF_x = 0;
278272
int16_t ddF_y = -2 * radius;
@@ -283,7 +277,7 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::fillCircle(
283277

284278
setClipping(center.getX() - radius, center.getY(), 2 * radius, 1);
285279
for (std::size_t i = 0; i < 2 * radius; ++i)
286-
this->writeData(setColor, 2);
280+
this->writeData(foregroundColor.color);
287281

288282
while(x < y)
289283
{
@@ -299,16 +293,16 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::fillCircle(
299293

300294
setClipping(center.getX() - x, center.getY() - y, 2 * x, 1);
301295
for (std::size_t i = 0; i < 2 * x; ++i)
302-
this->writeData(setColor, 2);
296+
this->writeData(foregroundColor.color);
303297
setClipping(center.getX() - y, center.getY() - x, 2 * y, 1);
304298
for (std::size_t i = 0; i < 2 * y; ++i)
305-
this->writeData(setColor, 2);
299+
this->writeData(foregroundColor.color);
306300
setClipping(center.getX() - x, center.getY() + y, 2 * x, 1);
307301
for (std::size_t i = 0; i < 2 * x; ++i)
308-
this->writeData(setColor, 2);
302+
this->writeData(foregroundColor.color);
309303
setClipping(center.getX() - y, center.getY() + x, 2 * y, 1);
310304
for (std::size_t i = 0; i < 2 * y; ++i)
311-
this->writeData(setColor, 2);
305+
this->writeData(foregroundColor.color);
312306
}
313307
}
314308

@@ -317,11 +311,6 @@ void
317311
Ili9341<Interface, Reset, Backlight, BufferSize>::drawImageRaw(glcd::Point upperLeft,
318312
uint16_t width, uint16_t height, modm::accessor::Flash<uint8_t> data)
319313
{
320-
uint8_t const setColor[] { uint8_t((foregroundColor.color >> 8) & 0xff),
321-
uint8_t(foregroundColor.color & 0xff) };
322-
uint8_t const clearColor[] { uint8_t((backgroundColor.color >> 8) & 0xff),
323-
uint8_t(backgroundColor.color & 0xff) };
324-
325314
BatchHandle h(*this);
326315

327316
setClipping(upperLeft.getX(), upperLeft.getY(), width, height);
@@ -333,9 +322,9 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::drawImageRaw(glcd::Point upper
333322
{
334323
uint8_t byte = data[(r / 8) * width + w];
335324
if (byte & bit)
336-
this->writeData(setColor, 2);
325+
this->writeData(foregroundColor.color);
337326
else
338-
this->writeData(clearColor, 2);
327+
this->writeData(backgroundColor.color);
339328
}
340329
// TODO: optimize, use ROL (rotate left)
341330
bit <<= 1;
@@ -351,13 +340,8 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::drawRaw(glcd::Point upperLeft,
351340
{
352341
BatchHandle h(*this);
353342

354-
uint16_t* buffer = (uint16_t*)data;
355-
for(size_t i = 0; i < size_t(width*height); i++) {
356-
buffer[i] = modm::fromBigEndian(buffer[i]);
357-
}
358-
359343
setClipping(upperLeft.getX(), upperLeft.getY(), width, height);
360-
this->writeData((uint8_t*)buffer, width * height * 2);
344+
this->writeData(data, width * height);
361345
}
362346

363347
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
@@ -391,13 +375,10 @@ void
391375
Ili9341<Interface, Reset, Backlight, BufferSize>::setColoredPixel(
392376
int16_t x, int16_t y, color::Rgb565 const &color)
393377
{
394-
auto const pixelColor { color };
395-
uint8_t const setColor[] { uint8_t((pixelColor.color >> 8) & 0xff), uint8_t(pixelColor.color & 0xff) };
396-
397378
BatchHandle h(*this);
398379

399380
this->setClipping(x, y, 1, 1);
400-
this->writeData(setColor, 2);
381+
this->writeData(foregroundColor.color);
401382
}
402383

403384
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>

src/modm/driver/display/ili9341_spi.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ class Ili9341SPIInterface: public ili9341, public modm::SpiDevice<SPI>
5555
{
5656
SPI::transferBlocking(const_cast<unsigned char *>(data), nullptr, length);
5757
}
58+
59+
writeData(color::Rgb565 data)
60+
{
61+
SPI::template transferBlocking<16>(data.value);
62+
}
63+
64+
writeData(color::Rgb565 const *data, std::size_t length)
65+
{
66+
SPI::template transferBlocking<16>((uint16_t*)(data), nullptr, length);
67+
}
68+
5869
void
5970
writeCommandValue8(Command command, uint8_t value)
6071
{

0 commit comments

Comments
 (0)