EI2I_4_projet_1_2017-2018 / Mbed 2 deprecated SSD1306

Dependencies:   mbed

Fork of SSD1306 by Masato YAMANISHI

Files at this revision

API Documentation at this revision

Comitter:
masato
Date:
Sun May 04 14:29:51 2014 +0000
Parent:
3:1d9df877c90a
Child:
5:4b89cc384f43
Commit message:
derived from Aidafruit SSD1306 library

Changed in this revision

ssd1306.cpp Show annotated file Show diff for this revision Revisions of this file
ssd1306.h Show annotated file Show diff for this revision Revisions of this file
--- a/ssd1306.cpp	Sat Feb 09 16:43:49 2013 +0000
+++ b/ssd1306.cpp	Sun May 04 14:29:51 2014 +0000
@@ -4,6 +4,8 @@
 
 #include <stdarg.h>
 
+#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
+
 SSD1306::SSD1306(PinName cs, PinName rs, PinName dc, PinName clk, PinName data)
     : _spi(data, NC, clk), 
       _cs(cs), 
@@ -243,6 +245,19 @@
         _send_data(_screen[i]);
 }
 
+void SSD1306::drawBitmap(int x, int y,
+                  const unsigned char *bitmap, int w, int h, int color) {
+  int16_t i, j, byteWidth = (w + 7) / 8;
+
+  for(j=0; j<h; j++) {
+    for(i=0; i<w; i++ ) {
+      if(pgm_read_byte(bitmap + j * byteWidth + i / 8) & (128 >> (i & 7))) {
+        color? set_pixel(x+i, y+j): clear_pixel(x+i, y+j);
+      }
+    }
+  }
+}
+
 void SSD1306::set_pixel(int x, int y)
 {
     if (x >= SSD1306_LCDWIDTH || y >= SSD1306_LCDHEIGHT) return;
--- a/ssd1306.h	Sat Feb 09 16:43:49 2013 +0000
+++ b/ssd1306.h	Sun May 04 14:29:51 2014 +0000
@@ -181,7 +181,8 @@
     
     // ----- BUFFER EDITING -----
 
-    void clear();
+    void clear();  
+    void drawBitmap(int x, int y, const unsigned char *bitmap, int w, int h, int color = 1);
     void set_pixel(int x, int y);
     void clear_pixel(int x, int y);
     void line(int x0, int y0, int x1, int y1);