Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of spk_oled_ssd1305 by
4spi_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 00023 /* rewritten to work with the SSD1306 driver JCY-MCU oled (from ebay). chris stevens 2013 00024 00025 */ 00026 00027 00028 #ifndef SPK_OLED_SSD1305_h 00029 #define SPK_OLED_SSD1305_h 00030 00031 #include "mbed.h" 00032 #include <string> 00033 00034 #define bufferCount 1024 00035 #define bufferWidth 128 00036 #define pixelWidth 128 00037 #define pixelHeight 64 00038 #define pixInPage 8 00039 #define pageCount 8 00040 00041 00042 00043 /** Display class for 128x64 OLEDs using the SSD1305 driver, connected via SPI 00044 * 00045 * Display ie. DENSITRON - DD-12864YO-3A 00046 * 00047 * This is a ground-up, minimal library. Further functionality as and when its needed or anybody wants to contribute. 00048 * 00049 * This library includes two processing sketches to create a font and full-screen image in the required byte representations. 00050 * 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! 00051 * 00052 * Terminology: 00053 * 'rows' are 8 pixel high rows across the display, 0 being the topmost and 7 the bottom. 00054 * 'lines' are single pixel lines, origin top left. 00055 * 00056 */ 00057 class SPKDisplay 00058 { 00059 public: 00060 /** Create a display object connected via SPI 00061 * 00062 * @param mosi SPI MOSI 00063 * @param clk SPI SCK 00064 * @param cs Chip Select - a digital out pin 00065 * @param dc Data/Command - a digital out pin 00066 * @param res Reset - a digital out pin 00067 * @param debugSerial An optional serial object to log to 00068 */ 00069 SPKDisplay(PinName mosi, PinName clk, PinName cs, PinName dc, PinName res, Serial *debugSerial = NULL); 00070 00071 /** Font - Assign the ASCII value of the character at the start of the implemented range */ 00072 const int *fontStartCharacter; 00073 00074 /** Font - Assign the ASCII value of the character at the end of the implemented range */ 00075 const int *fontEndCharacter; 00076 00077 /** Font - Assign the font, an array of 8x8px characters 00078 * 00079 * @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 00080 */ 00081 uint8_t const **fontCharacters; 00082 00083 // set display for black on white 00084 void inverse(); 00085 00086 // display a welcopme message encoded in tab0 in spk_ole_ssd1305.h 00087 void welcome(); 00088 // output the entire font as a bitmap 00089 void fontdemo(); 00090 00091 //set display for white on black (normal state after reset) 00092 void normal(); 00093 00094 // power on / power off the display - this puts the display to sleep - but doesn turn off tha actuall power pin. 00095 void displayPower(int P); 00096 00097 /** Completely clear the object's display representation */ 00098 void clearBuffer(); 00099 00100 /** Clear a row of the object's display representation 00101 * 00102 * @param row The row to clear. 00103 */ 00104 void clearBufferRow(int row); 00105 00106 /** Replace the object\s display representation with the contents of image 00107 * 00108 * @param image An array of 1056 bytes representing an image. 00109 * @note The processing sketch spk_oled_screenByteMaker--processing takes 132x64 images and creates the code to declare such arrays 00110 */ 00111 void imageToBuffer(const uint8_t* image); 00112 00113 /** Draw a horizontal line in the object's display representation 00114 * 00115 * @param y The y position of the line to draw 00116 */ 00117 void horizLineToBuffer(int y); 00118 00119 00120 /** Send the object's display representation to the OLED 00121 * 00122 * You can safely call this once per main loop, it will only transmit the buffer contents if there has been an update 00123 */ 00124 void sendBuffer(); 00125 00126 // send text to the buffer to write inthe tiny 5x7 font 00127 void textToBuffer(char *message, int row); 00128 00129 private: 00130 SPI *spi; 00131 DigitalOut *cs; 00132 DigitalOut *dc; 00133 DigitalOut *res; 00134 00135 Serial *debug; 00136 uint8_t buffer[bufferCount]; 00137 00138 bool bufferHasChanged; 00139 00140 void setup(); 00141 }; 00142 00143 #endif
Generated on Sat Jul 23 2022 17:07:20 by
