Hexiwear OLED

Dependents:   Hexi

Fork of Hexi_OLED_SSD1351 by Hexiwear

Committer:
khuang
Date:
Fri Aug 19 23:05:58 2016 +0000
Revision:
2:fc06b5b5bf6a
Parent:
1:3b5be0ee5f0c
Child:
3:4121d3cd9f60
Added Licensing and Reformatted Init Array for SSD1351 init

Who changed what in which revision?

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