Hexiwear OLED
Fork of Hexi_OLED_SSD1351 by
Hexi_OLED_SSD1351.cpp@9:18d4eb6328eb, 2017-04-12 (annotated)
- Committer:
- tdh50
- Date:
- Wed Apr 12 21:01:40 2017 +0000
- Revision:
- 9:18d4eb6328eb
- Parent:
- 8:ae5fad429790
Added GetPower() Function
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
khuang | 4:38086393d75b | 1 | /** OLED Display Driver for Hexiwear |
khuang | 4:38086393d75b | 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 | 1:3b5be0ee5f0c | 36 | #include "OLED_types.h" |
khuang | 1:3b5be0ee5f0c | 37 | #include "OLED_info.h" |
khuang | 1:3b5be0ee5f0c | 38 | #include "mbed.h" |
khuang | 1:3b5be0ee5f0c | 39 | #include "Hexi_OLED_SSD1351.h" |
khuang | 5:a5b4b36a1aed | 40 | #include "OpenSans_Font.h" |
khuang | 2:fc06b5b5bf6a | 41 | |
khuang | 2:fc06b5b5bf6a | 42 | const init_cmd_t seq[] = { |
khuang | 2:fc06b5b5bf6a | 43 | OLED_CMD_SET_CMD_LOCK, CMD_BYTE, |
khuang | 2:fc06b5b5bf6a | 44 | OLED_UNLOCK, DATA_BYTE, |
khuang | 2:fc06b5b5bf6a | 45 | OLED_CMD_SET_CMD_LOCK, CMD_BYTE, |
khuang | 2:fc06b5b5bf6a | 46 | OLED_ACC_TO_CMD_YES, DATA_BYTE, |
khuang | 2:fc06b5b5bf6a | 47 | OLED_CMD_DISPLAYOFF, CMD_BYTE, |
khuang | 2:fc06b5b5bf6a | 48 | OLED_CMD_SET_OSC_FREQ_AND_CLOCKDIV, CMD_BYTE, |
khuang | 2:fc06b5b5bf6a | 49 | 0xF1, DATA_BYTE, |
khuang | 2:fc06b5b5bf6a | 50 | OLED_CMD_SET_MUX_RATIO, CMD_BYTE, |
khuang | 2:fc06b5b5bf6a | 51 | 0x5F, DATA_BYTE, |
khuang | 2:fc06b5b5bf6a | 52 | OLED_CMD_SET_REMAP, CMD_BYTE, |
khuang | 2:fc06b5b5bf6a | 53 | OLED_REMAP_SETTINGS, DATA_BYTE, |
khuang | 2:fc06b5b5bf6a | 54 | OLED_CMD_SET_COLUMN, CMD_BYTE, |
khuang | 2:fc06b5b5bf6a | 55 | 0x00, DATA_BYTE, |
khuang | 2:fc06b5b5bf6a | 56 | 0x5F, DATA_BYTE, |
khuang | 2:fc06b5b5bf6a | 57 | OLED_CMD_SET_ROW, CMD_BYTE, |
khuang | 2:fc06b5b5bf6a | 58 | 0x00, DATA_BYTE, |
khuang | 2:fc06b5b5bf6a | 59 | 0x5F, DATA_BYTE, |
khuang | 2:fc06b5b5bf6a | 60 | OLED_CMD_STARTLINE, CMD_BYTE, |
khuang | 2:fc06b5b5bf6a | 61 | 0x80, DATA_BYTE, |
khuang | 2:fc06b5b5bf6a | 62 | OLED_CMD_DISPLAYOFFSET, CMD_BYTE, |
khuang | 2:fc06b5b5bf6a | 63 | 0x60, DATA_BYTE, |
khuang | 2:fc06b5b5bf6a | 64 | OLED_CMD_PRECHARGE, CMD_BYTE, |
khuang | 2:fc06b5b5bf6a | 65 | 0x32, CMD_BYTE, |
khuang | 2:fc06b5b5bf6a | 66 | OLED_CMD_VCOMH, CMD_BYTE, |
khuang | 2:fc06b5b5bf6a | 67 | 0x05, CMD_BYTE, |
khuang | 2:fc06b5b5bf6a | 68 | OLED_CMD_NORMALDISPLAY, CMD_BYTE, |
khuang | 2:fc06b5b5bf6a | 69 | OLED_CMD_CONTRASTABC, CMD_BYTE, |
khuang | 2:fc06b5b5bf6a | 70 | 0x8A, DATA_BYTE, |
khuang | 2:fc06b5b5bf6a | 71 | 0x51, DATA_BYTE, |
khuang | 2:fc06b5b5bf6a | 72 | 0x8A, DATA_BYTE, |
khuang | 2:fc06b5b5bf6a | 73 | OLED_CMD_CONTRASTMASTER, CMD_BYTE, |
khuang | 2:fc06b5b5bf6a | 74 | 0xCF, DATA_BYTE, |
khuang | 2:fc06b5b5bf6a | 75 | OLED_CMD_SETVSL, CMD_BYTE, |
khuang | 2:fc06b5b5bf6a | 76 | 0xA0, DATA_BYTE, |
khuang | 2:fc06b5b5bf6a | 77 | 0xB5, DATA_BYTE, |
khuang | 2:fc06b5b5bf6a | 78 | 0x55, DATA_BYTE, |
khuang | 2:fc06b5b5bf6a | 79 | OLED_CMD_PRECHARGE2, CMD_BYTE, |
khuang | 2:fc06b5b5bf6a | 80 | 0x01, DATA_BYTE, |
khuang | 2:fc06b5b5bf6a | 81 | OLED_CMD_DISPLAYON, CMD_BYTE |
khuang | 2:fc06b5b5bf6a | 82 | }; |
khuang | 1:3b5be0ee5f0c | 83 | |
khuang | 1:3b5be0ee5f0c | 84 | |
khuang | 1:3b5be0ee5f0c | 85 | |
khuang | 1:3b5be0ee5f0c | 86 | SSD1351::SSD1351(PinName mosiPin,PinName sclkPin,PinName pwrPin, PinName csPin,PinName rstPin, PinName dcPin): spi(mosiPin,NC,sclkPin) , power(pwrPin), cs(csPin),rst(rstPin),dc(dcPin) |
khuang | 1:3b5be0ee5f0c | 87 | { |
khuang | 1:3b5be0ee5f0c | 88 | |
khuang | 1:3b5be0ee5f0c | 89 | spi.frequency(8000000); |
khuang | 1:3b5be0ee5f0c | 90 | |
khuang | 1:3b5be0ee5f0c | 91 | |
khuang | 1:3b5be0ee5f0c | 92 | dc =0; |
khuang | 1:3b5be0ee5f0c | 93 | PowerOFF(); |
khuang | 1:3b5be0ee5f0c | 94 | wait_ms(1); |
khuang | 1:3b5be0ee5f0c | 95 | rst = 0 ; |
khuang | 1:3b5be0ee5f0c | 96 | wait_ms(1); |
khuang | 1:3b5be0ee5f0c | 97 | rst = 1 ; |
khuang | 1:3b5be0ee5f0c | 98 | wait_ms(1); |
khuang | 1:3b5be0ee5f0c | 99 | PowerON(); |
khuang | 6:0060ffa3f4dc | 100 | |
khuang | 1:3b5be0ee5f0c | 101 | currentChar_width = 0, |
khuang | 1:3b5be0ee5f0c | 102 | currentChar_height = 0; |
khuang | 1:3b5be0ee5f0c | 103 | colorMask = COLOR_WHITE; |
khuang | 1:3b5be0ee5f0c | 104 | |
khuang | 1:3b5be0ee5f0c | 105 | oled_text_properties.alignParam = OLED_TEXT_ALIGN_CENTER; |
khuang | 1:3b5be0ee5f0c | 106 | oled_text_properties.background = NULL; |
khuang | 3:4121d3cd9f60 | 107 | oled_text_properties.font = OpenSans_10x15_Regular; |
khuang | 6:0060ffa3f4dc | 108 | oled_text_properties.fontColor = COLOR_WHITE; |
khuang | 6:0060ffa3f4dc | 109 | SetTextProperties(&oled_text_properties); |
khuang | 6:0060ffa3f4dc | 110 | |
khuang | 1:3b5be0ee5f0c | 111 | oled_dynamic_area.areaBuffer = NULL; |
khuang | 1:3b5be0ee5f0c | 112 | oled_dynamic_area.height = 0; |
khuang | 1:3b5be0ee5f0c | 113 | oled_dynamic_area.width = 0; |
khuang | 1:3b5be0ee5f0c | 114 | oled_dynamic_area.xCrd = 0; |
khuang | 1:3b5be0ee5f0c | 115 | oled_dynamic_area.yCrd = 0; |
khuang | 1:3b5be0ee5f0c | 116 | |
khuang | 6:0060ffa3f4dc | 117 | |
khuang | 1:3b5be0ee5f0c | 118 | for (int i=0;i<39;i++) |
khuang | 1:3b5be0ee5f0c | 119 | { |
khuang | 2:fc06b5b5bf6a | 120 | SendCmd(seq[i].cmd, seq[i].type); |
khuang | 1:3b5be0ee5f0c | 121 | } |
khuang | 1:3b5be0ee5f0c | 122 | |
khuang | 1:3b5be0ee5f0c | 123 | |
khuang | 1:3b5be0ee5f0c | 124 | |
khuang | 1:3b5be0ee5f0c | 125 | } |
khuang | 1:3b5be0ee5f0c | 126 | |
khuang | 1:3b5be0ee5f0c | 127 | |
khuang | 1:3b5be0ee5f0c | 128 | SSD1351::~SSD1351(void) |
khuang | 1:3b5be0ee5f0c | 129 | { |
khuang | 6:0060ffa3f4dc | 130 | //TO_DO |
khuang | 6:0060ffa3f4dc | 131 | //Run Free and zero pointers. |
khuang | 6:0060ffa3f4dc | 132 | |
khuang | 1:3b5be0ee5f0c | 133 | } |
khuang | 1:3b5be0ee5f0c | 134 | |
khuang | 1:3b5be0ee5f0c | 135 | |
khuang | 1:3b5be0ee5f0c | 136 | |
khuang | 1:3b5be0ee5f0c | 137 | |
khuang | 1:3b5be0ee5f0c | 138 | void SSD1351::SendCmd(uint32_t cmd, |
khuang | 1:3b5be0ee5f0c | 139 | uint8_t isFirst) |
khuang | 1:3b5be0ee5f0c | 140 | { |
khuang | 1:3b5be0ee5f0c | 141 | |
khuang | 1:3b5be0ee5f0c | 142 | |
khuang | 1:3b5be0ee5f0c | 143 | |
khuang | 1:3b5be0ee5f0c | 144 | uint8_t |
khuang | 1:3b5be0ee5f0c | 145 | txSize = 1, |
khuang | 1:3b5be0ee5f0c | 146 | txBuf[4]; |
khuang | 1:3b5be0ee5f0c | 147 | |
khuang | 1:3b5be0ee5f0c | 148 | memcpy((void*)txBuf, (void*)&cmd, txSize ); |
khuang | 1:3b5be0ee5f0c | 149 | |
khuang | 1:3b5be0ee5f0c | 150 | if (isFirst ) |
khuang | 1:3b5be0ee5f0c | 151 | { |
khuang | 1:3b5be0ee5f0c | 152 | dc = 0; |
khuang | 1:3b5be0ee5f0c | 153 | } |
khuang | 1:3b5be0ee5f0c | 154 | else |
khuang | 1:3b5be0ee5f0c | 155 | { |
khuang | 1:3b5be0ee5f0c | 156 | dc = 1; |
khuang | 1:3b5be0ee5f0c | 157 | } |
khuang | 1:3b5be0ee5f0c | 158 | |
khuang | 1:3b5be0ee5f0c | 159 | cs = 0; |
khuang | 1:3b5be0ee5f0c | 160 | spi.write(*txBuf); |
khuang | 1:3b5be0ee5f0c | 161 | cs = 1; |
khuang | 1:3b5be0ee5f0c | 162 | |
khuang | 1:3b5be0ee5f0c | 163 | } |
khuang | 1:3b5be0ee5f0c | 164 | |
khuang | 1:3b5be0ee5f0c | 165 | |
khuang | 1:3b5be0ee5f0c | 166 | |
khuang | 1:3b5be0ee5f0c | 167 | void SSD1351::SendData ( const uint8_t* dataToSend, |
khuang | 1:3b5be0ee5f0c | 168 | uint32_t dataSize) |
khuang | 1:3b5be0ee5f0c | 169 | |
khuang | 1:3b5be0ee5f0c | 170 | { |
khuang | 1:3b5be0ee5f0c | 171 | |
khuang | 1:3b5be0ee5f0c | 172 | |
khuang | 7:9961c525e249 | 173 | uint16_t* arrayPtr = (uint16_t*)dataToSend; |
khuang | 1:3b5be0ee5f0c | 174 | |
khuang | 7:9961c525e249 | 175 | for( uint32_t i = 0; i < dataSize/2; i++ ) |
khuang | 7:9961c525e249 | 176 | { |
khuang | 7:9961c525e249 | 177 | arrayPtr[i] &= colorMask; |
khuang | 7:9961c525e249 | 178 | } |
khuang | 1:3b5be0ee5f0c | 179 | |
khuang | 1:3b5be0ee5f0c | 180 | |
khuang | 7:9961c525e249 | 181 | SendCmd( OLED_CMD_WRITERAM, CMD_BYTE ); |
khuang | 1:3b5be0ee5f0c | 182 | |
khuang | 7:9961c525e249 | 183 | /* sending data -> set DC pin */ |
khuang | 1:3b5be0ee5f0c | 184 | dc = 1; |
khuang | 1:3b5be0ee5f0c | 185 | cs = 0 ; |
khuang | 1:3b5be0ee5f0c | 186 | |
khuang | 7:9961c525e249 | 187 | const uint8_t* |
khuang | 7:9961c525e249 | 188 | /* traversing pointer */ |
khuang | 7:9961c525e249 | 189 | bufPtr = dataToSend; |
khuang | 1:3b5be0ee5f0c | 190 | |
khuang | 1:3b5be0ee5f0c | 191 | |
khuang | 7:9961c525e249 | 192 | for ( uint32_t i = 0; i < dataSize; i++) |
khuang | 7:9961c525e249 | 193 | { |
khuang | 7:9961c525e249 | 194 | spi.write(*bufPtr); |
khuang | 7:9961c525e249 | 195 | bufPtr += 1; |
khuang | 7:9961c525e249 | 196 | } |
khuang | 1:3b5be0ee5f0c | 197 | |
khuang | 1:3b5be0ee5f0c | 198 | cs = 1; |
khuang | 1:3b5be0ee5f0c | 199 | |
khuang | 1:3b5be0ee5f0c | 200 | } |
khuang | 1:3b5be0ee5f0c | 201 | |
khuang | 1:3b5be0ee5f0c | 202 | |
khuang | 1:3b5be0ee5f0c | 203 | oled_status_t SSD1351::DrawBox ( |
khuang | 6:0060ffa3f4dc | 204 | int8_t xCrd, |
khuang | 6:0060ffa3f4dc | 205 | int8_t yCrd, |
khuang | 6:0060ffa3f4dc | 206 | uint8_t width, |
khuang | 6:0060ffa3f4dc | 207 | uint8_t height, |
khuang | 1:3b5be0ee5f0c | 208 | uint16_t color |
khuang | 1:3b5be0ee5f0c | 209 | ) |
khuang | 1:3b5be0ee5f0c | 210 | { |
khuang | 1:3b5be0ee5f0c | 211 | |
khuang | 1:3b5be0ee5f0c | 212 | oled_status_t status; |
khuang | 1:3b5be0ee5f0c | 213 | oled_dynamic_area_t boxArea; |
khuang | 1:3b5be0ee5f0c | 214 | |
khuang | 1:3b5be0ee5f0c | 215 | boxArea.xCrd = xCrd; |
khuang | 1:3b5be0ee5f0c | 216 | boxArea.yCrd = yCrd; |
khuang | 1:3b5be0ee5f0c | 217 | boxArea.width = width; |
khuang | 1:3b5be0ee5f0c | 218 | boxArea.height = height; |
khuang | 1:3b5be0ee5f0c | 219 | |
khuang | 1:3b5be0ee5f0c | 220 | uint32_t |
khuang | 1:3b5be0ee5f0c | 221 | boxSize = width*height; |
khuang | 1:3b5be0ee5f0c | 222 | |
khuang | 1:3b5be0ee5f0c | 223 | SetDynamicArea( &boxArea ); |
khuang | 1:3b5be0ee5f0c | 224 | |
khuang | 7:9961c525e249 | 225 | /* helper pointer */ |
khuang | 1:3b5be0ee5f0c | 226 | uint8_t* |
khuang | 1:3b5be0ee5f0c | 227 | boxBuf = (uint8_t*)oled_dynamic_area.areaBuffer; |
khuang | 1:3b5be0ee5f0c | 228 | |
khuang | 1:3b5be0ee5f0c | 229 | if ( NULL == boxBuf ) |
khuang | 1:3b5be0ee5f0c | 230 | { |
khuang | 1:3b5be0ee5f0c | 231 | |
khuang | 1:3b5be0ee5f0c | 232 | return OLED_STATUS_ERROR; |
khuang | 1:3b5be0ee5f0c | 233 | } |
khuang | 1:3b5be0ee5f0c | 234 | |
khuang | 7:9961c525e249 | 235 | /* check the bounds */ |
khuang | 1:3b5be0ee5f0c | 236 | if AreCoordsNotValid( xCrd, yCrd, width, height ) |
khuang | 1:3b5be0ee5f0c | 237 | { |
khuang | 1:3b5be0ee5f0c | 238 | status = OLED_STATUS_INIT_ERROR; |
khuang | 1:3b5be0ee5f0c | 239 | } |
khuang | 1:3b5be0ee5f0c | 240 | |
khuang | 1:3b5be0ee5f0c | 241 | else |
khuang | 1:3b5be0ee5f0c | 242 | { |
khuang | 7:9961c525e249 | 243 | /* fill the buffer with color */ |
khuang | 1:3b5be0ee5f0c | 244 | |
khuang | 1:3b5be0ee5f0c | 245 | for ( uint16_t i = 0; i < boxSize; i++ ) |
khuang | 1:3b5be0ee5f0c | 246 | { |
khuang | 1:3b5be0ee5f0c | 247 | boxBuf[ 2*i ] = color >> 8; |
khuang | 1:3b5be0ee5f0c | 248 | boxBuf[ 2*i + 1 ] = color; |
khuang | 1:3b5be0ee5f0c | 249 | } |
khuang | 1:3b5be0ee5f0c | 250 | |
khuang | 7:9961c525e249 | 251 | /* set the locations */ |
khuang | 1:3b5be0ee5f0c | 252 | |
khuang | 7:9961c525e249 | 253 | /* adjust for the offset */ |
khuang | 1:3b5be0ee5f0c | 254 | OLED_AdjustColumnOffset(xCrd); |
khuang | 1:3b5be0ee5f0c | 255 | OLED_AdjustRowOffset(yCrd); |
khuang | 1:3b5be0ee5f0c | 256 | |
khuang | 2:fc06b5b5bf6a | 257 | SendCmd( OLED_CMD_SET_COLUMN, CMD_BYTE); |
khuang | 2:fc06b5b5bf6a | 258 | SendCmd( xCrd, DATA_BYTE ); |
khuang | 2:fc06b5b5bf6a | 259 | SendCmd( xCrd + (width-1), DATA_BYTE ); |
khuang | 2:fc06b5b5bf6a | 260 | SendCmd( OLED_CMD_SET_ROW, CMD_BYTE ); |
khuang | 2:fc06b5b5bf6a | 261 | SendCmd( yCrd, DATA_BYTE ); |
khuang | 7:9961c525e249 | 262 | SendCmd( yCrd + (height-1), DATA_BYTE ); |
khuang | 1:3b5be0ee5f0c | 263 | |
khuang | 7:9961c525e249 | 264 | /* fill the GRAM */ |
khuang | 1:3b5be0ee5f0c | 265 | SendData( (uint8_t*)boxBuf, boxSize*OLED_BYTES_PER_PIXEL ); |
khuang | 1:3b5be0ee5f0c | 266 | DestroyDynamicArea(); |
khuang | 1:3b5be0ee5f0c | 267 | |
khuang | 1:3b5be0ee5f0c | 268 | } |
khuang | 1:3b5be0ee5f0c | 269 | |
khuang | 1:3b5be0ee5f0c | 270 | return status; |
khuang | 1:3b5be0ee5f0c | 271 | } |
khuang | 1:3b5be0ee5f0c | 272 | |
khuang | 1:3b5be0ee5f0c | 273 | /** |
khuang | 1:3b5be0ee5f0c | 274 | * fill the entire screen |
khuang | 1:3b5be0ee5f0c | 275 | * @param color color to fill with |
khuang | 1:3b5be0ee5f0c | 276 | * @return status flag |
khuang | 1:3b5be0ee5f0c | 277 | */ |
khuang | 1:3b5be0ee5f0c | 278 | void SSD1351::FillScreen( uint16_t color ) |
khuang | 1:3b5be0ee5f0c | 279 | { |
khuang | 7:9961c525e249 | 280 | /* fill the screen buffer with color */ |
khuang | 1:3b5be0ee5f0c | 281 | for ( uint16_t i = 0; i < ( OLED_SCREEN_WIDTH * OLED_SCREEN_HEIGHT ); i++ ) |
khuang | 1:3b5be0ee5f0c | 282 | { |
khuang | 1:3b5be0ee5f0c | 283 | screenBuf[ 2*i ] = color >> 8; |
khuang | 1:3b5be0ee5f0c | 284 | screenBuf[ 2*i + 1 ] = color; |
khuang | 1:3b5be0ee5f0c | 285 | } |
khuang | 1:3b5be0ee5f0c | 286 | |
khuang | 7:9961c525e249 | 287 | /* set the locations */ |
khuang | 1:3b5be0ee5f0c | 288 | SetBorders( 0, 0, OLED_SCREEN_WIDTH, OLED_SCREEN_HEIGHT ); |
khuang | 1:3b5be0ee5f0c | 289 | |
khuang | 7:9961c525e249 | 290 | /* fill GRAM */ |
khuang | 1:3b5be0ee5f0c | 291 | SendData( (uint8_t*)screenBuf, OLED_SCREEN_WIDTH * OLED_SCREEN_HEIGHT * OLED_BYTES_PER_PIXEL ); |
khuang | 1:3b5be0ee5f0c | 292 | |
khuang | 1:3b5be0ee5f0c | 293 | } |
khuang | 1:3b5be0ee5f0c | 294 | |
khuang | 1:3b5be0ee5f0c | 295 | |
khuang | 1:3b5be0ee5f0c | 296 | |
khuang | 1:3b5be0ee5f0c | 297 | oled_status_t SSD1351::DrawPixel ( |
khuang | 6:0060ffa3f4dc | 298 | int8_t xCrd, |
khuang | 6:0060ffa3f4dc | 299 | int8_t yCrd, |
khuang | 1:3b5be0ee5f0c | 300 | uint16_t color |
khuang | 1:3b5be0ee5f0c | 301 | ) |
khuang | 1:3b5be0ee5f0c | 302 | { |
khuang | 7:9961c525e249 | 303 | /* check the bounds */ |
khuang | 1:3b5be0ee5f0c | 304 | if AreCoordsNotValid( xCrd, yCrd, 1, 1 ) |
khuang | 1:3b5be0ee5f0c | 305 | { |
khuang | 1:3b5be0ee5f0c | 306 | return OLED_STATUS_INIT_ERROR; |
khuang | 1:3b5be0ee5f0c | 307 | } |
khuang | 1:3b5be0ee5f0c | 308 | |
khuang | 1:3b5be0ee5f0c | 309 | else |
khuang | 1:3b5be0ee5f0c | 310 | { |
khuang | 7:9961c525e249 | 311 | /* set directions */ |
khuang | 1:3b5be0ee5f0c | 312 | SetBorders( xCrd, yCrd, OLED_SCREEN_WIDTH, OLED_SCREEN_HEIGHT); |
khuang | 1:3b5be0ee5f0c | 313 | |
khuang | 1:3b5be0ee5f0c | 314 | uint16_t |
khuang | 7:9961c525e249 | 315 | /* swap bytes */ |
khuang | 1:3b5be0ee5f0c | 316 | dot = color; |
khuang | 1:3b5be0ee5f0c | 317 | |
khuang | 1:3b5be0ee5f0c | 318 | OLED_SwapMe(dot); |
khuang | 1:3b5be0ee5f0c | 319 | |
khuang | 7:9961c525e249 | 320 | /* fill the GRAM */ |
khuang | 1:3b5be0ee5f0c | 321 | SendData( (uint8_t*)&dot, 2 ); |
khuang | 1:3b5be0ee5f0c | 322 | |
khuang | 1:3b5be0ee5f0c | 323 | return OLED_STATUS_SUCCESS; |
khuang | 1:3b5be0ee5f0c | 324 | } |
khuang | 1:3b5be0ee5f0c | 325 | } |
khuang | 1:3b5be0ee5f0c | 326 | |
khuang | 1:3b5be0ee5f0c | 327 | |
khuang | 1:3b5be0ee5f0c | 328 | oled_status_t SSD1351::DrawScreen ( |
khuang | 1:3b5be0ee5f0c | 329 | const uint8_t* image, |
khuang | 6:0060ffa3f4dc | 330 | int8_t xCrd, |
khuang | 6:0060ffa3f4dc | 331 | int8_t yCrd, |
khuang | 1:3b5be0ee5f0c | 332 | uint8_t width, |
khuang | 1:3b5be0ee5f0c | 333 | uint8_t height, |
khuang | 1:3b5be0ee5f0c | 334 | oled_transition_t transition |
khuang | 1:3b5be0ee5f0c | 335 | ) |
khuang | 1:3b5be0ee5f0c | 336 | { |
khuang | 1:3b5be0ee5f0c | 337 | oled_status_t |
khuang | 1:3b5be0ee5f0c | 338 | status = OLED_STATUS_SUCCESS; |
khuang | 1:3b5be0ee5f0c | 339 | |
khuang | 1:3b5be0ee5f0c | 340 | if AreCoordsNotValid( xCrd, yCrd, width, height ) |
khuang | 1:3b5be0ee5f0c | 341 | { |
khuang | 1:3b5be0ee5f0c | 342 | return OLED_STATUS_INIT_ERROR; |
khuang | 1:3b5be0ee5f0c | 343 | } |
khuang | 1:3b5be0ee5f0c | 344 | |
khuang | 1:3b5be0ee5f0c | 345 | switch ( transition ) |
khuang | 1:3b5be0ee5f0c | 346 | { |
khuang | 1:3b5be0ee5f0c | 347 | case OLED_TRANSITION_NONE: { |
khuang | 7:9961c525e249 | 348 | /* set the locations */ |
khuang | 1:3b5be0ee5f0c | 349 | SetBorders( xCrd, yCrd, width, height); |
khuang | 1:3b5be0ee5f0c | 350 | |
khuang | 7:9961c525e249 | 351 | /* fill the GRAM */ |
khuang | 1:3b5be0ee5f0c | 352 | SendData( (const uint8_t*)image, width * height * OLED_BYTES_PER_PIXEL ); |
khuang | 1:3b5be0ee5f0c | 353 | break; |
khuang | 1:3b5be0ee5f0c | 354 | } |
khuang | 1:3b5be0ee5f0c | 355 | |
khuang | 1:3b5be0ee5f0c | 356 | case OLED_TRANSITION_TOP_DOWN: { |
khuang | 1:3b5be0ee5f0c | 357 | TopDown( image, xCrd, yCrd, width, height ); |
khuang | 1:3b5be0ee5f0c | 358 | break; |
khuang | 1:3b5be0ee5f0c | 359 | } |
khuang | 1:3b5be0ee5f0c | 360 | |
khuang | 1:3b5be0ee5f0c | 361 | case OLED_TRANSITION_DOWN_TOP: { |
khuang | 1:3b5be0ee5f0c | 362 | DownTop( image, xCrd, yCrd, width, height ); |
khuang | 1:3b5be0ee5f0c | 363 | break; |
khuang | 1:3b5be0ee5f0c | 364 | } |
khuang | 1:3b5be0ee5f0c | 365 | |
khuang | 1:3b5be0ee5f0c | 366 | case OLED_TRANSITION_LEFT_RIGHT: { |
khuang | 1:3b5be0ee5f0c | 367 | LeftRight( image, xCrd, yCrd, width, height ); |
khuang | 1:3b5be0ee5f0c | 368 | break; |
khuang | 1:3b5be0ee5f0c | 369 | } |
khuang | 1:3b5be0ee5f0c | 370 | |
khuang | 1:3b5be0ee5f0c | 371 | case OLED_TRANSITION_RIGHT_LEFT: { |
khuang | 1:3b5be0ee5f0c | 372 | RightLeft( image, xCrd, yCrd, width, height ); |
khuang | 1:3b5be0ee5f0c | 373 | break; |
khuang | 1:3b5be0ee5f0c | 374 | } |
khuang | 1:3b5be0ee5f0c | 375 | |
khuang | 1:3b5be0ee5f0c | 376 | default: {} |
khuang | 1:3b5be0ee5f0c | 377 | } |
khuang | 1:3b5be0ee5f0c | 378 | |
khuang | 1:3b5be0ee5f0c | 379 | return status; |
khuang | 1:3b5be0ee5f0c | 380 | } |
khuang | 1:3b5be0ee5f0c | 381 | |
khuang | 1:3b5be0ee5f0c | 382 | |
khuang | 1:3b5be0ee5f0c | 383 | oled_status_t SSD1351::SetFont( |
khuang | 1:3b5be0ee5f0c | 384 | const uint8_t* newFont, |
khuang | 1:3b5be0ee5f0c | 385 | uint16_t newColor |
khuang | 1:3b5be0ee5f0c | 386 | ) |
khuang | 1:3b5be0ee5f0c | 387 | { |
khuang | 7:9961c525e249 | 388 | /* save the new values in intern variables */ |
khuang | 1:3b5be0ee5f0c | 389 | |
khuang | 1:3b5be0ee5f0c | 390 | selectedFont = newFont; |
khuang | 1:3b5be0ee5f0c | 391 | selectedFont_firstChar = newFont[2] | ( (uint16_t)newFont[3] << 8 ); |
khuang | 1:3b5be0ee5f0c | 392 | selectedFont_lastChar = newFont[4] | ( (uint16_t)newFont[5] << 8 ); |
khuang | 1:3b5be0ee5f0c | 393 | selectedFont_height = newFont[6]; |
khuang | 1:3b5be0ee5f0c | 394 | selectedFont_color = newColor; |
khuang | 1:3b5be0ee5f0c | 395 | |
khuang | 1:3b5be0ee5f0c | 396 | OLED_SwapMe( selectedFont_color ); |
khuang | 1:3b5be0ee5f0c | 397 | |
khuang | 1:3b5be0ee5f0c | 398 | return OLED_STATUS_SUCCESS; |
khuang | 1:3b5be0ee5f0c | 399 | } |
khuang | 1:3b5be0ee5f0c | 400 | |
khuang | 1:3b5be0ee5f0c | 401 | |
khuang | 1:3b5be0ee5f0c | 402 | void SSD1351::SetDynamicArea(oled_dynamic_area_t *dynamic_area) |
khuang | 1:3b5be0ee5f0c | 403 | { |
khuang | 1:3b5be0ee5f0c | 404 | |
khuang | 1:3b5be0ee5f0c | 405 | if( NULL == oled_dynamic_area.areaBuffer ) |
khuang | 1:3b5be0ee5f0c | 406 | { |
khuang | 1:3b5be0ee5f0c | 407 | oled_dynamic_area.areaBuffer = (oled_pixel_t)AllocateDynamicArea( dynamic_area->width * dynamic_area->height ); |
khuang | 1:3b5be0ee5f0c | 408 | } |
khuang | 1:3b5be0ee5f0c | 409 | else if( |
khuang | 1:3b5be0ee5f0c | 410 | ( dynamic_area->height != oled_dynamic_area.height ) || |
khuang | 1:3b5be0ee5f0c | 411 | ( dynamic_area->width != oled_dynamic_area.width ) |
khuang | 1:3b5be0ee5f0c | 412 | ) |
khuang | 1:3b5be0ee5f0c | 413 | { |
khuang | 1:3b5be0ee5f0c | 414 | DestroyDynamicArea(); |
khuang | 1:3b5be0ee5f0c | 415 | oled_dynamic_area.areaBuffer = (oled_pixel_t)AllocateDynamicArea( dynamic_area->width * dynamic_area->height ); |
khuang | 1:3b5be0ee5f0c | 416 | } |
khuang | 1:3b5be0ee5f0c | 417 | |
khuang | 1:3b5be0ee5f0c | 418 | oled_dynamic_area.xCrd = dynamic_area->xCrd; |
khuang | 1:3b5be0ee5f0c | 419 | oled_dynamic_area.yCrd = dynamic_area->yCrd; |
khuang | 1:3b5be0ee5f0c | 420 | oled_dynamic_area.width = dynamic_area->width; |
khuang | 1:3b5be0ee5f0c | 421 | oled_dynamic_area.height = dynamic_area->height; |
khuang | 1:3b5be0ee5f0c | 422 | } |
khuang | 1:3b5be0ee5f0c | 423 | |
khuang | 1:3b5be0ee5f0c | 424 | |
khuang | 1:3b5be0ee5f0c | 425 | void SSD1351::DestroyDynamicArea() |
khuang | 1:3b5be0ee5f0c | 426 | { |
khuang | 1:3b5be0ee5f0c | 427 | if ( NULL != oled_dynamic_area.areaBuffer ) |
khuang | 1:3b5be0ee5f0c | 428 | { |
khuang | 1:3b5be0ee5f0c | 429 | DestroyDynamicArea( oled_dynamic_area.areaBuffer ); |
khuang | 1:3b5be0ee5f0c | 430 | oled_dynamic_area.areaBuffer = NULL; |
khuang | 1:3b5be0ee5f0c | 431 | } |
khuang | 1:3b5be0ee5f0c | 432 | } |
khuang | 1:3b5be0ee5f0c | 433 | |
khuang | 1:3b5be0ee5f0c | 434 | |
khuang | 1:3b5be0ee5f0c | 435 | void SSD1351::SetTextProperties(oled_text_properties_t *textProperties) |
khuang | 1:3b5be0ee5f0c | 436 | { |
khuang | 1:3b5be0ee5f0c | 437 | oled_text_properties.font = textProperties->font; |
khuang | 1:3b5be0ee5f0c | 438 | oled_text_properties.fontColor = textProperties->fontColor; |
khuang | 1:3b5be0ee5f0c | 439 | oled_text_properties.alignParam = textProperties->alignParam; |
khuang | 1:3b5be0ee5f0c | 440 | oled_text_properties.background = textProperties->background; |
khuang | 1:3b5be0ee5f0c | 441 | |
khuang | 1:3b5be0ee5f0c | 442 | SetFont( oled_text_properties.font, oled_text_properties.fontColor ); |
khuang | 1:3b5be0ee5f0c | 443 | } |
khuang | 1:3b5be0ee5f0c | 444 | |
khuang | 7:9961c525e249 | 445 | void SSD1351::GetTextProperties(oled_text_properties_t *textProperties) |
khuang | 7:9961c525e249 | 446 | { |
khuang | 7:9961c525e249 | 447 | textProperties->font = oled_text_properties.font; |
khuang | 7:9961c525e249 | 448 | textProperties->fontColor = oled_text_properties.fontColor; |
khuang | 7:9961c525e249 | 449 | textProperties->alignParam = oled_text_properties.alignParam; |
khuang | 7:9961c525e249 | 450 | textProperties->background = oled_text_properties.background; |
khuang | 7:9961c525e249 | 451 | } |
khuang | 1:3b5be0ee5f0c | 452 | |
khuang | 1:3b5be0ee5f0c | 453 | uint8_t SSD1351::GetTextWidth(const uint8_t* text) |
khuang | 1:3b5be0ee5f0c | 454 | { |
khuang | 1:3b5be0ee5f0c | 455 | uint8_t chrCnt = 0; |
khuang | 1:3b5be0ee5f0c | 456 | uint8_t text_width = 0; |
khuang | 1:3b5be0ee5f0c | 457 | |
khuang | 1:3b5be0ee5f0c | 458 | while ( 0 != text[chrCnt] ) |
khuang | 1:3b5be0ee5f0c | 459 | { |
khuang | 1:3b5be0ee5f0c | 460 | text_width += *( selectedFont + 8 + (uint16_t)( ( text[chrCnt++] - selectedFont_firstChar ) << 2 ) ); |
khuang | 7:9961c525e249 | 461 | /* make 1px space between chars */ |
khuang | 1:3b5be0ee5f0c | 462 | text_width++; |
khuang | 1:3b5be0ee5f0c | 463 | } |
khuang | 7:9961c525e249 | 464 | /* remove the final space */ |
khuang | 1:3b5be0ee5f0c | 465 | text_width--; |
khuang | 1:3b5be0ee5f0c | 466 | |
khuang | 1:3b5be0ee5f0c | 467 | return text_width; |
khuang | 1:3b5be0ee5f0c | 468 | } |
khuang | 1:3b5be0ee5f0c | 469 | |
khuang | 1:3b5be0ee5f0c | 470 | |
khuang | 1:3b5be0ee5f0c | 471 | |
khuang | 1:3b5be0ee5f0c | 472 | uint8_t SSD1351::CharCount(uint8_t width, const uint8_t* font, const uint8_t* text, uint8_t length) |
khuang | 1:3b5be0ee5f0c | 473 | { |
khuang | 1:3b5be0ee5f0c | 474 | uint8_t chrCnt = 0; |
khuang | 1:3b5be0ee5f0c | 475 | uint8_t text_width = 0; |
khuang | 1:3b5be0ee5f0c | 476 | uint16_t firstChar; |
khuang | 1:3b5be0ee5f0c | 477 | |
khuang | 1:3b5be0ee5f0c | 478 | firstChar = font[2] | ( (uint16_t)font[3] << 8 ); |
khuang | 1:3b5be0ee5f0c | 479 | |
khuang | 1:3b5be0ee5f0c | 480 | while ( chrCnt < length ) |
khuang | 1:3b5be0ee5f0c | 481 | { |
khuang | 1:3b5be0ee5f0c | 482 | text_width += *( font + 8 + (uint16_t)( ( text[chrCnt++] - firstChar ) << 2 ) ); |
khuang | 1:3b5be0ee5f0c | 483 | if(text_width > width) |
khuang | 1:3b5be0ee5f0c | 484 | { |
khuang | 1:3b5be0ee5f0c | 485 | chrCnt--; |
khuang | 1:3b5be0ee5f0c | 486 | break; |
khuang | 1:3b5be0ee5f0c | 487 | } |
khuang | 7:9961c525e249 | 488 | /* make 1px space between chars */ |
khuang | 1:3b5be0ee5f0c | 489 | text_width++; |
khuang | 1:3b5be0ee5f0c | 490 | } |
khuang | 1:3b5be0ee5f0c | 491 | |
khuang | 1:3b5be0ee5f0c | 492 | return chrCnt; |
khuang | 1:3b5be0ee5f0c | 493 | } |
khuang | 1:3b5be0ee5f0c | 494 | |
khuang | 1:3b5be0ee5f0c | 495 | |
khuang | 1:3b5be0ee5f0c | 496 | |
khuang | 1:3b5be0ee5f0c | 497 | |
khuang | 6:0060ffa3f4dc | 498 | oled_status_t SSD1351::AddText( const uint8_t* text,int8_t xCrd, int8_t yCrd ) |
khuang | 1:3b5be0ee5f0c | 499 | { |
khuang | 1:3b5be0ee5f0c | 500 | uint16_t |
khuang | 1:3b5be0ee5f0c | 501 | chrCnt = 0; |
khuang | 1:3b5be0ee5f0c | 502 | oled_pixel_t |
khuang | 1:3b5be0ee5f0c | 503 | chrBuf = NULL; |
khuang | 1:3b5be0ee5f0c | 504 | |
khuang | 1:3b5be0ee5f0c | 505 | uint8_t |
khuang | 1:3b5be0ee5f0c | 506 | currentChar_x = 0, |
khuang | 1:3b5be0ee5f0c | 507 | currentChar_y = 0; |
khuang | 1:3b5be0ee5f0c | 508 | |
khuang | 1:3b5be0ee5f0c | 509 | uint8_t |
khuang | 1:3b5be0ee5f0c | 510 | text_height = 0, |
khuang | 1:3b5be0ee5f0c | 511 | text_width = 0; |
khuang | 1:3b5be0ee5f0c | 512 | |
khuang | 1:3b5be0ee5f0c | 513 | text_width = GetTextWidth(text); |
khuang | 1:3b5be0ee5f0c | 514 | |
khuang | 7:9961c525e249 | 515 | /* |
khuang | 1:3b5be0ee5f0c | 516 | * set default values, if necessary |
khuang | 1:3b5be0ee5f0c | 517 | */ |
khuang | 1:3b5be0ee5f0c | 518 | |
khuang | 1:3b5be0ee5f0c | 519 | text_height = selectedFont_height; |
khuang | 1:3b5be0ee5f0c | 520 | oled_dynamic_area_t textArea; |
khuang | 1:3b5be0ee5f0c | 521 | |
khuang | 1:3b5be0ee5f0c | 522 | textArea.width = text_width; |
khuang | 1:3b5be0ee5f0c | 523 | textArea.height = text_height; |
khuang | 1:3b5be0ee5f0c | 524 | textArea.xCrd = xCrd; |
khuang | 1:3b5be0ee5f0c | 525 | textArea.yCrd = yCrd; |
khuang | 1:3b5be0ee5f0c | 526 | SetDynamicArea(&textArea); |
khuang | 1:3b5be0ee5f0c | 527 | |
khuang | 1:3b5be0ee5f0c | 528 | currentChar_y = ( oled_dynamic_area.height - text_height ) >> 1; |
khuang | 1:3b5be0ee5f0c | 529 | |
khuang | 1:3b5be0ee5f0c | 530 | switch ( oled_text_properties.alignParam & OLED_TEXT_HALIGN_MASK ) |
khuang | 1:3b5be0ee5f0c | 531 | { |
khuang | 1:3b5be0ee5f0c | 532 | case OLED_TEXT_ALIGN_LEFT: |
khuang | 1:3b5be0ee5f0c | 533 | { |
khuang | 1:3b5be0ee5f0c | 534 | currentChar_x = 0; |
khuang | 1:3b5be0ee5f0c | 535 | break; |
khuang | 1:3b5be0ee5f0c | 536 | } |
khuang | 1:3b5be0ee5f0c | 537 | |
khuang | 1:3b5be0ee5f0c | 538 | case OLED_TEXT_ALIGN_RIGHT: |
khuang | 1:3b5be0ee5f0c | 539 | { |
khuang | 1:3b5be0ee5f0c | 540 | currentChar_x = ( oled_dynamic_area.width - text_width ); |
khuang | 1:3b5be0ee5f0c | 541 | break; |
khuang | 1:3b5be0ee5f0c | 542 | } |
khuang | 1:3b5be0ee5f0c | 543 | |
khuang | 1:3b5be0ee5f0c | 544 | case OLED_TEXT_ALIGN_CENTER: |
khuang | 1:3b5be0ee5f0c | 545 | { |
khuang | 1:3b5be0ee5f0c | 546 | currentChar_x += ( oled_dynamic_area.width - text_width ) >> 1 ; |
khuang | 1:3b5be0ee5f0c | 547 | break; |
khuang | 1:3b5be0ee5f0c | 548 | } |
khuang | 1:3b5be0ee5f0c | 549 | |
khuang | 1:3b5be0ee5f0c | 550 | case OLED_TEXT_ALIGN_NONE: |
khuang | 1:3b5be0ee5f0c | 551 | { |
khuang | 1:3b5be0ee5f0c | 552 | break; |
khuang | 1:3b5be0ee5f0c | 553 | } |
khuang | 1:3b5be0ee5f0c | 554 | |
khuang | 1:3b5be0ee5f0c | 555 | default: {} |
khuang | 1:3b5be0ee5f0c | 556 | } |
khuang | 1:3b5be0ee5f0c | 557 | |
khuang | 1:3b5be0ee5f0c | 558 | if ( CreateTextBackground() != OLED_STATUS_SUCCESS ) |
khuang | 1:3b5be0ee5f0c | 559 | { |
khuang | 1:3b5be0ee5f0c | 560 | return OLED_STATUS_ERROR; |
khuang | 1:3b5be0ee5f0c | 561 | } |
khuang | 1:3b5be0ee5f0c | 562 | |
khuang | 7:9961c525e249 | 563 | /* |
khuang | 1:3b5be0ee5f0c | 564 | * write the characters into designated space, one by one |
khuang | 1:3b5be0ee5f0c | 565 | */ |
khuang | 1:3b5be0ee5f0c | 566 | |
khuang | 1:3b5be0ee5f0c | 567 | chrCnt = 0; |
khuang | 1:3b5be0ee5f0c | 568 | while ( 0 != text[chrCnt] ) |
khuang | 1:3b5be0ee5f0c | 569 | { |
khuang | 1:3b5be0ee5f0c | 570 | WriteCharToBuf( text[chrCnt++], &chrBuf ); |
khuang | 1:3b5be0ee5f0c | 571 | |
khuang | 1:3b5be0ee5f0c | 572 | if ( NULL == chrBuf ) |
khuang | 1:3b5be0ee5f0c | 573 | { |
khuang | 1:3b5be0ee5f0c | 574 | return OLED_STATUS_INIT_ERROR; |
khuang | 1:3b5be0ee5f0c | 575 | } |
khuang | 1:3b5be0ee5f0c | 576 | |
khuang | 1:3b5be0ee5f0c | 577 | else |
khuang | 1:3b5be0ee5f0c | 578 | { |
khuang | 1:3b5be0ee5f0c | 579 | if ( |
khuang | 1:3b5be0ee5f0c | 580 | ( ( currentChar_x + currentChar_width ) > oled_dynamic_area.width ) |
khuang | 1:3b5be0ee5f0c | 581 | || ( ( currentChar_y + currentChar_height ) > oled_dynamic_area.height ) |
khuang | 1:3b5be0ee5f0c | 582 | ) |
khuang | 1:3b5be0ee5f0c | 583 | { |
khuang | 1:3b5be0ee5f0c | 584 | DestroyDynamicArea( chrBuf ); |
khuang | 1:3b5be0ee5f0c | 585 | chrBuf = NULL; |
khuang | 1:3b5be0ee5f0c | 586 | return OLED_STATUS_ERROR; |
khuang | 1:3b5be0ee5f0c | 587 | } |
khuang | 1:3b5be0ee5f0c | 588 | |
khuang | 7:9961c525e249 | 589 | /* copy data */ |
khuang | 1:3b5be0ee5f0c | 590 | oled_pixel_t |
khuang | 1:3b5be0ee5f0c | 591 | copyAddr = oled_dynamic_area.areaBuffer + ( currentChar_y * oled_dynamic_area.width + currentChar_x ); |
khuang | 1:3b5be0ee5f0c | 592 | |
khuang | 1:3b5be0ee5f0c | 593 | AddCharToTextArea( chrBuf, currentChar_width, currentChar_height, copyAddr, oled_dynamic_area.width ); |
khuang | 1:3b5be0ee5f0c | 594 | |
khuang | 1:3b5be0ee5f0c | 595 | currentChar_x += ( currentChar_width+1 ); |
khuang | 1:3b5be0ee5f0c | 596 | currentChar_y += 0; |
khuang | 1:3b5be0ee5f0c | 597 | |
khuang | 1:3b5be0ee5f0c | 598 | DestroyDynamicArea( chrBuf ); |
khuang | 1:3b5be0ee5f0c | 599 | chrBuf = NULL; |
khuang | 1:3b5be0ee5f0c | 600 | } |
khuang | 1:3b5be0ee5f0c | 601 | } |
khuang | 1:3b5be0ee5f0c | 602 | |
khuang | 1:3b5be0ee5f0c | 603 | UpdateBuffer( |
khuang | 1:3b5be0ee5f0c | 604 | oled_dynamic_area.xCrd, |
khuang | 1:3b5be0ee5f0c | 605 | oled_dynamic_area.yCrd, |
khuang | 1:3b5be0ee5f0c | 606 | oled_dynamic_area.width, |
khuang | 1:3b5be0ee5f0c | 607 | oled_dynamic_area.height, |
khuang | 1:3b5be0ee5f0c | 608 | (const uint8_t*)oled_dynamic_area.areaBuffer |
khuang | 1:3b5be0ee5f0c | 609 | ); |
khuang | 1:3b5be0ee5f0c | 610 | |
khuang | 1:3b5be0ee5f0c | 611 | return OLED_STATUS_SUCCESS; |
khuang | 1:3b5be0ee5f0c | 612 | } |
khuang | 1:3b5be0ee5f0c | 613 | |
khuang | 1:3b5be0ee5f0c | 614 | |
khuang | 1:3b5be0ee5f0c | 615 | oled_status_t SSD1351::AddText( const uint8_t* text) |
khuang | 1:3b5be0ee5f0c | 616 | { |
khuang | 1:3b5be0ee5f0c | 617 | uint16_t |
khuang | 1:3b5be0ee5f0c | 618 | chrCnt = 0; |
khuang | 1:3b5be0ee5f0c | 619 | oled_pixel_t |
khuang | 1:3b5be0ee5f0c | 620 | chrBuf = NULL; |
khuang | 1:3b5be0ee5f0c | 621 | |
khuang | 1:3b5be0ee5f0c | 622 | uint8_t |
khuang | 1:3b5be0ee5f0c | 623 | currentChar_x = 0, |
khuang | 1:3b5be0ee5f0c | 624 | currentChar_y = 0; |
khuang | 1:3b5be0ee5f0c | 625 | |
khuang | 1:3b5be0ee5f0c | 626 | uint8_t |
khuang | 1:3b5be0ee5f0c | 627 | text_height = 0, |
khuang | 1:3b5be0ee5f0c | 628 | text_width = 0; |
khuang | 1:3b5be0ee5f0c | 629 | |
khuang | 1:3b5be0ee5f0c | 630 | text_width = GetTextWidth(text); |
khuang | 1:3b5be0ee5f0c | 631 | |
khuang | 1:3b5be0ee5f0c | 632 | /** |
khuang | 1:3b5be0ee5f0c | 633 | * set default values, if necessary |
khuang | 1:3b5be0ee5f0c | 634 | */ |
khuang | 1:3b5be0ee5f0c | 635 | |
khuang | 1:3b5be0ee5f0c | 636 | text_height = selectedFont_height; |
khuang | 1:3b5be0ee5f0c | 637 | |
khuang | 8:ae5fad429790 | 638 | /* Disable this for now.Generated Fontwidth supposedly a lot wider than it really is*/ |
khuang | 8:ae5fad429790 | 639 | #if 0 |
khuang | 1:3b5be0ee5f0c | 640 | if (( oled_dynamic_area.width < text_width )||( oled_dynamic_area.height < text_height )) |
khuang | 1:3b5be0ee5f0c | 641 | { |
khuang | 1:3b5be0ee5f0c | 642 | oled_dynamic_area_t textArea; |
khuang | 1:3b5be0ee5f0c | 643 | textArea.width = text_width; |
khuang | 1:3b5be0ee5f0c | 644 | textArea.height = text_height; |
khuang | 1:3b5be0ee5f0c | 645 | SetDynamicArea(&textArea); |
khuang | 1:3b5be0ee5f0c | 646 | } |
khuang | 8:ae5fad429790 | 647 | #endif |
khuang | 1:3b5be0ee5f0c | 648 | |
khuang | 1:3b5be0ee5f0c | 649 | currentChar_y = ( oled_dynamic_area.height - text_height ) >> 1; |
khuang | 1:3b5be0ee5f0c | 650 | |
khuang | 1:3b5be0ee5f0c | 651 | switch ( oled_text_properties.alignParam & OLED_TEXT_HALIGN_MASK ) |
khuang | 1:3b5be0ee5f0c | 652 | { |
khuang | 1:3b5be0ee5f0c | 653 | case OLED_TEXT_ALIGN_LEFT: |
khuang | 1:3b5be0ee5f0c | 654 | { |
khuang | 1:3b5be0ee5f0c | 655 | currentChar_x = 0; |
khuang | 1:3b5be0ee5f0c | 656 | break; |
khuang | 1:3b5be0ee5f0c | 657 | } |
khuang | 1:3b5be0ee5f0c | 658 | |
khuang | 1:3b5be0ee5f0c | 659 | case OLED_TEXT_ALIGN_RIGHT: |
khuang | 1:3b5be0ee5f0c | 660 | { |
khuang | 1:3b5be0ee5f0c | 661 | currentChar_x = ( oled_dynamic_area.width - text_width ); |
khuang | 1:3b5be0ee5f0c | 662 | break; |
khuang | 1:3b5be0ee5f0c | 663 | } |
khuang | 1:3b5be0ee5f0c | 664 | |
khuang | 1:3b5be0ee5f0c | 665 | case OLED_TEXT_ALIGN_CENTER: |
khuang | 1:3b5be0ee5f0c | 666 | { |
khuang | 1:3b5be0ee5f0c | 667 | currentChar_x += ( oled_dynamic_area.width - text_width ) >> 1 ; |
khuang | 1:3b5be0ee5f0c | 668 | break; |
khuang | 1:3b5be0ee5f0c | 669 | } |
khuang | 1:3b5be0ee5f0c | 670 | |
khuang | 1:3b5be0ee5f0c | 671 | case OLED_TEXT_ALIGN_NONE: |
khuang | 1:3b5be0ee5f0c | 672 | { |
khuang | 1:3b5be0ee5f0c | 673 | break; |
khuang | 1:3b5be0ee5f0c | 674 | } |
khuang | 1:3b5be0ee5f0c | 675 | |
khuang | 1:3b5be0ee5f0c | 676 | default: {} |
khuang | 1:3b5be0ee5f0c | 677 | } |
khuang | 1:3b5be0ee5f0c | 678 | |
khuang | 1:3b5be0ee5f0c | 679 | if ( CreateTextBackground() != OLED_STATUS_SUCCESS ) |
khuang | 1:3b5be0ee5f0c | 680 | { |
khuang | 1:3b5be0ee5f0c | 681 | return OLED_STATUS_ERROR; |
khuang | 1:3b5be0ee5f0c | 682 | } |
khuang | 1:3b5be0ee5f0c | 683 | |
khuang | 1:3b5be0ee5f0c | 684 | /** |
khuang | 1:3b5be0ee5f0c | 685 | * write the characters into designated space, one by one |
khuang | 1:3b5be0ee5f0c | 686 | */ |
khuang | 1:3b5be0ee5f0c | 687 | |
khuang | 1:3b5be0ee5f0c | 688 | chrCnt = 0; |
khuang | 1:3b5be0ee5f0c | 689 | while ( 0 != text[chrCnt] ) |
khuang | 1:3b5be0ee5f0c | 690 | { |
khuang | 1:3b5be0ee5f0c | 691 | WriteCharToBuf( text[chrCnt++], &chrBuf ); |
khuang | 1:3b5be0ee5f0c | 692 | |
khuang | 1:3b5be0ee5f0c | 693 | if ( NULL == chrBuf ) |
khuang | 1:3b5be0ee5f0c | 694 | { |
khuang | 1:3b5be0ee5f0c | 695 | return OLED_STATUS_INIT_ERROR; |
khuang | 1:3b5be0ee5f0c | 696 | } |
khuang | 1:3b5be0ee5f0c | 697 | |
khuang | 1:3b5be0ee5f0c | 698 | else |
khuang | 1:3b5be0ee5f0c | 699 | { |
khuang | 1:3b5be0ee5f0c | 700 | if ( |
khuang | 1:3b5be0ee5f0c | 701 | ( ( currentChar_x + currentChar_width ) > oled_dynamic_area.width ) |
khuang | 1:3b5be0ee5f0c | 702 | || ( ( currentChar_y + currentChar_height ) > oled_dynamic_area.height ) |
khuang | 1:3b5be0ee5f0c | 703 | ) |
khuang | 1:3b5be0ee5f0c | 704 | { |
khuang | 1:3b5be0ee5f0c | 705 | DestroyDynamicArea( chrBuf ); |
khuang | 1:3b5be0ee5f0c | 706 | chrBuf = NULL; |
khuang | 1:3b5be0ee5f0c | 707 | return OLED_STATUS_ERROR; |
khuang | 1:3b5be0ee5f0c | 708 | } |
khuang | 1:3b5be0ee5f0c | 709 | |
khuang | 7:9961c525e249 | 710 | /* copy data */ |
khuang | 1:3b5be0ee5f0c | 711 | oled_pixel_t |
khuang | 1:3b5be0ee5f0c | 712 | copyAddr = oled_dynamic_area.areaBuffer + ( currentChar_y * oled_dynamic_area.width + currentChar_x ); |
khuang | 1:3b5be0ee5f0c | 713 | |
khuang | 1:3b5be0ee5f0c | 714 | AddCharToTextArea( chrBuf, currentChar_width, currentChar_height, copyAddr, oled_dynamic_area.width ); |
khuang | 1:3b5be0ee5f0c | 715 | |
khuang | 1:3b5be0ee5f0c | 716 | currentChar_x += ( currentChar_width+1 ); |
khuang | 1:3b5be0ee5f0c | 717 | currentChar_y += 0; |
khuang | 1:3b5be0ee5f0c | 718 | |
khuang | 1:3b5be0ee5f0c | 719 | DestroyDynamicArea( chrBuf ); |
khuang | 1:3b5be0ee5f0c | 720 | chrBuf = NULL; |
khuang | 1:3b5be0ee5f0c | 721 | } |
khuang | 1:3b5be0ee5f0c | 722 | } |
khuang | 1:3b5be0ee5f0c | 723 | |
khuang | 1:3b5be0ee5f0c | 724 | UpdateBuffer( |
khuang | 1:3b5be0ee5f0c | 725 | oled_dynamic_area.xCrd, |
khuang | 1:3b5be0ee5f0c | 726 | oled_dynamic_area.yCrd, |
khuang | 1:3b5be0ee5f0c | 727 | oled_dynamic_area.width, |
khuang | 1:3b5be0ee5f0c | 728 | oled_dynamic_area.height, |
khuang | 1:3b5be0ee5f0c | 729 | (const uint8_t*)oled_dynamic_area.areaBuffer |
khuang | 1:3b5be0ee5f0c | 730 | ); |
khuang | 1:3b5be0ee5f0c | 731 | |
khuang | 1:3b5be0ee5f0c | 732 | return OLED_STATUS_SUCCESS; |
khuang | 1:3b5be0ee5f0c | 733 | } |
khuang | 1:3b5be0ee5f0c | 734 | |
khuang | 1:3b5be0ee5f0c | 735 | |
khuang | 1:3b5be0ee5f0c | 736 | |
khuang | 1:3b5be0ee5f0c | 737 | oled_status_t SSD1351::DrawText( const uint8_t* text) |
khuang | 1:3b5be0ee5f0c | 738 | { |
khuang | 1:3b5be0ee5f0c | 739 | |
khuang | 1:3b5be0ee5f0c | 740 | if ( NULL == text ) |
khuang | 1:3b5be0ee5f0c | 741 | { |
khuang | 1:3b5be0ee5f0c | 742 | return OLED_STATUS_ERROR; |
khuang | 1:3b5be0ee5f0c | 743 | } |
khuang | 1:3b5be0ee5f0c | 744 | |
khuang | 1:3b5be0ee5f0c | 745 | AddText(text); |
khuang | 7:9961c525e249 | 746 | /* set the locations */ |
khuang | 1:3b5be0ee5f0c | 747 | SetBorders( oled_dynamic_area.xCrd, oled_dynamic_area.yCrd, oled_dynamic_area.width, oled_dynamic_area.height ); |
khuang | 7:9961c525e249 | 748 | /* fill the GRAM */ |
khuang | 1:3b5be0ee5f0c | 749 | SendData( (const uint8_t*)oled_dynamic_area.areaBuffer, oled_dynamic_area.width * oled_dynamic_area.height * OLED_BYTES_PER_PIXEL ); |
khuang | 1:3b5be0ee5f0c | 750 | |
khuang | 7:9961c525e249 | 751 | //free( currentTextAreaImage ); |
khuang | 1:3b5be0ee5f0c | 752 | return OLED_STATUS_SUCCESS; |
khuang | 1:3b5be0ee5f0c | 753 | } |
khuang | 1:3b5be0ee5f0c | 754 | |
khuang | 1:3b5be0ee5f0c | 755 | |
khuang | 1:3b5be0ee5f0c | 756 | void SSD1351::GetImageDimensions(uint8_t *width, uint8_t *height, const uint8_t* image) |
khuang | 1:3b5be0ee5f0c | 757 | { |
khuang | 1:3b5be0ee5f0c | 758 | *height = image[2] + (image[3] << 8); |
khuang | 1:3b5be0ee5f0c | 759 | *width = image[4] + (image[5] << 8); |
khuang | 1:3b5be0ee5f0c | 760 | } |
khuang | 1:3b5be0ee5f0c | 761 | |
khuang | 1:3b5be0ee5f0c | 762 | |
khuang | 1:3b5be0ee5f0c | 763 | oled_status_t SSD1351::AddImage ( const uint8_t* image ) |
khuang | 1:3b5be0ee5f0c | 764 | { |
khuang | 1:3b5be0ee5f0c | 765 | oled_status_t |
khuang | 1:3b5be0ee5f0c | 766 | status = OLED_STATUS_SUCCESS; |
khuang | 1:3b5be0ee5f0c | 767 | |
khuang | 7:9961c525e249 | 768 | /* check the bounds */ |
khuang | 1:3b5be0ee5f0c | 769 | if AreCoordsNotValid( oled_dynamic_area.xCrd, oled_dynamic_area.yCrd, oled_dynamic_area.width, oled_dynamic_area.height ) |
khuang | 1:3b5be0ee5f0c | 770 | { |
khuang | 1:3b5be0ee5f0c | 771 | status = OLED_STATUS_INIT_ERROR; |
khuang | 1:3b5be0ee5f0c | 772 | } |
khuang | 1:3b5be0ee5f0c | 773 | |
khuang | 1:3b5be0ee5f0c | 774 | else |
khuang | 1:3b5be0ee5f0c | 775 | { |
khuang | 1:3b5be0ee5f0c | 776 | Swap( (oled_pixel_t)oled_dynamic_area.areaBuffer, BMP_SkipHeader(image), oled_dynamic_area.width*oled_dynamic_area.height ); |
khuang | 1:3b5be0ee5f0c | 777 | |
khuang | 7:9961c525e249 | 778 | /* update the main screen buffer */ |
khuang | 1:3b5be0ee5f0c | 779 | UpdateBuffer( oled_dynamic_area.xCrd, oled_dynamic_area.yCrd, oled_dynamic_area.width, oled_dynamic_area.height, (const uint8_t *)oled_dynamic_area.areaBuffer ); |
khuang | 1:3b5be0ee5f0c | 780 | } |
khuang | 1:3b5be0ee5f0c | 781 | |
khuang | 1:3b5be0ee5f0c | 782 | return status; |
khuang | 1:3b5be0ee5f0c | 783 | } |
khuang | 1:3b5be0ee5f0c | 784 | |
khuang | 1:3b5be0ee5f0c | 785 | |
khuang | 6:0060ffa3f4dc | 786 | oled_status_t SSD1351::AddImage ( const uint8_t* image, int8_t xCrd, int8_t yCrd ) |
khuang | 1:3b5be0ee5f0c | 787 | { |
khuang | 1:3b5be0ee5f0c | 788 | oled_status_t |
khuang | 1:3b5be0ee5f0c | 789 | status = OLED_STATUS_SUCCESS; |
khuang | 1:3b5be0ee5f0c | 790 | |
khuang | 1:3b5be0ee5f0c | 791 | oled_dynamic_area_t image_dynamicArea; |
khuang | 1:3b5be0ee5f0c | 792 | |
khuang | 1:3b5be0ee5f0c | 793 | image_dynamicArea.xCrd = xCrd; |
khuang | 1:3b5be0ee5f0c | 794 | image_dynamicArea.yCrd = yCrd; |
khuang | 1:3b5be0ee5f0c | 795 | |
khuang | 1:3b5be0ee5f0c | 796 | GetImageDimensions(&image_dynamicArea.width, &image_dynamicArea.height, image); |
khuang | 1:3b5be0ee5f0c | 797 | SetDynamicArea(&image_dynamicArea); |
khuang | 1:3b5be0ee5f0c | 798 | |
khuang | 7:9961c525e249 | 799 | /* check the bounds */ |
khuang | 1:3b5be0ee5f0c | 800 | if AreCoordsNotValid( oled_dynamic_area.xCrd, oled_dynamic_area.yCrd, oled_dynamic_area.width, oled_dynamic_area.height ) |
khuang | 1:3b5be0ee5f0c | 801 | { |
khuang | 1:3b5be0ee5f0c | 802 | status = OLED_STATUS_INIT_ERROR; |
khuang | 1:3b5be0ee5f0c | 803 | } |
khuang | 1:3b5be0ee5f0c | 804 | |
khuang | 1:3b5be0ee5f0c | 805 | else |
khuang | 1:3b5be0ee5f0c | 806 | { |
khuang | 1:3b5be0ee5f0c | 807 | Swap( (oled_pixel_t)oled_dynamic_area.areaBuffer, BMP_SkipHeader(image), oled_dynamic_area.width*oled_dynamic_area.height ); |
khuang | 1:3b5be0ee5f0c | 808 | |
khuang | 7:9961c525e249 | 809 | /* update the main screen buffer */ |
khuang | 1:3b5be0ee5f0c | 810 | UpdateBuffer( oled_dynamic_area.xCrd, oled_dynamic_area.yCrd, oled_dynamic_area.width, oled_dynamic_area.height, (const uint8_t *)oled_dynamic_area.areaBuffer ); |
khuang | 1:3b5be0ee5f0c | 811 | } |
khuang | 1:3b5be0ee5f0c | 812 | |
khuang | 1:3b5be0ee5f0c | 813 | return status; |
khuang | 1:3b5be0ee5f0c | 814 | } |
khuang | 1:3b5be0ee5f0c | 815 | |
khuang | 1:3b5be0ee5f0c | 816 | |
khuang | 1:3b5be0ee5f0c | 817 | |
khuang | 1:3b5be0ee5f0c | 818 | oled_status_t SSD1351::DrawImage ( const uint8_t* image ) |
khuang | 1:3b5be0ee5f0c | 819 | { |
khuang | 1:3b5be0ee5f0c | 820 | |
khuang | 1:3b5be0ee5f0c | 821 | oled_status_t |
khuang | 1:3b5be0ee5f0c | 822 | status = OLED_STATUS_SUCCESS; |
khuang | 1:3b5be0ee5f0c | 823 | |
khuang | 1:3b5be0ee5f0c | 824 | status = AddImage( image ); |
khuang | 1:3b5be0ee5f0c | 825 | |
khuang | 7:9961c525e249 | 826 | /* set the locations */ |
khuang | 1:3b5be0ee5f0c | 827 | SetBorders( oled_dynamic_area.xCrd, oled_dynamic_area.yCrd, oled_dynamic_area.width, oled_dynamic_area.height ); |
khuang | 1:3b5be0ee5f0c | 828 | |
khuang | 7:9961c525e249 | 829 | /* fill the GRAM */ |
khuang | 1:3b5be0ee5f0c | 830 | SendData( (const uint8_t*)oled_dynamic_area.areaBuffer, oled_dynamic_area.width * oled_dynamic_area.height * OLED_BYTES_PER_PIXEL ); |
khuang | 1:3b5be0ee5f0c | 831 | |
khuang | 1:3b5be0ee5f0c | 832 | |
khuang | 1:3b5be0ee5f0c | 833 | return status; |
khuang | 1:3b5be0ee5f0c | 834 | } |
khuang | 1:3b5be0ee5f0c | 835 | |
khuang | 6:0060ffa3f4dc | 836 | oled_status_t SSD1351::DrawImage ( const uint8_t* image, int8_t xCrd, int8_t yCrd ) |
khuang | 1:3b5be0ee5f0c | 837 | { |
khuang | 1:3b5be0ee5f0c | 838 | |
khuang | 1:3b5be0ee5f0c | 839 | oled_status_t |
khuang | 1:3b5be0ee5f0c | 840 | status = OLED_STATUS_SUCCESS; |
khuang | 1:3b5be0ee5f0c | 841 | |
khuang | 1:3b5be0ee5f0c | 842 | status = AddImage( image,xCrd,yCrd); |
khuang | 1:3b5be0ee5f0c | 843 | |
khuang | 7:9961c525e249 | 844 | /* set the locations */ |
khuang | 1:3b5be0ee5f0c | 845 | SetBorders( oled_dynamic_area.xCrd, oled_dynamic_area.yCrd, oled_dynamic_area.width, oled_dynamic_area.height ); |
khuang | 1:3b5be0ee5f0c | 846 | |
khuang | 7:9961c525e249 | 847 | /* fill the GRAM */ |
khuang | 1:3b5be0ee5f0c | 848 | SendData( (const uint8_t*)oled_dynamic_area.areaBuffer, oled_dynamic_area.width * oled_dynamic_area.height * OLED_BYTES_PER_PIXEL ); |
khuang | 1:3b5be0ee5f0c | 849 | |
khuang | 1:3b5be0ee5f0c | 850 | |
khuang | 1:3b5be0ee5f0c | 851 | return status; |
khuang | 1:3b5be0ee5f0c | 852 | } |
khuang | 1:3b5be0ee5f0c | 853 | |
khuang | 1:3b5be0ee5f0c | 854 | |
khuang | 1:3b5be0ee5f0c | 855 | |
khuang | 1:3b5be0ee5f0c | 856 | void SSD1351::DimScreenON() |
khuang | 1:3b5be0ee5f0c | 857 | { |
khuang | 1:3b5be0ee5f0c | 858 | for ( int i = 0; i < 16; i++ ) |
khuang | 1:3b5be0ee5f0c | 859 | { |
khuang | 2:fc06b5b5bf6a | 860 | SendCmd( OLED_CMD_CONTRASTMASTER, CMD_BYTE ); |
khuang | 2:fc06b5b5bf6a | 861 | SendCmd( 0xC0 | (0xF-i), DATA_BYTE ); |
khuang | 1:3b5be0ee5f0c | 862 | wait_ms(20); |
khuang | 7:9961c525e249 | 863 | // OSA_TimeDelay( 20 ); |
khuang | 1:3b5be0ee5f0c | 864 | } |
khuang | 1:3b5be0ee5f0c | 865 | } |
khuang | 1:3b5be0ee5f0c | 866 | |
khuang | 1:3b5be0ee5f0c | 867 | |
khuang | 1:3b5be0ee5f0c | 868 | void SSD1351::DimScreenOFF() |
khuang | 1:3b5be0ee5f0c | 869 | { |
khuang | 2:fc06b5b5bf6a | 870 | SendCmd( OLED_CMD_CONTRASTMASTER, CMD_BYTE ); |
khuang | 2:fc06b5b5bf6a | 871 | SendCmd( 0xC0 | 0xF, DATA_BYTE ); |
khuang | 1:3b5be0ee5f0c | 872 | } |
khuang | 1:3b5be0ee5f0c | 873 | |
khuang | 1:3b5be0ee5f0c | 874 | |
khuang | 1:3b5be0ee5f0c | 875 | |
khuang | 1:3b5be0ee5f0c | 876 | void SSD1351::Swap( |
khuang | 1:3b5be0ee5f0c | 877 | oled_pixel_t imgDst, |
khuang | 1:3b5be0ee5f0c | 878 | const uint8_t* imgSrc, |
khuang | 1:3b5be0ee5f0c | 879 | uint16_t imgSize |
khuang | 1:3b5be0ee5f0c | 880 | ) |
khuang | 1:3b5be0ee5f0c | 881 | { |
khuang | 1:3b5be0ee5f0c | 882 | for ( int var = 0; var < imgSize; var++ ) |
khuang | 1:3b5be0ee5f0c | 883 | { |
khuang | 1:3b5be0ee5f0c | 884 | *imgDst = *imgSrc << 8; |
khuang | 1:3b5be0ee5f0c | 885 | imgSrc++; |
khuang | 1:3b5be0ee5f0c | 886 | *imgDst |= *imgSrc; |
khuang | 1:3b5be0ee5f0c | 887 | imgDst++; |
khuang | 1:3b5be0ee5f0c | 888 | imgSrc++; |
khuang | 1:3b5be0ee5f0c | 889 | } |
khuang | 1:3b5be0ee5f0c | 890 | } |
khuang | 1:3b5be0ee5f0c | 891 | |
khuang | 1:3b5be0ee5f0c | 892 | |
khuang | 1:3b5be0ee5f0c | 893 | void SSD1351::PowerON() |
khuang | 1:3b5be0ee5f0c | 894 | { |
khuang | 1:3b5be0ee5f0c | 895 | power = 1; |
khuang | 1:3b5be0ee5f0c | 896 | } |
khuang | 1:3b5be0ee5f0c | 897 | |
khuang | 1:3b5be0ee5f0c | 898 | void SSD1351::PowerOFF() |
khuang | 1:3b5be0ee5f0c | 899 | { |
khuang | 1:3b5be0ee5f0c | 900 | power = 0; |
khuang | 1:3b5be0ee5f0c | 901 | } |
khuang | 1:3b5be0ee5f0c | 902 | |
tdh50 | 9:18d4eb6328eb | 903 | bool SSD1351::GetPower() |
tdh50 | 9:18d4eb6328eb | 904 | { |
tdh50 | 9:18d4eb6328eb | 905 | return power; |
tdh50 | 9:18d4eb6328eb | 906 | } |
khuang | 1:3b5be0ee5f0c | 907 | |
khuang | 7:9961c525e249 | 908 | /* Formerly Known as GuiDriver_UpdateScreen */ |
khuang | 1:3b5be0ee5f0c | 909 | void SSD1351::UpdateBuffer ( |
khuang | 6:0060ffa3f4dc | 910 | int8_t xCrd, |
khuang | 6:0060ffa3f4dc | 911 | int8_t yCrd, |
khuang | 1:3b5be0ee5f0c | 912 | uint8_t width, |
khuang | 1:3b5be0ee5f0c | 913 | uint8_t height, |
khuang | 1:3b5be0ee5f0c | 914 | const uint8_t* image |
khuang | 1:3b5be0ee5f0c | 915 | ) |
khuang | 1:3b5be0ee5f0c | 916 | { |
khuang | 7:9961c525e249 | 917 | /* copy data */ |
khuang | 1:3b5be0ee5f0c | 918 | oled_pixel_t |
khuang | 1:3b5be0ee5f0c | 919 | copyAddr = (oled_pixel_t)screenBuf + ( yCrd*OLED_SCREEN_WIDTH + xCrd ); |
khuang | 1:3b5be0ee5f0c | 920 | |
khuang | 1:3b5be0ee5f0c | 921 | for ( uint8_t i = 0; i < height; i++ ) |
khuang | 1:3b5be0ee5f0c | 922 | { |
khuang | 1:3b5be0ee5f0c | 923 | memcpy( (void*)copyAddr, (void*)image, width*OLED_BYTES_PER_PIXEL ); |
khuang | 1:3b5be0ee5f0c | 924 | copyAddr += OLED_SCREEN_WIDTH; |
khuang | 1:3b5be0ee5f0c | 925 | image += width*OLED_BYTES_PER_PIXEL; |
khuang | 1:3b5be0ee5f0c | 926 | } |
khuang | 1:3b5be0ee5f0c | 927 | } |
khuang | 1:3b5be0ee5f0c | 928 | |
khuang | 3:4121d3cd9f60 | 929 | |
khuang | 6:0060ffa3f4dc | 930 | oled_status_t SSD1351::Label ( const uint8_t* text,int8_t xCrd, int8_t yCrd ) |
khuang | 3:4121d3cd9f60 | 931 | { |
khuang | 3:4121d3cd9f60 | 932 | |
khuang | 3:4121d3cd9f60 | 933 | if ( NULL == text ) |
khuang | 3:4121d3cd9f60 | 934 | { |
khuang | 3:4121d3cd9f60 | 935 | return OLED_STATUS_ERROR; |
khuang | 3:4121d3cd9f60 | 936 | } |
khuang | 3:4121d3cd9f60 | 937 | |
khuang | 3:4121d3cd9f60 | 938 | AddText(text,xCrd,yCrd); |
khuang | 3:4121d3cd9f60 | 939 | |
khuang | 7:9961c525e249 | 940 | /* set the locations */ |
khuang | 3:4121d3cd9f60 | 941 | SetBorders( oled_dynamic_area.xCrd, oled_dynamic_area.yCrd, oled_dynamic_area.width, oled_dynamic_area.height ); |
khuang | 3:4121d3cd9f60 | 942 | |
khuang | 7:9961c525e249 | 943 | /* fill the GRAM */ |
khuang | 3:4121d3cd9f60 | 944 | SendData( (const uint8_t*)oled_dynamic_area.areaBuffer, oled_dynamic_area.width * oled_dynamic_area.height * OLED_BYTES_PER_PIXEL ); |
khuang | 3:4121d3cd9f60 | 945 | |
khuang | 7:9961c525e249 | 946 | //free( currentTextAreaImage ); |
khuang | 3:4121d3cd9f60 | 947 | return OLED_STATUS_SUCCESS; |
khuang | 3:4121d3cd9f60 | 948 | } |
khuang | 3:4121d3cd9f60 | 949 | |
khuang | 3:4121d3cd9f60 | 950 | |
khuang | 6:0060ffa3f4dc | 951 | oled_status_t SSD1351::TextBox(const uint8_t* text, int8_t xCrd, int8_t yCrd,uint8_t width,uint8_t height) |
khuang | 3:4121d3cd9f60 | 952 | { |
khuang | 3:4121d3cd9f60 | 953 | |
khuang | 3:4121d3cd9f60 | 954 | if ( NULL == text ) |
khuang | 3:4121d3cd9f60 | 955 | { |
khuang | 3:4121d3cd9f60 | 956 | return OLED_STATUS_ERROR; |
khuang | 3:4121d3cd9f60 | 957 | } |
khuang | 3:4121d3cd9f60 | 958 | |
khuang | 3:4121d3cd9f60 | 959 | oled_dynamic_area_t textArea; |
khuang | 3:4121d3cd9f60 | 960 | textArea.width = width; |
khuang | 3:4121d3cd9f60 | 961 | textArea.height = height; |
khuang | 3:4121d3cd9f60 | 962 | textArea.xCrd = xCrd; |
khuang | 3:4121d3cd9f60 | 963 | textArea.yCrd = yCrd; |
khuang | 3:4121d3cd9f60 | 964 | |
khuang | 3:4121d3cd9f60 | 965 | SetDynamicArea(&textArea); |
khuang | 3:4121d3cd9f60 | 966 | DrawText(text); |
khuang | 3:4121d3cd9f60 | 967 | |
khuang | 3:4121d3cd9f60 | 968 | return OLED_STATUS_SUCCESS; |
khuang | 3:4121d3cd9f60 | 969 | |
khuang | 3:4121d3cd9f60 | 970 | } |
khuang | 3:4121d3cd9f60 | 971 | |
khuang | 3:4121d3cd9f60 | 972 | |
khuang | 1:3b5be0ee5f0c | 973 | /* Internal Functions */ |
khuang | 1:3b5be0ee5f0c | 974 | |
khuang | 1:3b5be0ee5f0c | 975 | /** |
khuang | 1:3b5be0ee5f0c | 976 | * [transpose description] |
khuang | 1:3b5be0ee5f0c | 977 | * @param transImage Transposed Image |
khuang | 1:3b5be0ee5f0c | 978 | * @param image Source Image |
khuang | 1:3b5be0ee5f0c | 979 | * @param width Width to Transpose |
khuang | 1:3b5be0ee5f0c | 980 | * @param height Height to Transpose |
khuang | 1:3b5be0ee5f0c | 981 | */ |
khuang | 1:3b5be0ee5f0c | 982 | void SSD1351::Transpose( |
khuang | 1:3b5be0ee5f0c | 983 | oled_pixel_t transImage, |
khuang | 1:3b5be0ee5f0c | 984 | const oled_pixel_t image, |
khuang | 1:3b5be0ee5f0c | 985 | uint8_t width, |
khuang | 1:3b5be0ee5f0c | 986 | uint8_t height |
khuang | 1:3b5be0ee5f0c | 987 | ) |
khuang | 1:3b5be0ee5f0c | 988 | { |
khuang | 1:3b5be0ee5f0c | 989 | for ( uint8_t i = 0; i < height; i++ ) |
khuang | 1:3b5be0ee5f0c | 990 | { |
khuang | 1:3b5be0ee5f0c | 991 | for ( uint8_t j = 0; j < width ; j++ ) |
khuang | 1:3b5be0ee5f0c | 992 | { |
khuang | 1:3b5be0ee5f0c | 993 | transImage[ j*height + i ] = image[ i*width + j ]; |
khuang | 1:3b5be0ee5f0c | 994 | } |
khuang | 1:3b5be0ee5f0c | 995 | } |
khuang | 1:3b5be0ee5f0c | 996 | } |
khuang | 1:3b5be0ee5f0c | 997 | |
khuang | 1:3b5be0ee5f0c | 998 | |
khuang | 1:3b5be0ee5f0c | 999 | |
khuang | 1:3b5be0ee5f0c | 1000 | /** |
khuang | 1:3b5be0ee5f0c | 1001 | * TopDown Transition Effect for Image |
khuang | 1:3b5be0ee5f0c | 1002 | * @param image image to be transitioned |
khuang | 1:3b5be0ee5f0c | 1003 | * @param xCrd x coordinate of image |
khuang | 1:3b5be0ee5f0c | 1004 | * @param yCrd y coordinate of image |
khuang | 1:3b5be0ee5f0c | 1005 | * @param width width of image |
khuang | 1:3b5be0ee5f0c | 1006 | * @param height height of image |
khuang | 1:3b5be0ee5f0c | 1007 | * @return status flag |
khuang | 1:3b5be0ee5f0c | 1008 | */ |
khuang | 1:3b5be0ee5f0c | 1009 | oled_status_t SSD1351::TopDown( |
khuang | 1:3b5be0ee5f0c | 1010 | const uint8_t* image, |
khuang | 6:0060ffa3f4dc | 1011 | int8_t xCrd, |
khuang | 6:0060ffa3f4dc | 1012 | int8_t yCrd, |
khuang | 1:3b5be0ee5f0c | 1013 | uint8_t width, |
khuang | 1:3b5be0ee5f0c | 1014 | uint8_t height |
khuang | 1:3b5be0ee5f0c | 1015 | ) |
khuang | 1:3b5be0ee5f0c | 1016 | { |
khuang | 1:3b5be0ee5f0c | 1017 | uint16_t |
khuang | 1:3b5be0ee5f0c | 1018 | transStep = OLED_TRANSITION_STEP; |
khuang | 1:3b5be0ee5f0c | 1019 | |
khuang | 1:3b5be0ee5f0c | 1020 | uint16_t |
khuang | 1:3b5be0ee5f0c | 1021 | partImgSize = width*transStep; |
khuang | 1:3b5be0ee5f0c | 1022 | |
khuang | 1:3b5be0ee5f0c | 1023 | oled_status_t |
khuang | 1:3b5be0ee5f0c | 1024 | status = OLED_STATUS_SUCCESS; |
khuang | 1:3b5be0ee5f0c | 1025 | |
khuang | 1:3b5be0ee5f0c | 1026 | uint8_t* |
khuang | 1:3b5be0ee5f0c | 1027 | partImgPtr = (uint8_t*)image + ( height - transStep ) * ( width * OLED_BYTES_PER_PIXEL ); |
khuang | 1:3b5be0ee5f0c | 1028 | |
khuang | 1:3b5be0ee5f0c | 1029 | /** |
khuang | 1:3b5be0ee5f0c | 1030 | * set locations |
khuang | 1:3b5be0ee5f0c | 1031 | */ |
khuang | 1:3b5be0ee5f0c | 1032 | |
khuang | 1:3b5be0ee5f0c | 1033 | while (1) |
khuang | 1:3b5be0ee5f0c | 1034 | { |
khuang | 1:3b5be0ee5f0c | 1035 | SetBorders( xCrd, yCrd, width, height ); |
khuang | 1:3b5be0ee5f0c | 1036 | |
khuang | 1:3b5be0ee5f0c | 1037 | if ( partImgSize > width*height ) |
khuang | 1:3b5be0ee5f0c | 1038 | { |
khuang | 1:3b5be0ee5f0c | 1039 | SendData( (const uint8_t*)image, width*height*OLED_BYTES_PER_PIXEL ); |
khuang | 1:3b5be0ee5f0c | 1040 | break; |
khuang | 1:3b5be0ee5f0c | 1041 | } |
khuang | 1:3b5be0ee5f0c | 1042 | else |
khuang | 1:3b5be0ee5f0c | 1043 | { |
khuang | 1:3b5be0ee5f0c | 1044 | SendData( (const uint8_t*)partImgPtr, partImgSize * OLED_BYTES_PER_PIXEL ); |
khuang | 1:3b5be0ee5f0c | 1045 | } |
khuang | 1:3b5be0ee5f0c | 1046 | |
khuang | 1:3b5be0ee5f0c | 1047 | |
khuang | 1:3b5be0ee5f0c | 1048 | /** |
khuang | 1:3b5be0ee5f0c | 1049 | * update variables |
khuang | 1:3b5be0ee5f0c | 1050 | */ |
khuang | 1:3b5be0ee5f0c | 1051 | |
khuang | 1:3b5be0ee5f0c | 1052 | partImgPtr -= ( width * transStep ) * OLED_BYTES_PER_PIXEL; |
khuang | 1:3b5be0ee5f0c | 1053 | partImgSize += ( width * transStep ); |
khuang | 1:3b5be0ee5f0c | 1054 | transStep++; |
khuang | 1:3b5be0ee5f0c | 1055 | } |
khuang | 1:3b5be0ee5f0c | 1056 | |
khuang | 1:3b5be0ee5f0c | 1057 | return status; |
khuang | 1:3b5be0ee5f0c | 1058 | } |
khuang | 1:3b5be0ee5f0c | 1059 | |
khuang | 1:3b5be0ee5f0c | 1060 | /** |
khuang | 1:3b5be0ee5f0c | 1061 | * DownTop Transition Effect for Image |
khuang | 1:3b5be0ee5f0c | 1062 | * @param image image to be transitioned |
khuang | 1:3b5be0ee5f0c | 1063 | * @param xCrd x coordinate of image |
khuang | 1:3b5be0ee5f0c | 1064 | * @param yCrd y coordinate of image |
khuang | 1:3b5be0ee5f0c | 1065 | * @param width width of image |
khuang | 1:3b5be0ee5f0c | 1066 | * @param height height of image |
khuang | 1:3b5be0ee5f0c | 1067 | * @return status flag |
khuang | 1:3b5be0ee5f0c | 1068 | */ |
khuang | 1:3b5be0ee5f0c | 1069 | |
khuang | 1:3b5be0ee5f0c | 1070 | oled_status_t SSD1351::DownTop( |
khuang | 1:3b5be0ee5f0c | 1071 | const uint8_t* image, |
khuang | 6:0060ffa3f4dc | 1072 | int8_t xCrd, |
khuang | 6:0060ffa3f4dc | 1073 | int8_t yCrd, |
khuang | 1:3b5be0ee5f0c | 1074 | uint8_t width, |
khuang | 1:3b5be0ee5f0c | 1075 | uint8_t height |
khuang | 1:3b5be0ee5f0c | 1076 | ) |
khuang | 1:3b5be0ee5f0c | 1077 | { |
khuang | 1:3b5be0ee5f0c | 1078 | uint16_t |
khuang | 1:3b5be0ee5f0c | 1079 | transStep = OLED_TRANSITION_STEP; |
khuang | 1:3b5be0ee5f0c | 1080 | |
khuang | 1:3b5be0ee5f0c | 1081 | uint16_t |
khuang | 1:3b5be0ee5f0c | 1082 | partImgSize = width*transStep; |
khuang | 1:3b5be0ee5f0c | 1083 | |
khuang | 1:3b5be0ee5f0c | 1084 | oled_status_t |
khuang | 1:3b5be0ee5f0c | 1085 | status = OLED_STATUS_SUCCESS; |
khuang | 1:3b5be0ee5f0c | 1086 | |
khuang | 1:3b5be0ee5f0c | 1087 | uint8_t* |
khuang | 1:3b5be0ee5f0c | 1088 | partImgPtr = (uint8_t*)image; |
khuang | 1:3b5be0ee5f0c | 1089 | |
khuang | 1:3b5be0ee5f0c | 1090 | uint8_t |
khuang | 1:3b5be0ee5f0c | 1091 | yCrd_moving = ( yCrd + height ) - 1; |
khuang | 1:3b5be0ee5f0c | 1092 | |
khuang | 1:3b5be0ee5f0c | 1093 | /** |
khuang | 1:3b5be0ee5f0c | 1094 | * set locations |
khuang | 1:3b5be0ee5f0c | 1095 | */ |
khuang | 1:3b5be0ee5f0c | 1096 | |
khuang | 1:3b5be0ee5f0c | 1097 | while (1) |
khuang | 1:3b5be0ee5f0c | 1098 | { |
khuang | 1:3b5be0ee5f0c | 1099 | if ( |
khuang | 1:3b5be0ee5f0c | 1100 | ( partImgSize > OLED_SCREEN_SIZE ) |
khuang | 1:3b5be0ee5f0c | 1101 | || ( yCrd_moving < yCrd ) |
khuang | 1:3b5be0ee5f0c | 1102 | ) |
khuang | 1:3b5be0ee5f0c | 1103 | { |
khuang | 7:9961c525e249 | 1104 | /* draw full image */ |
khuang | 1:3b5be0ee5f0c | 1105 | SetBorders( xCrd, yCrd, width, height ); |
khuang | 1:3b5be0ee5f0c | 1106 | SendData( (const uint8_t*)image, width * height * OLED_BYTES_PER_PIXEL ); |
khuang | 1:3b5be0ee5f0c | 1107 | break; |
khuang | 1:3b5be0ee5f0c | 1108 | } |
khuang | 1:3b5be0ee5f0c | 1109 | |
khuang | 1:3b5be0ee5f0c | 1110 | else |
khuang | 1:3b5be0ee5f0c | 1111 | { |
khuang | 1:3b5be0ee5f0c | 1112 | SetBorders( xCrd, yCrd_moving, width, ( yCrd + height ) - yCrd_moving ); |
khuang | 1:3b5be0ee5f0c | 1113 | SendData( (const uint8_t*)partImgPtr, partImgSize * OLED_BYTES_PER_PIXEL ); |
khuang | 1:3b5be0ee5f0c | 1114 | } |
khuang | 1:3b5be0ee5f0c | 1115 | |
khuang | 1:3b5be0ee5f0c | 1116 | /** |
khuang | 1:3b5be0ee5f0c | 1117 | * update variables |
khuang | 1:3b5be0ee5f0c | 1118 | */ |
khuang | 1:3b5be0ee5f0c | 1119 | |
khuang | 1:3b5be0ee5f0c | 1120 | yCrd_moving -= transStep; |
khuang | 1:3b5be0ee5f0c | 1121 | partImgSize += ( width * transStep ); |
khuang | 1:3b5be0ee5f0c | 1122 | transStep++; |
khuang | 1:3b5be0ee5f0c | 1123 | } |
khuang | 1:3b5be0ee5f0c | 1124 | |
khuang | 1:3b5be0ee5f0c | 1125 | return status; |
khuang | 1:3b5be0ee5f0c | 1126 | } |
khuang | 1:3b5be0ee5f0c | 1127 | |
khuang | 1:3b5be0ee5f0c | 1128 | |
khuang | 1:3b5be0ee5f0c | 1129 | /** |
khuang | 1:3b5be0ee5f0c | 1130 | * LeftRight Transition Effect for Image |
khuang | 1:3b5be0ee5f0c | 1131 | * @param image image to be transitioned |
khuang | 1:3b5be0ee5f0c | 1132 | * @param xCrd x coordinate of image |
khuang | 1:3b5be0ee5f0c | 1133 | * @param yCrd y coordinate of image |
khuang | 1:3b5be0ee5f0c | 1134 | * @param width width of image |
khuang | 1:3b5be0ee5f0c | 1135 | * @param height height of image |
khuang | 1:3b5be0ee5f0c | 1136 | * @return status flag |
khuang | 1:3b5be0ee5f0c | 1137 | */ |
khuang | 1:3b5be0ee5f0c | 1138 | |
khuang | 1:3b5be0ee5f0c | 1139 | oled_status_t SSD1351::LeftRight( |
khuang | 1:3b5be0ee5f0c | 1140 | const uint8_t* image, |
khuang | 6:0060ffa3f4dc | 1141 | int8_t xCrd, |
khuang | 6:0060ffa3f4dc | 1142 | int8_t yCrd, |
khuang | 1:3b5be0ee5f0c | 1143 | uint8_t width, |
khuang | 1:3b5be0ee5f0c | 1144 | uint8_t height |
khuang | 1:3b5be0ee5f0c | 1145 | ) |
khuang | 1:3b5be0ee5f0c | 1146 | { |
khuang | 1:3b5be0ee5f0c | 1147 | oled_status_t |
khuang | 1:3b5be0ee5f0c | 1148 | status = OLED_STATUS_SUCCESS; |
khuang | 1:3b5be0ee5f0c | 1149 | |
khuang | 1:3b5be0ee5f0c | 1150 | oled_dynamic_area_t |
khuang | 1:3b5be0ee5f0c | 1151 | transImageArea = |
khuang | 1:3b5be0ee5f0c | 1152 | { |
khuang | 1:3b5be0ee5f0c | 1153 | .xCrd = 0, |
khuang | 1:3b5be0ee5f0c | 1154 | .yCrd = 0, |
khuang | 1:3b5be0ee5f0c | 1155 | |
khuang | 1:3b5be0ee5f0c | 1156 | .width = 96, |
khuang | 1:3b5be0ee5f0c | 1157 | .height= 96 |
khuang | 1:3b5be0ee5f0c | 1158 | }; |
khuang | 1:3b5be0ee5f0c | 1159 | |
khuang | 1:3b5be0ee5f0c | 1160 | SetDynamicArea( &transImageArea ); |
khuang | 1:3b5be0ee5f0c | 1161 | |
khuang | 7:9961c525e249 | 1162 | /* helper pointer */ |
khuang | 1:3b5be0ee5f0c | 1163 | oled_pixel_t |
khuang | 1:3b5be0ee5f0c | 1164 | transImage = (oled_pixel_t)oled_dynamic_area.areaBuffer; |
khuang | 1:3b5be0ee5f0c | 1165 | |
khuang | 1:3b5be0ee5f0c | 1166 | if ( NULL == transImage ) |
khuang | 1:3b5be0ee5f0c | 1167 | { |
khuang | 1:3b5be0ee5f0c | 1168 | return OLED_STATUS_INIT_ERROR; |
khuang | 1:3b5be0ee5f0c | 1169 | } |
khuang | 1:3b5be0ee5f0c | 1170 | |
khuang | 7:9961c525e249 | 1171 | Transpose( transImage,(oled_pixel_t)image, width, height ); |
khuang | 1:3b5be0ee5f0c | 1172 | |
khuang | 2:fc06b5b5bf6a | 1173 | SendCmd( OLED_CMD_SET_REMAP, CMD_BYTE ); |
khuang | 2:fc06b5b5bf6a | 1174 | SendCmd( OLED_REMAP_SETTINGS | REMAP_VERTICAL_INCREMENT, DATA_BYTE ); |
khuang | 1:3b5be0ee5f0c | 1175 | |
khuang | 1:3b5be0ee5f0c | 1176 | uint16_t |
khuang | 1:3b5be0ee5f0c | 1177 | transStep = OLED_TRANSITION_STEP; |
khuang | 1:3b5be0ee5f0c | 1178 | |
khuang | 1:3b5be0ee5f0c | 1179 | uint16_t |
khuang | 1:3b5be0ee5f0c | 1180 | partImgSize = height*transStep; |
khuang | 1:3b5be0ee5f0c | 1181 | |
khuang | 1:3b5be0ee5f0c | 1182 | uint8_t* |
khuang | 1:3b5be0ee5f0c | 1183 | partImgPtr = (uint8_t*)transImage + ( width - transStep ) * ( height * OLED_BYTES_PER_PIXEL ); |
khuang | 1:3b5be0ee5f0c | 1184 | |
khuang | 1:3b5be0ee5f0c | 1185 | /** |
khuang | 1:3b5be0ee5f0c | 1186 | * set locations |
khuang | 1:3b5be0ee5f0c | 1187 | */ |
khuang | 1:3b5be0ee5f0c | 1188 | |
khuang | 1:3b5be0ee5f0c | 1189 | while (1) |
khuang | 1:3b5be0ee5f0c | 1190 | { |
khuang | 1:3b5be0ee5f0c | 1191 | SetBorders( xCrd, yCrd, width, height ); |
khuang | 1:3b5be0ee5f0c | 1192 | |
khuang | 1:3b5be0ee5f0c | 1193 | if ( partImgSize > width*height ) |
khuang | 1:3b5be0ee5f0c | 1194 | { |
khuang | 1:3b5be0ee5f0c | 1195 | SendData((const uint8_t*)transImage, width * height * OLED_BYTES_PER_PIXEL ); |
khuang | 1:3b5be0ee5f0c | 1196 | break; |
khuang | 1:3b5be0ee5f0c | 1197 | } |
khuang | 1:3b5be0ee5f0c | 1198 | else |
khuang | 1:3b5be0ee5f0c | 1199 | { |
khuang | 1:3b5be0ee5f0c | 1200 | SendData( (const uint8_t*)partImgPtr, partImgSize * OLED_BYTES_PER_PIXEL ); |
khuang | 1:3b5be0ee5f0c | 1201 | } |
khuang | 1:3b5be0ee5f0c | 1202 | |
khuang | 1:3b5be0ee5f0c | 1203 | |
khuang | 1:3b5be0ee5f0c | 1204 | partImgPtr -= ( transStep * height ) * OLED_BYTES_PER_PIXEL; |
khuang | 1:3b5be0ee5f0c | 1205 | partImgSize += ( transStep * height ); |
khuang | 1:3b5be0ee5f0c | 1206 | transStep++; |
khuang | 1:3b5be0ee5f0c | 1207 | |
khuang | 1:3b5be0ee5f0c | 1208 | } |
khuang | 1:3b5be0ee5f0c | 1209 | |
khuang | 2:fc06b5b5bf6a | 1210 | SendCmd( OLED_CMD_SET_REMAP, CMD_BYTE ); |
khuang | 2:fc06b5b5bf6a | 1211 | SendCmd( OLED_REMAP_SETTINGS, DATA_BYTE ); |
khuang | 1:3b5be0ee5f0c | 1212 | DestroyDynamicArea(); |
khuang | 1:3b5be0ee5f0c | 1213 | return status; |
khuang | 1:3b5be0ee5f0c | 1214 | } |
khuang | 1:3b5be0ee5f0c | 1215 | |
khuang | 1:3b5be0ee5f0c | 1216 | |
khuang | 1:3b5be0ee5f0c | 1217 | /** |
khuang | 1:3b5be0ee5f0c | 1218 | * RightLeft Transition Effect for Image |
khuang | 1:3b5be0ee5f0c | 1219 | * @param image image to be transitioned |
khuang | 1:3b5be0ee5f0c | 1220 | * @param xCrd x coordinate of image |
khuang | 1:3b5be0ee5f0c | 1221 | * @param yCrd y coordinate of image |
khuang | 1:3b5be0ee5f0c | 1222 | * @param width width of image |
khuang | 1:3b5be0ee5f0c | 1223 | * @param height height of image |
khuang | 1:3b5be0ee5f0c | 1224 | * @return status flag |
khuang | 1:3b5be0ee5f0c | 1225 | */ |
khuang | 1:3b5be0ee5f0c | 1226 | oled_status_t SSD1351::RightLeft( |
khuang | 1:3b5be0ee5f0c | 1227 | const uint8_t* image, |
khuang | 6:0060ffa3f4dc | 1228 | int8_t xCrd, |
khuang | 6:0060ffa3f4dc | 1229 | int8_t yCrd, |
khuang | 1:3b5be0ee5f0c | 1230 | uint8_t width, |
khuang | 1:3b5be0ee5f0c | 1231 | uint8_t height |
khuang | 1:3b5be0ee5f0c | 1232 | ) |
khuang | 1:3b5be0ee5f0c | 1233 | { |
khuang | 1:3b5be0ee5f0c | 1234 | oled_dynamic_area_t |
khuang | 1:3b5be0ee5f0c | 1235 | transImageArea = |
khuang | 1:3b5be0ee5f0c | 1236 | { |
khuang | 1:3b5be0ee5f0c | 1237 | .xCrd = 0, |
khuang | 1:3b5be0ee5f0c | 1238 | .yCrd = 0, |
khuang | 1:3b5be0ee5f0c | 1239 | |
khuang | 1:3b5be0ee5f0c | 1240 | .width = 96, |
khuang | 1:3b5be0ee5f0c | 1241 | .height= 96 |
khuang | 1:3b5be0ee5f0c | 1242 | }; |
khuang | 1:3b5be0ee5f0c | 1243 | |
khuang | 1:3b5be0ee5f0c | 1244 | SetDynamicArea( &transImageArea ); |
khuang | 1:3b5be0ee5f0c | 1245 | |
khuang | 7:9961c525e249 | 1246 | /* helper pointer */ |
khuang | 1:3b5be0ee5f0c | 1247 | oled_pixel_t |
khuang | 1:3b5be0ee5f0c | 1248 | transImage = oled_dynamic_area.areaBuffer; |
khuang | 1:3b5be0ee5f0c | 1249 | |
khuang | 1:3b5be0ee5f0c | 1250 | if ( NULL == transImage ) |
khuang | 1:3b5be0ee5f0c | 1251 | { |
khuang | 1:3b5be0ee5f0c | 1252 | return OLED_STATUS_INIT_ERROR; |
khuang | 1:3b5be0ee5f0c | 1253 | } |
khuang | 1:3b5be0ee5f0c | 1254 | |
khuang | 6:0060ffa3f4dc | 1255 | Transpose(transImage, (oled_pixel_t)image, width, height ); |
khuang | 1:3b5be0ee5f0c | 1256 | |
khuang | 2:fc06b5b5bf6a | 1257 | SendCmd( OLED_CMD_SET_REMAP, CMD_BYTE ); |
khuang | 2:fc06b5b5bf6a | 1258 | SendCmd( OLED_REMAP_SETTINGS | REMAP_VERTICAL_INCREMENT, DATA_BYTE ); |
khuang | 1:3b5be0ee5f0c | 1259 | |
khuang | 1:3b5be0ee5f0c | 1260 | |
khuang | 1:3b5be0ee5f0c | 1261 | uint16_t |
khuang | 1:3b5be0ee5f0c | 1262 | transStep = OLED_TRANSITION_STEP; |
khuang | 1:3b5be0ee5f0c | 1263 | |
khuang | 1:3b5be0ee5f0c | 1264 | uint16_t |
khuang | 1:3b5be0ee5f0c | 1265 | partImgSize = height * transStep; |
khuang | 1:3b5be0ee5f0c | 1266 | |
khuang | 1:3b5be0ee5f0c | 1267 | uint8_t* |
khuang | 1:3b5be0ee5f0c | 1268 | partImgPtr = (uint8_t*)transImage; |
khuang | 1:3b5be0ee5f0c | 1269 | |
khuang | 1:3b5be0ee5f0c | 1270 | uint8_t |
khuang | 1:3b5be0ee5f0c | 1271 | xCrd_moving = ( xCrd + width ) - 1; |
khuang | 1:3b5be0ee5f0c | 1272 | |
khuang | 1:3b5be0ee5f0c | 1273 | /** set locations */ |
khuang | 1:3b5be0ee5f0c | 1274 | |
khuang | 1:3b5be0ee5f0c | 1275 | while (1) |
khuang | 1:3b5be0ee5f0c | 1276 | { |
khuang | 1:3b5be0ee5f0c | 1277 | if (( partImgSize > width*height )|| ( xCrd_moving < xCrd )) |
khuang | 1:3b5be0ee5f0c | 1278 | { |
khuang | 1:3b5be0ee5f0c | 1279 | SetBorders( xCrd, yCrd, width, height ); |
khuang | 1:3b5be0ee5f0c | 1280 | SendData( (const uint8_t*)transImage, height * width * OLED_BYTES_PER_PIXEL ); |
khuang | 1:3b5be0ee5f0c | 1281 | break; |
khuang | 1:3b5be0ee5f0c | 1282 | } |
khuang | 1:3b5be0ee5f0c | 1283 | else |
khuang | 1:3b5be0ee5f0c | 1284 | { |
khuang | 1:3b5be0ee5f0c | 1285 | SetBorders( xCrd_moving, yCrd, ( xCrd + width ) - xCrd_moving, height ); |
khuang | 1:3b5be0ee5f0c | 1286 | SendData( (const uint8_t*)partImgPtr, partImgSize * OLED_BYTES_PER_PIXEL ); |
khuang | 1:3b5be0ee5f0c | 1287 | } |
khuang | 1:3b5be0ee5f0c | 1288 | |
khuang | 1:3b5be0ee5f0c | 1289 | /** update variables*/ |
khuang | 1:3b5be0ee5f0c | 1290 | |
khuang | 1:3b5be0ee5f0c | 1291 | xCrd_moving -= transStep; |
khuang | 1:3b5be0ee5f0c | 1292 | partImgSize += ( height * transStep ); |
khuang | 1:3b5be0ee5f0c | 1293 | transStep++; |
khuang | 1:3b5be0ee5f0c | 1294 | } |
khuang | 1:3b5be0ee5f0c | 1295 | |
khuang | 2:fc06b5b5bf6a | 1296 | SendCmd( OLED_CMD_SET_REMAP, CMD_BYTE ); |
khuang | 2:fc06b5b5bf6a | 1297 | SendCmd( OLED_REMAP_SETTINGS, DATA_BYTE ); |
khuang | 1:3b5be0ee5f0c | 1298 | |
khuang | 1:3b5be0ee5f0c | 1299 | DestroyDynamicArea(); |
khuang | 1:3b5be0ee5f0c | 1300 | |
khuang | 1:3b5be0ee5f0c | 1301 | return OLED_STATUS_SUCCESS; |
khuang | 1:3b5be0ee5f0c | 1302 | } |
khuang | 1:3b5be0ee5f0c | 1303 | |
khuang | 1:3b5be0ee5f0c | 1304 | |
khuang | 1:3b5be0ee5f0c | 1305 | /** |
khuang | 1:3b5be0ee5f0c | 1306 | * [setDirection description] |
khuang | 1:3b5be0ee5f0c | 1307 | * @param self [description] |
khuang | 1:3b5be0ee5f0c | 1308 | * @param xCrd [description] |
khuang | 1:3b5be0ee5f0c | 1309 | * @param yCrd [description] |
khuang | 1:3b5be0ee5f0c | 1310 | * @return [description] |
khuang | 1:3b5be0ee5f0c | 1311 | */ |
khuang | 1:3b5be0ee5f0c | 1312 | void SSD1351::SetBorders( |
khuang | 6:0060ffa3f4dc | 1313 | int8_t xCrd, |
khuang | 6:0060ffa3f4dc | 1314 | int8_t yCrd, |
khuang | 1:3b5be0ee5f0c | 1315 | uint8_t width, |
khuang | 1:3b5be0ee5f0c | 1316 | uint8_t height |
khuang | 1:3b5be0ee5f0c | 1317 | ) |
khuang | 1:3b5be0ee5f0c | 1318 | { |
khuang | 1:3b5be0ee5f0c | 1319 | |
khuang | 7:9961c525e249 | 1320 | /* adjust for the offset*/ |
khuang | 1:3b5be0ee5f0c | 1321 | OLED_AdjustColumnOffset(xCrd); |
khuang | 1:3b5be0ee5f0c | 1322 | OLED_AdjustRowOffset(yCrd); |
khuang | 1:3b5be0ee5f0c | 1323 | |
khuang | 2:fc06b5b5bf6a | 1324 | SendCmd( OLED_CMD_SET_COLUMN, CMD_BYTE ); |
khuang | 2:fc06b5b5bf6a | 1325 | SendCmd( xCrd, DATA_BYTE ); |
khuang | 2:fc06b5b5bf6a | 1326 | SendCmd( xCrd + (width-1), DATA_BYTE ); |
khuang | 2:fc06b5b5bf6a | 1327 | SendCmd( OLED_CMD_SET_ROW, CMD_BYTE ); |
khuang | 2:fc06b5b5bf6a | 1328 | SendCmd( yCrd, DATA_BYTE ); |
khuang | 2:fc06b5b5bf6a | 1329 | SendCmd( yCrd + (height-1), DATA_BYTE ); |
khuang | 1:3b5be0ee5f0c | 1330 | |
khuang | 1:3b5be0ee5f0c | 1331 | } |
khuang | 1:3b5be0ee5f0c | 1332 | |
khuang | 1:3b5be0ee5f0c | 1333 | /** |
khuang | 1:3b5be0ee5f0c | 1334 | * create the buffer for a partial image |
khuang | 1:3b5be0ee5f0c | 1335 | * @param imgBuf [description] |
khuang | 1:3b5be0ee5f0c | 1336 | * @param width [description] |
khuang | 1:3b5be0ee5f0c | 1337 | * @param height [description] |
khuang | 1:3b5be0ee5f0c | 1338 | * @return [description] |
khuang | 1:3b5be0ee5f0c | 1339 | */ |
khuang | 1:3b5be0ee5f0c | 1340 | oled_status_t SSD1351::CreateTextBackground() |
khuang | 1:3b5be0ee5f0c | 1341 | { |
khuang | 1:3b5be0ee5f0c | 1342 | uint8_t |
khuang | 1:3b5be0ee5f0c | 1343 | xCrd = oled_dynamic_area.xCrd, |
khuang | 1:3b5be0ee5f0c | 1344 | yCrd = oled_dynamic_area.yCrd, |
khuang | 1:3b5be0ee5f0c | 1345 | width = oled_dynamic_area.width, |
khuang | 1:3b5be0ee5f0c | 1346 | height = oled_dynamic_area.height; |
khuang | 1:3b5be0ee5f0c | 1347 | |
khuang | 1:3b5be0ee5f0c | 1348 | oled_pixel_t |
khuang | 1:3b5be0ee5f0c | 1349 | imgBuf = oled_dynamic_area.areaBuffer, |
khuang | 1:3b5be0ee5f0c | 1350 | copyAddr; |
khuang | 1:3b5be0ee5f0c | 1351 | |
khuang | 1:3b5be0ee5f0c | 1352 | const uint8_t* |
khuang | 1:3b5be0ee5f0c | 1353 | background = oled_text_properties.background; |
khuang | 1:3b5be0ee5f0c | 1354 | |
khuang | 7:9961c525e249 | 1355 | /* copy data */ |
khuang | 1:3b5be0ee5f0c | 1356 | |
khuang | 1:3b5be0ee5f0c | 1357 | if ( |
khuang | 1:3b5be0ee5f0c | 1358 | ( NULL == imgBuf ) |
khuang | 1:3b5be0ee5f0c | 1359 | || ( ( xCrd + width ) > OLED_SCREEN_WIDTH ) |
khuang | 1:3b5be0ee5f0c | 1360 | || ( ( yCrd + height ) > OLED_SCREEN_HEIGHT ) |
khuang | 1:3b5be0ee5f0c | 1361 | ) |
khuang | 1:3b5be0ee5f0c | 1362 | { |
khuang | 1:3b5be0ee5f0c | 1363 | return OLED_STATUS_INIT_ERROR; |
khuang | 1:3b5be0ee5f0c | 1364 | } |
khuang | 1:3b5be0ee5f0c | 1365 | |
khuang | 1:3b5be0ee5f0c | 1366 | if ( NULL == background ) |
khuang | 1:3b5be0ee5f0c | 1367 | { |
khuang | 1:3b5be0ee5f0c | 1368 | for ( uint8_t i = 0; i < height; i++ ) |
khuang | 1:3b5be0ee5f0c | 1369 | { |
khuang | 1:3b5be0ee5f0c | 1370 | memset( (void*)imgBuf, 0, width*OLED_BYTES_PER_PIXEL ); |
khuang | 1:3b5be0ee5f0c | 1371 | imgBuf += width; |
khuang | 1:3b5be0ee5f0c | 1372 | } |
khuang | 1:3b5be0ee5f0c | 1373 | } |
khuang | 1:3b5be0ee5f0c | 1374 | |
khuang | 1:3b5be0ee5f0c | 1375 | else |
khuang | 1:3b5be0ee5f0c | 1376 | { |
khuang | 1:3b5be0ee5f0c | 1377 | copyAddr = (oled_pixel_t)( BMP_SkipHeader( background ) ) + ( yCrd*OLED_SCREEN_WIDTH + xCrd ); |
khuang | 1:3b5be0ee5f0c | 1378 | for ( uint8_t i = 0; i < height; i++ ) |
khuang | 1:3b5be0ee5f0c | 1379 | { |
khuang | 1:3b5be0ee5f0c | 1380 | Swap( (oled_pixel_t)imgBuf, (const uint8_t*)copyAddr, width ); |
khuang | 1:3b5be0ee5f0c | 1381 | imgBuf += width; |
khuang | 1:3b5be0ee5f0c | 1382 | copyAddr += OLED_SCREEN_WIDTH; |
khuang | 1:3b5be0ee5f0c | 1383 | } |
khuang | 1:3b5be0ee5f0c | 1384 | } |
khuang | 1:3b5be0ee5f0c | 1385 | |
khuang | 1:3b5be0ee5f0c | 1386 | return OLED_STATUS_SUCCESS; |
khuang | 1:3b5be0ee5f0c | 1387 | } |
khuang | 1:3b5be0ee5f0c | 1388 | |
khuang | 1:3b5be0ee5f0c | 1389 | |
khuang | 1:3b5be0ee5f0c | 1390 | /** |
khuang | 1:3b5be0ee5f0c | 1391 | * Write the character to Buffer |
khuang | 1:3b5be0ee5f0c | 1392 | * @param charToWrite character to be written |
khuang | 1:3b5be0ee5f0c | 1393 | * @param chrBuf given pointer for buffer for the character |
khuang | 1:3b5be0ee5f0c | 1394 | */ |
khuang | 1:3b5be0ee5f0c | 1395 | void SSD1351::WriteCharToBuf( |
khuang | 1:3b5be0ee5f0c | 1396 | uint16_t charToWrite, |
khuang | 1:3b5be0ee5f0c | 1397 | oled_pixel_t* chrBuf |
khuang | 1:3b5be0ee5f0c | 1398 | ) |
khuang | 1:3b5be0ee5f0c | 1399 | { |
khuang | 1:3b5be0ee5f0c | 1400 | uint8_t |
khuang | 1:3b5be0ee5f0c | 1401 | foo = 0, |
khuang | 1:3b5be0ee5f0c | 1402 | mask; |
khuang | 1:3b5be0ee5f0c | 1403 | |
khuang | 1:3b5be0ee5f0c | 1404 | const uint8_t* |
khuang | 1:3b5be0ee5f0c | 1405 | pChTable = selectedFont + 8 + (uint16_t)( ( charToWrite - selectedFont_firstChar ) << 2 ); |
khuang | 1:3b5be0ee5f0c | 1406 | |
khuang | 1:3b5be0ee5f0c | 1407 | currentChar_width = *pChTable, |
khuang | 1:3b5be0ee5f0c | 1408 | currentChar_height = selectedFont_height; |
khuang | 1:3b5be0ee5f0c | 1409 | |
khuang | 1:3b5be0ee5f0c | 1410 | uint32_t |
khuang | 1:3b5be0ee5f0c | 1411 | offset = (uint32_t)pChTable[1] |
khuang | 1:3b5be0ee5f0c | 1412 | | ( (uint32_t)pChTable[2] << 8 ) |
khuang | 1:3b5be0ee5f0c | 1413 | | ( (uint32_t)pChTable[3] << 16 ); |
khuang | 1:3b5be0ee5f0c | 1414 | |
khuang | 1:3b5be0ee5f0c | 1415 | const uint8_t* |
khuang | 1:3b5be0ee5f0c | 1416 | pChBitMap = selectedFont + offset; |
khuang | 1:3b5be0ee5f0c | 1417 | |
khuang | 7:9961c525e249 | 1418 | /* allocate space for char image */ |
khuang | 1:3b5be0ee5f0c | 1419 | *chrBuf = (oled_pixel_t)AllocateDynamicArea( currentChar_height * currentChar_width ); |
khuang | 1:3b5be0ee5f0c | 1420 | |
khuang | 1:3b5be0ee5f0c | 1421 | if ( NULL == *chrBuf ) |
khuang | 1:3b5be0ee5f0c | 1422 | { |
khuang | 1:3b5be0ee5f0c | 1423 | return; |
khuang | 1:3b5be0ee5f0c | 1424 | } |
khuang | 1:3b5be0ee5f0c | 1425 | |
khuang | 1:3b5be0ee5f0c | 1426 | for ( uint8_t yCnt = 0; yCnt < currentChar_height; yCnt++ ) |
khuang | 1:3b5be0ee5f0c | 1427 | { |
khuang | 1:3b5be0ee5f0c | 1428 | mask = 0; |
khuang | 1:3b5be0ee5f0c | 1429 | |
khuang | 1:3b5be0ee5f0c | 1430 | for ( uint8_t xCnt = 0; xCnt < currentChar_width; xCnt++ ) |
khuang | 1:3b5be0ee5f0c | 1431 | { |
khuang | 1:3b5be0ee5f0c | 1432 | if ( 0 == mask ) |
khuang | 1:3b5be0ee5f0c | 1433 | { |
khuang | 1:3b5be0ee5f0c | 1434 | mask = 1; |
khuang | 1:3b5be0ee5f0c | 1435 | foo = *pChBitMap++; |
khuang | 1:3b5be0ee5f0c | 1436 | } |
khuang | 1:3b5be0ee5f0c | 1437 | |
khuang | 1:3b5be0ee5f0c | 1438 | if ( 0 != ( foo & mask ) ) |
khuang | 1:3b5be0ee5f0c | 1439 | { |
khuang | 1:3b5be0ee5f0c | 1440 | *( *chrBuf + yCnt*currentChar_width + xCnt ) = selectedFont_color; |
khuang | 1:3b5be0ee5f0c | 1441 | } |
khuang | 1:3b5be0ee5f0c | 1442 | |
khuang | 1:3b5be0ee5f0c | 1443 | else |
khuang | 1:3b5be0ee5f0c | 1444 | { |
khuang | 1:3b5be0ee5f0c | 1445 | *( *chrBuf + yCnt*currentChar_width + xCnt ) = 0; |
khuang | 1:3b5be0ee5f0c | 1446 | } |
khuang | 1:3b5be0ee5f0c | 1447 | |
khuang | 1:3b5be0ee5f0c | 1448 | mask <<= 1; |
khuang | 1:3b5be0ee5f0c | 1449 | } |
khuang | 1:3b5be0ee5f0c | 1450 | } |
khuang | 1:3b5be0ee5f0c | 1451 | } |
khuang | 1:3b5be0ee5f0c | 1452 | |
khuang | 1:3b5be0ee5f0c | 1453 | |
khuang | 1:3b5be0ee5f0c | 1454 | /** |
khuang | 1:3b5be0ee5f0c | 1455 | * Add subimage/character to the active image buffer |
khuang | 1:3b5be0ee5f0c | 1456 | * @param xOffset offset for the x-coordinate |
khuang | 1:3b5be0ee5f0c | 1457 | * @param yOffset offset for the y-coordinate |
khuang | 1:3b5be0ee5f0c | 1458 | * @param width desired width |
khuang | 1:3b5be0ee5f0c | 1459 | * @param height desired height |
khuang | 1:3b5be0ee5f0c | 1460 | * @return status flag |
khuang | 1:3b5be0ee5f0c | 1461 | */ |
khuang | 1:3b5be0ee5f0c | 1462 | oled_status_t SSD1351::AddCharToTextArea( |
khuang | 1:3b5be0ee5f0c | 1463 | oled_pixel_t chrPtr, |
khuang | 1:3b5be0ee5f0c | 1464 | uint8_t chrWidth, |
khuang | 1:3b5be0ee5f0c | 1465 | uint8_t chrHeight, |
khuang | 1:3b5be0ee5f0c | 1466 | oled_pixel_t copyAddr, |
khuang | 1:3b5be0ee5f0c | 1467 | uint8_t imgWidth |
khuang | 1:3b5be0ee5f0c | 1468 | ) |
khuang | 1:3b5be0ee5f0c | 1469 | { |
khuang | 1:3b5be0ee5f0c | 1470 | if ( NULL == copyAddr ) |
khuang | 1:3b5be0ee5f0c | 1471 | { |
khuang | 1:3b5be0ee5f0c | 1472 | return OLED_STATUS_INIT_ERROR; |
khuang | 1:3b5be0ee5f0c | 1473 | } |
khuang | 1:3b5be0ee5f0c | 1474 | |
khuang | 1:3b5be0ee5f0c | 1475 | for ( uint8_t i = 0; i < chrHeight; i++ ) |
khuang | 1:3b5be0ee5f0c | 1476 | { |
khuang | 1:3b5be0ee5f0c | 1477 | for ( uint8_t j = 0; j < chrWidth; j++ ) |
khuang | 1:3b5be0ee5f0c | 1478 | { |
khuang | 1:3b5be0ee5f0c | 1479 | if ( 0 != chrPtr[j] ) |
khuang | 1:3b5be0ee5f0c | 1480 | { |
khuang | 1:3b5be0ee5f0c | 1481 | copyAddr[j] = chrPtr[j]; |
khuang | 1:3b5be0ee5f0c | 1482 | } |
khuang | 1:3b5be0ee5f0c | 1483 | } |
khuang | 1:3b5be0ee5f0c | 1484 | copyAddr += imgWidth; |
khuang | 1:3b5be0ee5f0c | 1485 | chrPtr += chrWidth; |
khuang | 1:3b5be0ee5f0c | 1486 | } |
khuang | 1:3b5be0ee5f0c | 1487 | return OLED_STATUS_SUCCESS; |
khuang | 1:3b5be0ee5f0c | 1488 | } |
khuang | 1:3b5be0ee5f0c | 1489 | |
khuang | 1:3b5be0ee5f0c | 1490 | |
khuang | 1:3b5be0ee5f0c | 1491 | /** |
khuang | 1:3b5be0ee5f0c | 1492 | * Allocate memory for the desired image/character |
khuang | 1:3b5be0ee5f0c | 1493 | * @param area desired area dimensions |
khuang | 1:3b5be0ee5f0c | 1494 | */ |
khuang | 1:3b5be0ee5f0c | 1495 | void* SSD1351::AllocateDynamicArea( uint32_t area ) |
khuang | 1:3b5be0ee5f0c | 1496 | { |
khuang | 1:3b5be0ee5f0c | 1497 | void* |
khuang | 1:3b5be0ee5f0c | 1498 | ptr = malloc( area * OLED_BYTES_PER_PIXEL ); |
khuang | 1:3b5be0ee5f0c | 1499 | |
khuang | 1:3b5be0ee5f0c | 1500 | if ( NULL == ptr ) |
khuang | 1:3b5be0ee5f0c | 1501 | { |
khuang | 1:3b5be0ee5f0c | 1502 | return NULL; |
khuang | 1:3b5be0ee5f0c | 1503 | } |
khuang | 1:3b5be0ee5f0c | 1504 | |
khuang | 1:3b5be0ee5f0c | 1505 | return ptr; |
khuang | 1:3b5be0ee5f0c | 1506 | } |
khuang | 1:3b5be0ee5f0c | 1507 | |
khuang | 1:3b5be0ee5f0c | 1508 | |
khuang | 1:3b5be0ee5f0c | 1509 | /** |
khuang | 1:3b5be0ee5f0c | 1510 | * Deallocate current area |
khuang | 1:3b5be0ee5f0c | 1511 | * @param area pointer to current area |
khuang | 1:3b5be0ee5f0c | 1512 | */ |
khuang | 1:3b5be0ee5f0c | 1513 | oled_status_t SSD1351::DestroyDynamicArea( void* ptr ) |
khuang | 1:3b5be0ee5f0c | 1514 | { |
khuang | 1:3b5be0ee5f0c | 1515 | if ( NULL == ptr ) |
khuang | 1:3b5be0ee5f0c | 1516 | { |
khuang | 1:3b5be0ee5f0c | 1517 | return OLED_STATUS_INIT_ERROR; |
khuang | 1:3b5be0ee5f0c | 1518 | } |
khuang | 1:3b5be0ee5f0c | 1519 | |
khuang | 1:3b5be0ee5f0c | 1520 | free(ptr); |
khuang | 1:3b5be0ee5f0c | 1521 | |
khuang | 1:3b5be0ee5f0c | 1522 | return OLED_STATUS_SUCCESS; |
khuang | 1:3b5be0ee5f0c | 1523 | } |