A class for managing SSD1306 controlled LCD´s (cheap 128x64 models, 0.96'')
Dependents: mbed_ssd1306 USB_meter_SD_file_number_filtro_for EscanerRf escaner_RTOS ... more
Diff: ssd1306.cpp
- Revision:
- 4:35757c8b7625
- Parent:
- 3:bb6fba3e84ff
- Child:
- 8:09b1578f93d9
--- a/ssd1306.cpp Wed Nov 01 11:04:20 2017 +0000 +++ b/ssd1306.cpp Wed Nov 01 16:19:50 2017 +0000 @@ -1,5 +1,5 @@ /* -* ssd1306.cpp +* ssd1306.h * * Created on: 20 oct. 2017 * Author: Miguel Angel Rodriguez Jodar @@ -12,6 +12,15 @@ #include "ssd1306.h" #include "mbed.h" +/* I believe this charset was taken from the compilation from Joseph Gil years ago + * when I needed a charset for a different (FPGA) project, but I cannot remember + * exactly the website I took it from. + * What I do remember is that the owner of the website claimed that this charset + * is in the public domain. + * This a complete (256 ASCII codes) 8x8 charset, using the 437 page code (original IBM) + * so you can use its graphic blocks to build decent text based GUIs without the need + * to use plot, line and circle primitives + */ static const char charset[2048] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x81, 0x95, 0xB1, 0xB1, 0x95, 0x81, 0x7E, 0x7E, 0xFF, 0xEB, 0xCF, @@ -235,7 +244,6 @@ do_not_delete_bus = 0; #ifdef SSD1306_DEBUG printf ("SSD1306 debug: fb = 0x%08.8X\r\n", fb); - printf ("SSD1306 debug: I2C addr = 0x%02.2X\r\n", ssd1306_i2c_addr); #endif } @@ -255,7 +263,7 @@ void SSD1306::speed (I2CSpeed spd) { switch (spd) { - case Low: + case Slow: bus->frequency(100000); break; case Medium: @@ -300,12 +308,12 @@ int SSD1306::command (char c) { - return command_data (c, IS_COMMAND, IS_LAST); + return command_data (c, SSD1306_IS_COMMAND, SSD1306_IS_LAST); } int SSD1306::data (char d) { - return command_data (d, IS_DATA, IS_LAST); + return command_data (d, SSD1306_IS_DATA, SSD1306_IS_LAST); } int SSD1306::init (void) @@ -364,7 +372,7 @@ while (*s) putchar (*s++, refresh); } -void SSD1306::printf (char *fmt,...) +void SSD1306::printf (const char *fmt,...) { char *s = new char[129]; va_list args; @@ -417,12 +425,12 @@ display(); } -void SSD1306::plot (char x, char y, PlotStyle modo, bool refresh) +void SSD1306::plot (char x, char y, PlotStyle mode, bool refresh) { x = x % 128; y = y % 64; - switch (modo) { + switch (mode) { case Normal: fb[(y/8)*128+x] |= (1<<(y%8)); break; @@ -448,7 +456,7 @@ return false; } -void SSD1306::line (char x0, char y0, char x1, char y1, PlotStyle modo, bool refresh) +void SSD1306::line (char x0, char y0, char x1, char y1, PlotStyle mode, bool refresh) { int dx = abs (x1 - x0), sx = x0 < x1 ? 1 : -1; int dy = -abs (y1 - y0), sy = y0 < y1 ? 1 : -1; @@ -456,7 +464,7 @@ for (;;) { /* loop */ - plot (x0, y0, modo, false); + plot (x0, y0, mode, false); if (x0 == x1 && y0 == y1) break; e2 = 2 * err; if (e2 >= dy) { @@ -472,7 +480,7 @@ display(); } -void SSD1306::circle (char x0, char y0, char r, PlotStyle modo, bool refresh) +void SSD1306::circle (char x0, char y0, char r, PlotStyle mode, bool refresh) { int x = r-1; int y = 0; @@ -482,14 +490,14 @@ while (x >= y) { - plot (x0 + x, y0 + y, modo); - plot (x0 + y, y0 + x, modo); - plot (x0 - y, y0 + x, modo); - plot (x0 - x, y0 + y, modo); - plot (x0 - x, y0 - y, modo); - plot (x0 - y, y0 - x, modo); - plot (x0 + y, y0 - x, modo); - plot (x0 + x, y0 - y, modo); + plot (x0 + x, y0 + y, mode); + plot (x0 + y, y0 + x, mode); + plot (x0 - y, y0 + x, mode); + plot (x0 - x, y0 + y, mode); + plot (x0 - x, y0 - y, mode); + plot (x0 - y, y0 - x, mode); + plot (x0 + y, y0 - x, mode); + plot (x0 + x, y0 - y, mode); if (err <= 0) {