Driver for the Seeedstudio RGB OLED module for the xadow M0
Revision 7:5250c825c7bb, committed 2015-11-15
- Comitter:
- messi1
- Date:
- Sun Nov 15 23:07:48 2015 +0000
- Parent:
- 6:06c211302c93
- Child:
- 8:ff74bd4d94d6
- Commit message:
- Fixed 16bit collor transmission to the spi port according to the datasheet page32
Changed in this revision
include/SSD1331.h | Show annotated file Show diff for this revision Revisions of this file |
src/SSD1331.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/include/SSD1331.h Sat Nov 14 21:18:26 2015 +0000 +++ b/include/SSD1331.h Sun Nov 15 23:07:48 2015 +0000 @@ -114,47 +114,33 @@ #define CMD_SET_PRECHARGE_VOLTAGE 0xBB #define CMD_SET_V_VOLTAGE 0xBE -#define RGB(R,G,B) (((R>>3)<<11) | ((G>>2)<<5) | (B>>3)) - #define LOW 0 #define HIGH 1 -enum Color{ - COLOR_BLACK = RGB( 0, 0, 0), // black - COLOR_GREY = RGB(192,192,192), // grey - COLOR_WHITE = RGB(255,255,255), // white - COLOR_RED = RGB(255, 0, 0), // red - COLOR_PINK = RGB(255,192,203), // pink - COLOR_YELLOW = RGB(255,255, 0), // yellow - COLOR_GOLDEN = RGB(255,215, 0), // golden - COLOR_BROWN = RGB(128, 42, 42), // brown - COLOR_BLUE = RGB( 0, 0,255), // blue - COLOR_CYAN = RGB( 0,255,255), // cyan - COLOR_GREEN = RGB( 0,255, 0), // green - COLOR_PURPLE = RGB(160, 32,240), // purple + +/* some 16bit RGB color definitions */ +enum Color{ + Black = 0x0000, /* 0, 0, 0 */ + Navy = 0x000F, /* 0, 0, 128 */ + DarkGreen = 0x03E0, /* 0, 128, 0 */ + DarkCyan = 0x03EF, /* 0, 128, 128 */ + Maroon = 0x7800, /* 128, 0, 0 */ + Purple = 0x780F, /* 128, 0, 128 */ + Olive = 0x7BE0, /* 128, 128, 0 */ + LightGrey = 0xC618, /* 192, 192, 192 */ + DarkGrey = 0x7BEF, /* 128, 128, 128 */ + Blue = 0x001F, /* 0, 0, 255 */ + Green = 0x07E0, /* 0, 255, 0 */ + Cyan = 0x07FF, /* 0, 255, 255 */ + Red = 0xF800, /* 255, 0, 0 */ + Magenta = 0xF81F, /* 255, 0, 255 */ + Yellow = 0xFFE0, /* 255, 255, 0 */ + White = 0xFFFF, /* 255, 255, 255 */ + Orange = 0xFD20, /* 255, 165, 0 */ + GreenYellow = 0xAFE5, /* 173, 255, 47 */ + Pink = 0xF81F }; -/* some RGB color definitions */ -#define Black 0x0000 /* 0, 0, 0 */ -#define Navy 0x000F /* 0, 0, 128 */ -#define DarkGreen 0x03E0 /* 0, 128, 0 */ -#define DarkCyan 0x03EF /* 0, 128, 128 */ -#define Maroon 0x7800 /* 128, 0, 0 */ -#define Purple 0x780F /* 128, 0, 128 */ -#define Olive 0x7BE0 /* 128, 128, 0 */ -#define LightGrey 0xC618 /* 192, 192, 192 */ -#define DarkGrey 0x7BEF /* 128, 128, 128 */ -#define Blue 0x001F /* 0, 0, 255 */ -#define Green 0x07E0 /* 0, 255, 0 */ -#define Cyan 0x07FF /* 0, 255, 255 */ -#define Red 0xF800 /* 255, 0, 0 */ -#define Magenta 0xF81F /* 255, 0, 255 */ -#define Yellow 0xFFE0 /* 255, 255, 0 */ -#define White 0xFFFF /* 255, 255, 255 */ -#define Orange 0xFD20 /* 255, 165, 0 */ -#define GreenYellow 0xAFE5 /* 173, 255, 47 */ -#define Pink 0xF81F - enum DisplayMode{ //reset the above effect and turn the data to ON at the corresponding gray level. NormalDisplay = 0xA4,
--- a/src/SSD1331.cpp Sat Nov 14 21:18:26 2015 +0000 +++ b/src/SSD1331.cpp Sun Nov 15 23:07:48 2015 +0000 @@ -81,58 +81,28 @@ sendCmd(CMD_SET_COLUMN_ADDRESS, 0x00, 0x5f); //Set Column Address with start=0,end=95 //Contrast - sendCmd(CMD_SET_REMAP, 0x76); //Set remap & data format 0111 0000 // 65k Color/8bit buswidth/format1 + sendCmd(CMD_SET_REMAP, 0x72); //Set remap & data format 0111 0000 // 65k Color/8bit buswidth/format1 0x72 sendCmd(CMD_SET_DISPLAY_START_LINE, 0x00); //Set display start row RAM sendCmd(CMD_SET_DISPLAY_OFFSET, 0x00); //Set dispaly offset sendCmd(CMD_NORMAL_DISPLAY); //Set Display Mode sendCmd(CMD_SET_MULTIPLEX_RATIO, 0x3f); //Set Multiplex Ratio - sendCmd(CMD_SET_MASTER_CONFIGURE, 0x8f); //Set Master Configuration (External VCC Supply Selected) + sendCmd(CMD_SET_MASTER_CONFIGURE, 0x8e); //Set Master Configuration (External VCC Supply Selected) 0x8f or 0x8e sendCmd(CMD_POWER_SAVE_MODE, 0x1a); //Set Power Saving Mode - sendCmd(CMD_PHASE_PERIOD_ADJUSTMENT, 0x74); //Set Phase 1 & 2 Period Adjustment - sendCmd(CMD_DISPLAY_CLOCK_DIV, 0xd0); //Set Display Clock Divide Ratio / Oscillator Frequency - sendCmd(CMD_SET_PRECHARGE_SPEED_A, 0x81); //Set Second Pre-charge Speed of Color A - sendCmd(CMD_SET_PRECHARGE_SPEED_B, 0x82); //Set Second Pre-charge Speed of Color B - sendCmd(CMD_SET_PRECHARGE_SPEED_C, 0x83); //Set Second Pre-charge Speed of Color C - sendCmd(CMD_SET_PRECHARGE_VOLTAGE, 0x3e); //Set Pre-charge Level + sendCmd(CMD_PHASE_PERIOD_ADJUSTMENT, 0x31); //Set Phase 1 & 2 Period Adjustment 0x74 or 0x31 + sendCmd(CMD_DISPLAY_CLOCK_DIV, 0xf0); //Set Display Clock Divide Ratio / Oscillator Frequency 0xd0 or 0xf0 + sendCmd(CMD_SET_PRECHARGE_SPEED_A, 0x64); //Set Second Pre-charge Speed of Color A 0x81 or 0x64 + sendCmd(CMD_SET_PRECHARGE_SPEED_B, 0x78); //Set Second Pre-charge Speed of Color B 0x82 or 0x78 + sendCmd(CMD_SET_PRECHARGE_SPEED_C, 0x64); //Set Second Pre-charge Speed of Color C 0x83 or 0x64 + sendCmd(CMD_SET_PRECHARGE_VOLTAGE, 0x3a); //Set Pre-charge Level 3e or 3a sendCmd(CMD_SET_V_VOLTAGE, 0x3e); //Set VCOMH - sendCmd(CMD_MASTER_CURRENT_CONTROL, 0x0f); //Set Master Current Control - sendCmd(CMD_SET_CONTRAST_A, 0x80); //Set Contrast Control for Color gAh - sendCmd(CMD_SET_CONTRAST_B, 0x80); //Set Contrast Control for Color gBh - sendCmd(CMD_SET_CONTRAST_C, 0x80); //Set Contrast Control for Color gCh + sendCmd(CMD_MASTER_CURRENT_CONTROL, 0x06); //Set Master Current Control 0x6 or 0xf + sendCmd(CMD_SET_CONTRAST_A, 0x91); //Set Contrast Control for Color gAh 0x80 or 0x91 + sendCmd(CMD_SET_CONTRAST_B, 0x50); //Set Contrast Control for Color gBh 0x80 or 0x50 + sendCmd(CMD_SET_CONTRAST_C, 0x7d); //Set Contrast Control for Color gCh 0x80 or 0x7D clearArea(0,0, RGB_OLED_XMAX, RGB_OLED_YMAX); sendCmd(CMD_NORMAL_BRIGHTNESS_DISPLAY_ON); //display ON - -// sendCmd(CMD_SET_CONTRAST_A); //Set contrast for color A -// sendCmd(0x91); //145 -// sendCmd(CMD_SET_CONTRAST_B); //Set contrast for color B -// sendCmd(0x50); //80 -// sendCmd(CMD_SET_CONTRAST_C); //Set contrast for color C -// sendCmd(0x7D); //125 -// sendCmd(CMD_MASTER_CURRENT_CONTROL);//master current control -// sendCmd(0x06); //6 -// sendCmd(CMD_SET_PRECHARGE_SPEED_A);//Set Second Pre-change Speed For ColorA -// sendCmd(0x64); //100 -// sendCmd(CMD_SET_PRECHARGE_SPEED_B);//Set Second Pre-change Speed For ColorB -// sendCmd(0x78); //120 -// sendCmd(CMD_SET_PRECHARGE_SPEED_C);//Set Second Pre-change Speed For ColorC -// sendCmd(0x64); //100 -// sendCmd(CMD_SET_REMAP); //set remap & data format -// sendCmd(0x72); //0x72 -// sendCmd(CMD_SET_MULTIPLEX_RATIO); //Set multiplex ratio -// sendCmd(0x3F); -// sendCmd(CMD_SET_MASTER_CONFIGURE); //Set master configuration -// sendCmd(0x8E); -// sendCmd(CMD_PHASE_PERIOD_ADJUSTMENT);//phase 1 and 2 period adjustment -// sendCmd(0x31); //0x31 -// sendCmd(CMD_DISPLAY_CLOCK_DIV); //display clock divider/oscillator frequency -// sendCmd(0xF0); -// sendCmd(CMD_SET_PRECHARGE_VOLTAGE);//Set Pre-Change Level -// sendCmd(0x3A); -// sendCmd(CMD_SET_V_VOLTAGE); //Set vcomH -// sendCmd(0x3E); -// sendCmd(CMD_DEACTIVE_SCROLLING); //disable scrolling - + wait(0.1); } //------------------------------------------------------------------------------------ @@ -154,7 +124,7 @@ if (x1 >= RGB_OLED_WIDTH) x1 = RGB_OLED_XMAX; if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_YMAX; - uint8_t cmd[8] = { CMD_DRAW_LINE, x0, y0, x1, y1, (uint8_t)((color>>11)&0x1F), (uint8_t)((color>>5)&0x3F), (uint8_t)(color&0x1F) }; + uint8_t cmd[8] = { CMD_DRAW_LINE, x0, y0, x1, y1, (uint8_t)(((color>>11)&0x1F)<<1), (uint8_t)((color>>5)&0x3F), (uint8_t)((color&0x1F)<<1) }; sendCmd(cmd, 8); } @@ -167,8 +137,8 @@ if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_YMAX; uint8_t cmd[11] = { CMD_DRAW_RECTANGLE, x0, y0, x1, y1, - (uint8_t)((outColor>>11)&0x1F), (uint8_t)((outColor>>5)&0x3F), (uint8_t)(outColor&0x1F), - (uint8_t)((fillColor>>11)&0x1F), (uint8_t)((fillColor>>5)&0x3F), (uint8_t)(fillColor&0x1F)}; + (uint8_t)(((outColor>>11)&0x1F)<<1), (uint8_t)((outColor>>5)&0x3F), (uint8_t)((outColor&0x1F)<<1), + (uint8_t)(((fillColor>>11)&0x1F)<<1), (uint8_t)((fillColor>>5)&0x3F), (uint8_t)((fillColor&0x1F)<<1)}; sendCmd(CMD_FILL_WINDOW, ENABLE_FILL);//fill window sendCmd(cmd, 11);