Class Module for EA DOGS102 Graphic LCD display SPI Interface

Dependents:   mDotEVBM2X MTDOT-EVB-LinkCheck-AL MTDOT-EVBDemo-DRH MTDOT_BOX_EVB_LCD_Helloworld ... more

Committer:
falingtrea
Date:
Mon Jul 06 19:37:13 2015 +0000
Revision:
0:f40dbeaefe69
Child:
1:3b02b7fb79c9
Initial release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
falingtrea 0:f40dbeaefe69 1 /**
falingtrea 0:f40dbeaefe69 2 * @file DOGS102.cpp
falingtrea 0:f40dbeaefe69 3 * @brief Device driver - DOGS102 102x64 pixel Graphic LCD display W/RTOS Support
falingtrea 0:f40dbeaefe69 4 * @author Tim Barr
falingtrea 0:f40dbeaefe69 5 * @version 1.0
falingtrea 0:f40dbeaefe69 6 * @see http://www.lcd-module.com/eng/pdf/grafik/dogs102-6e.pdf
falingtrea 0:f40dbeaefe69 7 * @see http://www.lcd-module.com/eng/pdf/zubehoer/uc1701.pdf
falingtrea 0:f40dbeaefe69 8 *
falingtrea 0:f40dbeaefe69 9 * Copyright (c) 2015
falingtrea 0:f40dbeaefe69 10 *
falingtrea 0:f40dbeaefe69 11 * Licensed under the Apache License, Version 2.0 (the "License");
falingtrea 0:f40dbeaefe69 12 * you may not use this file except in compliance with the License.
falingtrea 0:f40dbeaefe69 13 * You may obtain a copy of the License at
falingtrea 0:f40dbeaefe69 14 *
falingtrea 0:f40dbeaefe69 15 * http://www.apache.org/licenses/LICENSE-2.0
falingtrea 0:f40dbeaefe69 16 *
falingtrea 0:f40dbeaefe69 17 * Unless required by applicable law or agreed to in writing, software
falingtrea 0:f40dbeaefe69 18 * distributed under the License is distributed on an "AS IS" BASIS,
falingtrea 0:f40dbeaefe69 19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
falingtrea 0:f40dbeaefe69 20 * See the License for the specific language governing permissions and
falingtrea 0:f40dbeaefe69 21 * limitations under the License.
falingtrea 0:f40dbeaefe69 22 */
falingtrea 0:f40dbeaefe69 23
falingtrea 0:f40dbeaefe69 24 #include "DOGS102.h"
falingtrea 0:f40dbeaefe69 25 #include "mbed_debug.h"
falingtrea 0:f40dbeaefe69 26 #include "rtos.h"
falingtrea 0:f40dbeaefe69 27
falingtrea 0:f40dbeaefe69 28 // macro to make sure x falls into range from low to high (inclusive)
falingtrea 0:f40dbeaefe69 29 #define CLIP(x, low, high) { if ( (x) < (low) ) x = (low); if ( (x) > (high) ) x = (high); } while (0);
falingtrea 0:f40dbeaefe69 30
falingtrea 0:f40dbeaefe69 31 DOGS102::DOGS102(SPI &spi, DigitalOut &lcd_cs, DigitalOut &cmnd_data)
falingtrea 0:f40dbeaefe69 32 {
falingtrea 0:f40dbeaefe69 33 _spi = &spi;
falingtrea 0:f40dbeaefe69 34 _lcd_cs = &lcd_cs;
falingtrea 0:f40dbeaefe69 35 _cmnd_data = &cmnd_data;
falingtrea 0:f40dbeaefe69 36
falingtrea 0:f40dbeaefe69 37 DOGS102::init();
falingtrea 0:f40dbeaefe69 38
falingtrea 0:f40dbeaefe69 39 return;
falingtrea 0:f40dbeaefe69 40 }
falingtrea 0:f40dbeaefe69 41 uint8_t DOGS102::setCursor(uint8_t xcur, uint8_t ycur)
falingtrea 0:f40dbeaefe69 42 {
falingtrea 0:f40dbeaefe69 43 uint8_t ypage;
falingtrea 0:f40dbeaefe69 44 uint8_t y_shift;
falingtrea 0:f40dbeaefe69 45
falingtrea 0:f40dbeaefe69 46 CLIP(xcur, 0, LCDWIDTH-1);
falingtrea 0:f40dbeaefe69 47 ypage = ycur/8;
falingtrea 0:f40dbeaefe69 48 CLIP(ypage, 0, LCDPAGES-1);
falingtrea 0:f40dbeaefe69 49 y_shift = ycur % 8;
falingtrea 0:f40dbeaefe69 50 DOGS102::writeCommand(SETPGADDR,ypage);
falingtrea 0:f40dbeaefe69 51 DOGS102::writeCommand(SETCOLADDRMSB,xcur>>4);
falingtrea 0:f40dbeaefe69 52 DOGS102::writeCommand(SETCOLADDRLSB,xcur);
falingtrea 0:f40dbeaefe69 53 return y_shift;
falingtrea 0:f40dbeaefe69 54 }
falingtrea 0:f40dbeaefe69 55
falingtrea 0:f40dbeaefe69 56 void DOGS102::clearBuffer(void)
falingtrea 0:f40dbeaefe69 57 {
falingtrea 0:f40dbeaefe69 58 memset(_lcdbuffer, 0, sizeof(_lcdbuffer));
falingtrea 0:f40dbeaefe69 59
falingtrea 0:f40dbeaefe69 60 if (!_update_flag)
falingtrea 0:f40dbeaefe69 61 {
falingtrea 0:f40dbeaefe69 62 DOGS102::sendBuffer(_lcdbuffer);
falingtrea 0:f40dbeaefe69 63 }
falingtrea 0:f40dbeaefe69 64
falingtrea 0:f40dbeaefe69 65 }
falingtrea 0:f40dbeaefe69 66
falingtrea 0:f40dbeaefe69 67 void DOGS102::writeText(uint8_t column, uint8_t page, const uint8_t *font_address, const char *text, const uint8_t size)
falingtrea 0:f40dbeaefe69 68 {
falingtrea 0:f40dbeaefe69 69 // Position of character data in memory array
falingtrea 0:f40dbeaefe69 70 uint16_t pos_array;
falingtrea 0:f40dbeaefe69 71 // temporary column, page address, and column_cnt are used
falingtrea 0:f40dbeaefe69 72 // to stay inside display area
falingtrea 0:f40dbeaefe69 73 uint8_t i,y, column_cnt = 0;
falingtrea 0:f40dbeaefe69 74
falingtrea 0:f40dbeaefe69 75 // font information, needed for calculation
falingtrea 0:f40dbeaefe69 76 uint8_t start_code, last_code, width, page_height, bytes_p_char;
falingtrea 0:f40dbeaefe69 77
falingtrea 0:f40dbeaefe69 78 uint8_t *txtbuffer;
falingtrea 0:f40dbeaefe69 79
falingtrea 0:f40dbeaefe69 80 start_code = font_address[2]; // get first defined character
falingtrea 0:f40dbeaefe69 81 last_code = font_address[3]; // get last defined character
falingtrea 0:f40dbeaefe69 82 width = font_address[4]; // width in pixel of one char
falingtrea 0:f40dbeaefe69 83 page_height = font_address[6]; // page count per char
falingtrea 0:f40dbeaefe69 84 bytes_p_char = font_address[7]; // bytes per char
falingtrea 0:f40dbeaefe69 85
falingtrea 0:f40dbeaefe69 86 if(page_height + page > LCDPAGES) //stay inside display area
falingtrea 0:f40dbeaefe69 87 page_height = LCDPAGES - page;
falingtrea 0:f40dbeaefe69 88
falingtrea 0:f40dbeaefe69 89 // The string is displayed character after character. If the font has more then one page,
falingtrea 0:f40dbeaefe69 90 // the top page is printed first, then the next page and so on
falingtrea 0:f40dbeaefe69 91 for(y = 0; y < page_height; y++)
falingtrea 0:f40dbeaefe69 92 {
falingtrea 0:f40dbeaefe69 93 txtbuffer = &_lcdbuffer[page*LCDWIDTH + column];
falingtrea 0:f40dbeaefe69 94 column_cnt = 0; // clear column_cnt start point
falingtrea 0:f40dbeaefe69 95 i = 0;
falingtrea 0:f40dbeaefe69 96 while(( i < size) && ((column_cnt + column) < LCDWIDTH))
falingtrea 0:f40dbeaefe69 97 {
falingtrea 0:f40dbeaefe69 98 if(text[i] < start_code || (uint8_t)text[i] > last_code) //make sure data is valid
falingtrea 0:f40dbeaefe69 99 i++;
falingtrea 0:f40dbeaefe69 100 else
falingtrea 0:f40dbeaefe69 101 {
falingtrea 0:f40dbeaefe69 102 // calculate position of ASCII character in font array
falingtrea 0:f40dbeaefe69 103 // bytes for header + (ASCII - startcode) * bytes per char)
falingtrea 0:f40dbeaefe69 104 pos_array = 8 + (uint8_t)(text[i++] - start_code) * bytes_p_char;
falingtrea 0:f40dbeaefe69 105
falingtrea 0:f40dbeaefe69 106 // get the dot pattern for the part of the char to print
falingtrea 0:f40dbeaefe69 107 pos_array += y*width;
falingtrea 0:f40dbeaefe69 108
falingtrea 0:f40dbeaefe69 109 // stay inside display area
falingtrea 0:f40dbeaefe69 110 if((column_cnt + width + column) > LCDWIDTH)
falingtrea 0:f40dbeaefe69 111 column_cnt = LCDWIDTH-width;
falingtrea 0:f40dbeaefe69 112
falingtrea 0:f40dbeaefe69 113 // copy character data to buffer
falingtrea 0:f40dbeaefe69 114 memcpy (txtbuffer+column_cnt,font_address+pos_array,width);
falingtrea 0:f40dbeaefe69 115 }
falingtrea 0:f40dbeaefe69 116
falingtrea 0:f40dbeaefe69 117 column_cnt += width;
falingtrea 0:f40dbeaefe69 118 }
falingtrea 0:f40dbeaefe69 119 if (!_update_flag)
falingtrea 0:f40dbeaefe69 120 {
falingtrea 0:f40dbeaefe69 121 setCursor(column,(page+y)*8); // set start position x and y
falingtrea 0:f40dbeaefe69 122 DOGS102::writeData(txtbuffer,column_cnt);
falingtrea 0:f40dbeaefe69 123 }
falingtrea 0:f40dbeaefe69 124 }
falingtrea 0:f40dbeaefe69 125 }
falingtrea 0:f40dbeaefe69 126
falingtrea 0:f40dbeaefe69 127 void DOGS102::writeBitmap(uint8_t column, uint8_t page, const uint8_t *bm_address)
falingtrea 0:f40dbeaefe69 128 {
falingtrea 0:f40dbeaefe69 129 uint8_t width, page_cnt, bm_pntr;
falingtrea 0:f40dbeaefe69 130
falingtrea 0:f40dbeaefe69 131 width = bm_address[0];
falingtrea 0:f40dbeaefe69 132 page_cnt = (bm_address[1] + 7) / 8; //height in pages, add 7 and divide by 8 for getting the used pages (byte boundaries)
falingtrea 0:f40dbeaefe69 133
falingtrea 0:f40dbeaefe69 134 if(width + column > LCDWIDTH) //stay inside display area
falingtrea 0:f40dbeaefe69 135 width = LCDWIDTH - column;
falingtrea 0:f40dbeaefe69 136 if(page_cnt + page > LCDPAGES)
falingtrea 0:f40dbeaefe69 137 page_cnt = LCDPAGES - page;
falingtrea 0:f40dbeaefe69 138
falingtrea 0:f40dbeaefe69 139 for (uint8_t i=0;i < page_cnt;i++ )
falingtrea 0:f40dbeaefe69 140 {
falingtrea 0:f40dbeaefe69 141 bm_pntr = 2+i*width;
falingtrea 0:f40dbeaefe69 142 memcpy(_lcdbuffer+column+((i+page)*LCDWIDTH),bm_address+bm_pntr, width);
falingtrea 0:f40dbeaefe69 143 }
falingtrea 0:f40dbeaefe69 144
falingtrea 0:f40dbeaefe69 145 if (_update_flag == 0)
falingtrea 0:f40dbeaefe69 146 {
falingtrea 0:f40dbeaefe69 147 DOGS102::sendBuffer(_lcdbuffer);
falingtrea 0:f40dbeaefe69 148 }
falingtrea 0:f40dbeaefe69 149 }
falingtrea 0:f40dbeaefe69 150
falingtrea 0:f40dbeaefe69 151 void DOGS102::startUpdate(void)
falingtrea 0:f40dbeaefe69 152 {
falingtrea 0:f40dbeaefe69 153 _update_flag++;
falingtrea 0:f40dbeaefe69 154 }
falingtrea 0:f40dbeaefe69 155
falingtrea 0:f40dbeaefe69 156 void DOGS102::endUpdate(void)
falingtrea 0:f40dbeaefe69 157 {
falingtrea 0:f40dbeaefe69 158 _update_flag--;
falingtrea 0:f40dbeaefe69 159
falingtrea 0:f40dbeaefe69 160 // fix boundary issue
falingtrea 0:f40dbeaefe69 161 if (_update_flag < 0)
falingtrea 0:f40dbeaefe69 162 _update_flag = 0;
falingtrea 0:f40dbeaefe69 163
falingtrea 0:f40dbeaefe69 164 if (_update_flag == 0)
falingtrea 0:f40dbeaefe69 165 {
falingtrea 0:f40dbeaefe69 166 DOGS102::sendBuffer(_lcdbuffer);
falingtrea 0:f40dbeaefe69 167 }
falingtrea 0:f40dbeaefe69 168 }
falingtrea 0:f40dbeaefe69 169
falingtrea 0:f40dbeaefe69 170 uint8_t DOGS102::getUpdateState(void)
falingtrea 0:f40dbeaefe69 171 {
falingtrea 0:f40dbeaefe69 172 return _update_flag;
falingtrea 0:f40dbeaefe69 173 }
falingtrea 0:f40dbeaefe69 174
falingtrea 0:f40dbeaefe69 175 uint8_t DOGS102::init(void)
falingtrea 0:f40dbeaefe69 176 {
falingtrea 0:f40dbeaefe69 177 uint8_t result = 0;
falingtrea 0:f40dbeaefe69 178
falingtrea 0:f40dbeaefe69 179 _spi->frequency(4000000);
falingtrea 0:f40dbeaefe69 180 _spi->format(8,3); // 8bit transfers, SPI mode 3
falingtrea 0:f40dbeaefe69 181 _lcd_cs->write(1); // initialize chip select pin
falingtrea 0:f40dbeaefe69 182 _cmnd_data->write(1); // initialize command/data pin
falingtrea 0:f40dbeaefe69 183 _update_flag = 0; // initialize update semaphore
falingtrea 0:f40dbeaefe69 184
falingtrea 0:f40dbeaefe69 185 // Reset all registers to POR values
falingtrea 0:f40dbeaefe69 186 // result = DOGS102::writeCommand(SOFTRESET);
falingtrea 0:f40dbeaefe69 187 osDelay(50);
falingtrea 0:f40dbeaefe69 188
falingtrea 0:f40dbeaefe69 189 // send initial setup commands to power up the display
falingtrea 0:f40dbeaefe69 190 result |= DOGS102::writeCommand(SETSCROLLLINE,0x00); // set scroll line to 0
falingtrea 0:f40dbeaefe69 191 result |= DOGS102::writeCommand(SETSEGDIR,0x01); // set reverse seg direction
falingtrea 0:f40dbeaefe69 192 result |= DOGS102::writeCommand(SETCOMDIR,0x00); // set normal com direction
falingtrea 0:f40dbeaefe69 193 result |= DOGS102::writeCommand(SETALLPIXELON,0x00); // disable all pixel on mode
falingtrea 0:f40dbeaefe69 194 result |= DOGS102::writeCommand(SETINVDISP,0x00); // Turn display inverse off
falingtrea 0:f40dbeaefe69 195 result |= DOGS102::writeCommand(SETLCDBIAS,0x00); // set bias ratio to 1/9
falingtrea 0:f40dbeaefe69 196 result |= DOGS102::writeCommand(SETPWRCTRL,0x07); // turn on booster,regulator and follower
falingtrea 0:f40dbeaefe69 197 result |= DOGS102::writeCommand(SETVLCDRESRATIO,0x07); // Set resistor ratio tomax
falingtrea 0:f40dbeaefe69 198 result |= DOGS102::writeCommand(SETELECVOL,0x10); // set contrast to 32 out of 63
falingtrea 0:f40dbeaefe69 199 result |= DOGS102::writeCommand(SETAPROGCTRL,0x83); // enable wrap around bits
falingtrea 0:f40dbeaefe69 200 result |= DOGS102::writeCommand(SETDISPEN,0x01); // set display enable bit
falingtrea 0:f40dbeaefe69 201
falingtrea 0:f40dbeaefe69 202 DOGS102::clearBuffer();
falingtrea 0:f40dbeaefe69 203
falingtrea 0:f40dbeaefe69 204 if(result != 0)
falingtrea 0:f40dbeaefe69 205 {
falingtrea 0:f40dbeaefe69 206 debug("%s %d: ILS29011:init failed\n\r", __FILE__, __LINE__);
falingtrea 0:f40dbeaefe69 207 }
falingtrea 0:f40dbeaefe69 208
falingtrea 0:f40dbeaefe69 209 return result;
falingtrea 0:f40dbeaefe69 210 }
falingtrea 0:f40dbeaefe69 211
falingtrea 0:f40dbeaefe69 212 uint8_t DOGS102::writeCommand(uint8_t const reg, uint8_t const data) const
falingtrea 0:f40dbeaefe69 213 {
falingtrea 0:f40dbeaefe69 214 uint8_t buf;
falingtrea 0:f40dbeaefe69 215 uint8_t result = 0;
falingtrea 0:f40dbeaefe69 216
falingtrea 0:f40dbeaefe69 217 switch (reg) // setup data byte for specific command register write
falingtrea 0:f40dbeaefe69 218 {
falingtrea 0:f40dbeaefe69 219 case SETCOLADDRLSB :
falingtrea 0:f40dbeaefe69 220 // use COLMASK for data
falingtrea 0:f40dbeaefe69 221 buf = SETCOLADDRLSB | (data & COLMASK);
falingtrea 0:f40dbeaefe69 222 break;
falingtrea 0:f40dbeaefe69 223 case SETCOLADDRMSB :
falingtrea 0:f40dbeaefe69 224 // use COLMASK for data
falingtrea 0:f40dbeaefe69 225 buf = SETCOLADDRMSB | (data & COLMASK);
falingtrea 0:f40dbeaefe69 226 break;
falingtrea 0:f40dbeaefe69 227 case SETPWRCTRL :
falingtrea 0:f40dbeaefe69 228 // use PCMASK for data
falingtrea 0:f40dbeaefe69 229 buf = SETPWRCTRL | (data & PCMASK);
falingtrea 0:f40dbeaefe69 230 break;
falingtrea 0:f40dbeaefe69 231 case SETSCROLLLINE :
falingtrea 0:f40dbeaefe69 232 // use SLMASK for data
falingtrea 0:f40dbeaefe69 233 buf = SETSCROLLLINE | (data & SLMASK);
falingtrea 0:f40dbeaefe69 234 break;
falingtrea 0:f40dbeaefe69 235 case SETPGADDR :
falingtrea 0:f40dbeaefe69 236 // use COLMASK for data
falingtrea 0:f40dbeaefe69 237 buf = SETPGADDR | (data & COLMASK);
falingtrea 0:f40dbeaefe69 238 break;
falingtrea 0:f40dbeaefe69 239 case SETVLCDRESRATIO :
falingtrea 0:f40dbeaefe69 240 // use PCMASK for data
falingtrea 0:f40dbeaefe69 241 buf = SETVLCDRESRATIO | (data & PCMASK);
falingtrea 0:f40dbeaefe69 242 break;
falingtrea 0:f40dbeaefe69 243 case SETELECVOL :
falingtrea 0:f40dbeaefe69 244 // double byte command use SLMASK for data
falingtrea 0:f40dbeaefe69 245 buf = data & SLMASK;
falingtrea 0:f40dbeaefe69 246 break;
falingtrea 0:f40dbeaefe69 247 case SETALLPIXELON :
falingtrea 0:f40dbeaefe69 248 // use LSBMASK for data
falingtrea 0:f40dbeaefe69 249 buf = SETALLPIXELON | (data & LSBMASK);
falingtrea 0:f40dbeaefe69 250 break;
falingtrea 0:f40dbeaefe69 251 case SETINVDISP :
falingtrea 0:f40dbeaefe69 252 // use LSBMASK for data
falingtrea 0:f40dbeaefe69 253 buf = SETINVDISP | (data & LSBMASK);
falingtrea 0:f40dbeaefe69 254 break;
falingtrea 0:f40dbeaefe69 255 case SETDISPEN :
falingtrea 0:f40dbeaefe69 256 // use LSBMASK for data
falingtrea 0:f40dbeaefe69 257 buf = SETDISPEN | (data & LSBMASK);
falingtrea 0:f40dbeaefe69 258 break;
falingtrea 0:f40dbeaefe69 259 case SETSEGDIR :
falingtrea 0:f40dbeaefe69 260 // use LSBMASK for data
falingtrea 0:f40dbeaefe69 261 buf = SETSEGDIR | (data & LSBMASK);
falingtrea 0:f40dbeaefe69 262 break;
falingtrea 0:f40dbeaefe69 263 case SETLCDBIAS :
falingtrea 0:f40dbeaefe69 264 // use LSBMASK for data
falingtrea 0:f40dbeaefe69 265 buf = SETLCDBIAS | (data & LSBMASK);
falingtrea 0:f40dbeaefe69 266 break;
falingtrea 0:f40dbeaefe69 267 case SETCOMDIR :
falingtrea 0:f40dbeaefe69 268 // use LC1MASK for data
falingtrea 0:f40dbeaefe69 269 buf = SETCOMDIR | ((data << 3) & COLMASK);
falingtrea 0:f40dbeaefe69 270 break;
falingtrea 0:f40dbeaefe69 271 case SOFTRESET :
falingtrea 0:f40dbeaefe69 272 // no data mask needed
falingtrea 0:f40dbeaefe69 273 buf = SOFTRESET;
falingtrea 0:f40dbeaefe69 274 break;
falingtrea 0:f40dbeaefe69 275 case SETAPROGCTRL :
falingtrea 0:f40dbeaefe69 276 // Double byte command use WAMASK and TCMASK for data
falingtrea 0:f40dbeaefe69 277 buf = data & (COLMASK | TCMASK);
falingtrea 0:f40dbeaefe69 278 break;
falingtrea 0:f40dbeaefe69 279 default :
falingtrea 0:f40dbeaefe69 280 debug("Command Register not valid\n\r");
falingtrea 0:f40dbeaefe69 281 result = 1;
falingtrea 0:f40dbeaefe69 282 }
falingtrea 0:f40dbeaefe69 283
falingtrea 0:f40dbeaefe69 284 if (result == 0)
falingtrea 0:f40dbeaefe69 285 {
falingtrea 0:f40dbeaefe69 286 _spi->frequency(4000000);
falingtrea 0:f40dbeaefe69 287 _spi->format(8,3); // 8bit transfers, SPI mode 3
falingtrea 0:f40dbeaefe69 288
falingtrea 0:f40dbeaefe69 289 _lcd_cs->write (0); // enable LCD SPI interface
falingtrea 0:f40dbeaefe69 290 _cmnd_data->write(0); // set to command mode
falingtrea 0:f40dbeaefe69 291
falingtrea 0:f40dbeaefe69 292 switch (reg) // send first byte of double byte command for these register
falingtrea 0:f40dbeaefe69 293 {
falingtrea 0:f40dbeaefe69 294 case SETELECVOL :
falingtrea 0:f40dbeaefe69 295 case SETAPROGCTRL :
falingtrea 0:f40dbeaefe69 296 _spi->write(reg);
falingtrea 0:f40dbeaefe69 297 break;
falingtrea 0:f40dbeaefe69 298 }
falingtrea 0:f40dbeaefe69 299
falingtrea 0:f40dbeaefe69 300 _spi->write(buf); // send command register
falingtrea 0:f40dbeaefe69 301
falingtrea 0:f40dbeaefe69 302 _cmnd_data->write(1); // set back to data mode
falingtrea 0:f40dbeaefe69 303 _lcd_cs->write(1); // disable LCD SPI Interface
falingtrea 0:f40dbeaefe69 304
falingtrea 0:f40dbeaefe69 305 }
falingtrea 0:f40dbeaefe69 306
falingtrea 0:f40dbeaefe69 307 if(result != 0)
falingtrea 0:f40dbeaefe69 308 {
falingtrea 0:f40dbeaefe69 309 debug("DOGS102:writeCommand failed\n\r");
falingtrea 0:f40dbeaefe69 310 }
falingtrea 0:f40dbeaefe69 311
falingtrea 0:f40dbeaefe69 312 return result;
falingtrea 0:f40dbeaefe69 313 }
falingtrea 0:f40dbeaefe69 314
falingtrea 0:f40dbeaefe69 315 void DOGS102::writeData(const uint8_t* data, uint8_t count) const
falingtrea 0:f40dbeaefe69 316 {
falingtrea 0:f40dbeaefe69 317 uint8_t result = 0;
falingtrea 0:f40dbeaefe69 318 uint8_t i;
falingtrea 0:f40dbeaefe69 319
falingtrea 0:f40dbeaefe69 320 _spi->frequency(4000000);
falingtrea 0:f40dbeaefe69 321 _spi->format(8,3); // 8bit transfers, SPI mode 3
falingtrea 0:f40dbeaefe69 322
falingtrea 0:f40dbeaefe69 323 _lcd_cs->write(0); // enable LCD SPI interface
falingtrea 0:f40dbeaefe69 324 i = 0; // initialize transfer counter
falingtrea 0:f40dbeaefe69 325
falingtrea 0:f40dbeaefe69 326 do
falingtrea 0:f40dbeaefe69 327 {
falingtrea 0:f40dbeaefe69 328 _spi->write(data[i]);
falingtrea 0:f40dbeaefe69 329 i++;
falingtrea 0:f40dbeaefe69 330 } while ((result == 0) && (i <= count)) ;
falingtrea 0:f40dbeaefe69 331
falingtrea 0:f40dbeaefe69 332 _lcd_cs->write(1); // disable LCD SPI interface
falingtrea 0:f40dbeaefe69 333
falingtrea 0:f40dbeaefe69 334 return;
falingtrea 0:f40dbeaefe69 335 }
falingtrea 0:f40dbeaefe69 336
falingtrea 0:f40dbeaefe69 337 void DOGS102::sendBuffer(const uint8_t* buffer)
falingtrea 0:f40dbeaefe69 338 {
falingtrea 0:f40dbeaefe69 339 //debug("Sending LCD Buffer\n");
falingtrea 0:f40dbeaefe69 340 for (int i=0; i<LCDPAGES; i++)
falingtrea 0:f40dbeaefe69 341 {
falingtrea 0:f40dbeaefe69 342 DOGS102::setCursor(0,i*8);
falingtrea 0:f40dbeaefe69 343 DOGS102::writeData(buffer + i*LCDWIDTH, LCDWIDTH);
falingtrea 0:f40dbeaefe69 344 }
falingtrea 0:f40dbeaefe69 345 }
falingtrea 0:f40dbeaefe69 346