Driver for the Seeedstudio RGB OLED module for the xadow M0

Committer:
messi1
Date:
Thu Dec 03 21:48:11 2015 +0000
Revision:
13:8dd215952d76
Parent:
11:162aa3e801df
Child:
17:1bcdc92af126
Fixed Chinese Typos

Who changed what in which revision?

UserRevisionLine numberNew contents of line
messi1 0:6e810b5b40a3 1 /*
messi1 0:6e810b5b40a3 2 * SSD1331.cpp
messi1 0:6e810b5b40a3 3 * A library for RGB OLED module
messi1 0:6e810b5b40a3 4 *
messi1 0:6e810b5b40a3 5 * Copyright (c) 2014 seeed technology inc.
messi1 0:6e810b5b40a3 6 * Copyright (c) 2012, Adafruit Industries.
messi1 0:6e810b5b40a3 7 *
messi1 0:6e810b5b40a3 8 * All rights reserved.
messi1 0:6e810b5b40a3 9 *
messi1 0:6e810b5b40a3 10 * This library is based on Adafruit's SSD1331-OLED-Driver-Library. Thanks to
messi1 0:6e810b5b40a3 11 * their contribution to the code, we modify it and add more interface to
messi1 0:6e810b5b40a3 12 * support our Seeed's Xadow RGB OLED 96*64 module.
messi1 0:6e810b5b40a3 13 *
messi1 0:6e810b5b40a3 14 * Below is the introduction of Adafruit's Color OLED module, we add it to here
messi1 0:6e810b5b40a3 15 * to express our thanks to them.
messi1 0:6e810b5b40a3 16 *
messi1 0:6e810b5b40a3 17 * ****************************************************************************
messi1 0:6e810b5b40a3 18 * This is a library for the 0.96" 16-bit Color OLED with SSD1331 driver chip
messi1 0:6e810b5b40a3 19 *
messi1 0:6e810b5b40a3 20 * Pick one up today in the adafruit shop!
messi1 0:6e810b5b40a3 21 * ------> http://www.adafruit.com/products/684
messi1 0:6e810b5b40a3 22 *
messi1 0:6e810b5b40a3 23 * These displays use SPI to communicate.
messi1 0:6e810b5b40a3 24 *
messi1 0:6e810b5b40a3 25 * Adafruit invests time and resources providing this open source code,
messi1 0:6e810b5b40a3 26 * please support Adafruit and open-source hardware by purchasing
messi1 0:6e810b5b40a3 27 * products from Adafruit!
messi1 0:6e810b5b40a3 28 *
messi1 0:6e810b5b40a3 29 * Written by Limor Fried/Ladyada for Adafruit Industries.
messi1 0:6e810b5b40a3 30 * Modifed by lawliet for Seeed Studio's RGB OLED module.
messi1 0:6e810b5b40a3 31 * BSD license, all text above must be included in any redistribution
messi1 0:6e810b5b40a3 32 * ******************************************************************************
messi1 0:6e810b5b40a3 33 *
messi1 0:6e810b5b40a3 34 * Software License Agreement (BSD License)
messi1 0:6e810b5b40a3 35 *
messi1 0:6e810b5b40a3 36 * Redistribution and use in source and binary forms, with or without
messi1 0:6e810b5b40a3 37 * modification, are permitted provided that the following conditions are met:
messi1 0:6e810b5b40a3 38 * 1. Redistributions of source code must retain the above copyright
messi1 0:6e810b5b40a3 39 * notice, this list of conditions and the following disclaimer.
messi1 0:6e810b5b40a3 40 * 2. Redistributions in binary form must reproduce the above copyright
messi1 0:6e810b5b40a3 41 * notice, this list of conditions and the following disclaimer in the
messi1 0:6e810b5b40a3 42 * documentation and/or other materials provided with the distribution.
messi1 0:6e810b5b40a3 43 * 3. Neither the name of the copyright holders nor the
messi1 0:6e810b5b40a3 44 * names of its contributors may be used to endorse or promote products
messi1 0:6e810b5b40a3 45 * derived from this software without specific prior written permission.
messi1 0:6e810b5b40a3 46 *
messi1 0:6e810b5b40a3 47 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
messi1 0:6e810b5b40a3 48 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
messi1 0:6e810b5b40a3 49 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
messi1 0:6e810b5b40a3 50 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
messi1 0:6e810b5b40a3 51 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
messi1 0:6e810b5b40a3 52 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
messi1 0:6e810b5b40a3 53 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
messi1 0:6e810b5b40a3 54 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
messi1 0:6e810b5b40a3 55 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
messi1 0:6e810b5b40a3 56 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
messi1 0:6e810b5b40a3 57 *
messi1 0:6e810b5b40a3 58 */
messi1 0:6e810b5b40a3 59 #include "DigitalOut.h"
messi1 0:6e810b5b40a3 60 #include "SPI.h"
messi1 0:6e810b5b40a3 61 #include "SSD1331.h"
messi1 5:9de43186f5ea 62 #include "wait_api.h"
messi1 0:6e810b5b40a3 63
messi1 2:e033aab5daad 64 SSD1331::SSD1331(PinName cs, PinName rst, PinName dc, PinName mosi, PinName miso, PinName sclk)
messi1 11:162aa3e801df 65 :SGL<uint8_t>(RGB_OLED_WIDTH, RGB_OLED_HEIGHT),
messi1 10:ef7440718431 66 _cs(cs),
messi1 10:ef7440718431 67 _dc(dc),
messi1 10:ef7440718431 68 _spiPort(mosi, miso, sclk)
messi1 0:6e810b5b40a3 69 {
messi1 2:e033aab5daad 70 _spiPort.format(8,3); //8bit frame and POL=1 /PHA=1(UpEdge Sampled)
messi1 2:e033aab5daad 71 _spiPort.frequency(25000000); // modify later
messi1 2:e033aab5daad 72
messi1 2:e033aab5daad 73 init();
messi1 0:6e810b5b40a3 74 };
messi1 0:6e810b5b40a3 75
messi1 4:1707ca53e7d5 76 //------------------------------------------------------------------------------------
messi1 5:9de43186f5ea 77 void SSD1331::init(void)
messi1 5:9de43186f5ea 78 {
messi1 5:9de43186f5ea 79 // initialize sequence
messi1 5:9de43186f5ea 80 sendCmd(CMD_DISPLAY_OFF); //OLED display OFF
messi1 5:9de43186f5ea 81
messi1 5:9de43186f5ea 82 //Row Address
messi1 5:9de43186f5ea 83 sendCmd(CMD_SET_ROW_ADDRESS, 0x00, 0x3f); //Set Row Address with start=0,end=63
messi1 5:9de43186f5ea 84 sendCmd(CMD_SET_COLUMN_ADDRESS, 0x00, 0x5f); //Set Column Address with start=0,end=95
messi1 5:9de43186f5ea 85
messi1 5:9de43186f5ea 86 //Contrast
messi1 7:5250c825c7bb 87 sendCmd(CMD_SET_REMAP, 0x72); //Set remap & data format 0111 0000 // 65k Color/8bit buswidth/format1 0x72
messi1 5:9de43186f5ea 88 sendCmd(CMD_SET_DISPLAY_START_LINE, 0x00); //Set display start row RAM
messi1 5:9de43186f5ea 89 sendCmd(CMD_SET_DISPLAY_OFFSET, 0x00); //Set dispaly offset
messi1 5:9de43186f5ea 90 sendCmd(CMD_NORMAL_DISPLAY); //Set Display Mode
messi1 5:9de43186f5ea 91 sendCmd(CMD_SET_MULTIPLEX_RATIO, 0x3f); //Set Multiplex Ratio
messi1 7:5250c825c7bb 92 sendCmd(CMD_SET_MASTER_CONFIGURE, 0x8e); //Set Master Configuration (External VCC Supply Selected) 0x8f or 0x8e
messi1 5:9de43186f5ea 93 sendCmd(CMD_POWER_SAVE_MODE, 0x1a); //Set Power Saving Mode
messi1 7:5250c825c7bb 94 sendCmd(CMD_PHASE_PERIOD_ADJUSTMENT, 0x31); //Set Phase 1 & 2 Period Adjustment 0x74 or 0x31
messi1 7:5250c825c7bb 95 sendCmd(CMD_DISPLAY_CLOCK_DIV, 0xf0); //Set Display Clock Divide Ratio / Oscillator Frequency 0xd0 or 0xf0
messi1 7:5250c825c7bb 96 sendCmd(CMD_SET_PRECHARGE_SPEED_A, 0x64); //Set Second Pre-charge Speed of Color A 0x81 or 0x64
messi1 7:5250c825c7bb 97 sendCmd(CMD_SET_PRECHARGE_SPEED_B, 0x78); //Set Second Pre-charge Speed of Color B 0x82 or 0x78
messi1 7:5250c825c7bb 98 sendCmd(CMD_SET_PRECHARGE_SPEED_C, 0x64); //Set Second Pre-charge Speed of Color C 0x83 or 0x64
messi1 7:5250c825c7bb 99 sendCmd(CMD_SET_PRECHARGE_VOLTAGE, 0x3a); //Set Pre-charge Level 3e or 3a
messi1 5:9de43186f5ea 100 sendCmd(CMD_SET_V_VOLTAGE, 0x3e); //Set VCOMH
messi1 7:5250c825c7bb 101 sendCmd(CMD_MASTER_CURRENT_CONTROL, 0x06); //Set Master Current Control 0x6 or 0xf
messi1 7:5250c825c7bb 102 sendCmd(CMD_SET_CONTRAST_A, 0x91); //Set Contrast Control for Color &#129;gA&#129;h 0x80 or 0x91
messi1 7:5250c825c7bb 103 sendCmd(CMD_SET_CONTRAST_B, 0x50); //Set Contrast Control for Color &#129;gB&#129;h 0x80 or 0x50
messi1 7:5250c825c7bb 104 sendCmd(CMD_SET_CONTRAST_C, 0x7d); //Set Contrast Control for Color &#129;gC&#129;h 0x80 or 0x7D
messi1 5:9de43186f5ea 105
messi1 5:9de43186f5ea 106 clearArea(0,0, RGB_OLED_XMAX, RGB_OLED_YMAX);
messi1 5:9de43186f5ea 107 sendCmd(CMD_NORMAL_BRIGHTNESS_DISPLAY_ON); //display ON
messi1 7:5250c825c7bb 108 wait(0.1);
messi1 5:9de43186f5ea 109 }
messi1 5:9de43186f5ea 110
messi1 5:9de43186f5ea 111 //------------------------------------------------------------------------------------
messi1 5:9de43186f5ea 112 void SSD1331::drawPixel(uint8_t x, uint8_t y, uint16_t color)
messi1 5:9de43186f5ea 113 {
messi1 6:06c211302c93 114 if (x >= RGB_OLED_WIDTH) x = RGB_OLED_XMAX;
messi1 6:06c211302c93 115 if (y >= RGB_OLED_HEIGHT) y = RGB_OLED_YMAX;
messi1 5:9de43186f5ea 116 // set column point set row point
messi1 5:9de43186f5ea 117 uint8_t cmdBuffer[6] = { CMD_SET_COLUMN_ADDRESS, x, x, CMD_SET_ROW_ADDRESS, y, y };
messi1 5:9de43186f5ea 118 sendCmd(cmdBuffer, 6); //Send buffer
messi1 5:9de43186f5ea 119 sendData(color); //fill 16bit colour
messi1 5:9de43186f5ea 120 }
messi1 5:9de43186f5ea 121
messi1 5:9de43186f5ea 122 //------------------------------------------------------------------------------------
messi1 5:9de43186f5ea 123 void SSD1331::drawLine(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint16_t color)
messi1 5:9de43186f5ea 124 {
messi1 6:06c211302c93 125 if (x0 >= RGB_OLED_WIDTH) x0 = RGB_OLED_XMAX;
messi1 6:06c211302c93 126 if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_YMAX;
messi1 6:06c211302c93 127 if (x1 >= RGB_OLED_WIDTH) x1 = RGB_OLED_XMAX;
messi1 6:06c211302c93 128 if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_YMAX;
messi1 5:9de43186f5ea 129
messi1 7:5250c825c7bb 130 uint8_t cmd[8] = { CMD_DRAW_LINE, x0, y0, x1, y1, (uint8_t)(((color>>11)&0x1F)<<1), (uint8_t)((color>>5)&0x3F), (uint8_t)((color&0x1F)<<1) };
messi1 5:9de43186f5ea 131 sendCmd(cmd, 8);
messi1 5:9de43186f5ea 132 }
messi1 5:9de43186f5ea 133
messi1 5:9de43186f5ea 134 //------------------------------------------------------------------------------------
messi1 8:ff74bd4d94d6 135 void SSD1331::drawRect(uint8_t left_x, uint8_t top_y, uint8_t width, uint8_t height, uint16_t color)
messi1 8:ff74bd4d94d6 136 {
messi1 8:ff74bd4d94d6 137 if (left_x >= RGB_OLED_WIDTH) left_x = RGB_OLED_XMAX;
messi1 8:ff74bd4d94d6 138 if (top_y >= RGB_OLED_HEIGHT) top_y = RGB_OLED_YMAX;
messi1 8:ff74bd4d94d6 139
messi1 8:ff74bd4d94d6 140 drawLine(left_x, top_y, left_x+width, top_y, color); // horizontal
messi1 8:ff74bd4d94d6 141 drawLine(left_x, top_y, left_x, top_y+height, color); // vertical
messi1 8:ff74bd4d94d6 142 drawLine(left_x, top_y+height, left_x+width, top_y+height, color); //horizontal
messi1 8:ff74bd4d94d6 143 drawLine(left_x+width, top_y, left_x+width, top_y+height, color); // vertical
messi1 8:ff74bd4d94d6 144 }
messi1 8:ff74bd4d94d6 145
messi1 8:ff74bd4d94d6 146 //------------------------------------------------------------------------------------
messi1 9:5a7bf0ce8518 147 void SSD1331::drawRect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint16_t outColor, uint16_t fillColor)
messi1 5:9de43186f5ea 148 {
messi1 6:06c211302c93 149 if (x0 >= RGB_OLED_WIDTH) x0 = RGB_OLED_XMAX;
messi1 6:06c211302c93 150 if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_YMAX;
messi1 6:06c211302c93 151 if (x1 >= RGB_OLED_WIDTH) x1 = RGB_OLED_XMAX;
messi1 6:06c211302c93 152 if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_YMAX;
messi1 5:9de43186f5ea 153
messi1 5:9de43186f5ea 154 uint8_t cmd[11] = { CMD_DRAW_RECTANGLE, x0, y0, x1, y1,
messi1 7:5250c825c7bb 155 (uint8_t)(((outColor>>11)&0x1F)<<1), (uint8_t)((outColor>>5)&0x3F), (uint8_t)((outColor&0x1F)<<1),
messi1 7:5250c825c7bb 156 (uint8_t)(((fillColor>>11)&0x1F)<<1), (uint8_t)((fillColor>>5)&0x3F), (uint8_t)((fillColor&0x1F)<<1)};
messi1 5:9de43186f5ea 157
messi1 5:9de43186f5ea 158 sendCmd(CMD_FILL_WINDOW, ENABLE_FILL);//fill window
messi1 5:9de43186f5ea 159 sendCmd(cmd, 11);
messi1 5:9de43186f5ea 160 wait(0.05);
messi1 5:9de43186f5ea 161 }
messi1 5:9de43186f5ea 162
messi1 5:9de43186f5ea 163 //------------------------------------------------------------------------------------
messi1 5:9de43186f5ea 164 void SSD1331::copyArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,uint8_t x2, uint8_t y2)
messi1 5:9de43186f5ea 165 {
messi1 6:06c211302c93 166 if (x0 >= RGB_OLED_WIDTH) x0 = RGB_OLED_XMAX;
messi1 6:06c211302c93 167 if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_YMAX;
messi1 6:06c211302c93 168 if (x1 >= RGB_OLED_WIDTH) x1 = RGB_OLED_XMAX;
messi1 6:06c211302c93 169 if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_YMAX;
messi1 6:06c211302c93 170 if (x2 >= RGB_OLED_WIDTH) x2 = RGB_OLED_XMAX;
messi1 6:06c211302c93 171 if (y2 >= RGB_OLED_HEIGHT) y2 = RGB_OLED_YMAX;
messi1 5:9de43186f5ea 172
messi1 5:9de43186f5ea 173 uint8_t cmd[7] = { CMD_COPY_WINDOW, x0, y0, x1, y1, x2, y2};
messi1 5:9de43186f5ea 174 sendCmd(cmd, 7);
messi1 5:9de43186f5ea 175 wait(0.05);
messi1 5:9de43186f5ea 176 }
messi1 5:9de43186f5ea 177
messi1 5:9de43186f5ea 178 //------------------------------------------------------------------------------------
messi1 5:9de43186f5ea 179 void SSD1331::dimArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1)
messi1 5:9de43186f5ea 180 {
messi1 6:06c211302c93 181 if (x0 >= RGB_OLED_WIDTH) x0 = RGB_OLED_XMAX;
messi1 6:06c211302c93 182 if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_YMAX;
messi1 6:06c211302c93 183 if (x1 >= RGB_OLED_WIDTH) x1 = RGB_OLED_XMAX;
messi1 6:06c211302c93 184 if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_YMAX;
messi1 5:9de43186f5ea 185
messi1 5:9de43186f5ea 186 uint8_t cmdBuffer[5] = { CMD_DIM_WINDOW, x0, y0, x1, y1 };
messi1 5:9de43186f5ea 187 sendCmd(cmdBuffer, 5); //Send buffer
messi1 5:9de43186f5ea 188 wait(0.05);
messi1 5:9de43186f5ea 189 }
messi1 5:9de43186f5ea 190
messi1 5:9de43186f5ea 191 //------------------------------------------------------------------------------------
messi1 5:9de43186f5ea 192 void SSD1331::clearArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1)
messi1 5:9de43186f5ea 193 {
messi1 6:06c211302c93 194 if (x0 >= RGB_OLED_WIDTH) x0 = RGB_OLED_XMAX;
messi1 6:06c211302c93 195 if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_YMAX;
messi1 6:06c211302c93 196 if (x1 >= RGB_OLED_WIDTH) x1 = RGB_OLED_XMAX;
messi1 6:06c211302c93 197 if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_YMAX;
messi1 5:9de43186f5ea 198
messi1 5:9de43186f5ea 199 uint8_t cmdBuffer[5] = { CMD_CLEAR_WINDOW, x0, y0, x1, y1 };
messi1 5:9de43186f5ea 200 sendCmd(cmdBuffer, 5); //Send buffer
messi1 5:9de43186f5ea 201 wait(0.05);
messi1 5:9de43186f5ea 202 }
messi1 5:9de43186f5ea 203
messi1 5:9de43186f5ea 204 //------------------------------------------------------------------------------------
messi1 6:06c211302c93 205 void SSD1331::moveArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2)
messi1 6:06c211302c93 206 {
messi1 6:06c211302c93 207 copyArea(x0, y0, x1, y1, x2, y2);
messi1 6:06c211302c93 208 clearArea(x0, y0, x1, y1);
messi1 6:06c211302c93 209 }
messi1 6:06c211302c93 210
messi1 6:06c211302c93 211 //------------------------------------------------------------------------------------
messi1 8:ff74bd4d94d6 212 void SSD1331::fillScreen(uint16_t color)
messi1 8:ff74bd4d94d6 213 {
messi1 9:5a7bf0ce8518 214 drawRect(0, 0, RGB_OLED_XMAX, RGB_OLED_YMAX, color, color);
messi1 8:ff74bd4d94d6 215 }
messi1 8:ff74bd4d94d6 216
messi1 8:ff74bd4d94d6 217 //------------------------------------------------------------------------------------
messi1 13:8dd215952d76 218 void SSD1331::setScrolling(ScrollDirection direction, uint8_t rowAddr, uint8_t rowNum, ScrollInterval interval)
messi1 5:9de43186f5ea 219 {
messi1 5:9de43186f5ea 220 uint8_t scolling_horizontal = 0x0;
messi1 5:9de43186f5ea 221 uint8_t scolling_vertical = 0x0;
messi1 5:9de43186f5ea 222 switch(direction){
messi1 9:5a7bf0ce8518 223 case SD_Horizontal:
messi1 5:9de43186f5ea 224 scolling_horizontal = 0x01;
messi1 5:9de43186f5ea 225 scolling_vertical = 0x00;
messi1 5:9de43186f5ea 226 break;
messi1 9:5a7bf0ce8518 227 case SD_Vertical:
messi1 5:9de43186f5ea 228 scolling_horizontal = 0x00;
messi1 5:9de43186f5ea 229 scolling_vertical = 0x01;
messi1 5:9de43186f5ea 230 break;
messi1 9:5a7bf0ce8518 231 case SD_Diagonal:
messi1 5:9de43186f5ea 232 scolling_horizontal = 0x01;
messi1 5:9de43186f5ea 233 scolling_vertical = 0x01;
messi1 5:9de43186f5ea 234 break;
messi1 5:9de43186f5ea 235 default:
messi1 5:9de43186f5ea 236 break;
messi1 5:9de43186f5ea 237 }
messi1 5:9de43186f5ea 238
messi1 9:5a7bf0ce8518 239 uint8_t cmdBuffer[6] = { CMD_CONTINUOUS_SCROLLING_SETUP, scolling_horizontal, rowAddr, rowNum, scolling_vertical, interval };
messi1 5:9de43186f5ea 240 sendCmd(cmdBuffer, 6); //Send buffer
messi1 5:9de43186f5ea 241 sendCmd(CMD_ACTIVE_SCROLLING);
messi1 5:9de43186f5ea 242 wait(0.05);
messi1 5:9de43186f5ea 243 }
messi1 5:9de43186f5ea 244
messi1 5:9de43186f5ea 245 //------------------------------------------------------------------------------------
messi1 13:8dd215952d76 246 void SSD1331::enableScrolling(bool enable)
messi1 5:9de43186f5ea 247 {
messi1 5:9de43186f5ea 248 if(enable)
messi1 5:9de43186f5ea 249 sendCmd(CMD_ACTIVE_SCROLLING);
messi1 5:9de43186f5ea 250 else
messi1 5:9de43186f5ea 251 sendCmd(CMD_DEACTIVE_SCROLLING);
messi1 5:9de43186f5ea 252 }
messi1 5:9de43186f5ea 253
messi1 5:9de43186f5ea 254 //------------------------------------------------------------------------------------
messi1 5:9de43186f5ea 255 void SSD1331::setDisplayMode(DisplayMode mode)
messi1 5:9de43186f5ea 256 {
messi1 5:9de43186f5ea 257 sendCmd(mode);
messi1 5:9de43186f5ea 258 }
messi1 5:9de43186f5ea 259
messi1 5:9de43186f5ea 260 //------------------------------------------------------------------------------------
messi1 9:5a7bf0ce8518 261 void SSD1331::setPowerMode(PowerMode power)
messi1 5:9de43186f5ea 262 {
messi1 5:9de43186f5ea 263 sendCmd(power);
messi1 5:9de43186f5ea 264 }
messi1 5:9de43186f5ea 265
messi1 5:9de43186f5ea 266 //------------------------------------------------------------------------------------
messi1 5:9de43186f5ea 267 // Private member functions
messi1 5:9de43186f5ea 268 //------------------------------------------------------------------------------------
messi1 3:af00512c9694 269 void SSD1331::sendCmd(uint8_t cmd)
messi1 2:e033aab5daad 270 {
messi1 2:e033aab5daad 271 _dc = 0;
messi1 2:e033aab5daad 272 _cs = 0;
messi1 2:e033aab5daad 273 _spiPort.write(cmd);
messi1 2:e033aab5daad 274 _cs = 1;
messi1 2:e033aab5daad 275 }
messi1 2:e033aab5daad 276
messi1 4:1707ca53e7d5 277 //------------------------------------------------------------------------------------
messi1 3:af00512c9694 278 void SSD1331::sendCmd(uint8_t cmd, uint8_t arg1)
messi1 2:e033aab5daad 279 {
messi1 2:e033aab5daad 280 _dc = 0;
messi1 2:e033aab5daad 281 _cs = 0;
messi1 2:e033aab5daad 282 _spiPort.write(cmd);
messi1 2:e033aab5daad 283 _spiPort.write(arg1);
messi1 2:e033aab5daad 284 _cs = 1;
messi1 2:e033aab5daad 285 }
messi1 4:1707ca53e7d5 286
messi1 4:1707ca53e7d5 287 //------------------------------------------------------------------------------------
messi1 3:af00512c9694 288 void SSD1331::sendCmd(uint8_t cmd, uint8_t arg1, uint8_t arg2)
messi1 0:6e810b5b40a3 289 {
messi1 2:e033aab5daad 290 _dc = 0;
messi1 2:e033aab5daad 291 _cs = 0;
messi1 2:e033aab5daad 292 _spiPort.write(cmd);
messi1 2:e033aab5daad 293 _spiPort.write(arg1);
messi1 2:e033aab5daad 294 _spiPort.write(arg2);
messi1 2:e033aab5daad 295 _cs = 1;
messi1 2:e033aab5daad 296 }
messi1 2:e033aab5daad 297
messi1 4:1707ca53e7d5 298 //------------------------------------------------------------------------------------
messi1 3:af00512c9694 299 void SSD1331::sendCmd(uint8_t *cmd, uint8_t count)
messi1 2:e033aab5daad 300 {
messi1 2:e033aab5daad 301 if(!cmd) return;
messi1 2:e033aab5daad 302
messi1 2:e033aab5daad 303 _dc = 0;
messi1 2:e033aab5daad 304 _cs = 0;
messi1 3:af00512c9694 305 for(uint8_t i=0; i<count; ++i)
messi1 2:e033aab5daad 306 _spiPort.write(*cmd++);
messi1 2:e033aab5daad 307 _cs = 1;
messi1 2:e033aab5daad 308 }
messi1 2:e033aab5daad 309
messi1 4:1707ca53e7d5 310 //------------------------------------------------------------------------------------
messi1 2:e033aab5daad 311 void SSD1331::sendData(uint16_t data)
messi1 2:e033aab5daad 312 {
messi1 2:e033aab5daad 313 _dc = HIGH;
messi1 2:e033aab5daad 314 _cs = LOW;
messi1 2:e033aab5daad 315 _spiPort.write(data >> 8);
messi1 2:e033aab5daad 316 _spiPort.write((data & 0x00ff));
messi1 2:e033aab5daad 317 _cs = HIGH;
messi1 2:e033aab5daad 318 }
messi1 2:e033aab5daad 319
messi1 4:1707ca53e7d5 320 //------------------------------------------------------------------------------------
messi1 4:1707ca53e7d5 321 int SSD1331::_getc()
messi1 4:1707ca53e7d5 322 {
messi1 4:1707ca53e7d5 323 return -1;
messi1 4:1707ca53e7d5 324 }
messi1 4:1707ca53e7d5 325
messi1 4:1707ca53e7d5 326 //------------------------------------------------------------------------------------
messi1 4:1707ca53e7d5 327 int SSD1331::_putc( int c )
messi1 4:1707ca53e7d5 328 {
messi1 4:1707ca53e7d5 329 return -1;
messi1 4:1707ca53e7d5 330 }