Skip to content

Commit e143244

Browse files
committed
adapt driver::touch2046 for new SPI
1 parent 1018d60 commit e143244

File tree

4 files changed

+126
-143
lines changed

4 files changed

+126
-143
lines changed

src/modm/driver/display/ili9341.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,9 @@ struct ili9341
138138
};
139139

140140
/// @ingroup modm_driver_ili9341
141-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize = 320>
141+
template <class Interface, class Reset, class Backlight>
142142
class Ili9341 : public Interface, public modm::ColorGraphicDisplay
143143
{
144-
static_assert(BufferSize >= 16, "at least a small buffer is required");
145-
146144
static constexpr uint16_t Width = 240;
147145
static constexpr uint16_t Height = 320;
148146
using BatchHandle = typename Interface::BatchHandle;
@@ -297,7 +295,7 @@ class Ili9341 : public Interface, public modm::ColorGraphicDisplay
297295

298296
Orientation orientation{Orientation::Landscape0};
299297

300-
uint8_t buffer[BufferSize * 2]{0};
298+
uint8_t buffer[4];
301299
};
302300

303301
} // namespace modm

src/modm/driver/display/ili9341_impl.hpp

Lines changed: 61 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
namespace modm
1616
{
1717

18-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
18+
template <class Interface, class Reset, class Backlight>
1919
void
20-
Ili9341<Interface, Reset, Backlight, BufferSize>::initialize()
20+
Ili9341<Interface, Reset, Backlight>::initialize()
2121
{
2222
constexpr uint8_t pwrCtrlA[] { 0x39, 0x2c, 0x00, 0x34, 0x02 };
2323
constexpr uint8_t pwrCtrlB[] { 0x00, 0xc1, 0x30 };
@@ -78,9 +78,9 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::initialize()
7878
}
7979
}
8080

81-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
81+
template <class Interface, class Reset, class Backlight>
8282
void
83-
Ili9341<Interface, Reset, Backlight, BufferSize>::reset(bool hardReset /* = false */)
83+
Ili9341<Interface, Reset, Backlight>::reset(bool hardReset /* = false */)
8484
{
8585
if (hardReset)
8686
{
@@ -98,9 +98,9 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::reset(bool hardReset /* = fals
9898
}
9999
}
100100

101-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
101+
template <class Interface, class Reset, class Backlight>
102102
uint16_t
103-
Ili9341<Interface, Reset, Backlight, BufferSize>::getIcModel()
103+
Ili9341<Interface, Reset, Backlight>::getIcModel()
104104
{
105105
BatchHandle h(*this);
106106

@@ -109,9 +109,9 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::getIcModel()
109109
return (buffer[2] << 8) | buffer[3];
110110
}
111111

112-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
112+
template <class Interface, class Reset, class Backlight>
113113
inline void
114-
Ili9341<Interface, Reset, Backlight, BufferSize>::setOrientation(glcd::Orientation orientation)
114+
Ili9341<Interface, Reset, Backlight>::setOrientation(glcd::Orientation orientation)
115115
{
116116
using MemoryAccessCtrl_t = ili9341::MemoryAccessCtrl_t;
117117
using MemoryAccessCtrl = ili9341::MemoryAccessCtrl;
@@ -139,140 +139,103 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::setOrientation(glcd::Orientati
139139
this->writeCommandValue8(Command::MemoryAccessCtrl, madCtrl.value);
140140
}
141141

142-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
142+
template <class Interface, class Reset, class Backlight>
143143
void
144-
Ili9341<Interface, Reset, Backlight, BufferSize>::turnOn()
144+
Ili9341<Interface, Reset, Backlight>::turnOn()
145145
{
146146
BatchHandle h(*this);
147147
this->writeCommand(Command::DisplayOn);
148148
}
149149

150-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
150+
template <class Interface, class Reset, class Backlight>
151151
void
152-
Ili9341<Interface, Reset, Backlight, BufferSize>::turnOff()
152+
Ili9341<Interface, Reset, Backlight>::turnOff()
153153
{
154154
BatchHandle h(*this);
155155
this->writeCommand(Command::DisplayOff);
156156
}
157157

158-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
158+
template <class Interface, class Reset, class Backlight>
159159
void
160-
Ili9341<Interface, Reset, Backlight, BufferSize>::setIdle(bool enable)
160+
Ili9341<Interface, Reset, Backlight>::setIdle(bool enable)
161161
{
162162
BatchHandle h(*this);
163163
this->writeCommand(enable ? Command::IdleModeOn : Command::IdleModeOff);
164164
}
165165

166-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
166+
template <class Interface, class Reset, class Backlight>
167167
void
168-
Ili9341<Interface, Reset, Backlight, BufferSize>::enableSleep(bool enable)
168+
Ili9341<Interface, Reset, Backlight>::enableSleep(bool enable)
169169
{
170170
BatchHandle h(*this);
171171
this->writeCommand(enable ? Command::EnterSleep : Command::LeaveSleep);
172172
}
173173

174-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
174+
template <class Interface, class Reset, class Backlight>
175175
void
176-
Ili9341<Interface, Reset, Backlight, BufferSize>::setBrightness(uint8_t level)
176+
Ili9341<Interface, Reset, Backlight>::setBrightness(uint8_t level)
177177
{
178178
BatchHandle h(*this);
179179
this->writeCommand(Command::WriteBrightness, &level, 1);
180180
}
181181

182-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
182+
template <class Interface, class Reset, class Backlight>
183183
void
184-
Ili9341<Interface, Reset, Backlight, BufferSize>::setInvert(bool invert)
184+
Ili9341<Interface, Reset, Backlight>::setInvert(bool invert)
185185
{
186186
BatchHandle h(*this);
187187
this->writeCommand(invert ? Command::InversionOn : Command::InversionOff);
188188
}
189189

190-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
190+
template <class Interface, class Reset, class Backlight>
191191
void
192-
Ili9341<Interface, Reset, Backlight, BufferSize>::clear()
192+
Ili9341<Interface, Reset, Backlight>::clear()
193193
{
194194
auto const saveForegroundColor { foregroundColor };
195195
foregroundColor = backgroundColor;
196196
fillRectangle(glcd::Point(0, 0), Width, Height);
197197
foregroundColor = saveForegroundColor;
198198
}
199199

200-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
200+
template <class Interface, class Reset, class Backlight>
201201
void
202-
Ili9341<Interface, Reset, Backlight, BufferSize>::drawHorizontalLine(
202+
Ili9341<Interface, Reset, Backlight>::drawHorizontalLine(
203203
glcd::Point start, uint16_t length)
204204
{
205-
uint16_t const pixelValue { modm::toBigEndian(foregroundColor.color) };
206-
auto minLength { std::min(std::size_t(length), BufferSize) };
207-
uint16_t *buffer16 { reinterpret_cast<uint16_t *>(buffer) };
208-
std::fill(buffer16, buffer16+minLength, pixelValue);
209-
210-
BatchHandle h(*this);
211-
212-
setClipping(start.getX(), start.getY(), length, 1);
213-
while (length > BufferSize)
214-
{
215-
this->writeData(buffer, BufferSize * 2);
216-
length -= BufferSize;
217-
}
218-
this->writeData(buffer, length * 2);
205+
fillRectangle(start, length, 1);
219206
}
220207

221-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
208+
template <class Interface, class Reset, class Backlight>
222209
void
223-
Ili9341<Interface, Reset, Backlight, BufferSize>::drawVerticalLine(
210+
Ili9341<Interface, Reset, Backlight>::drawVerticalLine(
224211
glcd::Point start, uint16_t length)
225212
{
226-
uint16_t const pixelValue { modm::toBigEndian(foregroundColor.color) };
227-
auto minLength { std::min(std::size_t(length), BufferSize) };
228-
uint16_t *buffer16 { reinterpret_cast<uint16_t *>(buffer) };
229-
std::fill(buffer16, buffer16+minLength, pixelValue);
230-
231-
BatchHandle h(*this);
232-
233-
setClipping(start.getX(), start.getY(), 1, length);
234-
while (length > BufferSize)
235-
{
236-
this->writeData(buffer, BufferSize * 2);
237-
length -= BufferSize;
238-
}
239-
this->writeData(buffer, length * 2);
213+
fillRectangle(start, 1, length);
240214
}
241215

242-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
216+
template <class Interface, class Reset, class Backlight>
243217
void
244-
Ili9341<Interface, Reset, Backlight, BufferSize>::fillRectangle(
218+
Ili9341<Interface, Reset, Backlight>::fillRectangle(
245219
glcd::Point upperLeft, uint16_t width, uint16_t height)
246220
{
247-
auto const x { upperLeft.getX() };
248-
auto const y { upperLeft.getY() };
249-
std::size_t pixelCount { std::size_t(width) * std::size_t(height) };
250-
251-
uint16_t const pixelValue { modm::toBigEndian(foregroundColor.color) };
252-
auto minLength { std::min(std::size_t(pixelCount), BufferSize) };
253-
uint16_t *buffer16 { reinterpret_cast<uint16_t *>(buffer) };
254-
std::fill(buffer16, buffer16+minLength, pixelValue);
221+
uint64_t pixelCount = uint64_t(width) * height;
255222

256223
BatchHandle h(*this);
257224

258-
setClipping(x, y, width, height);
259-
while (pixelCount > BufferSize)
225+
setClipping(upperLeft.getX(), upperLeft.getY(), width, height);
226+
while (pixelCount > std::numeric_limits<uint16_t>::max())
260227
{
261-
this->writeData(buffer, BufferSize * 2);
262-
pixelCount -= BufferSize;
228+
this->writeDataRepeat(foregroundColor, std::numeric_limits<uint16_t>::max());
229+
pixelCount -= std::numeric_limits<uint16_t>::max();
263230
}
264-
if (pixelCount)
265-
this->writeData(buffer, pixelCount * 2);
231+
this->writeDataRepeat(foregroundColor, pixelCount);
266232
}
267233

268-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
234+
template <class Interface, class Reset, class Backlight>
269235
void
270-
Ili9341<Interface, Reset, Backlight, BufferSize>::fillCircle(
236+
Ili9341<Interface, Reset, Backlight>::fillCircle(
271237
glcd::Point center, uint16_t radius)
272238
{
273-
uint8_t const setColor[] { uint8_t((foregroundColor.color >> 8) & 0xff),
274-
uint8_t(foregroundColor.color & 0xff) };
275-
276239
int16_t f = 1 - radius;
277240
int16_t ddF_x = 0;
278241
int16_t ddF_y = -2 * radius;
@@ -283,7 +246,7 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::fillCircle(
283246

284247
setClipping(center.getX() - radius, center.getY(), 2 * radius, 1);
285248
for (std::size_t i = 0; i < 2 * radius; ++i)
286-
this->writeData(setColor, 2);
249+
this->writeData(foregroundColor.color);
287250

288251
while(x < y)
289252
{
@@ -299,29 +262,24 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::fillCircle(
299262

300263
setClipping(center.getX() - x, center.getY() - y, 2 * x, 1);
301264
for (std::size_t i = 0; i < 2 * x; ++i)
302-
this->writeData(setColor, 2);
265+
this->writeData(foregroundColor.color);
303266
setClipping(center.getX() - y, center.getY() - x, 2 * y, 1);
304267
for (std::size_t i = 0; i < 2 * y; ++i)
305-
this->writeData(setColor, 2);
268+
this->writeData(foregroundColor.color);
306269
setClipping(center.getX() - x, center.getY() + y, 2 * x, 1);
307270
for (std::size_t i = 0; i < 2 * x; ++i)
308-
this->writeData(setColor, 2);
271+
this->writeData(foregroundColor.color);
309272
setClipping(center.getX() - y, center.getY() + x, 2 * y, 1);
310273
for (std::size_t i = 0; i < 2 * y; ++i)
311-
this->writeData(setColor, 2);
274+
this->writeData(foregroundColor.color);
312275
}
313276
}
314277

315-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
278+
template <class Interface, class Reset, class Backlight>
316279
void
317-
Ili9341<Interface, Reset, Backlight, BufferSize>::drawImageRaw(glcd::Point upperLeft,
280+
Ili9341<Interface, Reset, Backlight>::drawImageRaw(glcd::Point upperLeft,
318281
uint16_t width, uint16_t height, modm::accessor::Flash<uint8_t> data)
319282
{
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-
325283
BatchHandle h(*this);
326284

327285
setClipping(upperLeft.getX(), upperLeft.getY(), width, height);
@@ -333,9 +291,9 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::drawImageRaw(glcd::Point upper
333291
{
334292
uint8_t byte = data[(r / 8) * width + w];
335293
if (byte & bit)
336-
this->writeData(setColor, 2);
294+
this->writeData(foregroundColor.color);
337295
else
338-
this->writeData(clearColor, 2);
296+
this->writeData(backgroundColor.color);
339297
}
340298
// TODO: optimize, use ROL (rotate left)
341299
bit <<= 1;
@@ -344,25 +302,20 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::drawImageRaw(glcd::Point upper
344302
}
345303
}
346304

347-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
305+
template <class Interface, class Reset, class Backlight>
348306
void
349-
Ili9341<Interface, Reset, Backlight, BufferSize>::drawRaw(glcd::Point upperLeft,
307+
Ili9341<Interface, Reset, Backlight>::drawRaw(glcd::Point upperLeft,
350308
uint16_t width, uint16_t height, color::Rgb565* data)
351309
{
352310
BatchHandle h(*this);
353311

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-
359312
setClipping(upperLeft.getX(), upperLeft.getY(), width, height);
360-
this->writeData((uint8_t*)buffer, width * height * 2);
313+
this->writeData(data, width * height);
361314
}
362315

363-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
316+
template <class Interface, class Reset, class Backlight>
364317
void
365-
Ili9341<Interface, Reset, Backlight, BufferSize>::setScrollArea(
318+
Ili9341<Interface, Reset, Backlight>::setScrollArea(
366319
uint16_t topFixedRows, uint16_t bottomFixedRows, uint16_t firstRow)
367320
{
368321
BatchHandle h(*this);
@@ -376,33 +329,30 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::setScrollArea(
376329
this->writeCommand(Command::VerticalScrollDefinition, arg, 6);
377330
}
378331

379-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
332+
template <class Interface, class Reset, class Backlight>
380333
void
381-
Ili9341<Interface, Reset, Backlight, BufferSize>::scrollTo(uint16_t row)
334+
Ili9341<Interface, Reset, Backlight>::scrollTo(uint16_t row)
382335
{
383336
BatchHandle h(*this);
384337

385338
uint8_t arg[] { uint8_t((row >> 8) & 0xff), uint8_t(row & 0xff) };
386339
this->writeCommand(Command::VerticalScrollStartAddr, arg, 2);
387340
}
388341

389-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
342+
template <class Interface, class Reset, class Backlight>
390343
void
391-
Ili9341<Interface, Reset, Backlight, BufferSize>::setColoredPixel(
344+
Ili9341<Interface, Reset, Backlight>::setColoredPixel(
392345
int16_t x, int16_t y, color::Rgb565 const &color)
393346
{
394-
auto const pixelColor { color };
395-
uint8_t const setColor[] { uint8_t((pixelColor.color >> 8) & 0xff), uint8_t(pixelColor.color & 0xff) };
396-
397347
BatchHandle h(*this);
398348

399349
this->setClipping(x, y, 1, 1);
400-
this->writeData(setColor, 2);
350+
this->writeData(color);
401351
}
402352

403-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
353+
template <class Interface, class Reset, class Backlight>
404354
void
405-
Ili9341<Interface, Reset, Backlight, BufferSize>::setClipping(
355+
Ili9341<Interface, Reset, Backlight>::setClipping(
406356
uint16_t x, uint16_t y, uint16_t width, uint16_t height)
407357
{
408358
uint8_t buffer[4];
@@ -421,9 +371,9 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::setClipping(
421371
this->writeCommand(Command::MemoryWrite);
422372
}
423373

424-
template <class Interface, class Reset, class Backlight, std::size_t BufferSize>
374+
template <class Interface, class Reset, class Backlight>
425375
void
426-
Ili9341<Interface, Reset, Backlight, BufferSize>::drawBitmap(glcd::Point upperLeft,
376+
Ili9341<Interface, Reset, Backlight>::drawBitmap(glcd::Point upperLeft,
427377
uint16_t width, uint16_t height, modm::accessor::Flash<uint8_t> data)
428378
{
429379
BatchHandle h(*this);

0 commit comments

Comments
 (0)