Driver for the Seeedstudio RGB OLED module for the xadow M0
src/SSD1331.cpp@9:5a7bf0ce8518, 2015-11-17 (annotated)
- Committer:
- messi1
- Date:
- Tue Nov 17 19:45:22 2015 +0000
- Revision:
- 9:5a7bf0ce8518
- Parent:
- 8:ff74bd4d94d6
- Child:
- 10:ef7440718431
Add comments and fixed bugs of the crappy seeedstudio driver; Add new function like drawRect().;
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 | 7:5250c825c7bb | 84 | sendCmd(CMD_SET_REMAP, 0x72); //Set remap & data format 0111 0000 // 65k Color/8bit buswidth/format1 0x72 |
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 | 7:5250c825c7bb | 89 | sendCmd(CMD_SET_MASTER_CONFIGURE, 0x8e); //Set Master Configuration (External VCC Supply Selected) 0x8f or 0x8e |
messi1 | 5:9de43186f5ea | 90 | sendCmd(CMD_POWER_SAVE_MODE, 0x1a); //Set Power Saving Mode |
messi1 | 7:5250c825c7bb | 91 | sendCmd(CMD_PHASE_PERIOD_ADJUSTMENT, 0x31); //Set Phase 1 & 2 Period Adjustment 0x74 or 0x31 |
messi1 | 7:5250c825c7bb | 92 | sendCmd(CMD_DISPLAY_CLOCK_DIV, 0xf0); //Set Display Clock Divide Ratio / Oscillator Frequency 0xd0 or 0xf0 |
messi1 | 7:5250c825c7bb | 93 | sendCmd(CMD_SET_PRECHARGE_SPEED_A, 0x64); //Set Second Pre-charge Speed of Color A 0x81 or 0x64 |
messi1 | 7:5250c825c7bb | 94 | sendCmd(CMD_SET_PRECHARGE_SPEED_B, 0x78); //Set Second Pre-charge Speed of Color B 0x82 or 0x78 |
messi1 | 7:5250c825c7bb | 95 | sendCmd(CMD_SET_PRECHARGE_SPEED_C, 0x64); //Set Second Pre-charge Speed of Color C 0x83 or 0x64 |
messi1 | 7:5250c825c7bb | 96 | sendCmd(CMD_SET_PRECHARGE_VOLTAGE, 0x3a); //Set Pre-charge Level 3e or 3a |
messi1 | 5:9de43186f5ea | 97 | sendCmd(CMD_SET_V_VOLTAGE, 0x3e); //Set VCOMH |
messi1 | 7:5250c825c7bb | 98 | sendCmd(CMD_MASTER_CURRENT_CONTROL, 0x06); //Set Master Current Control 0x6 or 0xf |
messi1 | 7:5250c825c7bb | 99 | sendCmd(CMD_SET_CONTRAST_A, 0x91); //Set Contrast Control for Color gAh 0x80 or 0x91 |
messi1 | 7:5250c825c7bb | 100 | sendCmd(CMD_SET_CONTRAST_B, 0x50); //Set Contrast Control for Color gBh 0x80 or 0x50 |
messi1 | 7:5250c825c7bb | 101 | sendCmd(CMD_SET_CONTRAST_C, 0x7d); //Set Contrast Control for Color gCh 0x80 or 0x7D |
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 | 7:5250c825c7bb | 105 | wait(0.1); |
messi1 | 5:9de43186f5ea | 106 | } |
messi1 | 5:9de43186f5ea | 107 | |
messi1 | 5:9de43186f5ea | 108 | //------------------------------------------------------------------------------------ |
messi1 | 5:9de43186f5ea | 109 | void SSD1331::drawPixel(uint8_t x, uint8_t y, uint16_t color) |
messi1 | 5:9de43186f5ea | 110 | { |
messi1 | 6:06c211302c93 | 111 | if (x >= RGB_OLED_WIDTH) x = RGB_OLED_XMAX; |
messi1 | 6:06c211302c93 | 112 | if (y >= RGB_OLED_HEIGHT) y = RGB_OLED_YMAX; |
messi1 | 5:9de43186f5ea | 113 | // set column point set row point |
messi1 | 5:9de43186f5ea | 114 | uint8_t cmdBuffer[6] = { CMD_SET_COLUMN_ADDRESS, x, x, CMD_SET_ROW_ADDRESS, y, y }; |
messi1 | 5:9de43186f5ea | 115 | sendCmd(cmdBuffer, 6); //Send buffer |
messi1 | 5:9de43186f5ea | 116 | sendData(color); //fill 16bit colour |
messi1 | 5:9de43186f5ea | 117 | } |
messi1 | 5:9de43186f5ea | 118 | |
messi1 | 5:9de43186f5ea | 119 | //------------------------------------------------------------------------------------ |
messi1 | 5:9de43186f5ea | 120 | void SSD1331::drawLine(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint16_t color) |
messi1 | 5:9de43186f5ea | 121 | { |
messi1 | 6:06c211302c93 | 122 | if (x0 >= RGB_OLED_WIDTH) x0 = RGB_OLED_XMAX; |
messi1 | 6:06c211302c93 | 123 | if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_YMAX; |
messi1 | 6:06c211302c93 | 124 | if (x1 >= RGB_OLED_WIDTH) x1 = RGB_OLED_XMAX; |
messi1 | 6:06c211302c93 | 125 | if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_YMAX; |
messi1 | 5:9de43186f5ea | 126 | |
messi1 | 7:5250c825c7bb | 127 | 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 | 128 | sendCmd(cmd, 8); |
messi1 | 5:9de43186f5ea | 129 | } |
messi1 | 5:9de43186f5ea | 130 | |
messi1 | 5:9de43186f5ea | 131 | //------------------------------------------------------------------------------------ |
messi1 | 8:ff74bd4d94d6 | 132 | void SSD1331::drawRect(uint8_t left_x, uint8_t top_y, uint8_t width, uint8_t height, uint16_t color) |
messi1 | 8:ff74bd4d94d6 | 133 | { |
messi1 | 8:ff74bd4d94d6 | 134 | if (left_x >= RGB_OLED_WIDTH) left_x = RGB_OLED_XMAX; |
messi1 | 8:ff74bd4d94d6 | 135 | if (top_y >= RGB_OLED_HEIGHT) top_y = RGB_OLED_YMAX; |
messi1 | 8:ff74bd4d94d6 | 136 | |
messi1 | 8:ff74bd4d94d6 | 137 | drawLine(left_x, top_y, left_x+width, top_y, color); // horizontal |
messi1 | 8:ff74bd4d94d6 | 138 | drawLine(left_x, top_y, left_x, top_y+height, color); // vertical |
messi1 | 8:ff74bd4d94d6 | 139 | drawLine(left_x, top_y+height, left_x+width, top_y+height, color); //horizontal |
messi1 | 8:ff74bd4d94d6 | 140 | drawLine(left_x+width, top_y, left_x+width, top_y+height, color); // vertical |
messi1 | 8:ff74bd4d94d6 | 141 | } |
messi1 | 8:ff74bd4d94d6 | 142 | |
messi1 | 8:ff74bd4d94d6 | 143 | //------------------------------------------------------------------------------------ |
messi1 | 9:5a7bf0ce8518 | 144 | void SSD1331::drawRect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint16_t outColor, uint16_t fillColor) |
messi1 | 5:9de43186f5ea | 145 | { |
messi1 | 6:06c211302c93 | 146 | if (x0 >= RGB_OLED_WIDTH) x0 = RGB_OLED_XMAX; |
messi1 | 6:06c211302c93 | 147 | if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_YMAX; |
messi1 | 6:06c211302c93 | 148 | if (x1 >= RGB_OLED_WIDTH) x1 = RGB_OLED_XMAX; |
messi1 | 6:06c211302c93 | 149 | if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_YMAX; |
messi1 | 5:9de43186f5ea | 150 | |
messi1 | 5:9de43186f5ea | 151 | uint8_t cmd[11] = { CMD_DRAW_RECTANGLE, x0, y0, x1, y1, |
messi1 | 7:5250c825c7bb | 152 | (uint8_t)(((outColor>>11)&0x1F)<<1), (uint8_t)((outColor>>5)&0x3F), (uint8_t)((outColor&0x1F)<<1), |
messi1 | 7:5250c825c7bb | 153 | (uint8_t)(((fillColor>>11)&0x1F)<<1), (uint8_t)((fillColor>>5)&0x3F), (uint8_t)((fillColor&0x1F)<<1)}; |
messi1 | 5:9de43186f5ea | 154 | |
messi1 | 5:9de43186f5ea | 155 | sendCmd(CMD_FILL_WINDOW, ENABLE_FILL);//fill window |
messi1 | 5:9de43186f5ea | 156 | sendCmd(cmd, 11); |
messi1 | 5:9de43186f5ea | 157 | wait(0.05); |
messi1 | 5:9de43186f5ea | 158 | } |
messi1 | 5:9de43186f5ea | 159 | |
messi1 | 5:9de43186f5ea | 160 | //------------------------------------------------------------------------------------ |
messi1 | 5:9de43186f5ea | 161 | void SSD1331::copyArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,uint8_t x2, uint8_t y2) |
messi1 | 5:9de43186f5ea | 162 | { |
messi1 | 6:06c211302c93 | 163 | if (x0 >= RGB_OLED_WIDTH) x0 = RGB_OLED_XMAX; |
messi1 | 6:06c211302c93 | 164 | if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_YMAX; |
messi1 | 6:06c211302c93 | 165 | if (x1 >= RGB_OLED_WIDTH) x1 = RGB_OLED_XMAX; |
messi1 | 6:06c211302c93 | 166 | if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_YMAX; |
messi1 | 6:06c211302c93 | 167 | if (x2 >= RGB_OLED_WIDTH) x2 = RGB_OLED_XMAX; |
messi1 | 6:06c211302c93 | 168 | if (y2 >= RGB_OLED_HEIGHT) y2 = RGB_OLED_YMAX; |
messi1 | 5:9de43186f5ea | 169 | |
messi1 | 5:9de43186f5ea | 170 | uint8_t cmd[7] = { CMD_COPY_WINDOW, x0, y0, x1, y1, x2, y2}; |
messi1 | 5:9de43186f5ea | 171 | sendCmd(cmd, 7); |
messi1 | 5:9de43186f5ea | 172 | wait(0.05); |
messi1 | 5:9de43186f5ea | 173 | } |
messi1 | 5:9de43186f5ea | 174 | |
messi1 | 5:9de43186f5ea | 175 | //------------------------------------------------------------------------------------ |
messi1 | 5:9de43186f5ea | 176 | void SSD1331::dimArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) |
messi1 | 5:9de43186f5ea | 177 | { |
messi1 | 6:06c211302c93 | 178 | if (x0 >= RGB_OLED_WIDTH) x0 = RGB_OLED_XMAX; |
messi1 | 6:06c211302c93 | 179 | if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_YMAX; |
messi1 | 6:06c211302c93 | 180 | if (x1 >= RGB_OLED_WIDTH) x1 = RGB_OLED_XMAX; |
messi1 | 6:06c211302c93 | 181 | if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_YMAX; |
messi1 | 5:9de43186f5ea | 182 | |
messi1 | 5:9de43186f5ea | 183 | uint8_t cmdBuffer[5] = { CMD_DIM_WINDOW, x0, y0, x1, y1 }; |
messi1 | 5:9de43186f5ea | 184 | sendCmd(cmdBuffer, 5); //Send buffer |
messi1 | 5:9de43186f5ea | 185 | wait(0.05); |
messi1 | 5:9de43186f5ea | 186 | } |
messi1 | 5:9de43186f5ea | 187 | |
messi1 | 5:9de43186f5ea | 188 | //------------------------------------------------------------------------------------ |
messi1 | 5:9de43186f5ea | 189 | void SSD1331::clearArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) |
messi1 | 5:9de43186f5ea | 190 | { |
messi1 | 6:06c211302c93 | 191 | if (x0 >= RGB_OLED_WIDTH) x0 = RGB_OLED_XMAX; |
messi1 | 6:06c211302c93 | 192 | if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_YMAX; |
messi1 | 6:06c211302c93 | 193 | if (x1 >= RGB_OLED_WIDTH) x1 = RGB_OLED_XMAX; |
messi1 | 6:06c211302c93 | 194 | if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_YMAX; |
messi1 | 5:9de43186f5ea | 195 | |
messi1 | 5:9de43186f5ea | 196 | uint8_t cmdBuffer[5] = { CMD_CLEAR_WINDOW, x0, y0, x1, y1 }; |
messi1 | 5:9de43186f5ea | 197 | sendCmd(cmdBuffer, 5); //Send buffer |
messi1 | 5:9de43186f5ea | 198 | wait(0.05); |
messi1 | 5:9de43186f5ea | 199 | } |
messi1 | 5:9de43186f5ea | 200 | |
messi1 | 5:9de43186f5ea | 201 | //------------------------------------------------------------------------------------ |
messi1 | 6:06c211302c93 | 202 | void SSD1331::moveArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) |
messi1 | 6:06c211302c93 | 203 | { |
messi1 | 6:06c211302c93 | 204 | copyArea(x0, y0, x1, y1, x2, y2); |
messi1 | 6:06c211302c93 | 205 | clearArea(x0, y0, x1, y1); |
messi1 | 6:06c211302c93 | 206 | } |
messi1 | 6:06c211302c93 | 207 | |
messi1 | 6:06c211302c93 | 208 | //------------------------------------------------------------------------------------ |
messi1 | 8:ff74bd4d94d6 | 209 | void SSD1331::fillScreen(uint16_t color) |
messi1 | 8:ff74bd4d94d6 | 210 | { |
messi1 | 9:5a7bf0ce8518 | 211 | drawRect(0, 0, RGB_OLED_XMAX, RGB_OLED_YMAX, color, color); |
messi1 | 8:ff74bd4d94d6 | 212 | } |
messi1 | 8:ff74bd4d94d6 | 213 | |
messi1 | 8:ff74bd4d94d6 | 214 | //------------------------------------------------------------------------------------ |
messi1 | 9:5a7bf0ce8518 | 215 | void SSD1331::setScolling(ScollingDirection direction, uint8_t rowAddr, uint8_t rowNum, ScrollInterval interval) |
messi1 | 5:9de43186f5ea | 216 | { |
messi1 | 5:9de43186f5ea | 217 | uint8_t scolling_horizontal = 0x0; |
messi1 | 5:9de43186f5ea | 218 | uint8_t scolling_vertical = 0x0; |
messi1 | 5:9de43186f5ea | 219 | switch(direction){ |
messi1 | 9:5a7bf0ce8518 | 220 | case SD_Horizontal: |
messi1 | 5:9de43186f5ea | 221 | scolling_horizontal = 0x01; |
messi1 | 5:9de43186f5ea | 222 | scolling_vertical = 0x00; |
messi1 | 5:9de43186f5ea | 223 | break; |
messi1 | 9:5a7bf0ce8518 | 224 | case SD_Vertical: |
messi1 | 5:9de43186f5ea | 225 | scolling_horizontal = 0x00; |
messi1 | 5:9de43186f5ea | 226 | scolling_vertical = 0x01; |
messi1 | 5:9de43186f5ea | 227 | break; |
messi1 | 9:5a7bf0ce8518 | 228 | case SD_Diagonal: |
messi1 | 5:9de43186f5ea | 229 | scolling_horizontal = 0x01; |
messi1 | 5:9de43186f5ea | 230 | scolling_vertical = 0x01; |
messi1 | 5:9de43186f5ea | 231 | break; |
messi1 | 5:9de43186f5ea | 232 | default: |
messi1 | 5:9de43186f5ea | 233 | break; |
messi1 | 5:9de43186f5ea | 234 | } |
messi1 | 5:9de43186f5ea | 235 | |
messi1 | 9:5a7bf0ce8518 | 236 | uint8_t cmdBuffer[6] = { CMD_CONTINUOUS_SCROLLING_SETUP, scolling_horizontal, rowAddr, rowNum, scolling_vertical, interval }; |
messi1 | 5:9de43186f5ea | 237 | sendCmd(cmdBuffer, 6); //Send buffer |
messi1 | 5:9de43186f5ea | 238 | sendCmd(CMD_ACTIVE_SCROLLING); |
messi1 | 5:9de43186f5ea | 239 | wait(0.05); |
messi1 | 5:9de43186f5ea | 240 | } |
messi1 | 5:9de43186f5ea | 241 | |
messi1 | 5:9de43186f5ea | 242 | //------------------------------------------------------------------------------------ |
messi1 | 5:9de43186f5ea | 243 | void SSD1331::enableScolling(bool enable) |
messi1 | 5:9de43186f5ea | 244 | { |
messi1 | 5:9de43186f5ea | 245 | if(enable) |
messi1 | 5:9de43186f5ea | 246 | sendCmd(CMD_ACTIVE_SCROLLING); |
messi1 | 5:9de43186f5ea | 247 | else |
messi1 | 5:9de43186f5ea | 248 | sendCmd(CMD_DEACTIVE_SCROLLING); |
messi1 | 5:9de43186f5ea | 249 | } |
messi1 | 5:9de43186f5ea | 250 | |
messi1 | 5:9de43186f5ea | 251 | //------------------------------------------------------------------------------------ |
messi1 | 5:9de43186f5ea | 252 | void SSD1331::setDisplayMode(DisplayMode mode) |
messi1 | 5:9de43186f5ea | 253 | { |
messi1 | 5:9de43186f5ea | 254 | sendCmd(mode); |
messi1 | 5:9de43186f5ea | 255 | } |
messi1 | 5:9de43186f5ea | 256 | |
messi1 | 5:9de43186f5ea | 257 | //------------------------------------------------------------------------------------ |
messi1 | 9:5a7bf0ce8518 | 258 | void SSD1331::setPowerMode(PowerMode power) |
messi1 | 5:9de43186f5ea | 259 | { |
messi1 | 5:9de43186f5ea | 260 | sendCmd(power); |
messi1 | 5:9de43186f5ea | 261 | } |
messi1 | 5:9de43186f5ea | 262 | |
messi1 | 5:9de43186f5ea | 263 | //------------------------------------------------------------------------------------ |
messi1 | 5:9de43186f5ea | 264 | // Private member functions |
messi1 | 5:9de43186f5ea | 265 | //------------------------------------------------------------------------------------ |
messi1 | 3:af00512c9694 | 266 | void SSD1331::sendCmd(uint8_t cmd) |
messi1 | 2:e033aab5daad | 267 | { |
messi1 | 2:e033aab5daad | 268 | _dc = 0; |
messi1 | 2:e033aab5daad | 269 | _cs = 0; |
messi1 | 2:e033aab5daad | 270 | _spiPort.write(cmd); |
messi1 | 2:e033aab5daad | 271 | _cs = 1; |
messi1 | 2:e033aab5daad | 272 | } |
messi1 | 2:e033aab5daad | 273 | |
messi1 | 4:1707ca53e7d5 | 274 | //------------------------------------------------------------------------------------ |
messi1 | 3:af00512c9694 | 275 | void SSD1331::sendCmd(uint8_t cmd, uint8_t arg1) |
messi1 | 2:e033aab5daad | 276 | { |
messi1 | 2:e033aab5daad | 277 | _dc = 0; |
messi1 | 2:e033aab5daad | 278 | _cs = 0; |
messi1 | 2:e033aab5daad | 279 | _spiPort.write(cmd); |
messi1 | 2:e033aab5daad | 280 | _spiPort.write(arg1); |
messi1 | 2:e033aab5daad | 281 | _cs = 1; |
messi1 | 2:e033aab5daad | 282 | } |
messi1 | 4:1707ca53e7d5 | 283 | |
messi1 | 4:1707ca53e7d5 | 284 | //------------------------------------------------------------------------------------ |
messi1 | 3:af00512c9694 | 285 | void SSD1331::sendCmd(uint8_t cmd, uint8_t arg1, uint8_t arg2) |
messi1 | 0:6e810b5b40a3 | 286 | { |
messi1 | 2:e033aab5daad | 287 | _dc = 0; |
messi1 | 2:e033aab5daad | 288 | _cs = 0; |
messi1 | 2:e033aab5daad | 289 | _spiPort.write(cmd); |
messi1 | 2:e033aab5daad | 290 | _spiPort.write(arg1); |
messi1 | 2:e033aab5daad | 291 | _spiPort.write(arg2); |
messi1 | 2:e033aab5daad | 292 | _cs = 1; |
messi1 | 2:e033aab5daad | 293 | } |
messi1 | 2:e033aab5daad | 294 | |
messi1 | 4:1707ca53e7d5 | 295 | //------------------------------------------------------------------------------------ |
messi1 | 3:af00512c9694 | 296 | void SSD1331::sendCmd(uint8_t *cmd, uint8_t count) |
messi1 | 2:e033aab5daad | 297 | { |
messi1 | 2:e033aab5daad | 298 | if(!cmd) return; |
messi1 | 2:e033aab5daad | 299 | |
messi1 | 2:e033aab5daad | 300 | _dc = 0; |
messi1 | 2:e033aab5daad | 301 | _cs = 0; |
messi1 | 3:af00512c9694 | 302 | for(uint8_t i=0; i<count; ++i) |
messi1 | 2:e033aab5daad | 303 | _spiPort.write(*cmd++); |
messi1 | 2:e033aab5daad | 304 | _cs = 1; |
messi1 | 2:e033aab5daad | 305 | } |
messi1 | 2:e033aab5daad | 306 | |
messi1 | 4:1707ca53e7d5 | 307 | //------------------------------------------------------------------------------------ |
messi1 | 2:e033aab5daad | 308 | void SSD1331::sendData(uint16_t data) |
messi1 | 2:e033aab5daad | 309 | { |
messi1 | 2:e033aab5daad | 310 | _dc = HIGH; |
messi1 | 2:e033aab5daad | 311 | _cs = LOW; |
messi1 | 2:e033aab5daad | 312 | _spiPort.write(data >> 8); |
messi1 | 2:e033aab5daad | 313 | _spiPort.write((data & 0x00ff)); |
messi1 | 2:e033aab5daad | 314 | _cs = HIGH; |
messi1 | 2:e033aab5daad | 315 | } |
messi1 | 2:e033aab5daad | 316 | |
messi1 | 4:1707ca53e7d5 | 317 | //------------------------------------------------------------------------------------ |
messi1 | 4:1707ca53e7d5 | 318 | int SSD1331::_getc() |
messi1 | 4:1707ca53e7d5 | 319 | { |
messi1 | 4:1707ca53e7d5 | 320 | return -1; |
messi1 | 4:1707ca53e7d5 | 321 | } |
messi1 | 4:1707ca53e7d5 | 322 | |
messi1 | 4:1707ca53e7d5 | 323 | //------------------------------------------------------------------------------------ |
messi1 | 4:1707ca53e7d5 | 324 | int SSD1331::_putc( int c ) |
messi1 | 4:1707ca53e7d5 | 325 | { |
messi1 | 4:1707ca53e7d5 | 326 | return -1; |
messi1 | 4:1707ca53e7d5 | 327 | } |