Skip to content

Commit 0a9b0a8

Browse files
Merge pull request #67 from victorpv/ILI9341_without_DMA
Fix issue in Ili9341 without dma
2 parents c39ccfa + a6e0fad commit 0a9b0a8

2 files changed

Lines changed: 24 additions & 51 deletions

File tree

STM32F1/libraries/Adafruit_ILI9341/Adafruit_ILI9341.cpp

Lines changed: 23 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ void Adafruit_ILI9341::begin(void) {
253253
writedata(0x10); //SAP[2:0];BT[3:0]
254254

255255
writecommand(ILI9341_VMCTR1); //VCM control
256-
writedata(0x3e); //¶Ô±È¶Èµ÷½Ú
256+
writedata(0x3e); //???????
257257
writedata(0x28);
258258

259259
writecommand(ILI9341_VMCTR2); //VCM control2
@@ -327,11 +327,9 @@ void Adafruit_ILI9341::begin(void) {
327327
void Adafruit_ILI9341::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1,
328328
uint16_t y1) {
329329

330-
byte buf[4];
331330
writecommand(ILI9341_CASET); // Column addr set
332331
*dcport |= dcpinmask;
333332
*csport &= ~cspinmask;
334-
335333
SPI.write(x0 >> 8);
336334
SPI.write(x0 & 0xFF); // XSTART
337335
SPI.write(x1 >> 8);
@@ -340,13 +338,11 @@ void Adafruit_ILI9341::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1,
340338
writecommand(ILI9341_PASET); // Row addr set
341339
*dcport |= dcpinmask;
342340
*csport &= ~cspinmask;
343-
344341
SPI.write(y0>>8);
345342
SPI.write(y0); // YSTART
346343
SPI.write(y1>>8);
347344
SPI.write(y1); // YEND
348345

349-
350346
writecommand(ILI9341_RAMWR); // write to RAM
351347
}
352348

@@ -437,58 +433,33 @@ void Adafruit_ILI9341::fillScreen(uint16_t color) {
437433
}
438434

439435
// fill a rectangle
440-
void Adafruit_ILI9341::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) {
436+
void Adafruit_ILI9341::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
437+
uint16_t color) {
441438
int numPixels;
439+
// rudimentary clipping (drawChar w/big text requires this)
440+
if((x >= _width) || (y >= _height)) return;
441+
if((x + w - 1) >= _width) w = _width - x;
442+
if((y + h - 1) >= _height) h = _height - y;
442443

443-
unsigned char *buff;
444-
445-
// rudimentary clipping (drawChar w/big text requires this)
446-
if((x >= _width) || (y >= _height)) return;
447-
if((x + w - 1) >= _width) w = _width - x;
448-
if((y + h - 1) >= _height) h = _height - y;
444+
if (hwSPI) spi_begin();
445+
setAddrWindow(x, y, x+w-1, y+h-1);
449446

450-
if (hwSPI) spi_begin();
451-
setAddrWindow(x, y, x+w-1, y+h-1);
447+
uint8_t hi = color >> 8, lo = color;
452448

453-
uint8_t hi = color >> 8, lo = color;
449+
*dcport |= dcpinmask;
450+
*csport &= ~cspinmask;
454451

455-
*dcport |= dcpinmask;
456-
*csport &= ~cspinmask;
457-
if (true)
458-
{
459-
// Use DMA
460-
byte txBuf[h*2];// Buffer to be sent via DMA
461-
byte rxBuf[h*2];// Buffer to be sent via DMA
462-
463-
// need to build a buffer of the required height (h)
464-
// Note I suspect there is a faster way to do this
465-
for(int i=0;i<h*2;i++)
466-
{
467-
txBuf[i++] = hi&0xff;
468-
txBuf[i] = lo&0xff;
469-
}
470-
// Tansfer each line by DMA
471-
for(int i=0;i<w;i++)
472-
{
473-
//memcpy(rxBuf,txBuf,h*2);
474-
SPI.DMATransfer(txBuf,rxBuf,h*2);
475-
}
476-
}
477-
else
452+
for(y=h; y>0; y--)
453+
{
454+
for(x=w; x>0; x--)
478455
{
479-
// Non DMA method (currently not used)
480-
for(y=h; y>0; y--)
481-
{
482-
for(x=w; x>0; x--)
483-
{
484-
SPI.write(hi);
485-
SPI.write(lo);
486-
}
487-
}
488-
}
489-
490-
if (hwSPI) spi_end();
491-
*csport |= cspinmask;
456+
SPI.write(hi);
457+
SPI.write(lo);
458+
}
459+
}
460+
461+
if (hwSPI) spi_end();
462+
*csport |= cspinmask;
492463
}
493464

494465

@@ -658,3 +629,4 @@ uint8_t Adafruit_ILI9341::readcommand8(uint8_t c, uint8_t index) {
658629
}
659630
660631
*/
632+

STM32F1/libraries/Adafruit_ILI9341/Adafruit_ILI9341.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,4 @@ class Adafruit_ILI9341 : public Adafruit_GFX {
167167
};
168168

169169
#endif
170+

0 commit comments

Comments
 (0)