SPKDisplay - A mbed display class and processing imaging tools for 128x64 OLEDs using the SSD1305 driver, connected via SPI.
Dependents: SPK-DVIMXR SPK-DMXer
spk_oled_ssd1305.h
00001 // OLED display using SSD1305 driver 00002 // A library by *spark audio-visual 00003 00004 /* Copyright (c) 2011 Toby Harris, MIT License 00005 * 00006 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00007 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00008 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00009 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00010 * furnished to do so, subject to the following conditions: 00011 * 00012 * The above copyright notice and this permission notice shall be included in all copies or 00013 * substantial portions of the Software. 00014 * 00015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00016 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00017 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00018 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00020 */ 00021 00022 #ifndef SPK_OLED_SSD1305_h 00023 #define SPK_OLED_SSD1305_h 00024 00025 #include "mbed.h" 00026 #include <string> 00027 00028 #define bufferCount 1056 00029 #define bufferWidth 132 00030 #define pixelWidth 128 00031 #define pixelHeight 64 00032 #define pixInPage 8 00033 #define pageCount 8 00034 00035 /** Display class for 128x64 OLEDs using the SSD1305 driver, connected via SPI 00036 * 00037 * Display ie. DENSITRON - DD-12864YO-3A 00038 * 00039 * This is a ground-up, minimal library. Further functionality as and when its needed or anybody wants to contribute. 00040 * 00041 * This library includes two processing sketches to create a font and full-screen image in the required byte representations. 00042 * Without creating your font and any images, all this library will do is blank the screen and draw horizontal lines. But at least you'll know its working! 00043 * 00044 * Terminology: 00045 * 'rows' are 8 pixel high rows across the display, 0 being the topmost and 7 the bottom. 00046 * 'lines' are single pixel lines, origin top left. 00047 * 00048 * Example: 00049 * @code 00050 * // Create object and load font 00051 * SPKDisplay screen(p5, p7, p8, p10, p9) 00052 * screen.fontStartCharacter = &myStartChar; 00053 * screen.fontEndCharacter = &myEndChar; 00054 * screen.fontCharacters = myFontArray; 00055 * // Draw 00056 * screen.imageToBuffer(myImageByteArray); 00057 * screen.textToBuffer("*spark OLED SSD1305",0); 00058 * screen.textToBuffer("v01",1); 00059 * screen.sendBuffer 00060 * @endcode 00061 */ 00062 class SPKDisplay 00063 { 00064 public: 00065 /** Create a display object connected via SPI 00066 * 00067 * @param mosi SPI MOSI 00068 * @param clk SPI SCK 00069 * @param cs Chip Select - a digital out pin 00070 * @param dc Data/Command - a digital out pin 00071 * @param res Reset - a digital out pin 00072 * @param debugSerial An optional serial object to log to 00073 */ 00074 SPKDisplay(PinName mosi, PinName clk, PinName cs, PinName dc, PinName res, Serial *debugSerial = NULL); 00075 00076 /** Font - Assign the ASCII value of the character at the start of the implemented range */ 00077 const int *fontStartCharacter; 00078 00079 /** Font - Assign the ASCII value of the character at the end of the implemented range */ 00080 const int *fontEndCharacter; 00081 00082 /** Font - Assign the font, an array of 8x8px characters 00083 * 00084 * @note The processing sketch spk_oled_fontByteMaker--processing takes characterCount*8px x 8px images and creates the code to declare the font array needed by this method 00085 */ 00086 uint8_t const **fontCharacters; 00087 00088 /** Completely clear the object's display representation */ 00089 void clearBuffer(); 00090 00091 /** Clear a row of the object's display representation 00092 * 00093 * @param row The row to clear. 00094 */ 00095 void clearBufferRow(int row); 00096 00097 /** Replace the object\s display representation with the contents of image 00098 * 00099 * @param image An array of 1056 bytes representing an image. 00100 * @note The processing sketch spk_oled_screenByteMaker--processing takes 132x64 images and creates the code to declare such arrays 00101 */ 00102 void imageToBuffer(const uint8_t* image); 00103 00104 /** Draw a horizontal line in the object's display representation 00105 * 00106 * @param y The y position of the line to draw 00107 */ 00108 void horizLineToBuffer(int y); 00109 00110 /** Write a line of text in the object's display representation 00111 * Requires the font to have been set 00112 * 00113 * @param message The text to write. The text will be truncated if longer than the screen's width. 00114 * @param row The row in which to write the text 00115 */ 00116 void textToBuffer(std::string message, int row); 00117 00118 /** Write a single character in the object's display representation 00119 * Requires the font to have been set 00120 * 00121 * @param character The character to write. 00122 * @param x The x position to draw the character 00123 * @param row The row in which to write the character 00124 */ 00125 void characterToBuffer(char character, int x, int row); 00126 00127 /** Send the object's display representation to the OLED 00128 * 00129 * You can safely call this once per main loop, it will only transmit the buffer contents if there has been an update 00130 */ 00131 void sendBuffer(); 00132 00133 private: 00134 SPI *spi; 00135 DigitalOut *cs; 00136 DigitalOut *dc; 00137 DigitalOut *res; 00138 00139 Serial *debug; 00140 uint8_t buffer[bufferCount]; 00141 00142 bool bufferHasChanged; 00143 00144 void setup(); 00145 }; 00146 00147 #endif
Generated on Fri Jul 15 2022 01:46:06 by 1.7.2