An mbed library for 4D Systems uOLED-160-G1
Embed:
(wiki syntax)
Show/hide line numbers
OLED160G1.h
00001 /** 00002 * mbed library for 4D Systems uOLED-160-G1 00003 * 00004 * 00005 * Copyright (c) 2010 Steven Blair 00006 * 00007 * Permission is hereby granted, free of charge, to any person obtaining a copy 00008 * of this software and associated documentation files (the "Software"), to deal 00009 * in the Software without restriction, including without limitation the rights 00010 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00011 * copies of the Software, and to permit persons to whom the Software is 00012 * furnished to do so, subject to the following conditions: 00013 * 00014 * The above copyright notice and this permission notice shall be included in 00015 * all copies or substantial portions of the Software. 00016 * 00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00018 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00019 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00020 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00021 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00022 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00023 * THE SOFTWARE. 00024 */ 00025 00026 #ifndef _OLED160G1_H_ 00027 #define _OLED160G1_H_ 00028 00029 00030 #define OLED_BAUDRATE 115200 // 300 baud to 256kbaud supported (256k not always stable?) 00031 #define OLED_INIT_DELAY 1100 // milliseconds 00032 00033 // Initialisation routine 00034 #define OLED_DETECT_BAUDRATE 0x55 00035 00036 // Drawing routines 00037 #define OLED_CLEAR 0x45 00038 #define OLED_BKGCOLOR 0x42 00039 #define OLED_COPYPASTE 0x63 00040 #define OLED_PEN_SIZE 0x70 00041 00042 // Graphics 00043 #define OLED_LINE 0x4C 00044 #define OLED_CIRCLE 0x43 00045 #define OLED_CIRCLEFILL 0x69 00046 #define OLED_PUTPIXEL 0x50 00047 #define OLED_READPIXEL 0x52 00048 #define OLED_RECTANGLE 0x72 00049 00050 // Text properties 00051 #define OLED_TEXT 0x73 00052 #define OLED_SETFONTSIZE 0x46 00053 #define OLED_FONT5X7 0x01 00054 #define OLED_FONT8X8 0x02 00055 #define OLED_FONT8X12 0x03 00056 #define OLED_TEXTFORMATED 0x54 00057 #define OLED_SET_TEXT_BACKGROUND_TYPE 0x4F 00058 #define OLED_SET_BACKGROUND_COLOR 0x42 00059 #define OLED_SET_TEXT_TRANSPARENT 0x00 00060 #define OLED_SET_TEXT_OPAQUE 0x01 00061 00062 // OLED Control 00063 #define OLED_COMMAND_CONTROL 0x59 00064 #define OLED_COMMAND_DISPLAY 0x01 00065 #define OLED_COMMAND_CONTRAST 0x02 00066 #define OLED_COMMAND_POWER 0x03 00067 00068 // Responses 00069 #define OLED_ACK 0x06 // Ok 00070 #define OLED_NAK 0x15 // Error 00071 00072 // Colours 00073 #define OLED_WHITE 0xFFFF 00074 #define OLED_BLACK 0x0000 00075 #define OLED_BLUE 0xA6BF 00076 #define OLED_RED 0xF800 00077 00078 #define red_min 0//150 00079 #define red_max 255 00080 #define blue_min 0//185 00081 #define blue_max 255 00082 #define green_min 0//195 00083 #define green_max 255 00084 00085 00086 class OLED160G1 : public Stream { 00087 public: 00088 00089 /** 00090 * Default constructor. 00091 */ 00092 OLED160G1(PinName serialTx, PinName serialRx, PinName resetPin); 00093 00094 /** 00095 * Reset the display using the reset pin (the reset pin is active-low). 00096 */ 00097 void resetDisplay(); 00098 00099 /** 00100 * Initialise OLED display. 00101 */ 00102 void init(); 00103 00104 /** 00105 * Processes responses (ACK or NAK) from the OLED. A new command cannot be sent to the OLED until a NAK is received, so 00106 * this function waits for the minimum time needed. 00107 */ 00108 void getResponse(); 00109 00110 /** 00111 * Clear the OLED screen. 00112 */ 00113 void eraseScreen(); 00114 00115 /** 00116 * Calculate 16-bit value from RGB (0 to 63, 565 format) 00117 */ 00118 int toRGB(int red, int green, int blue); 00119 00120 /** 00121 * 00122 */ 00123 void drawPixel(char x, char y, int color); 00124 00125 /** 00126 * 00127 */ 00128 void drawLine(char x1, char y1, char x2, char y2, int color); 00129 00130 /** 00131 * 00132 */ 00133 void drawRectangle(char x, char y, char width, char height, int color); 00134 00135 /** 00136 * 00137 */ 00138 void drawCircle(char x, char y, char radius, int color); 00139 00140 /** 00141 * Set font size, for use with printf() or OLED_DrawSingleChar(); all other functions override this setting. 00142 * 00143 * @param : fontSize can be: OLED_FONT5X7, OLED_FONT8X8, or OLED_FONT8X12 00144 */ 00145 void setFontSize(char fontSize); 00146 00147 /** 00148 * Set font color, for use with printf(); all other functions override this setting. 00149 */ 00150 void setFontColor(int fontColor); 00151 00152 /** 00153 * Set the "pen size". 00154 * 00155 * @param penSize : 0 to draw solid objects; 1 to draw wireframe objects. 00156 */ 00157 void setPenSize(char penSize); 00158 00159 /** 00160 * Set whether or not text is drawn with an opaque or transparent background. 00161 * 00162 * @param : textBackgroundType can be OLED_SET_TEXT_TRANSPARENT or OLED_SET_TEXT_OPAQUE 00163 */ 00164 void setTextBackgroundType(char textBackgroundType); 00165 00166 /** 00167 * 00168 */ 00169 void setBackgroundColor(int color); 00170 00171 /** 00172 * 00173 */ 00174 void drawText(char column, char row, char font_size, char *mytext, int color); 00175 00176 /** 00177 * Draw a single ASCII character at the specified location. 00178 */ 00179 void drawSingleChar(char column, char row, char theChar, int color); 00180 00181 /** 00182 * Display control functions, such as display ON/OFF, contrast and power-up/power-down. 00183 * 00184 * @param value : can be 0x00 to 0x0F is mode is OLED_COMMAND_CONTRAST. Default contrast value is 0x08. 00185 */ 00186 void displayControl(char mode, char value); 00187 00188 /** 00189 * 00190 */ 00191 char getPenSize(); 00192 00193 /** 00194 * Get number of text rows 00195 */ 00196 int rows(); //TODO: must depend on font size 00197 00198 /** 00199 * Get number of text columns 00200 */ 00201 int columns(); 00202 00203 /** 00204 * Set text cursor location 00205 */ 00206 virtual void locate(int column, int row); 00207 00208 /** 00209 * 00210 */ 00211 int lastCount; 00212 00213 /** 00214 * 00215 */ 00216 int NAKCount; 00217 00218 protected: 00219 virtual int _putc(int value); 00220 virtual int _getc(); 00221 00222 /** 00223 * Text cursor column number 00224 */ 00225 short _column; 00226 00227 /** 00228 * Text cursor row number 00229 */ 00230 short _row; 00231 00232 char _fontSize; 00233 char _penSize; 00234 int _fontColor; 00235 00236 private: 00237 Serial s; 00238 DigitalOut reset; 00239 }; 00240 00241 #endif
Generated on Fri Jul 15 2022 19:03:01 by 1.7.2