Driver for the Seeedstudio RGB OLED module for the xadow M0
src/SSD1331.cpp@4:1707ca53e7d5, 2015-11-12 (annotated)
- Committer:
- messi1
- Date:
- Thu Nov 12 23:53:58 2015 +0000
- Revision:
- 4:1707ca53e7d5
- Parent:
- 3:af00512c9694
- Child:
- 5:9de43186f5ea
Improved drawLine function
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:6e810b5b40a3 | 62 | |
messi1 | 2:e033aab5daad | 63 | SSD1331::SSD1331(PinName cs, PinName rst, PinName dc, PinName mosi, PinName miso, PinName sclk) |
messi1 | 2:e033aab5daad | 64 | :SGL(RGB_OLED_WIDTH, RGB_OLED_HEIGHT), _cs(cs), _dc(dc), _spiPort(mosi, miso, sclk) |
messi1 | 0:6e810b5b40a3 | 65 | { |
messi1 | 2:e033aab5daad | 66 | _spiPort.format(8,3); //8bit frame and POL=1 /PHA=1(UpEdge Sampled) |
messi1 | 2:e033aab5daad | 67 | _spiPort.frequency(25000000); // modify later |
messi1 | 2:e033aab5daad | 68 | |
messi1 | 2:e033aab5daad | 69 | init(); |
messi1 | 0:6e810b5b40a3 | 70 | }; |
messi1 | 0:6e810b5b40a3 | 71 | |
messi1 | 4:1707ca53e7d5 | 72 | //------------------------------------------------------------------------------------ |
messi1 | 3:af00512c9694 | 73 | void SSD1331::sendCmd(uint8_t cmd) |
messi1 | 2:e033aab5daad | 74 | { |
messi1 | 2:e033aab5daad | 75 | _dc = 0; |
messi1 | 2:e033aab5daad | 76 | _cs = 0; |
messi1 | 2:e033aab5daad | 77 | _spiPort.write(cmd); |
messi1 | 2:e033aab5daad | 78 | _cs = 1; |
messi1 | 2:e033aab5daad | 79 | } |
messi1 | 2:e033aab5daad | 80 | |
messi1 | 4:1707ca53e7d5 | 81 | //------------------------------------------------------------------------------------ |
messi1 | 3:af00512c9694 | 82 | void SSD1331::sendCmd(uint8_t cmd, uint8_t arg1) |
messi1 | 2:e033aab5daad | 83 | { |
messi1 | 2:e033aab5daad | 84 | _dc = 0; |
messi1 | 2:e033aab5daad | 85 | _cs = 0; |
messi1 | 2:e033aab5daad | 86 | _spiPort.write(cmd); |
messi1 | 2:e033aab5daad | 87 | _spiPort.write(arg1); |
messi1 | 2:e033aab5daad | 88 | _cs = 1; |
messi1 | 2:e033aab5daad | 89 | } |
messi1 | 4:1707ca53e7d5 | 90 | |
messi1 | 4:1707ca53e7d5 | 91 | //------------------------------------------------------------------------------------ |
messi1 | 3:af00512c9694 | 92 | void SSD1331::sendCmd(uint8_t cmd, uint8_t arg1, uint8_t arg2) |
messi1 | 0:6e810b5b40a3 | 93 | { |
messi1 | 2:e033aab5daad | 94 | _dc = 0; |
messi1 | 2:e033aab5daad | 95 | _cs = 0; |
messi1 | 2:e033aab5daad | 96 | _spiPort.write(cmd); |
messi1 | 2:e033aab5daad | 97 | _spiPort.write(arg1); |
messi1 | 2:e033aab5daad | 98 | _spiPort.write(arg2); |
messi1 | 2:e033aab5daad | 99 | _cs = 1; |
messi1 | 2:e033aab5daad | 100 | } |
messi1 | 2:e033aab5daad | 101 | |
messi1 | 4:1707ca53e7d5 | 102 | //------------------------------------------------------------------------------------ |
messi1 | 3:af00512c9694 | 103 | void SSD1331::sendCmd(uint8_t *cmd, uint8_t count) |
messi1 | 2:e033aab5daad | 104 | { |
messi1 | 2:e033aab5daad | 105 | if(!cmd) return; |
messi1 | 2:e033aab5daad | 106 | |
messi1 | 2:e033aab5daad | 107 | _dc = 0; |
messi1 | 2:e033aab5daad | 108 | _cs = 0; |
messi1 | 3:af00512c9694 | 109 | for(uint8_t i=0; i<count; ++i) |
messi1 | 2:e033aab5daad | 110 | _spiPort.write(*cmd++); |
messi1 | 2:e033aab5daad | 111 | _cs = 1; |
messi1 | 2:e033aab5daad | 112 | } |
messi1 | 2:e033aab5daad | 113 | |
messi1 | 4:1707ca53e7d5 | 114 | //------------------------------------------------------------------------------------ |
messi1 | 2:e033aab5daad | 115 | void SSD1331::sendData(uint16_t data) |
messi1 | 2:e033aab5daad | 116 | { |
messi1 | 2:e033aab5daad | 117 | _dc = HIGH; |
messi1 | 2:e033aab5daad | 118 | _cs = LOW; |
messi1 | 2:e033aab5daad | 119 | _spiPort.write(data >> 8); |
messi1 | 2:e033aab5daad | 120 | _spiPort.write((data & 0x00ff)); |
messi1 | 2:e033aab5daad | 121 | _cs = HIGH; |
messi1 | 2:e033aab5daad | 122 | } |
messi1 | 2:e033aab5daad | 123 | |
messi1 | 4:1707ca53e7d5 | 124 | //------------------------------------------------------------------------------------ |
messi1 | 0:6e810b5b40a3 | 125 | void SSD1331::init(void) |
messi1 | 0:6e810b5b40a3 | 126 | { |
messi1 | 2:e033aab5daad | 127 | // initialize sequence |
messi1 | 2:e033aab5daad | 128 | sendCmd(CMD_DISPLAY_OFF); //OLED display OFF |
messi1 | 2:e033aab5daad | 129 | |
messi1 | 2:e033aab5daad | 130 | //Row Address |
messi1 | 2:e033aab5daad | 131 | sendCmd(CMD_SET_ROW_ADDRESS, 0x00, 0x3f); //Set Row Address with start=0,end=63 |
messi1 | 2:e033aab5daad | 132 | sendCmd(CMD_SET_COLUMN_ADDRESS, 0x00, 0x5f); //Set Column Address with start=0,end=95 |
messi1 | 2:e033aab5daad | 133 | |
messi1 | 2:e033aab5daad | 134 | //Contrast |
messi1 | 2:e033aab5daad | 135 | sendCmd(CMD_SET_REMAP, 0x76); //Set remap & data format 0111 0000 // 65k Color/8bit buswidth/format1 |
messi1 | 2:e033aab5daad | 136 | sendCmd(CMD_SET_DISPLAY_START_LINE, 0x00); //Set display start row RAM |
messi1 | 2:e033aab5daad | 137 | sendCmd(CMD_SET_DISPLAY_OFFSET, 0x00); //Set dispaly offset |
messi1 | 2:e033aab5daad | 138 | sendCmd(CMD_NORMAL_DISPLAY); //Set Display Mode |
messi1 | 2:e033aab5daad | 139 | sendCmd(CMD_SET_MULTIPLEX_RATIO, 0x3f); //Set Multiplex Ratio |
messi1 | 2:e033aab5daad | 140 | sendCmd(CMD_SET_MASTER_CONFIGURE, 0x8f); //Set Master Configuration (External VCC Supply Selected) |
messi1 | 2:e033aab5daad | 141 | sendCmd(CMD_POWER_SAVE_MODE, 0x1a); //Set Power Saving Mode |
messi1 | 2:e033aab5daad | 142 | sendCmd(CMD_PHASE_PERIOD_ADJUSTMENT, 0x74);//Set Phase 1 & 2 Period Adjustment |
messi1 | 2:e033aab5daad | 143 | sendCmd(CMD_DISPLAY_CLOCK_DIV, 0xd0); //Set Display Clock Divide Ratio / Oscillator Frequency |
messi1 | 2:e033aab5daad | 144 | sendCmd(CMD_SET_PRECHARGE_SPEED_A, 0x81); //Set Second Pre-charge Speed of Color A |
messi1 | 2:e033aab5daad | 145 | sendCmd(CMD_SET_PRECHARGE_SPEED_B, 0x82); //Set Second Pre-charge Speed of Color B |
messi1 | 2:e033aab5daad | 146 | sendCmd(CMD_SET_PRECHARGE_SPEED_C, 0x83); //Set Second Pre-charge Speed of Color C |
messi1 | 2:e033aab5daad | 147 | sendCmd(CMD_SET_PRECHARGE_VOLTAGE, 0x3e); //Set Pre-charge Level |
messi1 | 2:e033aab5daad | 148 | sendCmd(CMD_SET_V_VOLTAGE, 0x3e); //Set VCOMH |
messi1 | 2:e033aab5daad | 149 | sendCmd(CMD_MASTER_CURRENT_CONTROL, 0x0f); //Set Master Current Control |
messi1 | 2:e033aab5daad | 150 | sendCmd(CMD_SET_CONTRAST_A, 0x80); //Set Contrast Control for Color gAh |
messi1 | 2:e033aab5daad | 151 | sendCmd(CMD_SET_CONTRAST_B, 0x80); //Set Contrast Control for Color gBh |
messi1 | 2:e033aab5daad | 152 | sendCmd(CMD_SET_CONTRAST_C, 0x80); //Set Contrast Control for Color gCh |
messi1 | 2:e033aab5daad | 153 | |
messi1 | 2:e033aab5daad | 154 | fillRectangle(0,0, RGB_OLED_WIDTH, RGB_OLED_HEIGHT, 0x0); |
messi1 | 2:e033aab5daad | 155 | sendCmd(CMD_NORMAL_BRIGHTNESS_DISPLAY_ON); //display ON |
messi1 | 0:6e810b5b40a3 | 156 | |
messi1 | 2:e033aab5daad | 157 | // sendCmd(CMD_DISPLAY_OFF); //Display Off |
messi1 | 2:e033aab5daad | 158 | // sendCmd(CMD_SET_CONTRAST_A); //Set contrast for color A |
messi1 | 2:e033aab5daad | 159 | // sendCmd(0x91); //145 |
messi1 | 2:e033aab5daad | 160 | // sendCmd(CMD_SET_CONTRAST_B); //Set contrast for color B |
messi1 | 2:e033aab5daad | 161 | // sendCmd(0x50); //80 |
messi1 | 2:e033aab5daad | 162 | // sendCmd(CMD_SET_CONTRAST_C); //Set contrast for color C |
messi1 | 2:e033aab5daad | 163 | // sendCmd(0x7D); //125 |
messi1 | 2:e033aab5daad | 164 | // sendCmd(CMD_MASTER_CURRENT_CONTROL);//master current control |
messi1 | 2:e033aab5daad | 165 | // sendCmd(0x06); //6 |
messi1 | 2:e033aab5daad | 166 | // sendCmd(CMD_SET_PRECHARGE_SPEED_A);//Set Second Pre-change Speed For ColorA |
messi1 | 2:e033aab5daad | 167 | // sendCmd(0x64); //100 |
messi1 | 2:e033aab5daad | 168 | // sendCmd(CMD_SET_PRECHARGE_SPEED_B);//Set Second Pre-change Speed For ColorB |
messi1 | 2:e033aab5daad | 169 | // sendCmd(0x78); //120 |
messi1 | 2:e033aab5daad | 170 | // sendCmd(CMD_SET_PRECHARGE_SPEED_C);//Set Second Pre-change Speed For ColorC |
messi1 | 2:e033aab5daad | 171 | // sendCmd(0x64); //100 |
messi1 | 2:e033aab5daad | 172 | // sendCmd(CMD_SET_REMAP); //set remap & data format |
messi1 | 2:e033aab5daad | 173 | // sendCmd(0x72); //0x72 |
messi1 | 2:e033aab5daad | 174 | // sendCmd(CMD_SET_DISPLAY_START_LINE);//Set display Start Line |
messi1 | 2:e033aab5daad | 175 | // sendCmd(0x0); |
messi1 | 2:e033aab5daad | 176 | // sendCmd(CMD_SET_DISPLAY_OFFSET); //Set display offset |
messi1 | 2:e033aab5daad | 177 | // sendCmd(0x0); |
messi1 | 2:e033aab5daad | 178 | // sendCmd(CMD_NORMAL_DISPLAY); //Set display mode |
messi1 | 2:e033aab5daad | 179 | // sendCmd(CMD_SET_MULTIPLEX_RATIO); //Set multiplex ratio |
messi1 | 2:e033aab5daad | 180 | // sendCmd(0x3F); |
messi1 | 2:e033aab5daad | 181 | // sendCmd(CMD_SET_MASTER_CONFIGURE); //Set master configuration |
messi1 | 2:e033aab5daad | 182 | // sendCmd(0x8E); |
messi1 | 2:e033aab5daad | 183 | // sendCmd(CMD_POWER_SAVE_MODE); //Set Power Save Mode |
messi1 | 2:e033aab5daad | 184 | // sendCmd(0x00); //0x00 |
messi1 | 2:e033aab5daad | 185 | // sendCmd(CMD_PHASE_PERIOD_ADJUSTMENT);//phase 1 and 2 period adjustment |
messi1 | 2:e033aab5daad | 186 | // sendCmd(0x31); //0x31 |
messi1 | 2:e033aab5daad | 187 | // sendCmd(CMD_DISPLAY_CLOCK_DIV); //display clock divider/oscillator frequency |
messi1 | 2:e033aab5daad | 188 | // sendCmd(0xF0); |
messi1 | 2:e033aab5daad | 189 | // sendCmd(CMD_SET_PRECHARGE_VOLTAGE);//Set Pre-Change Level |
messi1 | 2:e033aab5daad | 190 | // sendCmd(0x3A); |
messi1 | 2:e033aab5daad | 191 | // sendCmd(CMD_SET_V_VOLTAGE); //Set vcomH |
messi1 | 2:e033aab5daad | 192 | // sendCmd(0x3E); |
messi1 | 2:e033aab5daad | 193 | // sendCmd(CMD_DEACTIVE_SCROLLING); //disable scrolling |
messi1 | 2:e033aab5daad | 194 | // sendCmd(CMD_NORMAL_BRIGHTNESS_DISPLAY_ON);//set display on |
messi1 | 0:6e810b5b40a3 | 195 | } |
messi1 | 0:6e810b5b40a3 | 196 | |
messi1 | 4:1707ca53e7d5 | 197 | //------------------------------------------------------------------------------------ |
messi1 | 3:af00512c9694 | 198 | void SSD1331::drawPixel(uint8_t x, uint8_t y, uint16_t color) |
messi1 | 0:6e810b5b40a3 | 199 | { |
messi1 | 0:6e810b5b40a3 | 200 | if ((x >= RGB_OLED_WIDTH) || (y >= RGB_OLED_HEIGHT)) |
messi1 | 0:6e810b5b40a3 | 201 | return; |
messi1 | 2:e033aab5daad | 202 | |
messi1 | 3:af00512c9694 | 203 | // set column point set row point |
messi1 | 4:1707ca53e7d5 | 204 | uint8_t cmd[6] = { CMD_SET_COLUMN_ADDRESS, x, x, CMD_SET_ROW_ADDRESS, y, y }; |
messi1 | 3:af00512c9694 | 205 | sendCmd(cmd, 6); |
messi1 | 2:e033aab5daad | 206 | |
messi1 | 0:6e810b5b40a3 | 207 | //fill 16bit colour |
messi1 | 2:e033aab5daad | 208 | sendData(color); |
messi1 | 0:6e810b5b40a3 | 209 | } |
messi1 | 0:6e810b5b40a3 | 210 | |
messi1 | 4:1707ca53e7d5 | 211 | //------------------------------------------------------------------------------------ |
messi1 | 4:1707ca53e7d5 | 212 | void SSD1331::drawLine(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint16_t color) |
messi1 | 0:6e810b5b40a3 | 213 | { |
messi1 | 4:1707ca53e7d5 | 214 | if (x0 >= RGB_OLED_WIDTH) x0 = RGB_OLED_WIDTH - 1; |
messi1 | 0:6e810b5b40a3 | 215 | if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_HEIGHT - 1; |
messi1 | 4:1707ca53e7d5 | 216 | if (x1 >= RGB_OLED_WIDTH) x1 = RGB_OLED_WIDTH - 1; |
messi1 | 0:6e810b5b40a3 | 217 | if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_HEIGHT - 1; |
messi1 | 4:1707ca53e7d5 | 218 | |
messi1 | 4:1707ca53e7d5 | 219 | uint8_t cmd[8] = { CMD_DRAW_LINE, x0, y0, x1, y1, (uint8_t)((color>>11)&0x1F), (uint8_t)((color>>5)&0x3F), (uint8_t)(color&0x1F) }; |
messi1 | 4:1707ca53e7d5 | 220 | sendCmd(cmd, 8); |
messi1 | 0:6e810b5b40a3 | 221 | } |
messi1 | 0:6e810b5b40a3 | 222 | |
messi1 | 4:1707ca53e7d5 | 223 | //------------------------------------------------------------------------------------ |
messi1 | 0:6e810b5b40a3 | 224 | void SSD1331::drawFrame(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t outColor, uint16_t fillColor) |
messi1 | 0:6e810b5b40a3 | 225 | { |
messi1 | 4:1707ca53e7d5 | 226 | if (x0 >= RGB_OLED_WIDTH) x0 = RGB_OLED_WIDTH - 1; |
messi1 | 0:6e810b5b40a3 | 227 | if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_HEIGHT - 1; |
messi1 | 4:1707ca53e7d5 | 228 | if (x1 >= RGB_OLED_WIDTH) x1 = RGB_OLED_WIDTH - 1; |
messi1 | 0:6e810b5b40a3 | 229 | if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_HEIGHT - 1; |
messi1 | 0:6e810b5b40a3 | 230 | |
messi1 | 2:e033aab5daad | 231 | sendCmd(CMD_FILL_WINDOW);//fill window |
messi1 | 2:e033aab5daad | 232 | sendCmd(ENABLE_FILL); |
messi1 | 2:e033aab5daad | 233 | sendCmd(CMD_DRAW_RECTANGLE);//draw rectangle |
messi1 | 2:e033aab5daad | 234 | sendCmd(x0);//start column |
messi1 | 2:e033aab5daad | 235 | sendCmd(y0);//start row |
messi1 | 2:e033aab5daad | 236 | sendCmd(x1);//end column |
messi1 | 2:e033aab5daad | 237 | sendCmd(y1);//end row |
messi1 | 2:e033aab5daad | 238 | sendCmd((uint8_t)((outColor>>11)&0x1F));//R |
messi1 | 2:e033aab5daad | 239 | sendCmd((uint8_t)((outColor>>5)&0x3F));//G |
messi1 | 2:e033aab5daad | 240 | sendCmd((uint8_t)(outColor&0x1F));//B |
messi1 | 2:e033aab5daad | 241 | sendCmd((uint8_t)((fillColor>>11)&0x1F));//R |
messi1 | 2:e033aab5daad | 242 | sendCmd((uint8_t)((fillColor>>5)&0x3F));//G |
messi1 | 2:e033aab5daad | 243 | sendCmd((uint8_t)(fillColor&0x1F));//B |
messi1 | 0:6e810b5b40a3 | 244 | } |
messi1 | 0:6e810b5b40a3 | 245 | |
messi1 | 4:1707ca53e7d5 | 246 | //------------------------------------------------------------------------------------ |
messi1 | 0:6e810b5b40a3 | 247 | void SSD1331::copyWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,uint16_t x2, uint16_t y2) |
messi1 | 0:6e810b5b40a3 | 248 | { |
messi1 | 2:e033aab5daad | 249 | sendCmd(CMD_COPY_WINDOW);//copy window |
messi1 | 2:e033aab5daad | 250 | sendCmd(x0);//start column |
messi1 | 2:e033aab5daad | 251 | sendCmd(y0);//start row |
messi1 | 2:e033aab5daad | 252 | sendCmd(x1);//end column |
messi1 | 2:e033aab5daad | 253 | sendCmd(y1);//end row |
messi1 | 2:e033aab5daad | 254 | sendCmd(x2);//new column |
messi1 | 2:e033aab5daad | 255 | sendCmd(y2);//new row |
messi1 | 0:6e810b5b40a3 | 256 | } |
messi1 | 0:6e810b5b40a3 | 257 | |
messi1 | 4:1707ca53e7d5 | 258 | //------------------------------------------------------------------------------------ |
messi1 | 0:6e810b5b40a3 | 259 | void SSD1331::dimWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) |
messi1 | 0:6e810b5b40a3 | 260 | { |
messi1 | 2:e033aab5daad | 261 | sendCmd(CMD_DIM_WINDOW);//copy area |
messi1 | 2:e033aab5daad | 262 | sendCmd(x0);//start column |
messi1 | 2:e033aab5daad | 263 | sendCmd(y0);//start row |
messi1 | 2:e033aab5daad | 264 | sendCmd(x1);//end column |
messi1 | 2:e033aab5daad | 265 | sendCmd(y1);//end row |
messi1 | 0:6e810b5b40a3 | 266 | } |
messi1 | 0:6e810b5b40a3 | 267 | |
messi1 | 4:1707ca53e7d5 | 268 | //------------------------------------------------------------------------------------ |
messi1 | 0:6e810b5b40a3 | 269 | void SSD1331::clearWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) |
messi1 | 0:6e810b5b40a3 | 270 | { |
messi1 | 2:e033aab5daad | 271 | sendCmd(CMD_CLEAR_WINDOW);//clear window |
messi1 | 2:e033aab5daad | 272 | sendCmd(x0);//start column |
messi1 | 2:e033aab5daad | 273 | sendCmd(y0);//start row |
messi1 | 2:e033aab5daad | 274 | sendCmd(x1);//end column |
messi1 | 2:e033aab5daad | 275 | sendCmd(y1);//end row |
messi1 | 0:6e810b5b40a3 | 276 | } |
messi1 | 0:6e810b5b40a3 | 277 | |
messi1 | 4:1707ca53e7d5 | 278 | //------------------------------------------------------------------------------------ |
messi1 | 0:6e810b5b40a3 | 279 | void SSD1331::setScolling(ScollingDirection direction, uint8_t rowAddr, uint8_t rowNum, uint8_t timeInterval) |
messi1 | 0:6e810b5b40a3 | 280 | { |
messi1 | 0:6e810b5b40a3 | 281 | uint8_t scolling_horizontal = 0x0; |
messi1 | 0:6e810b5b40a3 | 282 | uint8_t scolling_vertical = 0x0; |
messi1 | 0:6e810b5b40a3 | 283 | switch(direction){ |
messi1 | 0:6e810b5b40a3 | 284 | case Horizontal: |
messi1 | 0:6e810b5b40a3 | 285 | scolling_horizontal = 0x01; |
messi1 | 0:6e810b5b40a3 | 286 | scolling_vertical = 0x00; |
messi1 | 0:6e810b5b40a3 | 287 | break; |
messi1 | 0:6e810b5b40a3 | 288 | case Vertical: |
messi1 | 0:6e810b5b40a3 | 289 | scolling_horizontal = 0x00; |
messi1 | 0:6e810b5b40a3 | 290 | scolling_vertical = 0x01; |
messi1 | 0:6e810b5b40a3 | 291 | break; |
messi1 | 0:6e810b5b40a3 | 292 | case Diagonal: |
messi1 | 0:6e810b5b40a3 | 293 | scolling_horizontal = 0x01; |
messi1 | 0:6e810b5b40a3 | 294 | scolling_vertical = 0x01; |
messi1 | 0:6e810b5b40a3 | 295 | break; |
messi1 | 0:6e810b5b40a3 | 296 | default: |
messi1 | 0:6e810b5b40a3 | 297 | break; |
messi1 | 0:6e810b5b40a3 | 298 | } |
messi1 | 2:e033aab5daad | 299 | sendCmd(CMD_CONTINUOUS_SCROLLING_SETUP); |
messi1 | 2:e033aab5daad | 300 | sendCmd(scolling_horizontal); |
messi1 | 2:e033aab5daad | 301 | sendCmd(rowAddr); |
messi1 | 2:e033aab5daad | 302 | sendCmd(rowNum); |
messi1 | 2:e033aab5daad | 303 | sendCmd(scolling_vertical); |
messi1 | 2:e033aab5daad | 304 | sendCmd(timeInterval); |
messi1 | 2:e033aab5daad | 305 | sendCmd(CMD_ACTIVE_SCROLLING); |
messi1 | 0:6e810b5b40a3 | 306 | } |
messi1 | 0:6e810b5b40a3 | 307 | |
messi1 | 4:1707ca53e7d5 | 308 | //------------------------------------------------------------------------------------ |
messi1 | 0:6e810b5b40a3 | 309 | void SSD1331::enableScolling(bool enable) |
messi1 | 0:6e810b5b40a3 | 310 | { |
messi1 | 0:6e810b5b40a3 | 311 | if(enable) |
messi1 | 2:e033aab5daad | 312 | sendCmd(CMD_ACTIVE_SCROLLING); |
messi1 | 0:6e810b5b40a3 | 313 | else |
messi1 | 2:e033aab5daad | 314 | sendCmd(CMD_DEACTIVE_SCROLLING); |
messi1 | 0:6e810b5b40a3 | 315 | } |
messi1 | 0:6e810b5b40a3 | 316 | |
messi1 | 4:1707ca53e7d5 | 317 | //------------------------------------------------------------------------------------ |
messi1 | 0:6e810b5b40a3 | 318 | void SSD1331::setDisplayMode(DisplayMode mode) |
messi1 | 0:6e810b5b40a3 | 319 | { |
messi1 | 2:e033aab5daad | 320 | sendCmd(mode); |
messi1 | 0:6e810b5b40a3 | 321 | } |
messi1 | 0:6e810b5b40a3 | 322 | |
messi1 | 4:1707ca53e7d5 | 323 | //------------------------------------------------------------------------------------ |
messi1 | 0:6e810b5b40a3 | 324 | void SSD1331::setDisplayPower(DisplayPower power) |
messi1 | 0:6e810b5b40a3 | 325 | { |
messi1 | 2:e033aab5daad | 326 | sendCmd(power); |
messi1 | 0:6e810b5b40a3 | 327 | } |
messi1 | 4:1707ca53e7d5 | 328 | |
messi1 | 4:1707ca53e7d5 | 329 | //------------------------------------------------------------------------------------ |
messi1 | 4:1707ca53e7d5 | 330 | int SSD1331::_getc() |
messi1 | 4:1707ca53e7d5 | 331 | { |
messi1 | 4:1707ca53e7d5 | 332 | return -1; |
messi1 | 4:1707ca53e7d5 | 333 | } |
messi1 | 4:1707ca53e7d5 | 334 | |
messi1 | 4:1707ca53e7d5 | 335 | //------------------------------------------------------------------------------------ |
messi1 | 4:1707ca53e7d5 | 336 | int SSD1331::_putc( int c ) |
messi1 | 4:1707ca53e7d5 | 337 | { |
messi1 | 4:1707ca53e7d5 | 338 | return -1; |
messi1 | 4:1707ca53e7d5 | 339 | } |