1515namespace modm
1616{
1717
18- template <class Interface , class Reset , class Backlight , std:: size_t BufferSize >
18+ template <class Interface , class Reset , class Backlight >
1919void
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 >
8282void
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 >
102102uint16_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 >
113113inline 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 >
143143void
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 >
151151void
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 >
159159void
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 >
167167void
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 >
175175void
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 >
183183void
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 >
191191void
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 >
201201void
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 >
222209void
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 >
243217void
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 >
269235void
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 >
316279void
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 >
348306void
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 >
364317void
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 >
380333void
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 >
390343void
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 >
404354void
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 >
425375void
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