SSD1331 Oled driver library for 96x64 colour Oled display. Demo included in .h file
Dependents: Oled-SSD1331 PJ12_device
Diff: ssd1331.h
- Revision:
- 4:062b4708eb35
- Parent:
- 3:a4caac512e13
- Child:
- 5:4385fd242db0
--- a/ssd1331.h Thu May 12 21:36:11 2016 +0000 +++ b/ssd1331.h Wed May 18 22:16:21 2016 +0000 @@ -15,14 +15,14 @@ #define display_on 0xAF #define display_off 0xAE -// Font size +// Internal Font size settings #define NORMAL 0 #define WIDE 1 #define HIGH 2 #define WH 3 #define WHx36 4 -#define X_width 6 // character's width -#define Y_height 8 // character's height +#define X_width 6 +#define Y_height 8 // GAC hardware acceleration commands @@ -36,26 +36,18 @@ #define SCROLL_STOP 0x2E // Scroll Stop #define SCROLL_START 0x2F // Scroll Start -// some RGB color definitions RED GREEN BLUE +// Basic RGB color definitions RED GREEN BLUE values #define Black 0x0000 // 0, 0, 0 -#define Navy 0x8000 // 0, 0, 128 -#define DarkGreen 0x0400 // 0, 128, 0 -#define DarkCyan 0x8400 // 0, 128, 128 -#define Maroon 0x0010 // 128, 0, 0 -#define Purple 0x8010 // 128, 0, 128 -#define Olive 0x0410 // 128, 128, 0 #define LightGrey 0xC618 // 192, 192, 192 #define DarkGrey 0x7BEF // 128, 128, 128 #define Red 0xF800 // 255, 0, 0 #define Green 0x07E0 // 0, 255, 0 -#define Yellow 0x07FF // 255, 255, 0 +#define Cyan 0x07FF // 0, 255, 255 #define Blue 0x001F // 0, 0, 255 #define Magenta 0xF81F // 255, 0, 255 -#define Cyan 0xFFE0 // 0, 255, 255 +#define Yellow 0xFFE0 // 255, 255, 0 #define White 0xFFFF // 255, 255, 255 -#define Orange 0x053F // 255, 165, 0 -#define GreenYellow 0x2FF5 // 173, 255, 47 // example code /* @@ -67,7 +59,7 @@ char Time[50],Date[50]; void gettime(); -int main() { +uint8_t main() { while(1){ @@ -87,10 +79,10 @@ oled.circle (20, 60, 40 ,oled.toRGB(255,0,0) , 0); //circle oled.line( 0, 0, width, height, oled.toRGB(0,255,255)); //line oled.line( width, 0, 0, height, oled.toRGB(255,0,255)); //line - oled.rect(10,10,90,60,oled.toRGB(255,255,0)); //rectangle - oled.fillrect(20,20,40,40,oled.toRGB(255,255,255),oled.toRGB(0,255,0)); //fillrectangle + oled.rectangle(10,10,90,60,oled.toRGB(255,255,0)); //rectangle + oled.fillrectangle(20,20,40,40,oled.toRGB(255,255,255),oled.toRGB(0,255,0)); //fillrectangle - for(int y = 9; y >= 0; y--) { + for(uint8_t y = 9; y >= 0; y--) { oled.contrast(y); // set contrast level oled.foreground(oled.toRGB(255,255,255)); // set text colour oled.locate(1, 10); // set text start location @@ -158,34 +150,42 @@ // constructor ssd1331(PinName cs_pin, PinName rst_pin, PinName a0_pin, PinName mosi_pin, PinName miso_pin, PinName sclk_pin); - void pixel(int16_t x,int16_t y,unsigned int color); - void rect(int16_t x1,int16_t y1,int16_t x2,int16_t y2,unsigned int colorline); - void fillrect(int x1,int y1,int x2,int y2,unsigned int colorline,unsigned int colorfill); - void line( int x1,int y1,int x2,int y2,unsigned int color); - void circle (int radius, int x, int y,unsigned int color,int fill); - void Fill_Screen(unsigned int color); // fill screen with any colour - void foreground(unsigned int color); // text color - void background(unsigned int color); // background color - void SetFontSize(int); + void pixel(uint8_t x,uint8_t y, uint16_t color); // place a pixel x,y coordinates, color + void rect(uint8_t x1,uint8_t y1,uint8_t x2,uint8_t y2,uint16_t colorline); // draw rectangle, start x,y end x,y, color + void fillrect(uint8_t x1,uint8_t y1,uint8_t x2,uint8_t y2,uint16_t colorline,uint16_t colorfill); // fill rectangle start x,y, end x,y, outline color, fill color. + void line(uint8_t x1,uint8_t y1,uint8_t x2,uint8_t y2,uint16_t color); // draw line start x,y, end x,y, color + void circle (uint8_t radius, uint8_t x, uint8_t y,uint16_t color,uint16_t fill); // draw circle radius, position x,y, color + void Fill_Screen(uint16_t color); // fill screen with any colour + void foreground(uint16_t color); // set text color + void background(uint16_t color); // set background color + void SetFontSize(uint8_t); // set internal font size NORMAL, HIGH, WIDE, WH (high and wide), WHx36 (large 36x36 pixel size) void on(); // display on void off(); // display off - void cls(); // clear screen to black - void dim(); // flip dim/normal + void cls(); // clear screen to black screen + void dim(); // flip dim/normal on each call void contrast(char value); //0~9 low~high - void locate(int16_t column, int16_t row); // text start position - int toRGB(int16_t R,int16_t G,int16_t B); // get color from RGB values 00~FF(0~255) - int row(); - int column(); - void ScrollSet(int horizontal, int startline, int linecount, int vertical , int frame_interval); - void Scrollstart(); - void Scrollstop(); - void Copy(int src_x1,int src_y1,int src_x2,int src_y2, int dst_x,int dst_y); - void character(int x, int y, int c); // Print single character, x & y pixel co-ords. + void locate(uint8_t column, uint8_t row); // text start position x,y + uint16_t toRGB(uint16_t R,uint16_t G,uint16_t B); // get color from RGB values 00~FF(0~255) + uint8_t row(); // set row position (in pixels) + uint8_t column(); // set column position (in pixels) + void ScrollSet(int8_t horizontal, int8_t startline, int8_t linecount, int8_t vertical , int8_t frame_interval); // set up scroll function + void Scrollstart(); // start scrolling + void Scrollstop(); // stop scrolling + void Copy(uint8_t src_x1,uint8_t src_y1,uint8_t src_x2,uint8_t src_y2, uint8_t dst_x,uint8_t dst_y); // GAC function to copy/paste area on the screen + void character(uint8_t x, uint8_t y, uint16_t c); // Print single character, x & y pixel co-ords. void set_font(unsigned char* f); // set external font. Use oled.set_font(NULL) to restore default font - void Bitmap(const uint8_t *bitmap, int16_t x, int16_t y, int16_t w, int16_t h, unsigned char color); // load mono bitmap from flash - void Bitmap16(int16_t x, int16_t y, int16_t w, int16_t h,unsigned char *bitmap); // load bitmap from flash - int Bitmap16SD( int16_t x, int16_t y, unsigned char *Name_BMP); // uses up to 12.288k RAM, Fast - int Bitmap16SD2(int16_t x, int16_t y, unsigned char *Name_BMP); // uses 96b RAM, slower + void Bitmap(const uint8_t *bitmap, uint8_t x, uint8_t y, uint8_t w, uint8_t h, unsigned char color); // load mono bitmap from flash + void Bitmap16(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *bitmap); // load bitmap from flash + + int Bitmap16RAM(uint8_t x, uint8_t y, unsigned char *Name_BMP); // copy image to RAM, uses up to 12.288k RAM, Fast but need plenty of RAM + int Bitmap16FS(uint8_t x, uint8_t y, unsigned char *Name_BMP); // load from fielsystem, uses 96b RAM, slower, will work on any MCU + // use GIMP to generate images, open image, select image-scale image, set width/height(max 96x64), select File-Export As + // select Windows BMP image, Name it with .BMP extension, select export, select Compatability Options- check 'Do Not write colour space' + // select Advanced Options- check '16bit R5 G6 B5', select export. Copy the file to a SD card or to the local file system. + // image maximum size 96x64, smaller images can be placed anywhere on screen setting x,y co-ords but must fit within boundaries + // example: + // oled.Bitmap16FS(0,0,(unsigned char *)"/sd/image.bmp"); full size 96x64 image + // oled.Bitmap16RAM(20,20,(unsigned char *)"/sd/image.bmp"); place smaller image starting x-20, y-20 protected: // Stream implementation functions @@ -194,36 +194,35 @@ private: void Init(void); void RegWrite(unsigned char Command); - void RegWriteM(unsigned char *Command, int count); + void RegWriteM(unsigned char *Command, uint8_t count); void DataWrite(unsigned char c); - void DataWrite_to(unsigned int Dat); + void DataWrite_to(uint16_t Dat); void FontSizeConvert(int *lpx, int *lpy); - void PutChar(int x,int y,unsigned int a); - void PutCharInt(int x,int y,unsigned int a); + void PutChar(uint8_t x,uint8_t y,int a); + void PutCharInt(uint8_t x,uint8_t y,uint16_t a); void putp(int colour); unsigned char* font; - unsigned int Char_Color; // text color - unsigned int BGround_Color; // background color - void window(int16_t x, int16_t y, int16_t w, int16_t h); + uint16_t Char_Color; // text color + uint16_t BGround_Color; // background color + void window(uint8_t x, uint8_t y, uint8_t w, uint8_t h); void Maxwindow(); // reset display window to full size // pixel location - short _x; - short _y; + uint8_t _x; + uint8_t _y; // window location - short _x1; - short _x2; - short _y1; - short _y2; - int char_x; - int char_y; - int chr_size; - int cwidth; // character's width - int cvert; // character's height - int externalfont; + uint8_t _x1; + uint8_t _x2; + uint8_t _y1; + uint8_t _y2; + uint8_t char_x; + uint8_t char_y; + uint8_t chr_size; + uint8_t cwidth; // character's width + uint8_t cvert; // character's height + uint8_t externalfont; DigitalOut CS, RES, DC; - SPI spi; // mosi, miso, sclk - + SPI spi; // mosi, miso, sclk }; #endif