An mbed library for 4D Systems uOLED-160-G1
Fork of OLED160G1 by
OLED160G1.h@1:c22a582f62c0, 2012-10-31 (annotated)
- Committer:
- Renato
- Date:
- Wed Oct 31 12:20:52 2012 +0000
- Revision:
- 1:c22a582f62c0
- Parent:
- 0:296a7ee30b3a
Arterada para o 96-g1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sblair | 0:296a7ee30b3a | 1 | /** |
sblair | 0:296a7ee30b3a | 2 | * mbed library for 4D Systems uOLED-160-G1 |
sblair | 0:296a7ee30b3a | 3 | * |
sblair | 0:296a7ee30b3a | 4 | * |
sblair | 0:296a7ee30b3a | 5 | * Copyright (c) 2010 Steven Blair |
sblair | 0:296a7ee30b3a | 6 | * |
sblair | 0:296a7ee30b3a | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
sblair | 0:296a7ee30b3a | 8 | * of this software and associated documentation files (the "Software"), to deal |
sblair | 0:296a7ee30b3a | 9 | * in the Software without restriction, including without limitation the rights |
sblair | 0:296a7ee30b3a | 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
sblair | 0:296a7ee30b3a | 11 | * copies of the Software, and to permit persons to whom the Software is |
sblair | 0:296a7ee30b3a | 12 | * furnished to do so, subject to the following conditions: |
sblair | 0:296a7ee30b3a | 13 | * |
sblair | 0:296a7ee30b3a | 14 | * The above copyright notice and this permission notice shall be included in |
sblair | 0:296a7ee30b3a | 15 | * all copies or substantial portions of the Software. |
sblair | 0:296a7ee30b3a | 16 | * |
sblair | 0:296a7ee30b3a | 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
sblair | 0:296a7ee30b3a | 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
sblair | 0:296a7ee30b3a | 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
sblair | 0:296a7ee30b3a | 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
sblair | 0:296a7ee30b3a | 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
sblair | 0:296a7ee30b3a | 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
sblair | 0:296a7ee30b3a | 23 | * THE SOFTWARE. |
sblair | 0:296a7ee30b3a | 24 | */ |
sblair | 0:296a7ee30b3a | 25 | |
sblair | 0:296a7ee30b3a | 26 | #ifndef _OLED160G1_H_ |
sblair | 0:296a7ee30b3a | 27 | #define _OLED160G1_H_ |
sblair | 0:296a7ee30b3a | 28 | |
sblair | 0:296a7ee30b3a | 29 | |
Renato | 1:c22a582f62c0 | 30 | #define OLED_BAUDRATE 230400 // 300 baud to 256kbaud supported (256k not always stable?) |
Renato | 1:c22a582f62c0 | 31 | #define OLED_INIT_DELAY 1200 // milliseconds |
sblair | 0:296a7ee30b3a | 32 | |
sblair | 0:296a7ee30b3a | 33 | // Initialisation routine |
sblair | 0:296a7ee30b3a | 34 | #define OLED_DETECT_BAUDRATE 0x55 |
sblair | 0:296a7ee30b3a | 35 | |
sblair | 0:296a7ee30b3a | 36 | // Drawing routines |
sblair | 0:296a7ee30b3a | 37 | #define OLED_CLEAR 0x45 |
sblair | 0:296a7ee30b3a | 38 | #define OLED_BKGCOLOR 0x42 |
sblair | 0:296a7ee30b3a | 39 | #define OLED_COPYPASTE 0x63 |
sblair | 0:296a7ee30b3a | 40 | #define OLED_PEN_SIZE 0x70 |
sblair | 0:296a7ee30b3a | 41 | |
sblair | 0:296a7ee30b3a | 42 | // Graphics |
sblair | 0:296a7ee30b3a | 43 | #define OLED_LINE 0x4C |
sblair | 0:296a7ee30b3a | 44 | #define OLED_CIRCLE 0x43 |
sblair | 0:296a7ee30b3a | 45 | #define OLED_CIRCLEFILL 0x69 |
sblair | 0:296a7ee30b3a | 46 | #define OLED_PUTPIXEL 0x50 |
sblair | 0:296a7ee30b3a | 47 | #define OLED_READPIXEL 0x52 |
sblair | 0:296a7ee30b3a | 48 | #define OLED_RECTANGLE 0x72 |
sblair | 0:296a7ee30b3a | 49 | |
sblair | 0:296a7ee30b3a | 50 | // Text properties |
sblair | 0:296a7ee30b3a | 51 | #define OLED_TEXT 0x73 |
sblair | 0:296a7ee30b3a | 52 | #define OLED_SETFONTSIZE 0x46 |
sblair | 0:296a7ee30b3a | 53 | #define OLED_FONT5X7 0x01 |
sblair | 0:296a7ee30b3a | 54 | #define OLED_FONT8X8 0x02 |
sblair | 0:296a7ee30b3a | 55 | #define OLED_FONT8X12 0x03 |
sblair | 0:296a7ee30b3a | 56 | #define OLED_TEXTFORMATED 0x54 |
sblair | 0:296a7ee30b3a | 57 | #define OLED_SET_TEXT_BACKGROUND_TYPE 0x4F |
sblair | 0:296a7ee30b3a | 58 | #define OLED_SET_BACKGROUND_COLOR 0x42 |
sblair | 0:296a7ee30b3a | 59 | #define OLED_SET_TEXT_TRANSPARENT 0x00 |
sblair | 0:296a7ee30b3a | 60 | #define OLED_SET_TEXT_OPAQUE 0x01 |
sblair | 0:296a7ee30b3a | 61 | |
sblair | 0:296a7ee30b3a | 62 | // OLED Control |
sblair | 0:296a7ee30b3a | 63 | #define OLED_COMMAND_CONTROL 0x59 |
sblair | 0:296a7ee30b3a | 64 | #define OLED_COMMAND_DISPLAY 0x01 |
sblair | 0:296a7ee30b3a | 65 | #define OLED_COMMAND_CONTRAST 0x02 |
sblair | 0:296a7ee30b3a | 66 | #define OLED_COMMAND_POWER 0x03 |
sblair | 0:296a7ee30b3a | 67 | |
sblair | 0:296a7ee30b3a | 68 | // Responses |
sblair | 0:296a7ee30b3a | 69 | #define OLED_ACK 0x06 // Ok |
sblair | 0:296a7ee30b3a | 70 | #define OLED_NAK 0x15 // Error |
sblair | 0:296a7ee30b3a | 71 | |
sblair | 0:296a7ee30b3a | 72 | // Colours |
sblair | 0:296a7ee30b3a | 73 | #define OLED_WHITE 0xFFFF |
sblair | 0:296a7ee30b3a | 74 | #define OLED_BLACK 0x0000 |
sblair | 0:296a7ee30b3a | 75 | #define OLED_BLUE 0xA6BF |
sblair | 0:296a7ee30b3a | 76 | #define OLED_RED 0xF800 |
sblair | 0:296a7ee30b3a | 77 | |
sblair | 0:296a7ee30b3a | 78 | #define red_min 0//150 |
sblair | 0:296a7ee30b3a | 79 | #define red_max 255 |
sblair | 0:296a7ee30b3a | 80 | #define blue_min 0//185 |
sblair | 0:296a7ee30b3a | 81 | #define blue_max 255 |
sblair | 0:296a7ee30b3a | 82 | #define green_min 0//195 |
sblair | 0:296a7ee30b3a | 83 | #define green_max 255 |
sblair | 0:296a7ee30b3a | 84 | |
sblair | 0:296a7ee30b3a | 85 | |
sblair | 0:296a7ee30b3a | 86 | class OLED160G1 : public Stream { |
sblair | 0:296a7ee30b3a | 87 | public: |
sblair | 0:296a7ee30b3a | 88 | |
sblair | 0:296a7ee30b3a | 89 | /** |
sblair | 0:296a7ee30b3a | 90 | * Default constructor. |
sblair | 0:296a7ee30b3a | 91 | */ |
sblair | 0:296a7ee30b3a | 92 | OLED160G1(PinName serialTx, PinName serialRx, PinName resetPin); |
sblair | 0:296a7ee30b3a | 93 | |
sblair | 0:296a7ee30b3a | 94 | /** |
sblair | 0:296a7ee30b3a | 95 | * Reset the display using the reset pin (the reset pin is active-low). |
sblair | 0:296a7ee30b3a | 96 | */ |
sblair | 0:296a7ee30b3a | 97 | void resetDisplay(); |
sblair | 0:296a7ee30b3a | 98 | |
sblair | 0:296a7ee30b3a | 99 | /** |
sblair | 0:296a7ee30b3a | 100 | * Initialise OLED display. |
sblair | 0:296a7ee30b3a | 101 | */ |
sblair | 0:296a7ee30b3a | 102 | void init(); |
sblair | 0:296a7ee30b3a | 103 | |
sblair | 0:296a7ee30b3a | 104 | /** |
sblair | 0:296a7ee30b3a | 105 | * Processes responses (ACK or NAK) from the OLED. A new command cannot be sent to the OLED until a NAK is received, so |
sblair | 0:296a7ee30b3a | 106 | * this function waits for the minimum time needed. |
sblair | 0:296a7ee30b3a | 107 | */ |
sblair | 0:296a7ee30b3a | 108 | void getResponse(); |
sblair | 0:296a7ee30b3a | 109 | |
sblair | 0:296a7ee30b3a | 110 | /** |
sblair | 0:296a7ee30b3a | 111 | * Clear the OLED screen. |
sblair | 0:296a7ee30b3a | 112 | */ |
sblair | 0:296a7ee30b3a | 113 | void eraseScreen(); |
sblair | 0:296a7ee30b3a | 114 | |
sblair | 0:296a7ee30b3a | 115 | /** |
sblair | 0:296a7ee30b3a | 116 | * Calculate 16-bit value from RGB (0 to 63, 565 format) |
sblair | 0:296a7ee30b3a | 117 | */ |
sblair | 0:296a7ee30b3a | 118 | int toRGB(int red, int green, int blue); |
sblair | 0:296a7ee30b3a | 119 | |
sblair | 0:296a7ee30b3a | 120 | /** |
sblair | 0:296a7ee30b3a | 121 | * |
sblair | 0:296a7ee30b3a | 122 | */ |
sblair | 0:296a7ee30b3a | 123 | void drawPixel(char x, char y, int color); |
sblair | 0:296a7ee30b3a | 124 | |
sblair | 0:296a7ee30b3a | 125 | /** |
sblair | 0:296a7ee30b3a | 126 | * |
sblair | 0:296a7ee30b3a | 127 | */ |
sblair | 0:296a7ee30b3a | 128 | void drawLine(char x1, char y1, char x2, char y2, int color); |
sblair | 0:296a7ee30b3a | 129 | |
sblair | 0:296a7ee30b3a | 130 | /** |
sblair | 0:296a7ee30b3a | 131 | * |
sblair | 0:296a7ee30b3a | 132 | */ |
sblair | 0:296a7ee30b3a | 133 | void drawRectangle(char x, char y, char width, char height, int color); |
sblair | 0:296a7ee30b3a | 134 | |
sblair | 0:296a7ee30b3a | 135 | /** |
sblair | 0:296a7ee30b3a | 136 | * |
sblair | 0:296a7ee30b3a | 137 | */ |
sblair | 0:296a7ee30b3a | 138 | void drawCircle(char x, char y, char radius, int color); |
sblair | 0:296a7ee30b3a | 139 | |
sblair | 0:296a7ee30b3a | 140 | /** |
sblair | 0:296a7ee30b3a | 141 | * Set font size, for use with printf() or OLED_DrawSingleChar(); all other functions override this setting. |
sblair | 0:296a7ee30b3a | 142 | * |
sblair | 0:296a7ee30b3a | 143 | * @param : fontSize can be: OLED_FONT5X7, OLED_FONT8X8, or OLED_FONT8X12 |
sblair | 0:296a7ee30b3a | 144 | */ |
sblair | 0:296a7ee30b3a | 145 | void setFontSize(char fontSize); |
sblair | 0:296a7ee30b3a | 146 | |
sblair | 0:296a7ee30b3a | 147 | /** |
sblair | 0:296a7ee30b3a | 148 | * Set font color, for use with printf(); all other functions override this setting. |
sblair | 0:296a7ee30b3a | 149 | */ |
sblair | 0:296a7ee30b3a | 150 | void setFontColor(int fontColor); |
sblair | 0:296a7ee30b3a | 151 | |
sblair | 0:296a7ee30b3a | 152 | /** |
sblair | 0:296a7ee30b3a | 153 | * Set the "pen size". |
sblair | 0:296a7ee30b3a | 154 | * |
sblair | 0:296a7ee30b3a | 155 | * @param penSize : 0 to draw solid objects; 1 to draw wireframe objects. |
sblair | 0:296a7ee30b3a | 156 | */ |
sblair | 0:296a7ee30b3a | 157 | void setPenSize(char penSize); |
sblair | 0:296a7ee30b3a | 158 | |
sblair | 0:296a7ee30b3a | 159 | /** |
sblair | 0:296a7ee30b3a | 160 | * Set whether or not text is drawn with an opaque or transparent background. |
sblair | 0:296a7ee30b3a | 161 | * |
sblair | 0:296a7ee30b3a | 162 | * @param : textBackgroundType can be OLED_SET_TEXT_TRANSPARENT or OLED_SET_TEXT_OPAQUE |
sblair | 0:296a7ee30b3a | 163 | */ |
sblair | 0:296a7ee30b3a | 164 | void setTextBackgroundType(char textBackgroundType); |
sblair | 0:296a7ee30b3a | 165 | |
sblair | 0:296a7ee30b3a | 166 | /** |
sblair | 0:296a7ee30b3a | 167 | * |
sblair | 0:296a7ee30b3a | 168 | */ |
sblair | 0:296a7ee30b3a | 169 | void setBackgroundColor(int color); |
sblair | 0:296a7ee30b3a | 170 | |
sblair | 0:296a7ee30b3a | 171 | /** |
sblair | 0:296a7ee30b3a | 172 | * |
sblair | 0:296a7ee30b3a | 173 | */ |
sblair | 0:296a7ee30b3a | 174 | void drawText(char column, char row, char font_size, char *mytext, int color); |
sblair | 0:296a7ee30b3a | 175 | |
sblair | 0:296a7ee30b3a | 176 | /** |
sblair | 0:296a7ee30b3a | 177 | * Draw a single ASCII character at the specified location. |
sblair | 0:296a7ee30b3a | 178 | */ |
sblair | 0:296a7ee30b3a | 179 | void drawSingleChar(char column, char row, char theChar, int color); |
sblair | 0:296a7ee30b3a | 180 | |
sblair | 0:296a7ee30b3a | 181 | /** |
sblair | 0:296a7ee30b3a | 182 | * Display control functions, such as display ON/OFF, contrast and power-up/power-down. |
sblair | 0:296a7ee30b3a | 183 | * |
sblair | 0:296a7ee30b3a | 184 | * @param value : can be 0x00 to 0x0F is mode is OLED_COMMAND_CONTRAST. Default contrast value is 0x08. |
sblair | 0:296a7ee30b3a | 185 | */ |
sblair | 0:296a7ee30b3a | 186 | void displayControl(char mode, char value); |
sblair | 0:296a7ee30b3a | 187 | |
sblair | 0:296a7ee30b3a | 188 | /** |
sblair | 0:296a7ee30b3a | 189 | * |
sblair | 0:296a7ee30b3a | 190 | */ |
sblair | 0:296a7ee30b3a | 191 | char getPenSize(); |
sblair | 0:296a7ee30b3a | 192 | |
sblair | 0:296a7ee30b3a | 193 | /** |
sblair | 0:296a7ee30b3a | 194 | * Get number of text rows |
sblair | 0:296a7ee30b3a | 195 | */ |
sblair | 0:296a7ee30b3a | 196 | int rows(); //TODO: must depend on font size |
sblair | 0:296a7ee30b3a | 197 | |
sblair | 0:296a7ee30b3a | 198 | /** |
sblair | 0:296a7ee30b3a | 199 | * Get number of text columns |
sblair | 0:296a7ee30b3a | 200 | */ |
sblair | 0:296a7ee30b3a | 201 | int columns(); |
sblair | 0:296a7ee30b3a | 202 | |
sblair | 0:296a7ee30b3a | 203 | /** |
sblair | 0:296a7ee30b3a | 204 | * Set text cursor location |
sblair | 0:296a7ee30b3a | 205 | */ |
sblair | 0:296a7ee30b3a | 206 | virtual void locate(int column, int row); |
sblair | 0:296a7ee30b3a | 207 | |
sblair | 0:296a7ee30b3a | 208 | /** |
sblair | 0:296a7ee30b3a | 209 | * |
sblair | 0:296a7ee30b3a | 210 | */ |
sblair | 0:296a7ee30b3a | 211 | int lastCount; |
sblair | 0:296a7ee30b3a | 212 | |
sblair | 0:296a7ee30b3a | 213 | /** |
sblair | 0:296a7ee30b3a | 214 | * |
sblair | 0:296a7ee30b3a | 215 | */ |
sblair | 0:296a7ee30b3a | 216 | int NAKCount; |
sblair | 0:296a7ee30b3a | 217 | |
sblair | 0:296a7ee30b3a | 218 | protected: |
sblair | 0:296a7ee30b3a | 219 | virtual int _putc(int value); |
sblair | 0:296a7ee30b3a | 220 | virtual int _getc(); |
sblair | 0:296a7ee30b3a | 221 | |
sblair | 0:296a7ee30b3a | 222 | /** |
sblair | 0:296a7ee30b3a | 223 | * Text cursor column number |
sblair | 0:296a7ee30b3a | 224 | */ |
sblair | 0:296a7ee30b3a | 225 | short _column; |
sblair | 0:296a7ee30b3a | 226 | |
sblair | 0:296a7ee30b3a | 227 | /** |
sblair | 0:296a7ee30b3a | 228 | * Text cursor row number |
sblair | 0:296a7ee30b3a | 229 | */ |
sblair | 0:296a7ee30b3a | 230 | short _row; |
sblair | 0:296a7ee30b3a | 231 | |
sblair | 0:296a7ee30b3a | 232 | char _fontSize; |
sblair | 0:296a7ee30b3a | 233 | char _penSize; |
sblair | 0:296a7ee30b3a | 234 | int _fontColor; |
sblair | 0:296a7ee30b3a | 235 | |
sblair | 0:296a7ee30b3a | 236 | private: |
sblair | 0:296a7ee30b3a | 237 | Serial s; |
sblair | 0:296a7ee30b3a | 238 | DigitalOut reset; |
sblair | 0:296a7ee30b3a | 239 | }; |
sblair | 0:296a7ee30b3a | 240 | |
sblair | 0:296a7ee30b3a | 241 | #endif |