Driver for the Seeedstudio RGB OLED module for the xadow M0
src/SSD1331.cpp@5:9de43186f5ea, 2015-11-13 (annotated)
- Committer:
- messi1
- Date:
- Fri Nov 13 23:29:59 2015 +0000
- Revision:
- 5:9de43186f5ea
- Parent:
- 4:1707ca53e7d5
- Child:
- 6:06c211302c93
Improved all draw function in speed and timing
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 | 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 | 2:e033aab5daad | 65 | :SGL(RGB_OLED_WIDTH, RGB_OLED_HEIGHT), _cs(cs), _dc(dc), _spiPort(mosi, miso, sclk) |
messi1 | 0:6e810b5b40a3 | 66 | { |
messi1 | 2:e033aab5daad | 67 | _spiPort.format(8,3); //8bit frame and POL=1 /PHA=1(UpEdge Sampled) |
messi1 | 2:e033aab5daad | 68 | _spiPort.frequency(25000000); // modify later |
messi1 | 2:e033aab5daad | 69 | |
messi1 | 2:e033aab5daad | 70 | init(); |
messi1 | 0:6e810b5b40a3 | 71 | }; |
messi1 | 0:6e810b5b40a3 | 72 | |
messi1 | 4:1707ca53e7d5 | 73 | //------------------------------------------------------------------------------------ |
messi1 | 5:9de43186f5ea | 74 | void SSD1331::init(void) |
messi1 | 5:9de43186f5ea | 75 | { |
messi1 | 5:9de43186f5ea | 76 | // initialize sequence |
messi1 | 5:9de43186f5ea | 77 | sendCmd(CMD_DISPLAY_OFF); //OLED display OFF |
messi1 | 5:9de43186f5ea | 78 | |
messi1 | 5:9de43186f5ea | 79 | //Row Address |
messi1 | 5:9de43186f5ea | 80 | sendCmd(CMD_SET_ROW_ADDRESS, 0x00, 0x3f); //Set Row Address with start=0,end=63 |
messi1 | 5:9de43186f5ea | 81 | sendCmd(CMD_SET_COLUMN_ADDRESS, 0x00, 0x5f); //Set Column Address with start=0,end=95 |
messi1 | 5:9de43186f5ea | 82 | |
messi1 | 5:9de43186f5ea | 83 | //Contrast |
messi1 | 5:9de43186f5ea | 84 | sendCmd(CMD_SET_REMAP, 0x76); //Set remap & data format 0111 0000 // 65k Color/8bit buswidth/format1 |
messi1 | 5:9de43186f5ea | 85 | sendCmd(CMD_SET_DISPLAY_START_LINE, 0x00); //Set display start row RAM |
messi1 | 5:9de43186f5ea | 86 | sendCmd(CMD_SET_DISPLAY_OFFSET, 0x00); //Set dispaly offset |
messi1 | 5:9de43186f5ea | 87 | sendCmd(CMD_NORMAL_DISPLAY); //Set Display Mode |
messi1 | 5:9de43186f5ea | 88 | sendCmd(CMD_SET_MULTIPLEX_RATIO, 0x3f); //Set Multiplex Ratio |
messi1 | 5:9de43186f5ea | 89 | sendCmd(CMD_SET_MASTER_CONFIGURE, 0x8f); //Set Master Configuration (External VCC Supply Selected) |
messi1 | 5:9de43186f5ea | 90 | sendCmd(CMD_POWER_SAVE_MODE, 0x1a); //Set Power Saving Mode |
messi1 | 5:9de43186f5ea | 91 | sendCmd(CMD_PHASE_PERIOD_ADJUSTMENT, 0x74); //Set Phase 1 & 2 Period Adjustment |
messi1 | 5:9de43186f5ea | 92 | sendCmd(CMD_DISPLAY_CLOCK_DIV, 0xd0); //Set Display Clock Divide Ratio / Oscillator Frequency |
messi1 | 5:9de43186f5ea | 93 | sendCmd(CMD_SET_PRECHARGE_SPEED_A, 0x81); //Set Second Pre-charge Speed of Color A |
messi1 | 5:9de43186f5ea | 94 | sendCmd(CMD_SET_PRECHARGE_SPEED_B, 0x82); //Set Second Pre-charge Speed of Color B |
messi1 | 5:9de43186f5ea | 95 | sendCmd(CMD_SET_PRECHARGE_SPEED_C, 0x83); //Set Second Pre-charge Speed of Color C |
messi1 | 5:9de43186f5ea | 96 | sendCmd(CMD_SET_PRECHARGE_VOLTAGE, 0x3e); //Set Pre-charge Level |
messi1 | 5:9de43186f5ea | 97 | sendCmd(CMD_SET_V_VOLTAGE, 0x3e); //Set VCOMH |
messi1 | 5:9de43186f5ea | 98 | sendCmd(CMD_MASTER_CURRENT_CONTROL, 0x0f); //Set Master Current Control |
messi1 | 5:9de43186f5ea | 99 | sendCmd(CMD_SET_CONTRAST_A, 0x80); //Set Contrast Control for Color gAh |
messi1 | 5:9de43186f5ea | 100 | sendCmd(CMD_SET_CONTRAST_B, 0x80); //Set Contrast Control for Color gBh |
messi1 | 5:9de43186f5ea | 101 | sendCmd(CMD_SET_CONTRAST_C, 0x80); //Set Contrast Control for Color gCh |
messi1 | 5:9de43186f5ea | 102 | |
messi1 | 5:9de43186f5ea | 103 | clearArea(0,0, RGB_OLED_XMAX, RGB_OLED_YMAX); |
messi1 | 5:9de43186f5ea | 104 | sendCmd(CMD_NORMAL_BRIGHTNESS_DISPLAY_ON); //display ON |
messi1 | 5:9de43186f5ea | 105 | |
messi1 | 5:9de43186f5ea | 106 | // sendCmd(CMD_SET_CONTRAST_A); //Set contrast for color A |
messi1 | 5:9de43186f5ea | 107 | // sendCmd(0x91); //145 |
messi1 | 5:9de43186f5ea | 108 | // sendCmd(CMD_SET_CONTRAST_B); //Set contrast for color B |
messi1 | 5:9de43186f5ea | 109 | // sendCmd(0x50); //80 |
messi1 | 5:9de43186f5ea | 110 | // sendCmd(CMD_SET_CONTRAST_C); //Set contrast for color C |
messi1 | 5:9de43186f5ea | 111 | // sendCmd(0x7D); //125 |
messi1 | 5:9de43186f5ea | 112 | // sendCmd(CMD_MASTER_CURRENT_CONTROL);//master current control |
messi1 | 5:9de43186f5ea | 113 | // sendCmd(0x06); //6 |
messi1 | 5:9de43186f5ea | 114 | // sendCmd(CMD_SET_PRECHARGE_SPEED_A);//Set Second Pre-change Speed For ColorA |
messi1 | 5:9de43186f5ea | 115 | // sendCmd(0x64); //100 |
messi1 | 5:9de43186f5ea | 116 | // sendCmd(CMD_SET_PRECHARGE_SPEED_B);//Set Second Pre-change Speed For ColorB |
messi1 | 5:9de43186f5ea | 117 | // sendCmd(0x78); //120 |
messi1 | 5:9de43186f5ea | 118 | // sendCmd(CMD_SET_PRECHARGE_SPEED_C);//Set Second Pre-change Speed For ColorC |
messi1 | 5:9de43186f5ea | 119 | // sendCmd(0x64); //100 |
messi1 | 5:9de43186f5ea | 120 | // sendCmd(CMD_SET_REMAP); //set remap & data format |
messi1 | 5:9de43186f5ea | 121 | // sendCmd(0x72); //0x72 |
messi1 | 5:9de43186f5ea | 122 | // sendCmd(CMD_SET_MULTIPLEX_RATIO); //Set multiplex ratio |
messi1 | 5:9de43186f5ea | 123 | // sendCmd(0x3F); |
messi1 | 5:9de43186f5ea | 124 | // sendCmd(CMD_SET_MASTER_CONFIGURE); //Set master configuration |
messi1 | 5:9de43186f5ea | 125 | // sendCmd(0x8E); |
messi1 | 5:9de43186f5ea | 126 | // sendCmd(CMD_PHASE_PERIOD_ADJUSTMENT);//phase 1 and 2 period adjustment |
messi1 | 5:9de43186f5ea | 127 | // sendCmd(0x31); //0x31 |
messi1 | 5:9de43186f5ea | 128 | // sendCmd(CMD_DISPLAY_CLOCK_DIV); //display clock divider/oscillator frequency |
messi1 | 5:9de43186f5ea | 129 | // sendCmd(0xF0); |
messi1 | 5:9de43186f5ea | 130 | // sendCmd(CMD_SET_PRECHARGE_VOLTAGE);//Set Pre-Change Level |
messi1 | 5:9de43186f5ea | 131 | // sendCmd(0x3A); |
messi1 | 5:9de43186f5ea | 132 | // sendCmd(CMD_SET_V_VOLTAGE); //Set vcomH |
messi1 | 5:9de43186f5ea | 133 | // sendCmd(0x3E); |
messi1 | 5:9de43186f5ea | 134 | // sendCmd(CMD_DEACTIVE_SCROLLING); //disable scrolling |
messi1 | 5:9de43186f5ea | 135 | |
messi1 | 5:9de43186f5ea | 136 | } |
messi1 | 5:9de43186f5ea | 137 | |
messi1 | 5:9de43186f5ea | 138 | //------------------------------------------------------------------------------------ |
messi1 | 5:9de43186f5ea | 139 | void SSD1331::drawPixel(uint8_t x, uint8_t y, uint16_t color) |
messi1 | 5:9de43186f5ea | 140 | { |
messi1 | 5:9de43186f5ea | 141 | if (x >= RGB_OLED_WIDTH) x = RGB_OLED_WIDTH - 1; |
messi1 | 5:9de43186f5ea | 142 | if (y >= RGB_OLED_HEIGHT) y = RGB_OLED_HEIGHT - 1; |
messi1 | 5:9de43186f5ea | 143 | // set column point set row point |
messi1 | 5:9de43186f5ea | 144 | uint8_t cmdBuffer[6] = { CMD_SET_COLUMN_ADDRESS, x, x, CMD_SET_ROW_ADDRESS, y, y }; |
messi1 | 5:9de43186f5ea | 145 | sendCmd(cmdBuffer, 6); //Send buffer |
messi1 | 5:9de43186f5ea | 146 | sendData(color); //fill 16bit colour |
messi1 | 5:9de43186f5ea | 147 | } |
messi1 | 5:9de43186f5ea | 148 | |
messi1 | 5:9de43186f5ea | 149 | //------------------------------------------------------------------------------------ |
messi1 | 5:9de43186f5ea | 150 | void SSD1331::drawLine(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint16_t color) |
messi1 | 5:9de43186f5ea | 151 | { |
messi1 | 5:9de43186f5ea | 152 | if (x0 >= RGB_OLED_WIDTH) x0 = RGB_OLED_WIDTH - 1; |
messi1 | 5:9de43186f5ea | 153 | if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_HEIGHT - 1; |
messi1 | 5:9de43186f5ea | 154 | if (x1 >= RGB_OLED_WIDTH) x1 = RGB_OLED_WIDTH - 1; |
messi1 | 5:9de43186f5ea | 155 | if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_HEIGHT - 1; |
messi1 | 5:9de43186f5ea | 156 | |
messi1 | 5:9de43186f5ea | 157 | 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 | 5:9de43186f5ea | 158 | sendCmd(cmd, 8); |
messi1 | 5:9de43186f5ea | 159 | } |
messi1 | 5:9de43186f5ea | 160 | |
messi1 | 5:9de43186f5ea | 161 | //------------------------------------------------------------------------------------ |
messi1 | 5:9de43186f5ea | 162 | void SSD1331::drawFrame(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint16_t outColor, uint16_t fillColor) |
messi1 | 5:9de43186f5ea | 163 | { |
messi1 | 5:9de43186f5ea | 164 | if (x0 >= RGB_OLED_WIDTH) x0 = RGB_OLED_WIDTH - 1; |
messi1 | 5:9de43186f5ea | 165 | if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_HEIGHT - 1; |
messi1 | 5:9de43186f5ea | 166 | if (x1 >= RGB_OLED_WIDTH) x1 = RGB_OLED_WIDTH - 1; |
messi1 | 5:9de43186f5ea | 167 | if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_HEIGHT - 1; |
messi1 | 5:9de43186f5ea | 168 | |
messi1 | 5:9de43186f5ea | 169 | uint8_t cmd[11] = { CMD_DRAW_RECTANGLE, x0, y0, x1, y1, |
messi1 | 5:9de43186f5ea | 170 | (uint8_t)((outColor>>11)&0x1F), (uint8_t)((outColor>>5)&0x3F), (uint8_t)(outColor&0x1F), |
messi1 | 5:9de43186f5ea | 171 | (uint8_t)((fillColor>>11)&0x1F), (uint8_t)((fillColor>>5)&0x3F), (uint8_t)(fillColor&0x1F)}; |
messi1 | 5:9de43186f5ea | 172 | |
messi1 | 5:9de43186f5ea | 173 | sendCmd(CMD_FILL_WINDOW, ENABLE_FILL);//fill window |
messi1 | 5:9de43186f5ea | 174 | sendCmd(cmd, 11); |
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::copyArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,uint8_t x2, uint8_t y2) |
messi1 | 5:9de43186f5ea | 180 | { |
messi1 | 5:9de43186f5ea | 181 | if (x0 >= RGB_OLED_WIDTH) x0 = RGB_OLED_WIDTH - 1; |
messi1 | 5:9de43186f5ea | 182 | if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_HEIGHT - 1; |
messi1 | 5:9de43186f5ea | 183 | if (x1 >= RGB_OLED_WIDTH) x1 = RGB_OLED_WIDTH - 1; |
messi1 | 5:9de43186f5ea | 184 | if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_HEIGHT - 1; |
messi1 | 5:9de43186f5ea | 185 | |
messi1 | 5:9de43186f5ea | 186 | uint8_t cmd[7] = { CMD_COPY_WINDOW, x0, y0, x1, y1, x2, y2}; |
messi1 | 5:9de43186f5ea | 187 | sendCmd(cmd, 7); |
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::dimArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) |
messi1 | 5:9de43186f5ea | 193 | { |
messi1 | 5:9de43186f5ea | 194 | if (x0 >= RGB_OLED_WIDTH) x0 = RGB_OLED_WIDTH - 1; |
messi1 | 5:9de43186f5ea | 195 | if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_HEIGHT - 1; |
messi1 | 5:9de43186f5ea | 196 | if (x1 >= RGB_OLED_WIDTH) x1 = RGB_OLED_WIDTH - 1; |
messi1 | 5:9de43186f5ea | 197 | if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_HEIGHT - 1; |
messi1 | 5:9de43186f5ea | 198 | |
messi1 | 5:9de43186f5ea | 199 | uint8_t cmdBuffer[5] = { CMD_DIM_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 | 5:9de43186f5ea | 205 | void SSD1331::clearArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) |
messi1 | 5:9de43186f5ea | 206 | { |
messi1 | 5:9de43186f5ea | 207 | if (x0 >= RGB_OLED_WIDTH) x0 = RGB_OLED_WIDTH - 1; |
messi1 | 5:9de43186f5ea | 208 | if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_HEIGHT - 1; |
messi1 | 5:9de43186f5ea | 209 | if (x1 >= RGB_OLED_WIDTH) x1 = RGB_OLED_WIDTH - 1; |
messi1 | 5:9de43186f5ea | 210 | if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_HEIGHT - 1; |
messi1 | 5:9de43186f5ea | 211 | |
messi1 | 5:9de43186f5ea | 212 | uint8_t cmdBuffer[5] = { CMD_CLEAR_WINDOW, x0, y0, x1, y1 }; |
messi1 | 5:9de43186f5ea | 213 | sendCmd(cmdBuffer, 5); //Send buffer |
messi1 | 5:9de43186f5ea | 214 | wait(0.05); |
messi1 | 5:9de43186f5ea | 215 | } |
messi1 | 5:9de43186f5ea | 216 | |
messi1 | 5:9de43186f5ea | 217 | //------------------------------------------------------------------------------------ |
messi1 | 5:9de43186f5ea | 218 | void SSD1331::setScolling(ScollingDirection direction, uint8_t rowAddr, uint8_t rowNum, uint8_t timeInterval) |
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 | 5:9de43186f5ea | 223 | case Horizontal: |
messi1 | 5:9de43186f5ea | 224 | scolling_horizontal = 0x01; |
messi1 | 5:9de43186f5ea | 225 | scolling_vertical = 0x00; |
messi1 | 5:9de43186f5ea | 226 | break; |
messi1 | 5:9de43186f5ea | 227 | case Vertical: |
messi1 | 5:9de43186f5ea | 228 | scolling_horizontal = 0x00; |
messi1 | 5:9de43186f5ea | 229 | scolling_vertical = 0x01; |
messi1 | 5:9de43186f5ea | 230 | break; |
messi1 | 5:9de43186f5ea | 231 | case 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 | 5:9de43186f5ea | 239 | uint8_t cmdBuffer[6] = { CMD_CONTINUOUS_SCROLLING_SETUP, scolling_horizontal, rowAddr, rowNum, scolling_vertical, timeInterval }; |
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 | 5:9de43186f5ea | 246 | void SSD1331::enableScolling(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 | 5:9de43186f5ea | 261 | void SSD1331::setDisplayPower(DisplayPower 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 | } |