15
15
namespace modm
16
16
{
17
17
18
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
18
+ template <class Interface , class Reset , class Backlight >
19
19
void
20
- Ili9341<Interface, Reset, Backlight, BufferSize >::initialize()
20
+ Ili9341<Interface, Reset, Backlight>::initialize()
21
21
{
22
22
constexpr uint8_t pwrCtrlA[] { 0x39 , 0x2c , 0x00 , 0x34 , 0x02 };
23
23
constexpr uint8_t pwrCtrlB[] { 0x00 , 0xc1 , 0x30 };
@@ -78,9 +78,9 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::initialize()
78
78
}
79
79
}
80
80
81
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
81
+ template <class Interface , class Reset , class Backlight >
82
82
void
83
- Ili9341<Interface, Reset, Backlight, BufferSize >::reset(bool hardReset /* = false */ )
83
+ Ili9341<Interface, Reset, Backlight>::reset(bool hardReset /* = false */ )
84
84
{
85
85
if (hardReset)
86
86
{
@@ -98,9 +98,9 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::reset(bool hardReset /* = fals
98
98
}
99
99
}
100
100
101
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
101
+ template <class Interface , class Reset , class Backlight >
102
102
uint16_t
103
- Ili9341<Interface, Reset, Backlight, BufferSize >::getIcModel()
103
+ Ili9341<Interface, Reset, Backlight>::getIcModel()
104
104
{
105
105
BatchHandle h (*this );
106
106
@@ -109,9 +109,9 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::getIcModel()
109
109
return (buffer[2 ] << 8 ) | buffer[3 ];
110
110
}
111
111
112
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
112
+ template <class Interface , class Reset , class Backlight >
113
113
inline void
114
- Ili9341<Interface, Reset, Backlight, BufferSize >::setOrientation(glcd::Orientation orientation)
114
+ Ili9341<Interface, Reset, Backlight>::setOrientation(glcd::Orientation orientation)
115
115
{
116
116
using MemoryAccessCtrl_t = ili9341::MemoryAccessCtrl_t;
117
117
using MemoryAccessCtrl = ili9341::MemoryAccessCtrl;
@@ -139,140 +139,103 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::setOrientation(glcd::Orientati
139
139
this ->writeCommandValue8 (Command::MemoryAccessCtrl, madCtrl.value );
140
140
}
141
141
142
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
142
+ template <class Interface , class Reset , class Backlight >
143
143
void
144
- Ili9341<Interface, Reset, Backlight, BufferSize >::turnOn()
144
+ Ili9341<Interface, Reset, Backlight>::turnOn()
145
145
{
146
146
BatchHandle h (*this );
147
147
this ->writeCommand (Command::DisplayOn);
148
148
}
149
149
150
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
150
+ template <class Interface , class Reset , class Backlight >
151
151
void
152
- Ili9341<Interface, Reset, Backlight, BufferSize >::turnOff()
152
+ Ili9341<Interface, Reset, Backlight>::turnOff()
153
153
{
154
154
BatchHandle h (*this );
155
155
this ->writeCommand (Command::DisplayOff);
156
156
}
157
157
158
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
158
+ template <class Interface , class Reset , class Backlight >
159
159
void
160
- Ili9341<Interface, Reset, Backlight, BufferSize >::setIdle(bool enable)
160
+ Ili9341<Interface, Reset, Backlight>::setIdle(bool enable)
161
161
{
162
162
BatchHandle h (*this );
163
163
this ->writeCommand (enable ? Command::IdleModeOn : Command::IdleModeOff);
164
164
}
165
165
166
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
166
+ template <class Interface , class Reset , class Backlight >
167
167
void
168
- Ili9341<Interface, Reset, Backlight, BufferSize >::enableSleep(bool enable)
168
+ Ili9341<Interface, Reset, Backlight>::enableSleep(bool enable)
169
169
{
170
170
BatchHandle h (*this );
171
171
this ->writeCommand (enable ? Command::EnterSleep : Command::LeaveSleep);
172
172
}
173
173
174
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
174
+ template <class Interface , class Reset , class Backlight >
175
175
void
176
- Ili9341<Interface, Reset, Backlight, BufferSize >::setBrightness(uint8_t level)
176
+ Ili9341<Interface, Reset, Backlight>::setBrightness(uint8_t level)
177
177
{
178
178
BatchHandle h (*this );
179
179
this ->writeCommand (Command::WriteBrightness, &level, 1 );
180
180
}
181
181
182
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
182
+ template <class Interface , class Reset , class Backlight >
183
183
void
184
- Ili9341<Interface, Reset, Backlight, BufferSize >::setInvert(bool invert)
184
+ Ili9341<Interface, Reset, Backlight>::setInvert(bool invert)
185
185
{
186
186
BatchHandle h (*this );
187
187
this ->writeCommand (invert ? Command::InversionOn : Command::InversionOff);
188
188
}
189
189
190
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
190
+ template <class Interface , class Reset , class Backlight >
191
191
void
192
- Ili9341<Interface, Reset, Backlight, BufferSize >::clear()
192
+ Ili9341<Interface, Reset, Backlight>::clear()
193
193
{
194
194
auto const saveForegroundColor { foregroundColor };
195
195
foregroundColor = backgroundColor;
196
196
fillRectangle (glcd::Point (0 , 0 ), Width, Height);
197
197
foregroundColor = saveForegroundColor;
198
198
}
199
199
200
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
200
+ template <class Interface , class Reset , class Backlight >
201
201
void
202
- Ili9341<Interface, Reset, Backlight, BufferSize >::drawHorizontalLine(
202
+ Ili9341<Interface, Reset, Backlight>::drawHorizontalLine(
203
203
glcd::Point start, uint16_t length)
204
204
{
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 );
219
206
}
220
207
221
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
208
+ template <class Interface , class Reset , class Backlight >
222
209
void
223
- Ili9341<Interface, Reset, Backlight, BufferSize >::drawVerticalLine(
210
+ Ili9341<Interface, Reset, Backlight>::drawVerticalLine(
224
211
glcd::Point start, uint16_t length)
225
212
{
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);
240
214
}
241
215
242
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
216
+ template <class Interface , class Reset , class Backlight >
243
217
void
244
- Ili9341<Interface, Reset, Backlight, BufferSize >::fillRectangle(
218
+ Ili9341<Interface, Reset, Backlight>::fillRectangle(
245
219
glcd::Point upperLeft, uint16_t width, uint16_t height)
246
220
{
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;
255
222
256
223
BatchHandle h (*this );
257
224
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 () )
260
227
{
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 () ;
263
230
}
264
- if (pixelCount)
265
- this ->writeData (buffer, pixelCount * 2 );
231
+ this ->writeDataRepeat (&foregroundColor, pixelCount);
266
232
}
267
233
268
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
234
+ template <class Interface , class Reset , class Backlight >
269
235
void
270
- Ili9341<Interface, Reset, Backlight, BufferSize >::fillCircle(
236
+ Ili9341<Interface, Reset, Backlight>::fillCircle(
271
237
glcd::Point center, uint16_t radius)
272
238
{
273
- uint8_t const setColor[] { uint8_t ((foregroundColor.color >> 8 ) & 0xff ),
274
- uint8_t (foregroundColor.color & 0xff ) };
275
-
276
239
int16_t f = 1 - radius;
277
240
int16_t ddF_x = 0 ;
278
241
int16_t ddF_y = -2 * radius;
@@ -283,7 +246,7 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::fillCircle(
283
246
284
247
setClipping (center.getX () - radius, center.getY (), 2 * radius, 1 );
285
248
for (std::size_t i = 0 ; i < 2 * radius; ++i)
286
- this ->writeData (setColor, 2 );
249
+ this ->writeData (foregroundColor. color );
287
250
288
251
while (x < y)
289
252
{
@@ -299,29 +262,24 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::fillCircle(
299
262
300
263
setClipping (center.getX () - x, center.getY () - y, 2 * x, 1 );
301
264
for (std::size_t i = 0 ; i < 2 * x; ++i)
302
- this ->writeData (setColor, 2 );
265
+ this ->writeData (foregroundColor. color );
303
266
setClipping (center.getX () - y, center.getY () - x, 2 * y, 1 );
304
267
for (std::size_t i = 0 ; i < 2 * y; ++i)
305
- this ->writeData (setColor, 2 );
268
+ this ->writeData (foregroundColor. color );
306
269
setClipping (center.getX () - x, center.getY () + y, 2 * x, 1 );
307
270
for (std::size_t i = 0 ; i < 2 * x; ++i)
308
- this ->writeData (setColor, 2 );
271
+ this ->writeData (foregroundColor. color );
309
272
setClipping (center.getX () - y, center.getY () + x, 2 * y, 1 );
310
273
for (std::size_t i = 0 ; i < 2 * y; ++i)
311
- this ->writeData (setColor, 2 );
274
+ this ->writeData (foregroundColor. color );
312
275
}
313
276
}
314
277
315
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
278
+ template <class Interface , class Reset , class Backlight >
316
279
void
317
- Ili9341<Interface, Reset, Backlight, BufferSize >::drawImageRaw(glcd::Point upperLeft,
280
+ Ili9341<Interface, Reset, Backlight>::drawImageRaw(glcd::Point upperLeft,
318
281
uint16_t width, uint16_t height, modm::accessor::Flash<uint8_t > data)
319
282
{
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
-
325
283
BatchHandle h (*this );
326
284
327
285
setClipping (upperLeft.getX (), upperLeft.getY (), width, height);
@@ -333,9 +291,9 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::drawImageRaw(glcd::Point upper
333
291
{
334
292
uint8_t byte = data[(r / 8 ) * width + w];
335
293
if (byte & bit)
336
- this ->writeData (setColor, 2 );
294
+ this ->writeData (foregroundColor. color );
337
295
else
338
- this ->writeData (clearColor, 2 );
296
+ this ->writeData (backgroundColor. color );
339
297
}
340
298
// TODO: optimize, use ROL (rotate left)
341
299
bit <<= 1 ;
@@ -344,25 +302,20 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::drawImageRaw(glcd::Point upper
344
302
}
345
303
}
346
304
347
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
305
+ template <class Interface , class Reset , class Backlight >
348
306
void
349
- Ili9341<Interface, Reset, Backlight, BufferSize >::drawRaw(glcd::Point upperLeft,
307
+ Ili9341<Interface, Reset, Backlight>::drawRaw(glcd::Point upperLeft,
350
308
uint16_t width, uint16_t height, color::Rgb565* data)
351
309
{
352
310
BatchHandle h (*this );
353
311
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
-
359
312
setClipping (upperLeft.getX (), upperLeft.getY (), width, height);
360
- this ->writeData (( uint8_t *)buffer , width * height * 2 );
313
+ this ->writeData (data , width * height);
361
314
}
362
315
363
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
316
+ template <class Interface , class Reset , class Backlight >
364
317
void
365
- Ili9341<Interface, Reset, Backlight, BufferSize >::setScrollArea(
318
+ Ili9341<Interface, Reset, Backlight>::setScrollArea(
366
319
uint16_t topFixedRows, uint16_t bottomFixedRows, uint16_t firstRow)
367
320
{
368
321
BatchHandle h (*this );
@@ -376,33 +329,30 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::setScrollArea(
376
329
this ->writeCommand (Command::VerticalScrollDefinition, arg, 6 );
377
330
}
378
331
379
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
332
+ template <class Interface , class Reset , class Backlight >
380
333
void
381
- Ili9341<Interface, Reset, Backlight, BufferSize >::scrollTo(uint16_t row)
334
+ Ili9341<Interface, Reset, Backlight>::scrollTo(uint16_t row)
382
335
{
383
336
BatchHandle h (*this );
384
337
385
338
uint8_t arg[] { uint8_t ((row >> 8 ) & 0xff ), uint8_t (row & 0xff ) };
386
339
this ->writeCommand (Command::VerticalScrollStartAddr, arg, 2 );
387
340
}
388
341
389
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
342
+ template <class Interface , class Reset , class Backlight >
390
343
void
391
- Ili9341<Interface, Reset, Backlight, BufferSize >::setColoredPixel(
344
+ Ili9341<Interface, Reset, Backlight>::setColoredPixel(
392
345
int16_t x, int16_t y, color::Rgb565 const &color)
393
346
{
394
- auto const pixelColor { color };
395
- uint8_t const setColor[] { uint8_t ((pixelColor.color >> 8 ) & 0xff ), uint8_t (pixelColor.color & 0xff ) };
396
-
397
347
BatchHandle h (*this );
398
348
399
349
this ->setClipping (x, y, 1 , 1 );
400
- this ->writeData (setColor, 2 );
350
+ this ->writeData (color );
401
351
}
402
352
403
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
353
+ template <class Interface , class Reset , class Backlight >
404
354
void
405
- Ili9341<Interface, Reset, Backlight, BufferSize >::setClipping(
355
+ Ili9341<Interface, Reset, Backlight>::setClipping(
406
356
uint16_t x, uint16_t y, uint16_t width, uint16_t height)
407
357
{
408
358
uint8_t buffer[4 ];
@@ -421,9 +371,9 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::setClipping(
421
371
this ->writeCommand (Command::MemoryWrite);
422
372
}
423
373
424
- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
374
+ template <class Interface , class Reset , class Backlight >
425
375
void
426
- Ili9341<Interface, Reset, Backlight, BufferSize >::drawBitmap(glcd::Point upperLeft,
376
+ Ili9341<Interface, Reset, Backlight>::drawBitmap(glcd::Point upperLeft,
427
377
uint16_t width, uint16_t height, modm::accessor::Flash<uint8_t > data)
428
378
{
429
379
BatchHandle h (*this );
0 commit comments