X-Git-Url: https://git.rohieb.name/hackover2013-badge-firmware.git/blobdiff_plain/ce00990e52808c5f8e2ceefd38f9eeb44bb96eab..2f05268611277338f015e48c98b330078781172f:/drivers/lcd/tft/hw/ssd1331.c diff --git a/drivers/lcd/tft/hw/ssd1331.c b/drivers/lcd/tft/hw/ssd1331.c index ddc8694..a934ba2 100644 --- a/drivers/lcd/tft/hw/ssd1331.c +++ b/drivers/lcd/tft/hw/ssd1331.c @@ -49,20 +49,8 @@ static lcdProperties_t ssd1331Properties = { 96, 64, false, false, false }; /* Private Methods */ /*************************************************/ -// You can speed all of these slow GPIO calls up by using the SET/CLR macros! - -#define CMD(c) do { gpioSetValue( SSD1331_CS_PORT, SSD1331_CS_PIN, 1 ); \ - gpioSetValue( SSD1331_DC_PORT, SSD1331_DC_PIN, 0 ); \ - gpioSetValue( SSD1331_CS_PORT, SSD1331_CS_PIN, 0 ); \ - ssd1331SendByte( c ); \ - gpioSetValue( SSD1331_CS_PORT, SSD1331_CS_PIN, 1 ); \ - } while (0); -#define DATA(c) do { gpioSetValue( SSD1331_CS_PORT, SSD1331_CS_PIN, 1 ); \ - gpioSetValue( SSD1331_DC_PORT, SSD1331_DC_PIN, 1 ); \ - gpioSetValue( SSD1331_CS_PORT, SSD1331_CS_PIN, 0 ); \ - ssd1331SendByte( c ); \ - gpioSetValue( SSD1331_CS_PORT, SSD1331_CS_PIN, 1 ); \ - } while (0); +#define CMD(c) do { SET_CS; CLR_DC; CLR_CS; ssd1331SendByte( c ); SET_CS; } while (0) +#define DATA(c) do { SET_CS; SET_DC; CLR_CS; ssd1331SendByte( c ); SET_CS; } while (0); #define DELAY(mS) do { systickDelay( mS / CFG_SYSTICK_DELAY_IN_MS ); } while(0); /**************************************************************************/ @@ -78,17 +66,24 @@ void ssd1331SendByte(uint8_t byte) int8_t i; // Make sure clock pin starts high - gpioSetValue(SSD1331_SCK_PORT, SSD1331_SCK_PIN, 1); + SET_SCK; // Write from MSB to LSB for (i=7; i>=0; i--) { // Set clock pin low - gpioSetValue(SSD1331_SCK_PORT, SSD1331_SCK_PIN, 0); + CLR_SCK; // Set data pin high or low depending on the value of the current bit - gpioSetValue(SSD1331_SID_PORT, SSD1331_SID_PIN, byte & (1 << i) ? 1 : 0); + if (byte & (1 << i)) + { + SET_SID; + } + else + { + CLR_SID; + } // Set clock pin high - gpioSetValue(SSD1331_SCK_PORT, SSD1331_SCK_PIN, 1); + SET_SCK; } } @@ -121,8 +116,7 @@ uint16_t ssd1331Read(uint16_t addr) /**************************************************************************/ uint16_t ssd1331Type(void) { - // ToDo - return 0; + return 0x1331; } /**************************************************************************/ @@ -151,19 +145,38 @@ void ssd1331SetCursor(uint8_t x, uint8_t y) /**************************************************************************/ void ssd1331DrawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint16_t color) { + uint16_t x, pixels; + if ((x1 >= ssd1331Properties.width) || (x2 >= ssd1331Properties.width) || (y1 >= ssd1331Properties.height) || (y2 >= ssd1331Properties.height)) { return; } + // Switch x2 and x1 if required + if (x2 < x1) + { + x = x2; + x2 = x1; + x1 = x; + } + + // Switch y2 and y1 if required + if (y2 < y1) + { + x = y2; + y2 = y1; + y1 = x; + } + CMD(SSD1331_CMD_DRAWLINE); CMD(x1); CMD(y1); CMD(x2); CMD(y2); - CMD((color >> 11) << 1); - CMD((color >> 5) & 0x3F); - CMD((color << 1)& 0x3F); + CMD((uint8_t)((color >> 11) & 0x1F)); + CMD((uint8_t)((color >> 5) & 0x3F)); + CMD((uint8_t)(color & 0x1F)); + } /**************************************************************************/ @@ -242,7 +255,13 @@ void lcdInit(void) CMD(SSD1331_CMD_DISPLAYOFF); // 0xAE CMD(SSD1331_CMD_SETREMAP); // 0xA0 - CMD(0x76); // 0x74 + // A[2] = 1 = color order (0 = RGB, 1 = BGR) + // A[7:6] = 01 = 65K color + #if defined SSD1331_COLORORDER_BGR + CMD(0x76); + #else + CMD(0x72); + #endif CMD(SSD1331_CMD_STARTLINE); // 0xA1 CMD(0x0); CMD(SSD1331_CMD_DISPLAYOFFSET); // 0xA2 @@ -306,14 +325,14 @@ void lcdTest(void) { for(j=0;j<96;j++) { - if(i>55){DATA(invert565Color(COLOR_WHITE)>>8);DATA(invert565Color(COLOR_WHITE));} - else if(i>47){DATA(invert565Color(COLOR_BLUE)>>8);DATA(invert565Color(COLOR_BLUE));} - else if(i>39){DATA(invert565Color(COLOR_GREEN)>>8);DATA(invert565Color(COLOR_GREEN));} - else if(i>31){DATA(invert565Color(COLOR_CYAN)>>8);DATA(invert565Color(COLOR_CYAN));} - else if(i>23){DATA(invert565Color(COLOR_RED)>>8);DATA(invert565Color(COLOR_RED));} - else if(i>15){DATA(invert565Color(COLOR_MAGENTA)>>8);DATA(invert565Color(COLOR_MAGENTA));} - else if(i>7){DATA(invert565Color(COLOR_YELLOW)>>8);DATA(invert565Color(COLOR_YELLOW));} - else {DATA(invert565Color(COLOR_BLACK)>>8);DATA(invert565Color(COLOR_BLACK));} + if(i>55){DATA((uint8_t)COLOR_WHITE>>8);DATA((uint8_t)COLOR_WHITE);} + else if(i>47){DATA((uint8_t)COLOR_BLUE>>8);DATA((uint8_t)COLOR_BLUE);} + else if(i>39){DATA((uint8_t)COLOR_GREEN>>8);DATA((uint8_t)COLOR_GREEN);} + else if(i>31){DATA((uint8_t)COLOR_CYAN>>8);DATA((uint8_t)COLOR_CYAN);} + else if(i>23){DATA((uint8_t)COLOR_RED>>8);DATA((uint8_t)COLOR_RED);} + else if(i>15){DATA((uint8_t)COLOR_MAGENTA>>8);DATA((uint8_t)COLOR_MAGENTA);} + else if(i>7){DATA((uint8_t)COLOR_YELLOW>>8);DATA((uint8_t)COLOR_YELLOW);} + else {DATA((uint8_t)COLOR_BLACK>>8);DATA((uint8_t)COLOR_BLACK);} } } } @@ -325,7 +344,6 @@ void lcdTest(void) /**************************************************************************/ void lcdFillRGB(uint16_t data) { - data = invert565Color(data); ssd1331FillRect(0,0,ssd1331Properties.width-1,ssd1331Properties.height-1, data, data); } @@ -340,7 +358,6 @@ void lcdDrawPixel(uint16_t x, uint16_t y, uint16_t color) return; ssd1331SetCursor((uint8_t)x, (uint8_t)y); - color = invert565Color(color); DATA(color >> 8); DATA(color); } @@ -364,7 +381,6 @@ void lcdDrawPixels(uint16_t x, uint16_t y, uint16_t *data, uint32_t len) /**************************************************************************/ void lcdDrawHLine(uint16_t x0, uint16_t x1, uint16_t y, uint16_t color) { - color = invert565Color(color); ssd1331DrawLine((uint8_t)x0, (uint8_t)y, (uint8_t)x1, (uint8_t)y, color); } @@ -376,7 +392,6 @@ void lcdDrawHLine(uint16_t x0, uint16_t x1, uint16_t y, uint16_t color) /**************************************************************************/ void lcdDrawVLine(uint16_t x, uint16_t y0, uint16_t y1, uint16_t color) { - color = invert565Color(color); ssd1331DrawLine((uint8_t)x, (uint8_t)y0, (uint8_t)x, (uint8_t)y1, color); }