SSD1331 Oled driver library for 96x64 colour Oled display. Demo included in .h file
Dependents: Oled-SSD1331 PJ12_device
Diff: ssd1331.cpp
- Revision:
- 4:062b4708eb35
- Parent:
- 3:a4caac512e13
- Child:
- 5:4385fd242db0
diff -r a4caac512e13 -r 062b4708eb35 ssd1331.cpp
--- a/ssd1331.cpp Thu May 12 21:36:11 2016 +0000
+++ b/ssd1331.cpp Wed May 18 22:16:21 2016 +0000
@@ -198,10 +198,10 @@
}
}
-void ssd1331::PutChar(int column,int row,unsigned int value)
+void ssd1331::PutChar(uint8_t column,uint8_t row, int value)
{
if(externalfont) { // external font
- unsigned int hor,vert,offset,bpl,j,i,b;
+ uint8_t hor,vert,offset,bpl,j,i,b;
const unsigned char* sign;
unsigned char z,w;
// read font parameter from start of array
@@ -298,7 +298,7 @@
RegWriteM(cmd, 6);
}
-int ssd1331::toRGB(int16_t R,int16_t G,int16_t B)
+uint16_t ssd1331::toRGB(uint16_t R,uint16_t G,uint16_t B)
{
uint16_t c;
c = R >> 3;
@@ -309,16 +309,12 @@
return c;
}
-void ssd1331::rect(int16_t x1,int16_t y1,int16_t x2,int16_t y2,unsigned int colorline)
+void ssd1331::rect(uint8_t x1,uint8_t y1,uint8_t x2,uint8_t y2,uint16_t colorline)
{
- if ( x1 < 0 ) x1 = 0;
- else if ( x1 > width ) x1 = width;
- if ( y1 < 0 ) y1 = 0;
- else if ( y1 > height ) y1 = height;
- if ( x2 < 0 ) x2 = 0;
- else if ( x2 > width ) x2 = width;
- if ( y2 < 0 ) y2 = 0;
- else if ( y2 > height ) y2 = height;
+ if ( x1 > width ) x1 = width;
+ if ( y1 > height ) y1 = height;
+ if ( x2 > width ) x2 = width;
+ if ( y2 > height ) y2 = height;
unsigned char cmd[11]= { 0 };
cmd[0] = GAC_FILL_ENABLE_DISABLE;
@@ -339,16 +335,12 @@
wait_us(500);
}
-void ssd1331::fillrect(int x1,int y1,int x2,int y2,unsigned int colorline,unsigned int colorfill)
+void ssd1331::fillrect(uint8_t x1,uint8_t y1,uint8_t x2,uint8_t y2,uint16_t colorline,uint16_t colorfill)
{
- if ( x1 < 0 ) x1 = 0;
- else if ( x1 > width ) x1 = width;
- if ( y1 < 0 ) y1 = 0;
- else if ( y1 > height ) y1 = height;
- if ( x2 < 0 ) x2 = 0;
- else if ( x2 > width ) x2 = width;
- if ( y2 < 0 ) y2 = 0;
- else if ( y2 > height ) y2 = height;
+ if ( x1 > width ) x1 = width;
+ if ( y1 > height ) y1 = height;
+ if ( x2 > width ) x2 = width;
+ if ( y2 > height ) y2 = height;
unsigned char cmd[11]= { 0 };
cmd[0] = GAC_FILL_ENABLE_DISABLE;
@@ -369,16 +361,12 @@
wait_us(500);
}
-void ssd1331::line(int x1,int y1,int x2,int y2,unsigned int color)
+void ssd1331::line(uint8_t x1,uint8_t y1,uint8_t x2,uint8_t y2,uint16_t color)
{
- if ( x1 < 0 ) x1 = 0;
- else if ( x1 > width ) x1 = width;
- if ( y1 < 0 ) y1 = 0;
- else if ( y1 > height ) y1 = height;
- if ( x2 < 0 ) x2 = 0;
- else if ( x2 > width ) x2 = width;
- if ( y2 < 0 ) y2 = 0;
- else if ( y2 > height ) y2 = height;
+ if ( x1 > width ) x1 = width;
+ if ( y1 > height ) y1 = height;
+ if ( x2 > width ) x2 = width;
+ if ( y2 > height ) y2 = height;
unsigned char cmd[11]= { 0 };
cmd[0] = GAC_FILL_ENABLE_DISABLE;
@@ -396,9 +384,12 @@
wait_us(500);
}
-void ssd1331::circle (int radius, int x, int y , unsigned int col, int fill)
+void ssd1331::circle (uint8_t radius, uint8_t x, uint8_t y , uint16_t col, uint16_t fill)
{
- int cx, cy, d;
+ if ( x > width ) x = width;
+ if ( y > height ) y = height;
+
+ int16_t cx, cy, d;
d = 3 - 2 * radius;
cy = radius;
pixel(x, radius+y, col);
@@ -438,7 +429,7 @@
}
}
-void ssd1331::ScrollSet(int horizontal, int startline, int linecount, int vertical , int frame_interval)
+void ssd1331::ScrollSet(int8_t horizontal, int8_t startline, int8_t linecount, int8_t vertical , int8_t frame_interval)
{
unsigned char cmd[7];
if((startline>height+1)||((startline+linecount)>height+1)) return ;
@@ -452,7 +443,7 @@
RegWriteM(cmd,6);
}
-void ssd1331::Bitmap(const uint8_t *bitmap, int16_t x, int16_t y, int16_t w, int16_t h, unsigned char color) {
+void ssd1331::Bitmap(const uint8_t *bitmap, uint8_t x, uint8_t y, uint8_t w, uint8_t h, unsigned char color) {
window(x, y, w, h);
int16_t i, j, byteWidth = (w + 7) / 8;
@@ -466,7 +457,7 @@
Maxwindow();
}
-void ssd1331::Bitmap16( int16_t x, int16_t y, int16_t w, int16_t h, unsigned char *bitmap)
+void ssd1331::Bitmap16(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *bitmap)
{
unsigned int i,j;
int padd;
@@ -478,7 +469,9 @@
do {
padd ++;
} while (2*(w + padd)%4 != 0);
+
window(x, y, w, h);
+
bitmap_ptr += ((h - 1)* (w + padd));
for (j = 0; j < h; j++) { //Lines
@@ -492,7 +485,7 @@
Maxwindow();
}
-int ssd1331::Bitmap16SD( int16_t x, int16_t y, unsigned char *Name_BMP)
+int ssd1331::Bitmap16RAM(uint8_t x, uint8_t y, unsigned char *Name_BMP)
{
#define OffsetPixelWidth 18
#define OffsetPixelHeigh 22
@@ -580,7 +573,7 @@
return (fileSize);
}
-int ssd1331::Bitmap16SD2(int16_t x, int16_t y, unsigned char *Name_BMP) {
+int ssd1331::Bitmap16FS(uint8_t x, uint8_t y, unsigned char *Name_BMP) {
#define OffsetPixelWidth 18
#define OffsetPixelHeigh 22
#define OffsetFileSize 34
@@ -650,7 +643,7 @@
return(PixelWidth);
}
-void ssd1331::Copy(int src_x1,int src_y1,int src_x2,int src_y2, int dst_x,int dst_y)
+void ssd1331::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)
{
unsigned char cmd[8]= { 0 };
if ((src_x1>width)||(src_y1>height)||(src_x2>width)||(src_y2>height)) return;
@@ -665,28 +658,28 @@
RegWriteM(cmd,7);
}
-void ssd1331::Fill_Screen(unsigned int color)
+void ssd1331::Fill_Screen(uint16_t color)
{
BGround_Color = color;
fillrect(0,0,width,height,color,color);
}
-void ssd1331::locate(int16_t column, int16_t row)
+void ssd1331::locate(uint8_t column, uint8_t row)
{
char_x = column;
char_y = row;
}
-void ssd1331::foreground(unsigned int color)
+void ssd1331::foreground(uint16_t color)
{
Char_Color = color;
}
-void ssd1331::background(unsigned int color)
+void ssd1331::background(uint16_t color)
{
BGround_Color = color;
}
-void ssd1331::SetFontSize(int Csize)
+void ssd1331::SetFontSize(uint8_t Csize)
{
chr_size = Csize;
}
@@ -694,7 +687,6 @@
void ssd1331::putp(int colour)
{
pixel(_x, _y, colour);
-// wait_us(1000);
_x++;
if(_x > _x2) {
_x = _x1;
@@ -711,10 +703,10 @@
return c;
}
-void ssd1331::pixel(int16_t x,int16_t y,unsigned int Color)
+void ssd1331::pixel(uint8_t x,uint8_t y,uint16_t Color)
{
unsigned char cmd[7]= {Set_Column_Address,0x00,0x00,Set_Row_Address,0x00,0x00};
- if ((x<0)||(y<0)||(x>width)||(y>height)) return ;
+ if ((x>width)||(y>height)) return ;
cmd[1] = (unsigned char)x;
cmd[2] = (unsigned char)x;
cmd[4] = (unsigned char)y;
@@ -724,23 +716,12 @@
}
void ssd1331::Maxwindow()
-{
-
+{
unsigned char cmd[7]= {Set_Column_Address,0x00,0x5F,Set_Row_Address,0x00,0x3F};
RegWriteM(cmd, 6);
- /*
- RegWrite(0x75); // Set Row Address
- RegWrite(0); // Start = 0
- RegWrite(0x3F); // End = 63
- RegWrite(0x15); // Set Column Address
- RegWrite(0); // Start = 0
- RegWrite(0x5F); // End = 95
- char_x = 0;
- char_y = 0;
- */
}
-void ssd1331::window(int16_t x, int16_t y, int16_t w, int16_t h)
+void ssd1331::window(uint8_t x, uint8_t y, uint8_t w, uint8_t h)
{
_x = x;
_y = y;
@@ -770,11 +751,11 @@
return -1;
}
-int ssd1331::row()
+uint8_t ssd1331::row()
{
return char_y;
}
-int ssd1331::column()
+uint8_t ssd1331::column()
{
return char_x;
}
@@ -814,7 +795,7 @@
CS = 1; // CS dissable
}
-void ssd1331::RegWriteM(unsigned char *Command, int count)
+void ssd1331::RegWriteM(unsigned char *Command, uint8_t count)
{
int i;
DC = 0; // Command
@@ -833,7 +814,7 @@
CS = 1; // CS dissable
}
-void ssd1331::DataWrite_to(unsigned int Dat)
+void ssd1331::DataWrite_to(uint16_t Dat)
{
DC = 1; // DATA
CS = 0; // CS enable
@@ -842,3 +823,7 @@
CS = 1; // CS dissable
}
+
+
+
+
Display Module .95" 96x64 Oled with SPI interface