Graphic OLED 100x16 pixels interface
Dependents: mbed_nicovideo_search_api mbed_recent_nicovideo_display_pub
- グラフィック有機ELモジュール100x16
- 8×8 ドット日本語フォント「美咲フォント」
- misaki2cpp.py 美咲フォントをC++コードへ変換。
Revision 2:337a2655f815, committed 2014-08-04
- Comitter:
- va009039
- Date:
- Mon Aug 04 06:17:36 2014 +0000
- Parent:
- 1:a104653979bf
- Child:
- 3:a6650dd2dbc8
- Commit message:
- remove Text LCD
Changed in this revision
--- a/GraphicOLED.cpp Wed Apr 18 10:17:51 2012 +0000 +++ b/GraphicOLED.cpp Mon Aug 04 06:17:36 2014 +0000 @@ -2,12 +2,28 @@ #include "GraphicOLED.h" #include <ctype.h> -extern void font_4x8(char buf[], int i); -extern void font_8x8(char buf[], int i); +extern void font_4x8(uint8_t buf[], int i); +extern void font_8x8(uint8_t buf[], int i); + +GraphicOLED::GraphicOLED(PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7) : _rs(rs), _e(e), _d(d4, d5, d6, d7) { + _e = 1; + _rs = 0; // command mode + + wait_ms(15); // Wait 15ms to ensure powered up -GraphicOLED::GraphicOLED(PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7): - TextLCD(rs, e, d4, d5, d6, d7) -{ + // send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus) + for (int i=0; i<3; i++) { + writeByte(0x3); + wait_ms(2); // this command takes 1.64ms, so wait for it + } + writeByte(0x2); // 4-bit mode + wait_us(40); // most instructions take 40us + + //writeCommand(0x28); // Function set 001 BW N F - - + //writeCommand(0x0C); + //writeCommand(0x6); // Cursor Direction and Display Shift : 0000 01 CD S (CD 0-left, 1-right S(hift) 0-no, 1-yes + //cls(); + wait_ms(500); // wait 500ms writeCommand(0x00); // 0x0 x 5 writeCommand(0x00); @@ -19,14 +35,14 @@ _kanji_flag = false; } -void GraphicOLED::g_wrtie(int pat, int x, int y) +void GraphicOLED::g_write(uint8_t pat, int x, int y) { writeCommand(0x40+y); // y position writeCommand(0x80+x); // x position writeData(pat); } -void GraphicOLED::g_wrtie(char *buf, int len, int x, int y) +void GraphicOLED::g_write(uint8_t *buf, int len, int x, int y) { writeCommand(0x40+y); // y position while(len-- > 0) { @@ -35,19 +51,51 @@ } } +void GraphicOLED::writeCommand(uint8_t command) { + _rs = 0; + writeByte(command); +} + +void GraphicOLED::writeData(uint8_t data) { + _rs = 1; + writeByte(data); +} + +void GraphicOLED::writeByte(uint8_t value) { + _d = value >> 4; + wait_us(40); // most instructions take 40us + _e = 0; + wait_us(40); + _e = 1; + _d = value >> 0; + wait_us(40); + _e = 0; + wait_us(40); // most instructions take 40us + _e = 1; +} + void GraphicOLED::cls() { for(int y = 0; y < 2; y++) { for(int x = 0; x < 100; x++) { - g_wrtie(0x00, x, y); + g_write(0x00, x, y); } } locate(0,0); _kanji_flag = false; } +void GraphicOLED::locate(int column, int row) { + _column = column; + _row = row; +} + int GraphicOLED::columns() { return 25; } +int GraphicOLED::rows() { + return 2; +} + int GraphicOLED::_putc(int value) { if (value == '\n') { @@ -85,6 +133,10 @@ return value; } +int GraphicOLED::_getc() { + return -1; +} + void GraphicOLED::character(int column, int row, int c) { int i = 0; @@ -93,9 +145,9 @@ } else if (isprint(c)) { // 20 - 7e i = c - 32; } - char buf[4]; + uint8_t buf[4]; font_4x8(buf, i); - g_wrtie(buf, sizeof(buf), column*4, row); + g_write(buf, sizeof(buf), column*4, row); } void _jis(int *ph, int *pl) @@ -139,7 +191,7 @@ l = c & 0xff; _jis(&h, &l); int adrs = _jis2adrs(h<<8 | l); - char buf[8]; + uint8_t buf[8]; font_8x8(buf, adrs); - g_wrtie(buf, sizeof(buf), column*4, row); + g_write(buf, sizeof(buf), column*4, row); }
--- a/GraphicOLED.h Wed Apr 18 10:17:51 2012 +0000 +++ b/GraphicOLED.h Mon Aug 04 06:17:36 2014 +0000 @@ -1,14 +1,14 @@ // GraphicOLED.h -#ifndef MBED_GRAPHIC_OLED_H -#define MBED_GRAPHIC_OLED_H -#include "TextLCD.h" +#pragma once + +#include "mbed.h" #define iskanji(c) ((c)>=0x81 && (c)<=0x9F || (c)>=0xE0 && (c)<=0xFC) #define iskanji2(c) ((c)>=0x40 && (c)<=0xFC && (c)!=0x7F) /** GraphicOLED interface for WS0010 * - * Currently support shift-jis KANJI(misaki font) + * Currently support UTF-8 KANJI(misaki font) * * @code * #include "mbed.h" @@ -21,7 +21,7 @@ * } * @endcode */ -class GraphicOLED : public TextLCD { +class GraphicOLED : public Stream { public: /** Create a GraphicOLED interface * @@ -30,15 +30,57 @@ * @param d4-d7 Data lines for using as a 4-bit interface */ GraphicOLED(PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7); + +#if DOXYGEN_ONLY + /** Write a character to the LCD + * + * @param c The character to write to the display + */ + int putc(int c); + + /** Write a formated string to the LCD + * + * @param format A printf-style format string, followed by the + * variables to use in formating the string. + */ + int printf(const char* format, ...); +#endif + + /** Locate to a screen column and row + * + * @param column The horizontal position from the left, indexed from 0 + * @param row The vertical position from the top, indexed from 0 + */ + void locate(int column, int row); + + /** Clear the screen and locate to 0,0 */ void cls(); + + int rows(); int columns(); -protected: - void g_wrtie(int pat, int x, int y); - void g_wrtie(char *buf, int len, int x, int y); - virtual int _putc(int value); - void character(int column, int row, int c); + + void g_write(uint8_t pat, int x, int y); + void g_write(uint8_t *buf, int len, int x, int y); + +private: void character2(int column, int row, int c); bool _kanji_flag; int _kanji_1st; + + // Stream implementation functions + virtual int _putc(int value); + virtual int _getc(); + + int address(int column, int row); + void character(int column, int row, int c); + void writeByte(uint8_t value); + void writeCommand(uint8_t command); + void writeData(uint8_t data); + + DigitalOut _rs, _e; + BusOut _d; + + int _column; + int _row; }; -#endif \ No newline at end of file +
--- a/misaki_4x8_jis201.cpp Wed Apr 18 10:17:51 2012 +0000 +++ b/misaki_4x8_jis201.cpp Mon Aug 04 06:17:36 2014 +0000 @@ -1,7 +1,8 @@ // misaki_4x8_jis201.cpp +#include "mbed.h" // // misaki_bdf_b11a.tar.gz misaki_4x8_jisx0201.bdf -const char misaki_4x8_jisx0201[][4] = { // 20-7e, a1-df +const uint8_t misaki_4x8_jisx0201[][4] = { // 20-7e, a1-df {0,0,0,0},{0,47,0,0},{3,0,3,0},{63,18,63,0},{22,63,26,0},{18,8,36,0},{50,61,42,0},{2,1,0,0},{0,62,65,0}, {65,62,0,0},{10,7,10,0},{8,62,8,0},{0,64,32,0},{8,8,8,0},{0,32,0,0},{16,8,4,0},{28,42,28,0},{36,62,32,0}, {50,42,36,0},{34,42,20,0},{24,20,62,0},{46,42,18,0},{28,42,18,0},{2,58,6,0},{20,42,20,0},{36,42,28,0}, @@ -24,7 +25,7 @@ {35,17,15,0},{33,33,24,0},{1,0,1,0},{2,5,2,0}, }; -void font_4x8(char buf[], int i) +void font_4x8(uint8_t buf[], int i) { for(int k = 0; k < 4; k++) { buf[k] = misaki_4x8_jisx0201[i][k];
--- a/misaki_8x8.cpp Wed Apr 18 10:17:51 2012 +0000 +++ b/misaki_8x8.cpp Mon Aug 04 06:17:36 2014 +0000 @@ -1,4 +1,6 @@ -const char misaki_gothic[] = { // misaki_bdf_b11a.tar.gz misaki_gothic.bdf +#include "mbed.h" + +const uint8_t misaki_gothic[] = { // misaki_bdf_b11a.tar.gz misaki_gothic.bdf 0,0,0,0,0,0,0,32,64,0,0,0,0,0,32,80,32,0,0,0,0,80,48,0,0,0,0,0,96,96,0,0,0,0,0, 0,0,24,24,0,0,0,0,0,54,54,0,0,0,0,0,86,54,0,0,0,0,2,1,81,9,9,6,0,0,0,95,0,0,0, 1,2,1,2,0,0,0,0,2,5,2,0,0,0,0,0,0,2,1,0,0,0,0,1,2,0,0,0,0,0,1,0,1,0,0, @@ -2281,7 +2283,7 @@ 95,21,91,21,64,31,87, }; -void font_8x8(char buf[], int i) +void font_8x8(uint8_t buf[], int i) { for(int j = 0; j < 7; j++) { buf[j] = misaki_gothic[i*7+j];