Hexiwear OLED

Dependents:   Hexi

Fork of Hexi_OLED_SSD1351 by Hexiwear

Committer:
khuang
Date:
Thu Aug 18 23:01:06 2016 +0000
Revision:
1:3b5be0ee5f0c
Child:
2:fc06b5b5bf6a
Hexiwear OLED Display Driver enabled.; Allow images and text to be displayed.

Who changed what in which revision?

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