Demonstration of SSD1308 OLED driver library
Dependencies: mbed SSD1308_128x64_I2C
Revision 3:1337e3d65ed0, committed 2012-07-18
- Comitter:
- wim
- Date:
- Wed Jul 18 13:59:03 2012 +0000
- Parent:
- 2:d86478c0f5da
- Child:
- 4:83b4e905be5b
- Commit message:
- Update 180712
Changed in this revision
--- a/FixedWidthFont.h Mon Jul 09 20:46:27 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -#ifndef FIXEDWIDTHFONT_H -#define FIXEDWIDTHFONT_H - -//#ifdef SSD1308_USE_FONT -//======================== -const uint8_t fontData[][8] = { -{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, -{0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00}, -{0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00}, -{0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00}, -{0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00}, -{0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00}, -{0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00}, -{0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00}, -{0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00}, -{0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00}, -{0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00}, -{0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00}, -{0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00}, -{0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00}, -{0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00}, -{0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00}, -{0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00}, -{0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00}, -{0x00,0x62,0x51,0x49,0x49,0x46,0x00,0x00}, -{0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00}, -{0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00}, -{0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00}, -{0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00}, -{0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00}, -{0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00}, -{0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00}, -{0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00}, -{0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00}, -{0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00}, -{0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00}, -{0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00}, -{0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00}, -{0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00}, -{0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00}, -{0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00}, -{0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00}, -{0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00}, -{0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00}, -{0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00}, -{0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00}, -{0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00}, -{0x00,0x41,0x7F,0x41,0x00,0x00,0x00,0x00}, -{0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00}, -{0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00}, -{0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00}, -{0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00}, -{0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00}, -{0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00}, -{0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00}, -{0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00}, -{0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00}, -{0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00}, -{0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00}, -{0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00}, -{0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00}, -{0x00,0x3F,0x40,0x38,0x40,0x3F,0x00,0x00}, -{0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00}, -{0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00}, -{0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00}, -{0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00}, -{0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00}, -{0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00}, -{0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00}, -{0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00}, -{0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00}, -{0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00}, -{0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00}, -{0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00}, -{0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00}, -{0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00}, -{0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00}, -{0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00}, -{0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00}, -{0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00}, -{0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00}, -{0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00}, -{0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00}, -{0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00}, -{0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00}, -{0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00}, -{0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00}, -{0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00}, -{0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00}, -{0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00}, -{0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00}, -{0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00}, -{0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00}, -{0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00}, -{0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00}, -{0x00,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00}, -{0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00}, -{0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00}, -{0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00}, -{0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00}, -{0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00}, -{0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00} -}; -//#endif // use font - -#endif // include \ No newline at end of file
--- a/SSD1308.cpp Mon Jul 09 20:46:27 2012 +0000 +++ b/SSD1308.cpp Wed Jul 18 13:59:03 2012 +0000 @@ -3,8 +3,11 @@ // The SSD1308 is used for example in the Seeed 128x64 OLED Display // http://www.seeedstudio.com/depot/grove-oled-display-12864-p-781.html?cPath=163_167 // -// The original code is using (and has been submitted as a part of) Jeff Rowberg's I2Cdevlib library, +// The original code by Andrew Schamp is using (and has been submitted as a part of) Jeff Rowberg's I2Cdevlib library, // which should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib +// Some parts also mashed up from Graphic Library for driving monochrome displays based on the PCD8544, +// Copyright (c) 2011, Wim De Roeve, who in turn did partial port of code found on +// http://serdisplib.sourceforge.net/ser/pcd8544.html#links and by Petras Saduikis <petras@petras.co.uk> // // Changelog: // 2011-08-25 - Initial release by Andrew Schamp <schamp@gmail.com> @@ -39,10 +42,19 @@ //#define SSD1308_USE_FONT //#ifdef SSD1308_USE_FONT -#include "FixedWidthFont.h" + +//#include "font_3x5.h" +//#include "font_5x7.h" +//#include "font_6x8.h" +#include "font_8x8.h" +//#include "font_8x12.h" +//#include "font_16x20.h" +#include "font_16x24.h" //#endif -//Constructor +//@brief Constructor +//@param I2C &i2c reference to i2c +//@param uint8_t deviceAddress slaveaddress // SSD1308::SSD1308(I2C &i2c, uint8_t deviceAddress) : _i2c(i2c) { // m_devAddr = deviceAddress; @@ -53,14 +65,21 @@ initialize(); } -// High level Init, most settings remain at Power-On reset value +// @brief High level Init, most settings remain at Power-On reset value // void SSD1308::initialize() { setHorizontalAddressingMode(); + clearDisplay(); + + setInverted(false); + + setDisplayOn(); } +// @brief clear the display +// #if(0) // Standard version void SSD1308::clearDisplay() { @@ -71,7 +90,7 @@ for (uint8_t page = 0; page < PAGES; page++) { for (uint8_t col = 0; col < COLUMNS; col++) { - sendData(0x00); + _sendData(0x00); } } @@ -102,6 +121,9 @@ #endif +// @brief fill the display +// @param uint8_t pattern fillpattern vertical patch or 8 bits +// #if(0) //Standard version void SSD1308::fillDisplay(uint8_t pattern) { @@ -113,36 +135,51 @@ for (uint8_t page = 0; page < PAGES; page++) { for (uint8_t col = 0; col < COLUMNS; col++) { - sendData(pattern); + _sendData(pattern); } } //setDisplayOn(); } #else + //Optimised version // Save lots of I2C S,P, address and datacommands: // Send S, address, DATA_MODE, data, data, data,...., P // -void SSD1308::fillDisplay(uint8_t pattern) { - +void SSD1308::fillDisplay(uint8_t pattern, + uint8_t start_page, uint8_t end_page, + uint8_t start_col, uint8_t end_col) { + + int count = (end_page - start_page + 1) * (end_col - start_col + 1); + //setDisplayOff(); - setPageAddress(0, MAX_PAGE); // all pages - setColumnAddress(0, MAX_COL); // all columns - + setPageAddress(start_page, end_page); // set page window + setColumnAddress(start_col, end_col); // set column window + _i2c.start(); _i2c.write(_writeOpcode); _i2c.write(DATA_MODE); - for (int i=0; i<(PAGES * COLUMNS); i++) { + for (int i=0; i<count; i++) { _i2c.write(pattern); // Write Data } _i2c.stop(); //setDisplayOn(); } + #endif +// @brief write a bitmap to the display +// @param uint8_t* data pointer to bitmap +// @param uint8_t start_page begin page (0..MAX_PAGE) +// @param uint8_t end_page end page (start_page..MAX_PAGE) +// @param uint8_t start_col begin column (0..MAX_COL) +// @param uint8_t end_col end column (start_col..MAX_COL) +// +#if(0) +//Standard version void SSD1308::writeBitmap(int len, uint8_t* data) { //setDisplayOff(); @@ -159,41 +196,71 @@ //setDisplayOn(); } +#else + +//Optimised version +// Save lots of I2C S,P, address and datacommands: +// Send S, address, DATA_MODE, data, data, data,...., P +// +void SSD1308::writeBitmap(uint8_t* data, + uint8_t start_page, uint8_t end_page, + uint8_t start_col, uint8_t end_col){ + + int count = (end_page - start_page + 1) * (end_col - start_col + 1); + + //setDisplayOff(); + setPageAddress(start_page, end_page); // set page window + setColumnAddress(start_col, end_col); // set column window + + _i2c.start(); + _i2c.write(_writeOpcode); + _i2c.write(DATA_MODE); + for (int i=0; i<count; i++) { + _i2c.write(data[i]); // Write Data + } + _i2c.stop(); + + //setDisplayOn(); +} +#endif -// Write single character to the display using the 8x8 fontable -// Start at current cursor location -// char chr character -// bool inverted invert pixels -void SSD1308::writeChar(char chr, bool inverted) { +// @brief Write single character to the display using the 8x8 fontable +// @brief Start at current cursor location +// @param char chr character to write +// +void SSD1308::writeChar(char chr) { const uint8_t char_index = chr - 0x20; + for (uint8_t i = 0; i < 8; i++) { -// const uint8_t b = pgm_read_byte( &fontData[char_index][i] ); -// const uint8_t b = fontData[char_index][i]; -// sendData( b ); - if (inverted) { - sendData( ~fontData[char_index][i] ); + if (_inverted) { + _sendData( ~font_8x8[char_index][i] ); } else { - sendData( fontData[char_index][i] ); + _sendData( font_8x8[char_index][i] ); } } } -// Write a string to the display using the 8x8 fontable -// Start at current cursor location -void SSD1308::writeString(uint8_t row, uint8_t col, uint16_t len, const char * text, bool inverted) { +// @brief Write a string to the display using the 8x8 font +// @brief Start at selected cursor location +// @param uint8_t row row number (0...ROWS/FONT_HEIGHT) +// @param uint8_t col column number (0...COLUMNS/FONT_WIDTH) +// @param uint16_t len number of chars in text +// @param const char * text pointer to text +// +void SSD1308::writeString(uint8_t row, uint8_t col, uint16_t len, const char * text) { uint16_t index = 0; setPageAddress(row, MAX_PAGE); - const uint8_t col_addr = FONT_WIDTH*col; + const uint8_t col_addr = FONT8x8_WIDTH*col; setColumnAddress(col_addr, MAX_COL); while ((col+index) < CHARS && (index < len)) { // write first line, starting at given position - writeChar(text[index++], inverted); + writeChar(text[index++]); } // write remaining lines @@ -204,7 +271,7 @@ setColumnAddress(0, MAX_COL); bool wrapEntireScreen = false; while (index + 1 < len) { - writeChar(text[index++], inverted); + writeChar(text[index++]); // if we've written the last character space on the screen, // reset the page and column address so that it wraps around from the top again if (!wrapEntireScreen && (row*CHARS + col + index) > 127) { @@ -216,22 +283,47 @@ } } -// Write command that has no parameters + + +// @brief Write large character (16x24 font) +// @param uint8_t row row number (0...MAX_ROW) +// @param uint8_t col column number (0...MAX_COL) +// @param char chr Used for displaying numbers 0 - 9 and '+', '-', '.' +// +void SSD1308::writeBigChar(uint8_t row, uint8_t col, char chr) { + + writeBitmap((uint8_t*) font_16x24[int(chr) - FONT16x24_START], + row, (row + FONT16x24_BYTES - 1), + col, (col + FONT16x24_WIDTH - 1)); +} + + +// @brief Write command that has no parameters // -void SSD1308::sendCommand(uint8_t command) { +void SSD1308::_sendCommand(uint8_t command) { // I2Cdev::writeByte(m_devAddr, COMMAND_MODE, command); +#if(0) char databytes[2]; databytes[0] = COMMAND_MODE; databytes[1] = command; _i2c.write(_writeOpcode, databytes, 2); // Write command +#endif + + _i2c.start(); + _i2c.write(_writeOpcode); + + _i2c.write(COMMAND_MODE); + _i2c.write(command); // Write Command + + _i2c.stop(); } -// Write command that has one parameter +// @brief Write command that has one parameter // -void SSD1308::sendCommand(uint8_t command, uint8_t param1) { +void SSD1308::_sendCommand(uint8_t command, uint8_t param1) { // Note continuationbit is set, so COMMAND_MODE must be // repeated before each databyte that serves as parameter! @@ -248,9 +340,9 @@ } -// Write command that has two parameters +// @brief Write command that has two parameters // -void SSD1308::sendCommand(uint8_t command, uint8_t param1, uint8_t param2) { +void SSD1308::_sendCommand(uint8_t command, uint8_t param1, uint8_t param2) { // Note continuationbit is set, so COMMAND_MODE must be // repeated before each databyte that serves as parameter! @@ -269,11 +361,10 @@ } - - -// Write command that has multiple parameters +#if(0) +// @brief Write command that has multiple parameters // -void SSD1308::sendCommands(uint8_t len, uint8_t* commands) { +void SSD1308::_sendCommands(uint8_t len, uint8_t* commands) { // I2Cdev::writeBytes(m_devAddr, COMMAND_MODE, len, commands); // Note this original code is not correct, continuationbit is set, @@ -289,10 +380,13 @@ _i2c.stop(); } +#endif -// Write databyte to display -// Start at current cursor location -void SSD1308::sendData(uint8_t data){ +// @brief Write databyte to display +// @brief Start at current cursor location +// @param uint8_t data databyte to write +// +void SSD1308::_sendData(uint8_t data){ // I2Cdev::writeByte(m_devAddr, DATA_MODE, data); char databytes[2]; @@ -303,9 +397,12 @@ } -// Write len bytes from buffer data to display -// Start at current cursor location -void SSD1308::sendData(uint8_t len, uint8_t* data) { +// @brief Write len bytes from buffer data to display, +// @brief Start at current cursor location +// @param uint8_t len number of bytes to write +// @param uint8_t* data pointer to data +// +void SSD1308::_sendData(uint8_t len, uint8_t* data) { // I2Cdev::writeBytes(m_devAddr, DATA_MODE, len, data); _i2c.start(); @@ -333,41 +430,49 @@ } void SSD1308::setMemoryAddressingMode(uint8_t mode){ - uint8_t cmds[2] = { SET_MEMORY_ADDRESSING_MODE, mode }; - sendCommands(2, cmds); + + _sendCommand(SET_MEMORY_ADDRESSING_MODE, mode); } + +// @param uint8_t start startpage (valid range 0..MAX_PAGE) +// @param uint8_t end endpage (valid range start..MAX_PAGE) +// void SSD1308::setPageAddress(uint8_t start, uint8_t end) { - uint8_t data[3] = { SET_PAGE_ADDRESS, start, end }; - sendCommands(3, data); -} -void SSD1308::setColumnAddress(uint8_t start, uint8_t end) { - uint8_t data[3] = { SET_COLUMN_ADDRESS, start, end }; - sendCommands(3, data); + _sendCommand(SET_PAGE_ADDRESS, start, end); } -// takes one byte, 0x00 (lowest) - 0xFF (highest) +// @param uint8_t start startcolumn (valid range 0..MAX_COL) +// @param uint8_t end endcolumn (valid range start..MAX_COL) +// +void SSD1308::setColumnAddress(uint8_t start, uint8_t end) { + + _sendCommand(SET_COLUMN_ADDRESS, start, end); +} + +// @brief Set Contrast +// @param uint8_t contrast (valid range 0x00 (lowest) - 0xFF (highest)) void SSD1308::setContrastControl(uint8_t contrast) { -// uint8_t cmds[2] = { SET_CONTRAST, contrast }; -// sendCommands(2, cmds); - sendCommand(SET_CONTRAST, contrast); + _sendCommand(SET_CONTRAST, contrast); } -// Enable Display +// @brief Enable Display // void SSD1308::setDisplayOn() { - sendCommand(SET_DISPLAY_POWER_ON); + _sendCommand(SET_DISPLAY_POWER_ON); } -// Disable Display +// @brief Disable Display // void SSD1308::setDisplayOff() { - sendCommand(SET_DISPLAY_POWER_OFF); + _sendCommand(SET_DISPLAY_POWER_OFF); } +// @brief Enable or Disable Display +// @param bool on void SSD1308::setDisplayPower(bool on) { if (on) { setDisplayOn(); @@ -376,81 +481,113 @@ } } -// White on Black background +// @brief White pixels on Black background // void SSD1308::setDisplayNormal() { - sendCommand(SET_NORMAL_DISPLAY); + _sendCommand(SET_NORMAL_DISPLAY); +} + +// @brief Black pixels on White background +// +void SSD1308::setDisplayInverse() { + _sendCommand(SET_INVERSE_DISPLAY); } -// Black on White background -// -void SSD1308::setDisplayInverse() { - sendCommand(SET_INVERSE_DISPLAY); -} +// @brief Blink display by fading in and out over a set number of frames +// @param bool on +// +void SSD1308::setDisplayBlink(bool on){ + if (on) { + _sendCommand(SET_FADE_BLINK, (BLINK_ENABLE | FADE_INTERVAL_128_FRAMES)); + } + else { + _sendCommand(SET_FADE_BLINK, FADE_BLINK_DISABLE); + } +} -// Display Flip (Left/Right, Up/Down) -// +// @brief Fade out display in set number of frames +// @param bool on +// +void SSD1308::setDisplayFade(bool on) { + if (on) { + _sendCommand(SET_FADE_BLINK, (FADE_OUT_ENABLE | FADE_INTERVAL_128_FRAMES)); + } + else { + _sendCommand(SET_FADE_BLINK, FADE_BLINK_DISABLE); + } +} + +// @brief Display Flip (Left/Right, Up/Down) +// @param bool left flip Left/Right +// @param bool down flip Up/Down +// void SSD1308::setDisplayFlip(bool left, bool down) { if (left) { // column address 0 is mapped to SEG0 (Reset) - sendCommand(SET_SEGMENT_REMAP_0); + _sendCommand(SET_SEGMENT_REMAP_0); } else { // column address 127 is mapped to SEG0 - sendCommand(SET_SEGMENT_REMAP_127); + _sendCommand(SET_SEGMENT_REMAP_127); } if (down) { // Reset mode - sendCommand(SET_COMMON_REMAP_0); + _sendCommand(SET_COMMON_REMAP_0); } else { // Flip Up/Down (Need to rewrite display before H effect shows) - sendCommand(SET_COMMON_REMAP_63); + _sendCommand(SET_COMMON_REMAP_63); } } -// Sets Internal Iref +// @brief Sets Internal Iref // void SSD1308::setInternalIref() { - uint8_t cmds[2] = {SET_IREF_SELECTION, INTERNAL_IREF}; - sendCommands(2, cmds); +// uint8_t cmds[2] = {SET_IREF_SELECTION, INTERNAL_IREF}; +// _sendCommands(2, cmds); + + _sendCommand(SET_IREF_SELECTION, INTERNAL_IREF); } -// Sets External Iref +// @brief Sets External Iref (default) // void SSD1308::setExternalIref() { - uint8_t cmds[2] = {SET_IREF_SELECTION, EXTERNAL_IREF}; - sendCommands(2, cmds); +// uint8_t cmds[2] = {SET_IREF_SELECTION, EXTERNAL_IREF}; +// _sendCommands(2, cmds); + _sendCommand(SET_IREF_SELECTION, EXTERNAL_IREF); } -// Low level Init -// Init the configuration registers in accordance with the datasheet +// @brief Low level Init +// @brief Init the configuration registers in accordance with the datasheet // void SSD1308::_init() { //not complete yet - sendCommand(SET_DISPLAY_POWER_OFF); + _sendCommand(SET_DISPLAY_POWER_OFF); // column address 0 is mapped to SEG0 (Reset) // row address 0 is mapped to COMM0 (Reset) - sendCommand(SET_SEGMENT_REMAP_0); - sendCommand(SET_COMMON_REMAP_0); + _sendCommand(SET_SEGMENT_REMAP_0); + _sendCommand(SET_COMMON_REMAP_0); - uint8_t cmds[2] = { SET_COMMON_CONF, COMMON_BASE | COMMON_ALTERNATIVE | COMMON_LEFTRIGHT_NORMAL}; - sendCommands(2, cmds); +// uint8_t cmds[2] = { SET_COMMON_CONF, COMMON_BASE | COMMON_ALTERNATIVE | COMMON_LEFTRIGHT_NORMAL}; +// _sendCommands(2, cmds); + _sendCommand(SET_COMMON_CONF, COMMON_BASE | COMMON_ALTERNATIVE | COMMON_LEFTRIGHT_NORMAL); - setHorizontalAddressingMode(); + setHorizontalAddressingMode(); // (Non-Reset) - setExternalIref(); - - sendCommand(SET_NORMAL_DISPLAY); + setExternalIref(); // (Reset) + + _sendCommand(SET_CONTRAST, 0x7F); // (Reset) + + _sendCommand(SET_NORMAL_DISPLAY); clearDisplay(); - sendCommand(SET_DISPLAY_POWER_ON); + _sendCommand(SET_DISPLAY_POWER_ON); }
--- a/SSD1308.h Mon Jul 09 20:46:27 2012 +0000 +++ b/SSD1308.h Wed Jul 18 13:59:03 2012 +0000 @@ -3,8 +3,11 @@ // The SSD1308 is used for example in the Seeed 128x64 OLED Display // http://www.seeedstudio.com/depot/grove-oled-display-12864-p-781.html?cPath=163_167 // -// The original code is using (and has been submitted as a part of) Jeff Rowberg's I2Cdevlib library, +// The original code by Andrew Schamp is using (and has been submitted as a part of) Jeff Rowberg's I2Cdevlib library, // which should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib +// Some parts also mashed up from Graphic Library for driving monochrome displays based on the PCD8544, +// Copyright (c) 2011, Wim De Roeve, who in turn did partial port of code found on +// http://serdisplib.sourceforge.net/ser/pcd8544.html#links and by Petras Saduikis <petras@petras.co.uk> // // Changelog: // 2011-08-25 - Initial release by Andrew Schamp <schamp@gmail.com> @@ -45,36 +48,57 @@ #define SSD1308_SA1 0x7A #define SSD1308_DEF_SA SSD1308_SA0 +// Display dimensions #define ROWS 64 #define COLUMNS 128 #define PAGES (ROWS / 8) #define MAX_PAGE (PAGES - 1) #define MAX_COL (COLUMNS - 1) -#define FONT_WIDTH 8 -#define CHARS (COLUMNS / FONT_WIDTH) +// Character dimensions 8x8 font +#define CHARS (COLUMNS / FONT8x8_WIDTH) +// Command and Datamode +#define COMMAND_MODE 0x80 // continuation bit is set! +#define DATA_MODE 0x40 + +// Commands and Parameter defines #define HORIZONTAL_ADDRESSING_MODE 0x00 #define VERTICAL_ADDRESSING_MODE 0x01 #define PAGE_ADDRESSING_MODE 0x02 - -#define SET_MEMORY_ADDRESSING_MODE 0x20 // takes one byte +#define SET_MEMORY_ADDRESSING_MODE 0x20 // takes one byte as given above #define SET_COLUMN_ADDRESS 0x21 // takes two bytes, start address and end address of display data RAM #define SET_PAGE_ADDRESS 0x22 // takes two bytes, start address and end address of display data RAM +// Command maybe unsupported by SSD1308 +#define FADE_INTERVAL_8_FRAMES 0x00 +#define FADE_INTERVAL_16_FRAMES 0x01 +#define FADE_INTERVAL_24_FRAMES 0x02 +#define FADE_INTERVAL_32_FRAMES 0x03 +#define FADE_INTERVAL_64_FRAMES 0x07 +#define FADE_INTERVAL_128_FRAMES 0x0F +#define FADE_BLINK_DISABLE 0x00 +#define FADE_OUT_ENABLE 0x20 +#define BLINK_ENABLE 0x30 +#define SET_FADE_BLINK 0x23 // takes one byte + // bit5-4 = 0, fade/blink mode + // bit3-0 = Time interval in frames + +#define SET_DISPLAY_START_LINE 0x40 // | with a row number 0-63 to set start row. Reset = 0 + #define SET_CONTRAST 0x81 // takes one byte, 0x00 - 0xFF #define SET_SEGMENT_REMAP_0 0xA0 // column address 0 is mapped to SEG0 (Reset) #define SET_SEGMENT_REMAP_127 0xA1 // column address 127 is mapped to SEG0 +#define SET_DISPLAY_GDDRAM 0xA4 // restores display to contents of RAM #define SET_ENTIRE_DISPLAY_ON 0xA5 // turns all pixels on, does not affect RAM -#define SET_DISPLAY_GDDRAM 0xA4 // restores display to contents of RAM -#define SET_NORMAL_DISPLAY 0xA6 // a data of 1 indicates 'ON' -#define SET_INVERSE_DISPLAY 0xA7 // a data of 0 indicates 'ON' +#define SET_NORMAL_DISPLAY 0xA6 // a databit of 1 indicates pixel 'ON' +#define SET_INVERSE_DISPLAY 0xA7 // a databit of 1 indicates pixel 'OFF' -#define SET_MULTIPLEX_RATIO 0xA8 // takes one byte, from 16 to 63 (0x +#define SET_MULTIPLEX_RATIO 0xA8 // takes one byte, from 16xMUX to 64xMUX (MUX Ratio = byte+1; Default 64) #define EXTERNAL_IREF 0x10 #define INTERNAL_IREF 0x00 @@ -83,9 +107,6 @@ #define SET_DISPLAY_POWER_OFF 0xAE #define SET_DISPLAY_POWER_ON 0xAF -#define COMMAND_MODE 0x80 // continuation bit is set! -#define DATA_MODE 0x40 - #define PAGE0 0x00 #define PAGE1 0x01 #define PAGE2 0x02 @@ -99,54 +120,97 @@ #define SET_COMMON_REMAP_0 0xC0 // row address 0 is mapped to COM0 (Reset) #define SET_COMMON_REMAP_63 0xC8 // row address 63 is mapped to COM0 +#define SET_DISPLAY_OFFSET 0xD3 // takes one byte from 0-63 for vertical shift, Reset = 0 -#define SET_DISPLAY_OFFSET 0xD3 +#define SET_DISPLAY_CLOCK 0xD5 // takes one byte + // bit7-4 = Osc Freq DCLK (Reset = 1000b) + // bit3-0 = Divide ration (Reset = oooob, Ratio = 1) -#define SET_DISPLAY_CLOCK 0xD5 +#define SET_PRECHARGE_TIME 0xD9 // takes one byte + // bit7-4 = Phase2, upto 15 DCLKs (Reset = 0010b) + // bit3-0 = Phase1, upto 15 DCLKs (Reset = 0010b) + #define COMMON_BASE 0x02 // #define COMMON_SEQUENTIAL 0x00 // Sequential common pins config #define COMMON_ALTERNATIVE 0x10 // Odd/Even common pins config (Reset) #define COMMON_LEFTRIGHT_NORMAL 0x00 // LeftRight Normal (Reset) #define COMMON_LEFTRIGHT_FLIP 0x20 // LeftRight Flip -#define SET_COMMON_CONF 0xDA +#define SET_COMMON_CONF 0xDA // takes one byte as given above + #define VCOMH_DESELECT_0_65_CODE 0x00 #define VCOMH_DESELECT_0_77_CODE 0x20 #define VCOMH_DESELECT_0_83_CODE 0x30 -#define SET_VCOMH_DESELECT_LEVEL 0xDB +#define SET_VCOMH_DESELECT_LEVEL 0xDB // takes one byte as given above #define NOP 0xE3 -#define SET_RIGHT_HORIZONTAL_SCROLL 0x26 -#define SET_LEFT_HORIZONTAL_SCROLL 0x27 -#define SET_VERTICAL_RIGHT_HORIZONTAL_SCROLL 0x29 -#define SET_VERTICAL_LEFT_HORIZONTAL_SCROLL 0x2A +#define SCROLL_INTERVAL_5_FRAMES 0x00 +#define SCROLL_INTERVAL_64_FRAMES 0x01 +#define SCROLL_INTERVAL_128_FRAMES 0x02 +#define SCROLL_INTERVAL_256_FRAMES 0x03 +#define SCROLL_INTERVAL_3_FRAMES 0x04 +#define SCROLL_INTERVAL_4_FRAMES 0x05 +#define SCROLL_INTERVAL_25_FRAMES 0x06 +#define SCROLL_INTERVAL_2_FRAMES 0x07 + +#define SET_RIGHT_HOR_SCROLL 0x26 // takes 6 bytes: 0x00, PageStart, Scroll_Interval, PageEnd, 0x00, 0xFF +#define SET_LEFT_HOR_SCROLL 0x27 // takes 6 bytes: 0x00, PageStart, Scroll_Interval, PageEnd, 0x00, 0xFF + +#define SET_VERT_RIGHT_HOR_SCROLL 0x29 // takes 5 bytes: 0x00, PageStart, Scroll_Interval, PageEnd, VertOffset +#define SET_VERT_LEFT_HOR_SCROLL 0x2A // takes 5 bytes: 0x00, PageStart, Scroll_Interval, PageEnd, VertOffset #define SET_DEACTIVATE_SCROLL 0x2E #define SET_ACTIVATE_SCROLL 0x2F -#define SET_VERTICAL_SCROLL_AREA 0xA3 +#define SET_VERTICAL_SCROLL_AREA 0xA3 // takes 2 bytes: Rows in Top Area (Reset=0), Rows in Scroll Area (Reset=64) -class SSD1308 { +class SSD1308 : public Stream { public: - // constructor - // takes a 8bit I2C address to use (0x78 by default, assumes D/C# (pin 13) grounded) +// Constructor + // takes 8bit I2C address to use for the controller (0x78 by default, assumes D/C# (pin 13) grounded) SSD1308(I2C &i2c, uint8_t address = SSD1308_DEF_SA); +// High Level methods void initialize(); + void clearDisplay(); - void fillDisplay(uint8_t pattern); // pattern +// void fillDisplay(uint8_t pattern); // pattern + void fillDisplay(uint8_t pattern = 0x00, + uint8_t start_page=0, uint8_t end_page=MAX_PAGE, + uint8_t start_col=0, uint8_t end_col=MAX_COL); + + void writeBitmap(uint8_t* data, + uint8_t start_page=0, uint8_t end_page=MAX_PAGE, + uint8_t start_col=0, uint8_t end_col=MAX_COL); - void writeBitmap(int len, uint8_t* data); + //void setXY(uint8_t, uint8_t y); + + // Select inverted or normal text + void setInverted(bool inverted) { _inverted = inverted; }; + + // write char at current cursor location + void writeChar(char chr); + + // write large char at cursor location + void writeBigChar(uint8_t row, uint8_t col, char chr); // x, y is position (x is row (i.e., page), y is character (0-15), starting at top-left) // text will wrap around until it is done. - void writeString(uint8_t row, uint8_t col, uint16_t len, const char* txt, bool inverted = false); + void writeString(uint8_t row, uint8_t col, uint16_t len, const char* txt); + + // Stream implementation - provides printf() interface + // You would otherwise be forced to use writeChar() or writeString() + virtual int _putc(int value) { writeChar(value); return 1; }; + virtual int _getc() { return -1; }; + +// Future extension with graphics features + // this must be defined by the subclass +// virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; - //void setXY(uint8_t, uint8_t y); - +// Medium Level methods void setHorizontalAddressingMode(); void setVerticalAddressingMode(); void setPageAddressingMode(); @@ -190,73 +254,64 @@ void setDisplayNormal(); void setDisplayInverse(); - + void setDisplayBlink(bool on); + void setDisplayFade(bool on); + // Display Flip (Up/Down, Left/Right) // void setDisplayFlip(bool left, bool down); - // Set vertical shift by COM from 0 - 63 (0x00 - 0x3F) // set to 0x00 after RESET void setDisplayOffset(uint8_t offset); - // divide ratio 0x00-0x0F, value +1 (reset 0x00) - // oscillator freq 0x00-0x0F (reset 0x08) + // Divide ratio 0x00-0x0F, value +1 (reset 0x00) + // Oscillator freq 0x00-0x0F (reset 0x08) void setDisplayClock(uint8_t divideRatio, uint8_t oscFreq); - // phase1 0x01-0x0F period of up to 15 DCLK clocks (reset 0x02, 0 is invalid) - // phase2 0x01-0x0F period of up to 15 DCLK clocks (reset 0x02, 0 is invalid) + // Phase1 0x01-0x0F period of up to 15 DCLK clocks (reset 0x02, 0 is invalid) + // Phase2 0x01-0x0F period of up to 15 DCLK clocks (reset 0x02, 0 is invalid) void setPrechargePeriod(uint8_t phase1, uint8_t phase2); - #define VCOM_DESELECT_0_65 0x00 - #define VCOM_DESELECT_0_77 0x02 - #define VCOM_DESELECT_0_83 0x03 void setVcomhDeselectLevel(uint8_t level); - // command for no-operation + // Command for no-operation void nop(); - #define SCROLL_INTERVAL_5_FRAMES 0x00 - #define SCROLL_INTERVAL_64_FRAMES 0x01 - #define SCROLL_INTERVAL_128_FRAMES 0x02 - #define SCROLL_INTERVAL_256_FRAMES 0x03 - #define SCROLL_INTERVAL_3_FRAMES 0x04 - #define SCROLL_INTERVAL_4_FRAMES 0x05 - #define SCROLL_INTERVAL_25_FRAMES 0x06 - #define SCROLL_INTERVAL_2_FRAMES 0x07 - // end_page must not be less than start_page + // End_page must not be less than start_page void setContinuousHorizontalScroll(bool left, uint8_t start_page, uint8_t interval, uint8_t end_page); - // horizontal scroll by one column per interval - // offset = 1 (0x01) to 63 (0x3F) + // Horizontal scroll by one column per interval + // Offset = 1 (0x01) to 63 (0x3F) void setContinuousVerticalAndHorizontalScroll(bool left, uint8_t start_page, uint8_t interval, uint8_t end_page, uint8_t offset); - // note, after deactivating scrolling, the RAM data needs to be rewritten + // Note, after deactivating scrolling, the RAM data needs to be rewritten void deactivateScroll(); void activateScroll(); - void setVerticalScrollArea(uint8_t topRowsFixed, uint8_t scrollRows); - - void sendData(uint8_t data); - void sendData(uint8_t len, uint8_t* data); - + void setVerticalScrollArea(uint8_t topRowsFixed, uint8_t scrollRows); private: - // sends a command and optional params to device - void sendCommand(uint8_t command); - void sendCommand(uint8_t command, uint8_t param1); - void sendCommand(uint8_t command, uint8_t param1, uint8_t param2); - - void sendCommands(uint8_t len, uint8_t* buf); - void writeChar(char chr, bool inverted); + +// Low Level methods + // Sends a command and optional params to device + void _sendCommand(uint8_t command); + void _sendCommand(uint8_t command, uint8_t param1); + void _sendCommand(uint8_t command, uint8_t param1, uint8_t param2); +// void sendCommands(uint8_t len, uint8_t* buf); + + // Sends data to device + void _sendData(uint8_t data); + void _sendData(uint8_t len, uint8_t* data); // Init the configuration registers in accordance with the datasheet void _init(); - - I2C _i2c; // I2C bus + + I2C _i2c; // I2C bus reference // uint8_t m_devAddr; // contains the I2C address of the device uint8_t _readOpcode; uint8_t _writeOpcode; - + + bool _inverted; // inverted or normal text }; #endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/font_16x24.h Wed Jul 18 13:59:03 2012 +0000 @@ -0,0 +1,58 @@ + +#ifndef _FONT_16x24_H_ +#define _FONT_16x24_H_ + +//----- DEFINES ----- +#define FONT16x24_START 0x20 +#define FONT16x24_END 0x44 +#define FONT16x24_WIDTH 11 +#define FONT16x24_HEIGHT 24 +#define FONT16x24_BYTES 3 + +//Used for displaying numbers 0 - 9 and '+', '-', '.' + +const uint8_t font_16x24[36][3][11] = +{ + + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// 0x20 + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// 0x21 + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// 0x22 + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// 0x23 + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// 0x24 + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// 0x25 + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// 0x26 + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// 0x27 + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// 0x28 + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// 0x29 + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// 0x2A + + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,64,64,64,254,254,64,64 , 0,0,0,0,0,0,0,15,15,0,0 ,// '+'// 0x2B + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// // 0x2C + + 0,0,0,0,0,0,0,0,0,0,0 , 0,64,64,64,64,64,64,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// '-'// 0x2D + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,60,60,60,0,0,0,0,0 ,// '.'// 0x2E + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// 0x2F + + 0,128,192,224,224,96,224,224,192,128,0 , 112,255,255,1,0,0,0,0,255,255,254 , 0,15,31,60,56,48,56,56,31,15,3 , //'0' 0x30 + 0,0,0,0,128,224,224,0,0,0,0 , 0,0,3,3,3,255,255,0,0,0,0 , 0,0,56,56,56,63,63,56,56,56,0 , //'1' 0x31 + 0,192,192,224,96,96,224,224,192,128,0 , 0,1,0,0,128,192,224,249,63,31,0 , 0,60,62,63,63,59,57,56,56,56,56 , //'2' 0x32 + 0,192,224,224,96,96,224,224,192,192,0 , 0,1,0,0,48,48,56,125,239,207,0 , 0,28,56,56,48,48,56,60,31,15,1 , //'3' 0x33 + 0,0,0,0,0,128,192,224,224,0,0 , 224,240,248,222,207,199,193,255,255,192,192 , 0,0,0,0,0,0,0,63,63,0,0 , //'4' 0x34 + 0,224,224,224,224,224,224,224,224,224,224 , 0,63,63,63,56,56,48,112,240,224,0 , 0,28,56,56,48,48,56,60,31,15,1 , //'5' 0x35 + 0,0,128,192,192,224,96,96,224,224,0 , 224,254,255,55,57,24,24,56,240,240,192 , 0,15,31,28,56,48,48,56,31,15,7 , //'6' 0x36 + 0,224,224,224,224,224,224,224,224,224,224 , 0,0,0,0,128,224,248,126,31,7,1 , 0,0,56,62,31,7,1,0,0,0,0 , //'7' 0x37 + 0,128,192,224,224,96,96,224,192,192,0 , 0,207,255,127,56,48,112,112,255,239,199 , 3,15,31,60,56,48,48,56,31,31,15 , //'8' 0x38 + 0,128,192,224,224,96,224,224,192,128,0 , 12,63,127,241,224,192,192,225,255,255,254 , 0,0,56,48,48,56,56,30,15,7,0 , //'9' 0x39 + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// 0x3A + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// 0x3B + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// 0x3C + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// 0x3D + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// 0x3E + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// 0x3F + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// 0x40 + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// 0x41 + 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0 ,// 0x42 + 0,128,192,224,224,96,224,224,192,128,0 , 112,112,112,1,0,0,0,0,112,112,112 , 0,0,0,0,0,0,0,0,0,0,0 //'C' 0x43 +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/font_8x8.h Wed Jul 18 13:59:03 2012 +0000 @@ -0,0 +1,114 @@ +#ifndef _FONT_8x8_H_ +#define _FONT_8x8_H_ + + +//----- DEFINES ----- +#define FONT8x8_START 0x20 +//#define FONT8x8_END 0x44 +#define FONT8x8_WIDTH 8 +#define FONT8x8_HEIGHT 8 +#define FONT8x8_BYTES 1 + +//#ifdef SSD1308_USE_FONT +//======================== +const uint8_t font_8x8[][8] = { +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00}, +{0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00}, +{0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00}, +{0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00}, +{0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00}, +{0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00}, +{0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00}, +{0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00}, +{0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00}, +{0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00}, +{0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00}, +{0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00}, +{0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00}, +{0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00}, +{0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00}, +{0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00}, +{0x00,0x62,0x51,0x49,0x49,0x46,0x00,0x00}, +{0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00}, +{0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00}, +{0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00}, +{0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00}, +{0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00}, +{0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00}, +{0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00}, +{0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00}, +{0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00}, +{0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00}, +{0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00}, +{0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00}, +{0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00}, +{0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00}, +{0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00}, +{0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00}, +{0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00}, +{0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00}, +{0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00}, +{0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00}, +{0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00}, +{0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00}, +{0x00,0x41,0x7F,0x41,0x00,0x00,0x00,0x00}, +{0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00}, +{0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00}, +{0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00}, +{0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00}, +{0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00}, +{0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00}, +{0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00}, +{0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00}, +{0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00}, +{0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00}, +{0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00}, +{0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00}, +{0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00}, +{0x00,0x3F,0x40,0x38,0x40,0x3F,0x00,0x00}, +{0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00}, +{0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00}, +{0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00}, +{0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00}, +{0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00}, +{0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00}, +{0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00}, +{0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00}, +{0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00}, +{0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00}, +{0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00}, +{0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00}, +{0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00}, +{0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00}, +{0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00}, +{0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00}, +{0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00}, +{0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00}, +{0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00}, +{0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00}, +{0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00}, +{0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00}, +{0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00}, +{0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00}, +{0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00}, +{0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00}, +{0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00}, +{0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00}, +{0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00}, +{0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00}, +{0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00}, +{0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00}, +{0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00}, +{0x00,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00}, +{0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00}, +{0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00}, +{0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00}, +{0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00}, +{0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00} +}; +//#endif // use font + +#endif // include \ No newline at end of file
--- a/main.cpp Mon Jul 09 20:46:27 2012 +0000 +++ b/main.cpp Wed Jul 18 13:59:03 2012 +0000 @@ -7,7 +7,6 @@ * version 0.2 Initial Release */ #include "mbed.h" -//#include "FixedWidthFont.h" #include "mbed_logo.h" #include "SSD1308.h" @@ -36,21 +35,22 @@ SSD1308 oled = SSD1308(i2c, SSD1308_SA0); void show_menu() { - pc.printf("0: Exit\n\r"); - pc.printf("1: Show Menu\n\r"); - pc.printf("2: Send Message\n\r"); - pc.printf("3: Fill Display\n\r"); - pc.printf("4: Display cleared\n\r"); - pc.printf("5: Display off\n\r"); - pc.printf("6: Display on\n\r"); - pc.printf("7: Display Invert\n\r"); - pc.printf("8: Display Normal\n\r"); - pc.printf("9: Display Bitmap\n\r"); - pc.printf("A: Brightness Ramp\n\r"); - pc.printf("B: Send Inverted Message\n\r"); - pc.printf("C: Flip and Mirror\n\r"); + pc.printf("0: Exit\r"); + pc.printf("1: Show Menu\r"); + pc.printf("2: Send Message\r"); + pc.printf("3: Fill Display\r"); + pc.printf("4: Display cleared\r"); + pc.printf("5: Display off\r"); + pc.printf("6: Display on\r"); + pc.printf("7: Display Invert\r"); + pc.printf("8: Display Normal\r"); + pc.printf("9: Display Bitmap\r"); + pc.printf("A: Brightness Ramp\r"); + pc.printf("B: Send Inverted Message\r"); + pc.printf("C: Flip and Mirror\r"); + pc.printf("D: Blink\r"); + pc.printf("E: Big Chars\r"); -// pc.printf("D: \n\r"); // pc.printf("E: \n\r"); // pc.printf("F: \n\r"); // pc.printf("\n\r"); @@ -167,8 +167,9 @@ if(pc.readable()) { command = pc.getc(); - pc.printf("command= %c \n\r", command); - + //pc.printf("command= %c \n\r", command); + pc.printf("\r"); + switch (command) { case '0' : pc.printf("Done\n\r"); @@ -185,8 +186,10 @@ break; case '3' : - pc.printf("Fill Display 0xAA\n\r"); - oled.fillDisplay(0xA5); + pc.printf("Fill part of Display 0xA5\n\r"); +// oled.fillDisplay(0xA5); + + oled.fillDisplay(0xA5, 2, 5, 0, 63); break; case '4' : @@ -215,30 +218,39 @@ case '9' : pc.printf("Display bitmap\r\n"); - oled.writeBitmap((PAGES*COLUMNS), (uint8_t*) mbed_logo); - +// oled.writeBitmap((PAGES*COLUMNS), (uint8_t*) mbed_logo); + oled.writeBitmap((uint8_t*) mbed_logo); + break; case 'A' : + pc.printf("Brightness Ramp Down\r\n"); - for (int contrast=0x7F; contrast >= 0x00; contrast--) { + for (int contrast=0x7F; contrast >= 0x10; contrast--) { oled.setContrastControl(contrast); wait(0.05); } wait(1); - + pc.printf("Brightness Ramp Up\r\n"); - for (int contrast=0x00; contrast <= 0x7F; contrast++) { + for (int contrast=0x10; contrast <= 0x7F; contrast++) { oled.setContrastControl(contrast); wait(0.05); } + pc.printf("Brightness Ramp Done\r\n"); + break; case 'B' : pc.printf("Send Inverted Message\n\r"); - oled.writeString(0, 0, 13, "Hello World !", true); + oled.setInverted(true); + oled.writeString(0, 0, 13, "Hello World !"); + oled.setInverted(false); + + oled.printf(" Result is %d", 12345); + break; case 'C' : @@ -246,8 +258,34 @@ left = !left; down = !down; oled.setDisplayFlip(left, down); - break; - + break; + + case 'D' : + pc.printf("D: Blink and Fade (not supported) \n\r"); + +// oled.setDisplayBlink(true); +// wait(4); +// oled.setDisplayBlink(false); + + oled.setDisplayFade(true); + wait(4); + oled.setDisplayFade(false); + + pc.printf("D: Blink done\n\r"); + break; + + + case 'E' : + pc.printf("E: Big Chars\n\r"); + + oled.writeBigChar(0, 0, '+'); + oled.writeBigChar(0, 16, '7'); + oled.writeBigChar(0, 32, '8'); + oled.writeBigChar(0, 48, '9'); + + pc.printf("E: Big Chars done\n\r"); + break; + } //switch }//if }//while
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Jul 18 13:59:03 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/737756e0b479 \ No newline at end of file
--- a/mbed.lib Mon Jul 09 20:46:27 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/projects/libraries/svn/mbed/trunk@43 \ No newline at end of file