SSD1331 Oled driver library for 96x64 colour Oled display. Demo included in .h file
Dependents: Oled-SSD1331 PJ12_device
Diff: ssd1331.h
- Revision:
- 0:3d7d1aec706b
- Child:
- 1:f3f6624f45d4
diff -r 000000000000 -r 3d7d1aec706b ssd1331.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ssd1331.h Tue Apr 26 22:51:28 2016 +0000
@@ -0,0 +1,186 @@
+
+#ifndef __ssd1331_H__
+#define __ssd1331_H__
+
+#include "mbed.h"
+
+
+// Screen Settings
+#define width 96-1 // Max X axial direction in screen
+#define height 64-1 // Max Y axial direction in screen
+#define Set_Column_Address 0x15
+#define Set_Row_Address 0x75
+#define contrastA 0x81
+#define contrastB 0x82
+#define contrastC 0x83
+#define display_on 0xAF
+#define display_off 0xAE
+
+// Font size
+#define NORMAL 0
+#define WIDE 1
+#define HIGH 2
+#define WH 3
+#define WHx36 4
+#define X_width 6 // character's width
+#define Y_width 8 // character's height
+
+
+// GAC hardware acceleration commands
+#define GAC_DRAW_LINE 0x21 // Draw Line
+#define GAC_DRAW_RECTANGLE 0x22 // Rectangle
+#define GAC_COPY_AREA 0x23 // Copy Area
+#define GAC_DIM_WINDOW 0x24 // Dim Window
+#define GAC_CLEAR_WINDOW 0x25 // Clear Window
+#define GAC_FILL_ENABLE_DISABLE 0x26 // Enable Fill
+#define SCROLL_SETUP 0x27 // Setup scroll
+#define SCROLL_STOP 0x2E // Scroll Stop
+#define SCROLL_START 0x2F // Scroll Start
+
+// example code
+/*
+#include "mbed.h"
+#include "ssd1331.h"
+
+ssd1331 oled(D8, D9, D10, D11, NC, D13); // cs, res, dc, miso(nc), sck (KL25z)
+
+char Time[50],Date[50];
+void gettime();
+
+int main() {
+
+ while(1){
+
+ oled.Fill_Screen(oled.toRGB(255,0,0)); //red
+ wait_ms(500);
+ oled.Fill_Screen(oled.toRGB(0,255,0)); //green
+ wait_ms(500);
+ oled.Fill_Screen(oled.toRGB(0,0,255)); //blue
+ wait_ms(500);
+ oled.Fill_Screen(oled.toRGB(255,255,255)); //white
+ wait_ms(500);
+
+ oled.cls(); // clear screen to black
+
+ oled.circle (20, 40, 30 ,oled.toRGB(0,0,255) , 1); //fill circle
+ oled.circle (20, 40, 30 ,oled.toRGB(255,255,255) , 0); //circle
+ 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.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--) {
+ oled.contrast(y); // set contrast level
+ oled.foreground(oled.toRGB(255,255,255)); // set text colour
+ oled.locate(1, 10); // set text start location
+ oled.printf("%d",y); // std printf
+ wait_ms(300);
+ }
+
+ wait_ms(1000);
+ oled.contrast(9); // set contrast to maximum
+ wait_ms(2000);
+ oled.cls();
+
+ oled.SetFontSize(HIGH); // set tall font
+ oled.foreground(oled.toRGB(0,255,0)); // set text colour
+ oled.locate(0, 10);
+ oled.printf( "HIGH 12345");
+
+ oled.SetFontSize(WIDE); // set text to wide
+ oled.foreground(oled.toRGB(0,0,255));
+ oled.locate(0, 28);
+ oled.printf( "WIDE 123");
+
+ oled.SetFontSize(WH); // set text to wide and tall
+ oled.foreground(oled.toRGB(255,0,0));
+ oled.locate(0, 40);
+ oled.printf( "WH 123");
+
+ oled.SetFontSize(NORMAL); // set text to normal
+ oled.foreground(oled.toRGB(255,255,255));
+
+ oled.ScrollSet(0,8,18,1,0); // set scroll function
+ oled.Scrollstart(); // start scroll
+
+ gettime();wait(1);gettime();wait(1);gettime();wait(1);
+ oled.ScrollSet(0,8,18,-2,0);
+ oled.Scrollstart();
+ gettime();wait(1);gettime();wait(1);gettime();wait(1);
+
+ oled.ScrollSet(0,8,18,3,0);
+ oled.Scrollstart();
+
+ gettime();wait(1);gettime();wait(1);gettime();wait(1);
+
+ oled.ScrollSet(0,8,18,-4,0);
+ oled.Scrollstart();
+
+ gettime();wait(1);gettime();wait(1);gettime();wait(1);
+
+ oled.Scrollstop(); // stop scroll
+ wait(1);
+ }
+}
+void gettime()
+{
+ time_t seconds = time(NULL);
+ strftime(Time,40,"%H:%M:%S %a", localtime(&seconds));
+ strftime(Date,40,"%d-%b-%Y", localtime(&seconds));
+ oled.locate(0, 0);
+ oled.printf(Time);
+}
+*/
+
+class ssd1331 : public Stream {
+public:
+ // constructor
+ ssd1331(PinName cs_pin, PinName rst_pin, PinName a0_pin, PinName mosi_pin, PinName miso_pin, PinName sclk_pin);
+
+ void pixel(int x,int y,unsigned int color);
+ void rectangle(int x1,int y1,int x2,int y2,unsigned int colorline);
+ void fillrectangle(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 on(); // display on
+ void off(); // display off
+ void cls(); // clear screen to black
+ void dim(); // flip dim/normal
+ void contrast(char value); //0~9 low~high
+ void locate(int column, int row); // text start position
+ int toRGB(int R,int G,int 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);
+
+protected:
+ // Stream implementation functions
+ virtual int _putc(int c);
+ virtual int _getc();
+private:
+ void Init(void);
+ void RegWrite(unsigned char Command);
+ void RegWriteM(unsigned char *Command, int count);
+ void DataWrite(unsigned char c);
+ void DataWrite_to(unsigned int Dat);
+ void FontSizeConvert(int *lpx, int *lpy);
+ void PutChar(int x,int y,unsigned int a);
+ unsigned int Char_Color; // text color
+ unsigned int BGround_Color; // background color
+ int x_locate;
+ int y_locate;
+ int chr_size;
+
+ DigitalOut CS, RES, DC;
+ SPI spi; // mosi, miso, sclk
+};
+
+#endif
\ No newline at end of file
Display Module .95" 96x64 Oled with SPI interface