Hexiwear OLED
Fork of Hexi_OLED_SSD1351 by
Hexi_OLED_SSD1351.h@6:0060ffa3f4dc, 2016-08-26 (annotated)
- Committer:
- khuang
- Date:
- Fri Aug 26 19:56:07 2016 +0000
- Revision:
- 6:0060ffa3f4dc
- Parent:
- 5:a5b4b36a1aed
- Child:
- 7:9961c525e249
Added OpenSans Font. Added proper licensing text. Changed a xCrd,yCrd, width, height variables to correct types. Moved SetTextProperties Init inside constructor.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
khuang | 5:a5b4b36a1aed | 1 | /** OLED Display Driver for Hexiwear |
khuang | 3:4121d3cd9f60 | 2 | * This file contains OLED driver functionality for drawing images and text |
khuang | 2:fc06b5b5bf6a | 3 | * |
khuang | 2:fc06b5b5bf6a | 4 | * Redistribution and use in source and binary forms, with or without modification, |
khuang | 2:fc06b5b5bf6a | 5 | * are permitted provided that the following conditions are met: |
khuang | 2:fc06b5b5bf6a | 6 | * |
khuang | 2:fc06b5b5bf6a | 7 | * Redistributions of source code must retain the above copyright notice, this list |
khuang | 5:a5b4b36a1aed | 8 | * of conditions and the following disclaimer. |
khuang | 2:fc06b5b5bf6a | 9 | * |
khuang | 2:fc06b5b5bf6a | 10 | * Redistributions in binary form must reproduce the above copyright notice, this |
khuang | 5:a5b4b36a1aed | 11 | * list of conditions and the following disclaimer in the documentation and/or |
khuang | 5:a5b4b36a1aed | 12 | * other materials provided with the distribution. |
khuang | 2:fc06b5b5bf6a | 13 | * |
khuang | 2:fc06b5b5bf6a | 14 | * Neither the name of NXP, nor the names of its |
khuang | 5:a5b4b36a1aed | 15 | * contributors may be used to endorse or promote products derived from this |
khuang | 5:a5b4b36a1aed | 16 | * software without specific prior written permission. |
khuang | 2:fc06b5b5bf6a | 17 | * |
khuang | 2:fc06b5b5bf6a | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
khuang | 2:fc06b5b5bf6a | 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
khuang | 2:fc06b5b5bf6a | 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
khuang | 2:fc06b5b5bf6a | 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
khuang | 2:fc06b5b5bf6a | 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
khuang | 2:fc06b5b5bf6a | 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
khuang | 2:fc06b5b5bf6a | 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
khuang | 2:fc06b5b5bf6a | 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
khuang | 2:fc06b5b5bf6a | 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
khuang | 2:fc06b5b5bf6a | 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
khuang | 2:fc06b5b5bf6a | 28 | * |
khuang | 2:fc06b5b5bf6a | 29 | * visit: http://www.mikroe.com and http://www.nxp.com |
khuang | 2:fc06b5b5bf6a | 30 | * |
khuang | 2:fc06b5b5bf6a | 31 | * get support at: http://www.mikroe.com/forum and https://community.nxp.com |
khuang | 2:fc06b5b5bf6a | 32 | * |
khuang | 2:fc06b5b5bf6a | 33 | * Project HEXIWEAR, 2015 |
khuang | 2:fc06b5b5bf6a | 34 | */ |
khuang | 2:fc06b5b5bf6a | 35 | |
khuang | 3:4121d3cd9f60 | 36 | #ifndef HG_HEXI_OLED_SSD1351 |
khuang | 3:4121d3cd9f60 | 37 | #define HG_HEXI_OLED_SSD1351 |
khuang | 1:3b5be0ee5f0c | 38 | |
khuang | 1:3b5be0ee5f0c | 39 | #include "mbed.h" |
khuang | 1:3b5be0ee5f0c | 40 | #include "OLED_types.h" |
khuang | 1:3b5be0ee5f0c | 41 | #include "OLED_info.h" |
khuang | 1:3b5be0ee5f0c | 42 | |
khuang | 1:3b5be0ee5f0c | 43 | |
khuang | 3:4121d3cd9f60 | 44 | /** OLED Display Driver for Hexiwear |
khuang | 3:4121d3cd9f60 | 45 | */ |
khuang | 1:3b5be0ee5f0c | 46 | class SSD1351{ |
khuang | 1:3b5be0ee5f0c | 47 | |
khuang | 1:3b5be0ee5f0c | 48 | public: |
khuang | 1:3b5be0ee5f0c | 49 | |
khuang | 3:4121d3cd9f60 | 50 | /** |
khuang | 3:4121d3cd9f60 | 51 | * Create a Hexiwear OLED Driver connected to the specified pins |
khuang | 3:4121d3cd9f60 | 52 | * |
khuang | 3:4121d3cd9f60 | 53 | * @param mosiPin SPI Master Out, Slave In Pin |
khuang | 3:4121d3cd9f60 | 54 | * @param sclkPin SPI CLock Pin |
khuang | 3:4121d3cd9f60 | 55 | * @param pwrPin OLED Power Pin |
khuang | 3:4121d3cd9f60 | 56 | * @param csPin OLED Chip Select Pin |
khuang | 3:4121d3cd9f60 | 57 | * @param rstPin OLED Reset Pin |
khuang | 3:4121d3cd9f60 | 58 | * @param dcPin OLED DC Pin |
khuang | 3:4121d3cd9f60 | 59 | */ |
khuang | 3:4121d3cd9f60 | 60 | SSD1351(PinName mosiPin,PinName sclkPin,PinName pwrPin, PinName csPin,PinName rstPin, PinName dcPin); |
khuang | 1:3b5be0ee5f0c | 61 | |
khuang | 3:4121d3cd9f60 | 62 | /** |
khuang | 3:4121d3cd9f60 | 63 | * Destroy the Hexiwear instance |
khuang | 3:4121d3cd9f60 | 64 | */ |
khuang | 1:3b5be0ee5f0c | 65 | ~SSD1351(); |
khuang | 1:3b5be0ee5f0c | 66 | |
khuang | 1:3b5be0ee5f0c | 67 | /** |
khuang | 1:3b5be0ee5f0c | 68 | * Send the command to OLED |
khuang | 1:3b5be0ee5f0c | 69 | * @param cmd OLED command from the datasheet |
khuang | 1:3b5be0ee5f0c | 70 | * @param isFirst designate if this is the first byte in the command |
khuang | 1:3b5be0ee5f0c | 71 | */ |
khuang | 1:3b5be0ee5f0c | 72 | void SendCmd(uint32_t cmd, |
khuang | 1:3b5be0ee5f0c | 73 | uint8_t isFirst); |
khuang | 1:3b5be0ee5f0c | 74 | |
khuang | 1:3b5be0ee5f0c | 75 | |
khuang | 1:3b5be0ee5f0c | 76 | /** |
khuang | 1:3b5be0ee5f0c | 77 | * Send data to OLED |
khuang | 1:3b5be0ee5f0c | 78 | * @param dataToSend data to send to OLED |
khuang | 1:3b5be0ee5f0c | 79 | * @param dataSize data-size |
khuang | 1:3b5be0ee5f0c | 80 | */ |
khuang | 1:3b5be0ee5f0c | 81 | void SendData ( const uint8_t* dataToSend, |
khuang | 1:3b5be0ee5f0c | 82 | uint32_t dataSize); |
khuang | 1:3b5be0ee5f0c | 83 | |
khuang | 1:3b5be0ee5f0c | 84 | /** |
khuang | 1:3b5be0ee5f0c | 85 | * draw box on OLED |
khuang | 1:3b5be0ee5f0c | 86 | * @param xCrd x-coordinate for box's uper left corner |
khuang | 1:3b5be0ee5f0c | 87 | * @param yCrd y-coordinate for box's uper left corner |
khuang | 1:3b5be0ee5f0c | 88 | * @param width box's width |
khuang | 1:3b5be0ee5f0c | 89 | * @param height box's height |
khuang | 1:3b5be0ee5f0c | 90 | * @param color color of the box |
khuang | 1:3b5be0ee5f0c | 91 | * @return status flag |
khuang | 1:3b5be0ee5f0c | 92 | */ |
khuang | 1:3b5be0ee5f0c | 93 | oled_status_t DrawBox ( |
khuang | 6:0060ffa3f4dc | 94 | int8_t xCrd, |
khuang | 6:0060ffa3f4dc | 95 | int8_t yCrd, |
khuang | 6:0060ffa3f4dc | 96 | uint8_t width, |
khuang | 6:0060ffa3f4dc | 97 | uint8_t height, |
khuang | 1:3b5be0ee5f0c | 98 | uint16_t color |
khuang | 1:3b5be0ee5f0c | 99 | ); |
khuang | 1:3b5be0ee5f0c | 100 | |
khuang | 1:3b5be0ee5f0c | 101 | /** |
khuang | 1:3b5be0ee5f0c | 102 | * Fill the entire screen with specified color |
khuang | 1:3b5be0ee5f0c | 103 | * @param color color to fill with |
khuang | 1:3b5be0ee5f0c | 104 | */ |
khuang | 1:3b5be0ee5f0c | 105 | void FillScreen( uint16_t color ); |
khuang | 1:3b5be0ee5f0c | 106 | |
khuang | 1:3b5be0ee5f0c | 107 | |
khuang | 1:3b5be0ee5f0c | 108 | |
khuang | 1:3b5be0ee5f0c | 109 | /** |
khuang | 1:3b5be0ee5f0c | 110 | * Draw a single pixel |
khuang | 1:3b5be0ee5f0c | 111 | * @param xCrd pixel's x coordinate |
khuang | 1:3b5be0ee5f0c | 112 | * @param yCrd pixel's y coordinate |
khuang | 1:3b5be0ee5f0c | 113 | * @param color pixel's color |
khuang | 1:3b5be0ee5f0c | 114 | * @return status flag |
khuang | 1:3b5be0ee5f0c | 115 | */ |
khuang | 1:3b5be0ee5f0c | 116 | oled_status_t DrawPixel ( |
khuang | 6:0060ffa3f4dc | 117 | int8_t xCrd, |
khuang | 6:0060ffa3f4dc | 118 | int8_t yCrd, |
khuang | 1:3b5be0ee5f0c | 119 | uint16_t color |
khuang | 1:3b5be0ee5f0c | 120 | ); |
khuang | 1:3b5be0ee5f0c | 121 | |
khuang | 1:3b5be0ee5f0c | 122 | |
khuang | 1:3b5be0ee5f0c | 123 | /** |
khuang | 1:3b5be0ee5f0c | 124 | * Draw the whole screen |
khuang | 1:3b5be0ee5f0c | 125 | * @param image image to draw |
khuang | 1:3b5be0ee5f0c | 126 | * @param xCrd image x-coordinate |
khuang | 1:3b5be0ee5f0c | 127 | * @param yCrd image y-coordinate |
khuang | 1:3b5be0ee5f0c | 128 | * @param width image width |
khuang | 1:3b5be0ee5f0c | 129 | * @param height image height |
khuang | 1:3b5be0ee5f0c | 130 | * @param transition transition style for the new image arrival |
khuang | 1:3b5be0ee5f0c | 131 | * @return status flag |
khuang | 1:3b5be0ee5f0c | 132 | */ |
khuang | 1:3b5be0ee5f0c | 133 | oled_status_t DrawScreen ( |
khuang | 1:3b5be0ee5f0c | 134 | const uint8_t* image, |
khuang | 6:0060ffa3f4dc | 135 | int8_t xCrd, |
khuang | 6:0060ffa3f4dc | 136 | int8_t yCrd, |
khuang | 1:3b5be0ee5f0c | 137 | uint8_t width, |
khuang | 1:3b5be0ee5f0c | 138 | uint8_t height, |
khuang | 1:3b5be0ee5f0c | 139 | oled_transition_t transition |
khuang | 1:3b5be0ee5f0c | 140 | ); |
khuang | 1:3b5be0ee5f0c | 141 | |
khuang | 1:3b5be0ee5f0c | 142 | |
khuang | 1:3b5be0ee5f0c | 143 | /** |
khuang | 1:3b5be0ee5f0c | 144 | * Set the font to use |
khuang | 1:3b5be0ee5f0c | 145 | * @param newFont desired font |
khuang | 1:3b5be0ee5f0c | 146 | * @param newColor desired color |
khuang | 1:3b5be0ee5f0c | 147 | * @return status flag |
khuang | 1:3b5be0ee5f0c | 148 | */ |
khuang | 1:3b5be0ee5f0c | 149 | oled_status_t SetFont( |
khuang | 1:3b5be0ee5f0c | 150 | const uint8_t* newFont, |
khuang | 1:3b5be0ee5f0c | 151 | uint16_t newColor |
khuang | 1:3b5be0ee5f0c | 152 | ); |
khuang | 1:3b5be0ee5f0c | 153 | |
khuang | 1:3b5be0ee5f0c | 154 | |
khuang | 1:3b5be0ee5f0c | 155 | /** |
khuang | 1:3b5be0ee5f0c | 156 | * Set OLED dynamic area |
khuang | 1:3b5be0ee5f0c | 157 | * @param dynamic_area data-structure with desired values |
khuang | 1:3b5be0ee5f0c | 158 | */ |
khuang | 1:3b5be0ee5f0c | 159 | void SetDynamicArea(oled_dynamic_area_t *dynamic_area); |
khuang | 1:3b5be0ee5f0c | 160 | |
khuang | 1:3b5be0ee5f0c | 161 | /** |
khuang | 1:3b5be0ee5f0c | 162 | * Destroy current OLED dynamic area |
khuang | 1:3b5be0ee5f0c | 163 | */ |
khuang | 1:3b5be0ee5f0c | 164 | void DestroyDynamicArea(); |
khuang | 1:3b5be0ee5f0c | 165 | |
khuang | 1:3b5be0ee5f0c | 166 | |
khuang | 1:3b5be0ee5f0c | 167 | /** |
khuang | 1:3b5be0ee5f0c | 168 | * Set OLED text properties |
khuang | 1:3b5be0ee5f0c | 169 | * @param textProperties data-structure with desired properties |
khuang | 1:3b5be0ee5f0c | 170 | */ |
khuang | 1:3b5be0ee5f0c | 171 | void SetTextProperties(oled_text_properties_t *textProperties); |
khuang | 1:3b5be0ee5f0c | 172 | |
khuang | 1:3b5be0ee5f0c | 173 | |
khuang | 1:3b5be0ee5f0c | 174 | /** |
khuang | 1:3b5be0ee5f0c | 175 | * Return the width in [px] required for the given string to be displayed |
khuang | 1:3b5be0ee5f0c | 176 | * @param text desired string |
khuang | 1:3b5be0ee5f0c | 177 | * @return required text width in [px] |
khuang | 1:3b5be0ee5f0c | 178 | */ |
khuang | 1:3b5be0ee5f0c | 179 | uint8_t GetTextWidth(const uint8_t* text); |
khuang | 1:3b5be0ee5f0c | 180 | |
khuang | 1:3b5be0ee5f0c | 181 | |
khuang | 1:3b5be0ee5f0c | 182 | /** |
khuang | 1:3b5be0ee5f0c | 183 | * Count the characters |
khuang | 1:3b5be0ee5f0c | 184 | * @param width text width |
khuang | 1:3b5be0ee5f0c | 185 | * @param font text font |
khuang | 1:3b5be0ee5f0c | 186 | * @param text given text string |
khuang | 1:3b5be0ee5f0c | 187 | * @param length text length |
khuang | 1:3b5be0ee5f0c | 188 | * @return character count |
khuang | 1:3b5be0ee5f0c | 189 | */ |
khuang | 1:3b5be0ee5f0c | 190 | uint8_t CharCount(uint8_t width, const uint8_t* font, const uint8_t* text, uint8_t length); |
khuang | 1:3b5be0ee5f0c | 191 | |
khuang | 1:3b5be0ee5f0c | 192 | /** |
khuang | 1:3b5be0ee5f0c | 193 | * Add text to the main screen buffer at position x,y. |
khuang | 3:4121d3cd9f60 | 194 | * @param text text to add |
khuang | 1:3b5be0ee5f0c | 195 | * @param xCrd x-coordinate for the given text |
khuang | 1:3b5be0ee5f0c | 196 | * @param yCrd y-coordinate for the given text |
khuang | 3:4121d3cd9f60 | 197 | * @return status flag |
khuang | 1:3b5be0ee5f0c | 198 | */ |
khuang | 6:0060ffa3f4dc | 199 | oled_status_t AddText( const uint8_t* text,int8_t xCrd, int8_t yCrd ); |
khuang | 1:3b5be0ee5f0c | 200 | /** |
khuang | 1:3b5be0ee5f0c | 201 | * Add text to the main screen buffer. Used with SetDynamicArea() Function. |
khuang | 1:3b5be0ee5f0c | 202 | * @param text text to add |
khuang | 1:3b5be0ee5f0c | 203 | * @return status flag |
khuang | 1:3b5be0ee5f0c | 204 | */ |
khuang | 1:3b5be0ee5f0c | 205 | oled_status_t AddText( const uint8_t* text); |
khuang | 3:4121d3cd9f60 | 206 | |
khuang | 1:3b5be0ee5f0c | 207 | /** |
khuang | 1:3b5be0ee5f0c | 208 | * Write text on OLED at position set in Dynamic Area Field. Used with SetDynamicArea() Function. |
khuang | 1:3b5be0ee5f0c | 209 | * @param text desired text |
khuang | 1:3b5be0ee5f0c | 210 | * |
khuang | 1:3b5be0ee5f0c | 211 | */ |
khuang | 1:3b5be0ee5f0c | 212 | oled_status_t DrawText ( const uint8_t* text); |
khuang | 1:3b5be0ee5f0c | 213 | |
khuang | 1:3b5be0ee5f0c | 214 | /** |
khuang | 1:3b5be0ee5f0c | 215 | * Return the dimensions of image |
khuang | 1:3b5be0ee5f0c | 216 | * @param width given image's width |
khuang | 1:3b5be0ee5f0c | 217 | * @param height given image's height |
khuang | 1:3b5be0ee5f0c | 218 | * @param image desired image |
khuang | 1:3b5be0ee5f0c | 219 | */ |
khuang | 1:3b5be0ee5f0c | 220 | void GetImageDimensions(uint8_t *width, uint8_t *height, const uint8_t* image); |
khuang | 1:3b5be0ee5f0c | 221 | |
khuang | 1:3b5be0ee5f0c | 222 | /** |
khuang | 1:3b5be0ee5f0c | 223 | * Add image to the main screen buffer.Used with SetDynamicArea() Function. |
khuang | 1:3b5be0ee5f0c | 224 | * @param image desired image |
khuang | 1:3b5be0ee5f0c | 225 | * @return status flag |
khuang | 1:3b5be0ee5f0c | 226 | */ |
khuang | 1:3b5be0ee5f0c | 227 | oled_status_t AddImage ( const uint8_t* image ); |
khuang | 1:3b5be0ee5f0c | 228 | |
khuang | 1:3b5be0ee5f0c | 229 | /** |
khuang | 1:3b5be0ee5f0c | 230 | * Add image to the main screen buffer at position x,y |
khuang | 1:3b5be0ee5f0c | 231 | * @param image desired image |
khuang | 3:4121d3cd9f60 | 232 | * @param xCrd image x-coordinate |
khuang | 3:4121d3cd9f60 | 233 | * @param yCrd image y-coordinate |
khuang | 1:3b5be0ee5f0c | 234 | * @return status flag |
khuang | 1:3b5be0ee5f0c | 235 | */ |
khuang | 6:0060ffa3f4dc | 236 | oled_status_t AddImage ( const uint8_t* image, int8_t xCrd, int8_t yCrd ); |
khuang | 1:3b5be0ee5f0c | 237 | |
khuang | 1:3b5be0ee5f0c | 238 | /** |
khuang | 3:4121d3cd9f60 | 239 | * Send image to OLED GRAM.Used with SetDynamicArea() Function for positioning image. |
khuang | 1:3b5be0ee5f0c | 240 | * @param image desired image |
khuang | 1:3b5be0ee5f0c | 241 | * @return status flag |
khuang | 1:3b5be0ee5f0c | 242 | */ |
khuang | 1:3b5be0ee5f0c | 243 | oled_status_t DrawImage ( const uint8_t* image ); |
khuang | 1:3b5be0ee5f0c | 244 | /** |
khuang | 3:4121d3cd9f60 | 245 | * Send image to OLED GRAM at position x,y. |
khuang | 1:3b5be0ee5f0c | 246 | * @param image desired image |
khuang | 3:4121d3cd9f60 | 247 | * @param xCrd image x-coordinate |
khuang | 3:4121d3cd9f60 | 248 | * @param yCrd image y-coordinate |
khuang | 1:3b5be0ee5f0c | 249 | * @return status flag |
khuang | 1:3b5be0ee5f0c | 250 | */ |
khuang | 6:0060ffa3f4dc | 251 | oled_status_t DrawImage ( const uint8_t* image, int8_t xCrd, int8_t yCrd ); |
khuang | 1:3b5be0ee5f0c | 252 | |
khuang | 1:3b5be0ee5f0c | 253 | /** |
khuang | 1:3b5be0ee5f0c | 254 | * Dim OLED screen on |
khuang | 1:3b5be0ee5f0c | 255 | */ |
khuang | 1:3b5be0ee5f0c | 256 | void DimScreenON(); |
khuang | 1:3b5be0ee5f0c | 257 | |
khuang | 1:3b5be0ee5f0c | 258 | /** |
khuang | 1:3b5be0ee5f0c | 259 | * Return OLED back to full contrast |
khuang | 1:3b5be0ee5f0c | 260 | */ |
khuang | 1:3b5be0ee5f0c | 261 | void DimScreenOFF(); |
khuang | 1:3b5be0ee5f0c | 262 | |
khuang | 1:3b5be0ee5f0c | 263 | /** |
khuang | 1:3b5be0ee5f0c | 264 | * Swap image's bytes per pixel to obtain the correct color format |
khuang | 1:3b5be0ee5f0c | 265 | * @param imgDst desired image |
khuang | 1:3b5be0ee5f0c | 266 | * @param imgSrc original image |
khuang | 1:3b5be0ee5f0c | 267 | * @param imgSize image's size |
khuang | 1:3b5be0ee5f0c | 268 | */ |
khuang | 1:3b5be0ee5f0c | 269 | void Swap( |
khuang | 1:3b5be0ee5f0c | 270 | oled_pixel_t imgDst, |
khuang | 1:3b5be0ee5f0c | 271 | const uint8_t* imgSrc, |
khuang | 1:3b5be0ee5f0c | 272 | uint16_t imgSize |
khuang | 1:3b5be0ee5f0c | 273 | ); |
khuang | 1:3b5be0ee5f0c | 274 | |
khuang | 1:3b5be0ee5f0c | 275 | |
khuang | 1:3b5be0ee5f0c | 276 | /** |
khuang | 1:3b5be0ee5f0c | 277 | * Turn on Power for OLED Display |
khuang | 1:3b5be0ee5f0c | 278 | */ |
khuang | 1:3b5be0ee5f0c | 279 | void PowerON(); |
khuang | 1:3b5be0ee5f0c | 280 | |
khuang | 1:3b5be0ee5f0c | 281 | /** |
khuang | 1:3b5be0ee5f0c | 282 | * Turn off Power for OLED Display |
khuang | 1:3b5be0ee5f0c | 283 | */ |
khuang | 1:3b5be0ee5f0c | 284 | void PowerOFF(); |
khuang | 1:3b5be0ee5f0c | 285 | |
khuang | 1:3b5be0ee5f0c | 286 | /** |
khuang | 1:3b5be0ee5f0c | 287 | * update the main screen buffer |
khuang | 1:3b5be0ee5f0c | 288 | * with the given image |
khuang | 1:3b5be0ee5f0c | 289 | |
khuang | 1:3b5be0ee5f0c | 290 | * @param xCrd image x-coordinate |
khuang | 1:3b5be0ee5f0c | 291 | * @param yCrd image y-coordinate |
khuang | 1:3b5be0ee5f0c | 292 | * @param width image width |
khuang | 1:3b5be0ee5f0c | 293 | * @param height image height |
khuang | 1:3b5be0ee5f0c | 294 | * @param image image for buffer |
khuang | 1:3b5be0ee5f0c | 295 | */ |
khuang | 1:3b5be0ee5f0c | 296 | void UpdateBuffer ( |
khuang | 6:0060ffa3f4dc | 297 | int8_t xCrd, |
khuang | 6:0060ffa3f4dc | 298 | int8_t yCrd, |
khuang | 1:3b5be0ee5f0c | 299 | uint8_t width, |
khuang | 1:3b5be0ee5f0c | 300 | uint8_t height, |
khuang | 1:3b5be0ee5f0c | 301 | const uint8_t* image |
khuang | 1:3b5be0ee5f0c | 302 | ); |
khuang | 1:3b5be0ee5f0c | 303 | |
khuang | 1:3b5be0ee5f0c | 304 | |
khuang | 3:4121d3cd9f60 | 305 | /** |
khuang | 3:4121d3cd9f60 | 306 | * Write text on OLED at position x,y. Recommended for Static Text. |
khuang | 3:4121d3cd9f60 | 307 | * @param text desired text |
khuang | 3:4121d3cd9f60 | 308 | * @param xCrd x-coordinate for the given text |
khuang | 3:4121d3cd9f60 | 309 | * @param yCrd y-coordinate for the given text |
khuang | 3:4121d3cd9f60 | 310 | */ |
khuang | 3:4121d3cd9f60 | 311 | |
khuang | 3:4121d3cd9f60 | 312 | oled_status_t Label(const uint8_t* text, |
khuang | 6:0060ffa3f4dc | 313 | int8_t xCrd, |
khuang | 6:0060ffa3f4dc | 314 | int8_t yCrd ); |
khuang | 3:4121d3cd9f60 | 315 | |
khuang | 3:4121d3cd9f60 | 316 | /** |
khuang | 3:4121d3cd9f60 | 317 | * Create a text box of width,height at position x,y. Recommended for Dynamic Text. |
khuang | 3:4121d3cd9f60 | 318 | * Text is aligned in textbox accordingly to the align parameter set by SetTextProperties(). |
khuang | 3:4121d3cd9f60 | 319 | * @param text desired text |
khuang | 3:4121d3cd9f60 | 320 | * @param xCrd x-coordinate for the textbox |
khuang | 3:4121d3cd9f60 | 321 | * @param yCrd y-coordinate for the textbox |
khuang | 3:4121d3cd9f60 | 322 | * @param width width of the textbox |
khuang | 3:4121d3cd9f60 | 323 | * @param height height of the textbox |
khuang | 3:4121d3cd9f60 | 324 | */ |
khuang | 3:4121d3cd9f60 | 325 | |
khuang | 3:4121d3cd9f60 | 326 | oled_status_t TextBox(const uint8_t* text, |
khuang | 6:0060ffa3f4dc | 327 | int8_t xCrd, |
khuang | 6:0060ffa3f4dc | 328 | int8_t yCrd, |
khuang | 3:4121d3cd9f60 | 329 | uint8_t width, |
khuang | 3:4121d3cd9f60 | 330 | uint8_t height); |
khuang | 3:4121d3cd9f60 | 331 | |
khuang | 1:3b5be0ee5f0c | 332 | |
khuang | 1:3b5be0ee5f0c | 333 | private: |
khuang | 1:3b5be0ee5f0c | 334 | |
khuang | 1:3b5be0ee5f0c | 335 | SPI spi; |
khuang | 1:3b5be0ee5f0c | 336 | DigitalOut power; |
khuang | 1:3b5be0ee5f0c | 337 | DigitalOut cs; |
khuang | 1:3b5be0ee5f0c | 338 | DigitalOut rst; |
khuang | 1:3b5be0ee5f0c | 339 | DigitalOut dc; |
khuang | 1:3b5be0ee5f0c | 340 | |
khuang | 1:3b5be0ee5f0c | 341 | |
khuang | 1:3b5be0ee5f0c | 342 | const uint8_t* selectedFont; |
khuang | 1:3b5be0ee5f0c | 343 | |
khuang | 1:3b5be0ee5f0c | 344 | uint8_t |
khuang | 1:3b5be0ee5f0c | 345 | currentChar_width, |
khuang | 1:3b5be0ee5f0c | 346 | currentChar_height, |
khuang | 1:3b5be0ee5f0c | 347 | screenBuf[OLED_GRAM_SIZE]; |
khuang | 1:3b5be0ee5f0c | 348 | |
khuang | 1:3b5be0ee5f0c | 349 | uint16_t |
khuang | 1:3b5be0ee5f0c | 350 | selectedFont_color, |
khuang | 1:3b5be0ee5f0c | 351 | selectedFont_firstChar, // first character in the font table |
khuang | 1:3b5be0ee5f0c | 352 | selectedFont_lastChar, // last character in the font table |
khuang | 1:3b5be0ee5f0c | 353 | selectedFont_height, |
khuang | 1:3b5be0ee5f0c | 354 | colorMask; |
khuang | 1:3b5be0ee5f0c | 355 | |
khuang | 1:3b5be0ee5f0c | 356 | oled_dynamic_area_t oled_dynamic_area; |
khuang | 1:3b5be0ee5f0c | 357 | oled_text_properties_t oled_text_properties; |
khuang | 1:3b5be0ee5f0c | 358 | |
khuang | 1:3b5be0ee5f0c | 359 | |
khuang | 1:3b5be0ee5f0c | 360 | //Internal Functions |
khuang | 1:3b5be0ee5f0c | 361 | void Transpose( oled_pixel_t transImage, const oled_pixel_t image, uint8_t width, uint8_t height ); |
khuang | 6:0060ffa3f4dc | 362 | oled_status_t TopDown ( const uint8_t* image, int8_t xCrd, int8_t yCrd, uint8_t width, uint8_t height ); |
khuang | 6:0060ffa3f4dc | 363 | oled_status_t DownTop ( const uint8_t* image, int8_t xCrd, int8_t yCrd, uint8_t width, uint8_t height ); |
khuang | 6:0060ffa3f4dc | 364 | oled_status_t LeftRight ( const uint8_t* image, int8_t xCrd, int8_t yCrd, uint8_t width, uint8_t height ); |
khuang | 6:0060ffa3f4dc | 365 | oled_status_t RightLeft ( const uint8_t* image, int8_t xCrd, int8_t yCrd, uint8_t width, uint8_t height ); |
khuang | 6:0060ffa3f4dc | 366 | void SetBorders( int8_t xCrd, int8_t yCrd, uint8_t width, uint8_t height ); |
khuang | 1:3b5be0ee5f0c | 367 | oled_status_t CreateTextBackground(); |
khuang | 1:3b5be0ee5f0c | 368 | void WriteCharToBuf( uint16_t charToWrite, oled_pixel_t* chrBuf ); |
khuang | 1:3b5be0ee5f0c | 369 | oled_status_t AddCharToTextArea( oled_pixel_t chrPtr, uint8_t chrWidth, uint8_t chrHeight, oled_pixel_t copyAddr, uint8_t imgWidth ); |
khuang | 1:3b5be0ee5f0c | 370 | void* AllocateDynamicArea( uint32_t area ); |
khuang | 1:3b5be0ee5f0c | 371 | oled_status_t DestroyDynamicArea(void * ptr); |
khuang | 1:3b5be0ee5f0c | 372 | |
khuang | 1:3b5be0ee5f0c | 373 | }; |
khuang | 1:3b5be0ee5f0c | 374 | |
khuang | 1:3b5be0ee5f0c | 375 | #endif |