Permalink
Browse files

sped up BMP drawing

  • Loading branch information...
ladyada committed Apr 17, 2012
1 parent 84db24d commit 3a1ed0946e2f8332c620268b1906c8122dea13a3
Showing with 27 additions and 25 deletions.
  1. +16 −13 Adafruit_HX8340B.cpp
  2. +1 −1 Adafruit_HX8340B.h
  3. +6 −7 examples/hx8340b/hx8340b.pde
  4. +4 −4 examples/hx8340bmp/{hx8340bmp.ino → hx8340bmp.pde}
View
@@ -1,4 +1,3 @@
-//#include <Wire.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include <stdlib.h>
@@ -7,7 +6,7 @@
#include "Adafruit_GFX.h"
#include "Adafruit_HX8340B.h"
-
+// use bitbang SPI (not suggested)
Adafruit_HX8340B::Adafruit_HX8340B(int8_t SID, int8_t SCLK, int8_t RST, int8_t CS) {
sid = SID;
sclk = SCLK;
@@ -16,6 +15,7 @@ Adafruit_HX8340B::Adafruit_HX8340B(int8_t SID, int8_t SCLK, int8_t RST, int8_t C
hwSPI = false;
}
+// use hardware SPI
Adafruit_HX8340B::Adafruit_HX8340B(int8_t RST, int8_t CS) {
sid = -1;
sclk = -1;
@@ -27,7 +27,7 @@ Adafruit_HX8340B::Adafruit_HX8340B(int8_t RST, int8_t CS) {
void Adafruit_HX8340B::begin() {
// Constructor for underlying GFX library
- constructor(176, 220);
+ constructor(HX8340B_LCDWIDTH, HX8340B_LCDHEIGHT);
// set pin directions
if (! hwSPI) {
@@ -159,12 +159,6 @@ void Adafruit_HX8340B::begin() {
//clearDisplay();
}
-// clear everything
-void Adafruit_HX8340B::clearDisplay(void) {
- fillRect(0, 0, HX8340B_LCDWIDTH, HX8340B_LCDHEIGHT, 0x0000);
-}
-
-
// clear everything
void Adafruit_HX8340B::fillDisplay(uint16_t c) {
fillRect(0, 0, HX8340B_LCDWIDTH, HX8340B_LCDHEIGHT, c);
@@ -173,20 +167,29 @@ void Adafruit_HX8340B::fillDisplay(uint16_t c) {
void Adafruit_HX8340B::invertDisplay(uint8_t i) {
}
-void Adafruit_HX8340B::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t c) {
+void Adafruit_HX8340B::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) {
setWindow(x, y, x+w-1, y+h-1);
*csport &= ~cspinmask;
- for (int16_t i=0;i<w*h;i++)
+ uint32_t i = w;
+ i *= h;
+
+ while (i--)
{
- writeData(c >> 8);
- writeData(c);
+ writeData((color>>8) & 0xFF);
+ writeData(color & 0xFF);
}
*csport |= cspinmask;
}
+void Adafruit_HX8340B::pushColor(uint16_t color) {
+ *csport &= ~cspinmask;
+ writeData((color>>8) & 0xFF);
+ writeData(color & 0xFF);
+ *csport |= cspinmask;
+}
// the most basic function, set a single pixel
void Adafruit_HX8340B::drawPixel(int16_t x, int16_t y, uint16_t color) {
View
@@ -102,11 +102,11 @@ class Adafruit_HX8340B : public Adafruit_GFX {
void HX8340B_command(uint8_t c);
void writeData(uint8_t c);
- void clearDisplay(void);
void invertDisplay(uint8_t i);
void display();
void fillDisplay(uint16_t c);
+ void pushColor(uint16_t color);
void drawPixel(int16_t x, int16_t y, uint16_t color);
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t c);
void setWindow(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1);
@@ -158,7 +158,7 @@ void testdrawrects(uint16_t color) {
void testfillrects(uint16_t color1, uint16_t color2) {
display.fillScreen(BLACK);
- for (int16_t x=display.height()-1; x > 6; x-=6) {
+ for (int16_t x=display.width()-1; x > 6; x-=6) {
display.fillRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color1);
display.drawRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color2);
}
@@ -227,10 +227,10 @@ void tftPrintTest() {
display.println("Hello World!");
display.setTextColor(YELLOW, GREEN);
display.setTextSize(2);
- display.print("Hello Wo");
+ display.println("Hello World!");
display.setTextColor(BLUE);
display.setTextSize(3);
- display.print(1234.567);
+ display.println(1234.567);
delay(1500);
display.setCursor(0, 5);
display.fillScreen(BLACK);
@@ -242,10 +242,9 @@ void tftPrintTest() {
display.print(p, 5);
display.println(" Want pi?");
display.print(8675309, HEX); // print 8,675,309 out in HEX!
- display.print(" Print HEX");
+ display.println(" Print HEX");
display.setTextColor(WHITE);
- display.println("Sketch has been");
- display.println("running for: ");
+ display.println("Sketch has been running for: ");
display.setTextColor(MAGENTA);
display.print(millis() / 1000);
display.setTextColor(WHITE);
@@ -297,4 +296,4 @@ void lcdTestPattern(void)
else {display.writeData(BLACK>>8);display.writeData(BLACK);}
}
}
-}
+}
@@ -141,8 +141,8 @@ void bmpDraw(char *filename, uint8_t x, uint8_t y) {
if((x+w-1) >= display.width()) w = display.width() - x;
if((y+h-1) >= display.height()) h = display.height() - y;
+ display.setWindow(x, y, x+w-1, y+h-1);
for (row=0; row<h; row++) { // For each scanline...
- //display.goTo(x, y+row);
// Seek to start of scan line. It might seem labor-
// intensive to be doing this on every line, but this
@@ -172,9 +172,9 @@ void bmpDraw(char *filename, uint8_t x, uint8_t y) {
g = sdbuffer[buffidx++];
r = sdbuffer[buffidx++];
- display.drawPixel(x+col, y+row, display.Color565(r,g,b));
+ //display.drawPixel(x+col, y+row, display.Color565(r,g,b));
// optimized!
- //display.pushColor(display.Color565(r,g,b));
+ display.pushColor(display.Color565(r,g,b));
} // end pixel
} // end scanline
Serial.print("Loaded in ");
@@ -206,4 +206,4 @@ uint32_t read32(File f) {
((uint8_t *)&result)[2] = f.read();
((uint8_t *)&result)[3] = f.read(); // MSB
return result;
-}
+}

0 comments on commit 3a1ed09

Please sign in to comment.