Skip to content

Commit 324a3c2

Browse files
committed
[driver] Ili9241: Add drawRaw() method
1 parent 8a030c4 commit 324a3c2

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

src/modm/driver/display/ili9341.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ class Ili9341 : public Interface, public modm::GraphicDisplay
251251
uint16_t width, uint16_t height,
252252
modm::accessor::Flash<uint8_t> data) override;
253253

254+
virtual void
255+
drawRaw(glcd::Point upperLeft, uint16_t width, uint16_t height, glcd::Color* data);
256+
254257
void
255258
setScrollArea(uint16_t topFixedRows, uint16_t bottomFixedRows, uint16_t firstRow);
256259
void

src/modm/driver/display/ili9341_impl.hpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,10 @@ void
202202
Ili9341<Interface, Reset, Backlight, BufferSize>::drawHorizontalLine(
203203
glcd::Point start, uint16_t length)
204204
{
205-
auto const fgColor { foregroundColor.getValue() };
205+
uint16_t const pixelValue { modm::toBigEndian(foregroundColor.getValue()) };
206206
auto minLength { std::min(std::size_t(length), BufferSize) };
207207
uint16_t *buffer16 { reinterpret_cast<uint16_t *>(buffer) };
208-
for (std::size_t i = 0; i < minLength; ++i)
209-
buffer16[i] = modm::toBigEndian(fgColor);
208+
std::fill(buffer16, buffer16+minLength, pixelValue);
210209

211210
BatchHandle h(*this);
212211

@@ -224,11 +223,10 @@ void
224223
Ili9341<Interface, Reset, Backlight, BufferSize>::drawVerticalLine(
225224
glcd::Point start, uint16_t length)
226225
{
227-
auto const fgColor { foregroundColor.getValue() };
226+
uint16_t const pixelValue { modm::toBigEndian(foregroundColor.getValue()) };
228227
auto minLength { std::min(std::size_t(length), BufferSize) };
229228
uint16_t *buffer16 { reinterpret_cast<uint16_t *>(buffer) };
230-
for (std::size_t i = 0; i < minLength; ++i)
231-
buffer16[i] = modm::toBigEndian(fgColor);
229+
std::fill(buffer16, buffer16+minLength, pixelValue);
232230

233231
BatchHandle h(*this);
234232

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

253-
auto const fgColor { foregroundColor.getValue() };
251+
uint16_t const pixelValue { modm::toBigEndian(foregroundColor.getValue()) };
254252
auto minLength { std::min(std::size_t(pixelCount), BufferSize) };
255253
uint16_t *buffer16 { reinterpret_cast<uint16_t *>(buffer) };
256-
for (std::size_t i = 0; i < minLength; ++i)
257-
buffer16[i] = modm::toBigEndian(fgColor);
254+
std::fill(buffer16, buffer16+minLength, pixelValue);
258255

259256
BatchHandle h(*this);
260257

@@ -350,6 +347,22 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::drawImageRaw(glcd::Point upper
350347
}
351348
}
352349

350+
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
351+
void
352+
Ili9341<Interface, Reset, Backlight, BufferSize>::drawRaw(glcd::Point upperLeft,
353+
uint16_t width, uint16_t height, glcd::Color* data)
354+
{
355+
BatchHandle h(*this);
356+
357+
uint16_t* buffer = (uint16_t*)data;
358+
for(size_t i = 0; i < size_t(width*height); i++) {
359+
buffer[i] = modm::fromBigEndian(buffer[i]);
360+
}
361+
362+
setClipping(upperLeft.getX(), upperLeft.getY(), width, height);
363+
this->writeData((uint8_t*)buffer, width * height * 2);
364+
}
365+
353366
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
354367
void
355368
Ili9341<Interface, Reset, Backlight, BufferSize>::setScrollArea(

0 commit comments

Comments
 (0)