Demonstration of SSD1308 OLED driver library
Dependencies: mbed SSD1308_128x64_I2C
Revision 0:2ded56b8407d, committed 2012-06-19
- Comitter:
- wim
- Date:
- Tue Jun 19 20:00:10 2012 +0000
- Child:
- 1:00053cb70ac5
- Commit message:
- First code port
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FixedWidthFont.h Tue Jun 19 20:00:10 2012 +0000 @@ -0,0 +1,106 @@ +#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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SSD1308.cpp Tue Jun 19 20:00:10 2012 +0000 @@ -0,0 +1,221 @@ +// I2Cdev library collection - SSD1308 I2C device class header file +// Based on Solomon Systech SSD1308 datasheet, rev. 1, 10/2008 +// 8/25/2011 by Andrew Schamp <schamp@gmail.com> +// 19/06/2012 Ported to mbed (WH) +// +// This I2C device library is using (and submitted as a part of) Jeff Rowberg's I2Cdevlib library, +// which should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib +// Note WH: I2Cdevlib not used for mbed port +// +// Changelog: +// 2011-08-25 - initial release +// 2012-06-19 - Ported to mbed (WH) + +/* ============================================ +I2Cdev device library code is placed under the MIT license +Copyright (c) 2011 Andrew Schamp +Copyright (c) 2012 WH (mbed port) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +=============================================== +*/ +#include "mbed.h" +#include "SSD1308.h" + +#define SSD1308_USE_FONT +//#ifdef SSD1308_USE_FONT +#include "FixedWidthFont.h" +//#endif + +SSD1308::SSD1308(I2C &i2c, uint8_t deviceAddress) : _i2c(i2c) { +// m_devAddr = deviceAddress; + + _writeOpcode = deviceAddress & 0xFE; // low order bit = 0 for write + _readOpcode = deviceAddress | 0x01; // low order bit = 1 for read +} + +void SSD1308::initialize() { + setHorizontalAddressingMode(); + clearDisplay(); +} + +void SSD1308::clearDisplay() { + setDisplayOff(); + setPageAddress(0, MAX_PAGE); // all pages + setColumnAddress(0, MAX_COL); // all columns + for (uint8_t page = 0; page < PAGES; page++) + { + for (uint8_t col = 0; col < COLUMNS; col++) + { + sendData(0x0); + } + } + setDisplayOn(); +} + +void SSD1308::fillDisplay() { + setPageAddress(0, MAX_PAGE); // all pages + setColumnAddress(0, MAX_COL); // all columns + + uint8_t b = 0; + for (uint8_t page = 0; page < PAGES; page++) + { + for (uint8_t col = 0; col < COLUMNS; col++) + { + sendData(b++); + } + } +} + +void SSD1308::writeChar(char chr) { +//#ifdef SSD1308_USE_FONT + 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 ); + } +//#endif +} + +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; + setColumnAddress(col_addr, MAX_COL); + + while ((col+index) < CHARS && (index < len)) { + // write first line, starting at given position + writeChar(text[index++]); + } + + // write remaining lines + // write until the end of memory + // then wrap around again from the top. + if (index + 1 < len) { + setPageAddress(row + 1, MAX_PAGE); + setColumnAddress(0, MAX_COL); + bool wrapEntireScreen = false; + while (index + 1 < len) { + 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) { + setPageAddress(0, MAX_PAGE); + setColumnAddress(0, MAX_COL); + wrapEntireScreen = true; + } + } + } +} + +void SSD1308::sendCommand(uint8_t command) { +// I2Cdev::writeByte(m_devAddr, COMMAND_MODE, command); + + char databytes[2]; + + databytes[0] = COMMAND_MODE; + databytes[1] = command; + _i2c.write(_writeOpcode, databytes, 2); // Write command + +} + +void SSD1308::sendCommands(uint8_t len, uint8_t* commands) { +// I2Cdev::writeBytes(m_devAddr, COMMAND_MODE, len, commands); + + int i; + + _i2c.start(); + _i2c.write(_writeOpcode); + _i2c.write(COMMAND_MODE); + for (i=0; i<len ; i++) { + _i2c.write(commands[i]); // Write Commands + } + _i2c.stop(); + +} + +void SSD1308::sendData(uint8_t data){ +// I2Cdev::writeByte(m_devAddr, DATA_MODE, data); + + char databytes[2]; + + databytes[0] = DATA_MODE; + databytes[1] = data; + _i2c.write(_writeOpcode, databytes, 2); // Write Data + +} + +void SSD1308::sendData(uint8_t len, uint8_t* data) { +// I2Cdev::writeBytes(m_devAddr, DATA_MODE, len, data); + + int i; + + _i2c.start(); + _i2c.write(_writeOpcode); + _i2c.write(DATA_MODE); + for (i=0; i<len ; i++) { + _i2c.write(data[i]); // Write Data + } + _i2c.stop(); + +} + +void SSD1308::setHorizontalAddressingMode(){ + setMemoryAddressingMode(HORIZONTAL_ADDRESSING_MODE); +} + +void SSD1308::setVerticalAddressingMode() { + setMemoryAddressingMode(VERTICAL_ADDRESSING_MODE); +} + +void SSD1308::setPageAddressingMode(){ + setMemoryAddressingMode(PAGE_ADDRESSING_MODE); +} + +void SSD1308::setMemoryAddressingMode(uint8_t mode){ + uint8_t cmds[2] = { SET_MEMORY_ADDRESSING_MODE, mode }; + sendCommands(2, cmds); +} + +void SSD1308::setDisplayOn() { + sendCommand(SET_DISPLAY_POWER_ON); +} + +void SSD1308::setDisplayOff() { + sendCommand(SET_DISPLAY_POWER_OFF); +} + +void SSD1308::setDisplayPower(bool on) { + if (on) { + setDisplayOn(); + } else { + setDisplayOff(); + } +} + +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); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SSD1308.h Tue Jun 19 20:00:10 2012 +0000 @@ -0,0 +1,242 @@ +// I2Cdev library collection - SSD1308 I2C device class header file +// Based on Solomon Systech SSD1308 datasheet, rev. 1, 10/2008 +// 8/25/2011 by Andrew Schamp <schamp@gmail.com> +// 19/06/2012 Ported to mbed (WH) +// +// This I2C device library is using (and submitted as a part of) Jeff Rowberg's I2Cdevlib library, +// which should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib +// Note WH: I2Cdevlib not used for mbed port +// +// Changelog: +// 2011-08-25 - initial release +// 2012-06-19 - Ported to mbed (WH) + +/* ============================================ +I2Cdev device library code is placed under the MIT license +Copyright (c) 2011 Andrew Schamp +Copyright (c) 2012 WH (mbed port) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +=============================================== +*/ + +#ifndef SSD1308_H +#define SSD1308_H + +// This is the I2C address (8 bit) +// which one is used is determined by the D/C# pin. +// with D/C# (pin 13) grounded, address is 0x78 +// with D/C# tied high it is 0x7A +// assume grounded by default. +#define SSD1308_SA0 0x78 +#define SSD1308_SA1 0x7A +#define SSD1308_DEF_SA SSD1308_SA0 + +#define ROWS 64 +#define COLUMNS 128 +#define PAGES 8 +#define PAGE_WIDTH (ROWS / 8) +#define FONT_WIDTH 8 +#define CHARS (COLUMNS / FONT_WIDTH) +#define MAX_PAGE (PAGES - 1) +#define MAX_COL (COLUMNS - 1) + +#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_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 + +#define SET_CONTRAST 0x81 // takes one byte, 0x00 - 0xFF + +#define SET_SEGMENT_REMAP_0 0xA0 // column address 0 is mapped to SEG0 +#define SET_SEGMENT_REMAP_127 0xA1 // column address 127 is mapped to SEG0 + +#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_MULTIPLEX_RATIO 0xA8 // takes one byte, from 16 to 63 (0x + +#define EXTERNAL_IREF 0x10 +#define INTERNAL_IREF 0x00 +#define SET_IREF_SELECTION 0xAD // sets internal or external Iref + +#define SET_DISPLAY_POWER_OFF 0xAE +#define SET_DISPLAY_POWER_ON 0xAF + +#define COMMAND_MODE 0x80 +#define DATA_MODE 0x40 + +#define PAGE0 0x00 +#define PAGE1 0x01 +#define PAGE2 0x02 +#define PAGE3 0x03 +#define PAGE4 0x04 +#define PAGE5 0x05 +#define PAGE6 0x06 +#define PAGE7 0x07 +#define SET_PAGE_START_ADDRESS 0xB0 // | with a page number to get start address + +#define SET_DISPLAY_OFFSET 0xD3 + +#define SET_DISPLAY_CLOCK 0xD5 + +#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 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 SET_DEACTIVATE_SCROLL 0x2E +#define SET_ACTIVATE_SCROLL 0x2F + +#define SET_VERTICAL_SCROLL_AREA 0xA3 + +class SSD1308 { + public: + + // constructor + // takes a 8bit I2C address to use (0x78 by default, assumes D/C# (pin 13) grounded) + SSD1308(I2C &i2c, uint8_t address = SSD1308_DEF_SA); + + void initialize(); + void clearDisplay(); + void fillDisplay(); // crosshatches + + // 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); + + //void setXY(uint8_t, uint8_t y); + + void setHorizontalAddressingMode(); + void setVerticalAddressingMode(); + void setPageAddressingMode(); + + void setMemoryAddressingMode(uint8_t mode); + + // takes one byte, 0x00-0x0F + void setLowerColumnStartAddressForPageAddressingMode(uint8_t address); + + // takes one byte, 0x10-0x1F + void setHigherColumnStartAddressForPageAddressingMode(uint8_t address); + + // takes two bytes, start address and end address of display data RAM + void setColumnAddress(uint8_t start, uint8_t end); + + // takes two bytes, start address and end address of display data RAM + void setPageAddress(uint8_t start, uint8_t end); + + // takes one byte, PAGE0 - PAGE7 + void setPageStartForPageAddressingMode(uint8_t page); + + // takes one byte, 0x40-0x7F + void setDisplayStartLine(uint8_t line); + + // takes one byte, 0x00 (lowest) - 0xFF (highest) + void setContrastControl(uint8_t contrast); + + void setEntireDisplayOn(); + void setEntireDisplayRAM(); + void setEntireDisplay(bool on); + void setNormalDisplay(); + void setInverseDisplay(); + + // setMultiplexRatio + + void setInternalIref(); + void setExternalIref(); + + void setDisplayOn(); + void setDisplayOff(); + void setDisplayPower(bool on); + + // 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) + 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) + 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 + 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 + 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) + 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 + 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); + // write the configuration registers in accordance with the datasheet and app note 3944 +// void initialize(); + + + private: + // sends a single-byte command (given) to device + void sendCommand(uint8_t command); + void sendCommands(uint8_t len, uint8_t* buf); + + void writeChar(char chr); + + I2C _i2c; // I2C bus +// uint8_t m_devAddr; // contains the I2C address of the device + uint8_t _readOpcode; + uint8_t _writeOpcode; + +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jun 19 20:00:10 2012 +0000 @@ -0,0 +1,205 @@ +/* mbed Seeed 128x64 OLED Test + * http://www.seeedstudio.com/depot/grove-oled-display-12864-p-781.html?cPath=163_167 + * + * Copyright (c) 2012 Wim Huiskamp + * Released under the MIT License: http://mbed.org/license/mit + * + * version 0.2 Initial Release + */ +#include "mbed.h" +#include "FixedWidthFont.h" +#include "SSD1308.h" + +//Pin Defines for I2C Bus +//#define D_SDA p9 +//#define D_SCL p10 +#define D_SDA p28 +#define D_SCL p27 +I2C i2c(D_SDA, D_SCL); + +//Host PC Baudrate (Virtual Com Port on USB) +#define D_BAUDRATE 9600 +//#define D_BAUDRATE 57600 + +// mbed Interface Hardware definitions +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut heartbeatLED(LED4); + +// Host PC Communication channels +Serial pc(USBTX, USBRX); // tx, rx + +// Instantiate OLED +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: \n\r"); + pc.printf("4: \n\r"); + pc.printf("5: \n\r"); + pc.printf("6: \n\r"); + pc.printf("7: \n\r"); + pc.printf("A: \n\r"); + pc.printf("B: \n\r"); + pc.printf("P: \n\r"); + pc.printf("\n\r"); +} + + +void oled_Test() { + pc.printf("OLED test start\r"); + + oled.setDisplayOff(); + pc.printf("display off\r\n"); + wait(0.5); + + oled.setDisplayOn(); + pc.printf("display on\r\n"); + wait(0.5); + + oled.clearDisplay(); + pc.printf("display cleared\r\n"); + wait(0.5); + + oled.fillDisplay(); + pc.printf("display filled\r\n"); + wait(0.5); + + oled.clearDisplay(); + pc.printf("display cleared\r\n"); + wait(0.5); + + oled.writeString(0, 0, 8, "Foobar!!"); + pc.printf("printed something\r\n"); + wait(3); + + oled.writeString(1, 8, 8, "baz quux"); + pc.printf("printed something\r\n"); + wait(3); + + oled.writeString(2, 0, 272, "a long, rather lengthy, extended string passage thing, eh, that just goes on, and on, and on, and on, and on, and on, and on, yes, further, continuing, extending, expanding beyond all reason or sanity!!!!! and yet, there's more! so much more! for ever and ever, oh yeah"); + pc.printf("printed something\r\n"); + wait(3); + + pc.printf("OLED test done\r\n"); +} + +// Variables for Heartbeat and Status monitoring +Ticker heartbeat; +bool heartbeatflag=false; + +// Local functions +void clear_screen() { +//ANSI Terminal Commands + pc.printf("\x1B[2J"); + pc.printf("\x1B[H"); +} + + +void init_interfaces() { + // Init Host PC communication, default is 9600 + pc.baud(D_BAUDRATE); + + // Init I/F hardware +// i2c.frequency(100000); + i2c.frequency(400000); // according to the spec the max bitrate for the SSD1308 is 400 kbit/s +} + + +// Heartbeat monitor +void pulse() { + heartbeatLED = !heartbeatLED; +} + +void heartbeat_start() { + heartbeat.attach(&pulse, 0.5); +} + +void heartbeat_stop() { + heartbeat.detach(); +} + + +int main() { + bool running=true; + char command; + + init_interfaces(); + + heartbeat_start(); + + clear_screen(); + + pc.printf("Hello World!\n\r"); + +// Quick test + oled_Test(); + + while(1) { + myled1 = 1; + wait(0.2); + + myled1 = 0; + wait(0.2); + pc.printf("*"); + } + + +// Interactive Test + show_menu(); + + while(running) { + + if(pc.readable()) { + command = pc.getc(); + pc.printf("command= %c \n\r", command); + + switch (command) { + case '0' : + pc.printf("Done\n\r"); + running = false; + break; + + case '1' : + show_menu(); + break; + + case '2' : + pc.printf("Hello World!\n\r"); + break; + + case '3' : + break; + + case '4' : + break; + + case '5' : + break; + case '6' : + break; + + case '7' : + break; + + case 'A' : + break; + + case 'B' : + + break; + + case 'P' : + + break; + + } //switch + }//if + }//while + + pc.printf("Bye World!\n\r"); +}//main +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.lib Tue Jun 19 20:00:10 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/projects/libraries/svn/mbed/trunk@43 \ No newline at end of file