SG12864A
Dependents: SG12864A_TestProgram
Diff: SG12864A.cpp
- Revision:
- 1:aacd73a4e7ee
- Parent:
- 0:238f2d048222
- Child:
- 2:91c03e41c927
--- a/SG12864A.cpp Mon Jul 19 12:43:25 2010 +0000 +++ b/SG12864A.cpp Tue Jul 20 03:59:17 2010 +0000 @@ -7,6 +7,10 @@ #include "SG12864A.h" +#define setPixel(x,y) buffer[((COLUMNS * 2)* (y / 8)) + x] |= (1 << (y % 8)) +#define unsetPixel(x,y) buffer[((COLUMNS * 2)* (y / 8)) + x] &= ~(1 << (y % 8)) +#define swap(a,b) {int c=a;a=b;b=c;} + SG12864A::SG12864A(PinName di, PinName rw, PinName en, @@ -29,22 +33,101 @@ ioCS1(cs1), ioCS2(cs2), ioRES(res) { + bufferClear(); setDirectionToWrite(); } SG12864A::~SG12864A() { } +void SG12864A::bufferPush(void) { + for (uint8_t i = 0; i < PAGES; i++) { + // CS1 + setPageAddress(SG12864A::CS1, i); + setColumnAddress(SG12864A::CS1, 0); + for (uint8_t j = 0; j < COLUMNS; j++) { + writeData(CS1, buffer[0 + ((COLUMNS * 2) * i) + j]); + } + // CS2 + setPageAddress(SG12864A::CS2, i); + setColumnAddress(SG12864A::CS2, 0); + for (uint8_t j = 0; j < COLUMNS; j++) { + writeData(CS2, buffer[COLUMNS + ((COLUMNS * 2) * i) + j]); + } + } +} + +void SG12864A::bufferPull(void) { +} + +void SG12864A::bufferClear(void) { + for (int i = 0; i < sizeof(buffer); i++) { + buffer[i] = 0x00; + } +} + +void SG12864A::bufferDrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) { + /* + * Bresenham's line algorithm + */ + bool steep = abs(y2 - y1) > abs(x2 - x1); + if (steep) { + swap(x1, y1); + swap(x2, y2); + } + if (x1 > x2) { + swap(x1, x2); + swap(y1, y2); + } + int deltax = x2 - x1; + int deltay = abs(y2 - y1); + int error = deltax / 2; + int ystep; + int y = y1; + if (y1 < y2) { + ystep = 1; + } else { + ystep = -1; + } + for (int x = x1; x <= x2; x++) { + if (steep) { + setPixel(y,x); + } else { + setPixel(x,y); + } + error = error - deltay; + if (error < 0) { + y = y + ystep; + error = error + deltax; + } + } +} + +void SG12864A::bufferDrawBox(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) { + for (int x = x1; x <= x2; x++) { + setPixel(x, y1); + setPixel(x, y2); + } + for (int y = y1; y <= y2; y++) { + setPixel(x1, y); + setPixel(x2, y); + } +} + +void SG12864A::bufferFillBox(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) { + for (int x = x1; x <= x2; x++) { + for (int y = y1; y <= y2; y++) { + setPixel(x, y); + } + } +} + /** * High Level Interface. * * Reset display module. */ void SG12864A::reset(void) { - setDisplayOnOff(SG12864A::CS1, false); - setDisplayOnOff(SG12864A::CS2, false); - clear(); - reset(true); wait_ms(200); reset(false);