Test for STM32F4

Dependents:   Nucleo_SSD1331

Fork of RGB_OLED_SSD1331 by Juergen M

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?

UserRevisionLine numberNew contents of line
messi1 0:6e810b5b40a3 1 /*
messi1 0:6e810b5b40a3 2 * SSD1331.h
messi1 0:6e810b5b40a3 3 * A library for RGB OLED module
messi1 0:6e810b5b40a3 4 *
messi1 3:af00512c9694 5 * Copyright (c) 2015 Juergen Messerer
messi1 0:6e810b5b40a3 6 * Copyright (c) 2014 seeed technology inc.
messi1 0:6e810b5b40a3 7 * Copyright (c) 2012, Adafruit Industries.
messi1 0:6e810b5b40a3 8 *
messi1 0:6e810b5b40a3 9 * All rights reserved.
messi1 0:6e810b5b40a3 10 *
messi1 0:6e810b5b40a3 11 * This library is based on Adafruit's SSD1331-OLED-Driver-Library. Thanks to
messi1 0:6e810b5b40a3 12 * their contribution to the code, we modify it and add more interface to
messi1 0:6e810b5b40a3 13 * support our Seeed's Xadow RGB OLED 96*64 module.
messi1 0:6e810b5b40a3 14 *
messi1 0:6e810b5b40a3 15 * Below is the introduction of Adafruit's Color OLED module, we add it to here
messi1 0:6e810b5b40a3 16 * to express our thanks to them.
messi1 0:6e810b5b40a3 17 *
messi1 0:6e810b5b40a3 18 * ****************************************************************************
messi1 0:6e810b5b40a3 19 * This is a library for the 0.96" 16-bit Color OLED with SSD1331 driver chip
messi1 0:6e810b5b40a3 20 *
messi1 0:6e810b5b40a3 21 * Pick one up today in the adafruit shop!
messi1 0:6e810b5b40a3 22 * ------> http://www.adafruit.com/products/684
messi1 0:6e810b5b40a3 23 *
messi1 0:6e810b5b40a3 24 * These displays use SPI to communicate.
messi1 0:6e810b5b40a3 25 *
messi1 0:6e810b5b40a3 26 * Adafruit invests time and resources providing this open source code,
messi1 0:6e810b5b40a3 27 * please support Adafruit and open-source hardware by purchasing
messi1 0:6e810b5b40a3 28 * products from Adafruit!
messi1 0:6e810b5b40a3 29 *
messi1 0:6e810b5b40a3 30 * Written by Limor Fried/Ladyada for Adafruit Industries.
messi1 0:6e810b5b40a3 31 * Modifed by lawliet for Seeed Studio's RGB OLED module.
messi1 0:6e810b5b40a3 32 * BSD license, all text above must be included in any redistribution
messi1 0:6e810b5b40a3 33 * ******************************************************************************
messi1 0:6e810b5b40a3 34 *
messi1 0:6e810b5b40a3 35 * Software License Agreement (BSD License)
messi1 0:6e810b5b40a3 36 *
messi1 0:6e810b5b40a3 37 * Redistribution and use in source and binary forms, with or without
messi1 0:6e810b5b40a3 38 * modification, are permitted provided that the following conditions are met:
messi1 0:6e810b5b40a3 39 * 1. Redistributions of source code must retain the above copyright
messi1 0:6e810b5b40a3 40 * notice, this list of conditions and the following disclaimer.
messi1 0:6e810b5b40a3 41 * 2. Redistributions in binary form must reproduce the above copyright
messi1 0:6e810b5b40a3 42 * notice, this list of conditions and the following disclaimer in the
messi1 0:6e810b5b40a3 43 * documentation and/or other materials provided with the distribution.
messi1 0:6e810b5b40a3 44 * 3. Neither the name of the copyright holders nor the
messi1 0:6e810b5b40a3 45 * names of its contributors may be used to endorse or promote products
messi1 0:6e810b5b40a3 46 * derived from this software without specific prior written permission.
messi1 0:6e810b5b40a3 47 *
messi1 0:6e810b5b40a3 48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
messi1 0:6e810b5b40a3 49 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
messi1 0:6e810b5b40a3 50 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
messi1 0:6e810b5b40a3 51 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
messi1 0:6e810b5b40a3 52 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
messi1 0:6e810b5b40a3 53 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
messi1 0:6e810b5b40a3 54 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
messi1 0:6e810b5b40a3 55 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
messi1 0:6e810b5b40a3 56 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
messi1 0:6e810b5b40a3 57 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
messi1 0:6e810b5b40a3 58 *
messi1 0:6e810b5b40a3 59 */
messi1 0:6e810b5b40a3 60
messi1 0:6e810b5b40a3 61 #ifndef _SSD1331_H_
messi1 0:6e810b5b40a3 62 #define _SSD1331_H_
messi1 5:9de43186f5ea 63
messi1 0:6e810b5b40a3 64 #include "DigitalOut.h"
messi1 0:6e810b5b40a3 65 #include "PinNames.h"
messi1 0:6e810b5b40a3 66 #include "SGL.h"
messi1 2:e033aab5daad 67 #include "Stream.h"
messi1 0:6e810b5b40a3 68
messi1 0:6e810b5b40a3 69
messi1 0:6e810b5b40a3 70 #define RGB_OLED_WIDTH 96
messi1 0:6e810b5b40a3 71 #define RGB_OLED_HEIGHT 64
messi1 5:9de43186f5ea 72 #define RGB_OLED_XMAX RGB_OLED_WIDTH-1
messi1 5:9de43186f5ea 73 #define RGB_OLED_YMAX RGB_OLED_HEIGHT-1
messi1 0:6e810b5b40a3 74
messi1 0:6e810b5b40a3 75 #define CMD_DRAW_LINE 0x21
messi1 0:6e810b5b40a3 76 #define CMD_DRAW_RECTANGLE 0x22
messi1 0:6e810b5b40a3 77 #define CMD_COPY_WINDOW 0x23
messi1 0:6e810b5b40a3 78 #define CMD_DIM_WINDOW 0x24
messi1 0:6e810b5b40a3 79 #define CMD_CLEAR_WINDOW 0x25
messi1 0:6e810b5b40a3 80 #define CMD_FILL_WINDOW 0x26
messi1 1:b55525d2db34 81 #define DISABLE_FILL 0x00
messi1 1:b55525d2db34 82 #define ENABLE_FILL 0x01
messi1 0:6e810b5b40a3 83 #define CMD_CONTINUOUS_SCROLLING_SETUP 0x27
messi1 0:6e810b5b40a3 84 #define CMD_DEACTIVE_SCROLLING 0x2E
messi1 0:6e810b5b40a3 85 #define CMD_ACTIVE_SCROLLING 0x2F
messi1 0:6e810b5b40a3 86
messi1 0:6e810b5b40a3 87 #define CMD_SET_COLUMN_ADDRESS 0x15
messi1 0:6e810b5b40a3 88 #define CMD_SET_ROW_ADDRESS 0x75
messi1 0:6e810b5b40a3 89 #define CMD_SET_CONTRAST_A 0x81
messi1 0:6e810b5b40a3 90 #define CMD_SET_CONTRAST_B 0x82
messi1 0:6e810b5b40a3 91 #define CMD_SET_CONTRAST_C 0x83
messi1 0:6e810b5b40a3 92 #define CMD_MASTER_CURRENT_CONTROL 0x87
messi1 0:6e810b5b40a3 93 #define CMD_SET_PRECHARGE_SPEED_A 0x8A
messi1 0:6e810b5b40a3 94 #define CMD_SET_PRECHARGE_SPEED_B 0x8B
messi1 0:6e810b5b40a3 95 #define CMD_SET_PRECHARGE_SPEED_C 0x8C
messi1 0:6e810b5b40a3 96 #define CMD_SET_REMAP 0xA0
messi1 0:6e810b5b40a3 97 #define CMD_SET_DISPLAY_START_LINE 0xA1
messi1 0:6e810b5b40a3 98 #define CMD_SET_DISPLAY_OFFSET 0xA2
messi1 0:6e810b5b40a3 99 #define CMD_NORMAL_DISPLAY 0xA4
messi1 0:6e810b5b40a3 100 #define CMD_ENTIRE_DISPLAY_ON 0xA5
messi1 0:6e810b5b40a3 101 #define CMD_ENTIRE_DISPLAY_OFF 0xA6
messi1 0:6e810b5b40a3 102 #define CMD_INVERSE_DISPLAY 0xA7
messi1 0:6e810b5b40a3 103 #define CMD_SET_MULTIPLEX_RATIO 0xA8
messi1 0:6e810b5b40a3 104 #define CMD_DIM_MODE_SETTING 0xAB
messi1 0:6e810b5b40a3 105 #define CMD_SET_MASTER_CONFIGURE 0xAD
messi1 0:6e810b5b40a3 106 #define CMD_DIM_MODE_DISPLAY_ON 0xAC
messi1 0:6e810b5b40a3 107 #define CMD_DISPLAY_OFF 0xAE
messi1 0:6e810b5b40a3 108 #define CMD_NORMAL_BRIGHTNESS_DISPLAY_ON 0xAF
messi1 0:6e810b5b40a3 109 #define CMD_POWER_SAVE_MODE 0xB0
messi1 0:6e810b5b40a3 110 #define CMD_PHASE_PERIOD_ADJUSTMENT 0xB1
messi1 0:6e810b5b40a3 111 #define CMD_DISPLAY_CLOCK_DIV 0xB3
messi1 0:6e810b5b40a3 112 #define CMD_SET_GRAy_SCALE_TABLE 0xB8
messi1 0:6e810b5b40a3 113 #define CMD_ENABLE_LINEAR_GRAY_SCALE_TABLE 0xB9
messi1 0:6e810b5b40a3 114 #define CMD_SET_PRECHARGE_VOLTAGE 0xBB
messi1 0:6e810b5b40a3 115 #define CMD_SET_V_VOLTAGE 0xBE
messi1 0:6e810b5b40a3 116
messi1 0:6e810b5b40a3 117 #define RGB(R,G,B) (((R>>3)<<11) | ((G>>2)<<5) | (B>>3))
messi1 0:6e810b5b40a3 118
messi1 0:6e810b5b40a3 119 #define LOW 0
messi1 0:6e810b5b40a3 120 #define HIGH 1
messi1 0:6e810b5b40a3 121
messi1 0:6e810b5b40a3 122 enum Color{
messi1 0:6e810b5b40a3 123 COLOR_BLACK = RGB( 0, 0, 0), // black
messi1 0:6e810b5b40a3 124 COLOR_GREY = RGB(192,192,192), // grey
messi1 0:6e810b5b40a3 125 COLOR_WHITE = RGB(255,255,255), // white
messi1 0:6e810b5b40a3 126 COLOR_RED = RGB(255, 0, 0), // red
messi1 0:6e810b5b40a3 127 COLOR_PINK = RGB(255,192,203), // pink
messi1 0:6e810b5b40a3 128 COLOR_YELLOW = RGB(255,255, 0), // yellow
messi1 0:6e810b5b40a3 129 COLOR_GOLDEN = RGB(255,215, 0), // golden
messi1 0:6e810b5b40a3 130 COLOR_BROWN = RGB(128, 42, 42), // brown
messi1 0:6e810b5b40a3 131 COLOR_BLUE = RGB( 0, 0,255), // blue
messi1 0:6e810b5b40a3 132 COLOR_CYAN = RGB( 0,255,255), // cyan
messi1 0:6e810b5b40a3 133 COLOR_GREEN = RGB( 0,255, 0), // green
messi1 0:6e810b5b40a3 134 COLOR_PURPLE = RGB(160, 32,240), // purple
messi1 0:6e810b5b40a3 135 };
messi1 0:6e810b5b40a3 136
messi1 2:e033aab5daad 137 /* some RGB color definitions */
messi1 2:e033aab5daad 138 #define Black 0x0000 /* 0, 0, 0 */
messi1 2:e033aab5daad 139 #define Navy 0x000F /* 0, 0, 128 */
messi1 2:e033aab5daad 140 #define DarkGreen 0x03E0 /* 0, 128, 0 */
messi1 2:e033aab5daad 141 #define DarkCyan 0x03EF /* 0, 128, 128 */
messi1 2:e033aab5daad 142 #define Maroon 0x7800 /* 128, 0, 0 */
messi1 2:e033aab5daad 143 #define Purple 0x780F /* 128, 0, 128 */
messi1 2:e033aab5daad 144 #define Olive 0x7BE0 /* 128, 128, 0 */
messi1 2:e033aab5daad 145 #define LightGrey 0xC618 /* 192, 192, 192 */
messi1 2:e033aab5daad 146 #define DarkGrey 0x7BEF /* 128, 128, 128 */
messi1 2:e033aab5daad 147 #define Blue 0x001F /* 0, 0, 255 */
messi1 2:e033aab5daad 148 #define Green 0x07E0 /* 0, 255, 0 */
messi1 2:e033aab5daad 149 #define Cyan 0x07FF /* 0, 255, 255 */
messi1 2:e033aab5daad 150 #define Red 0xF800 /* 255, 0, 0 */
messi1 2:e033aab5daad 151 #define Magenta 0xF81F /* 255, 0, 255 */
messi1 2:e033aab5daad 152 #define Yellow 0xFFE0 /* 255, 255, 0 */
messi1 2:e033aab5daad 153 #define White 0xFFFF /* 255, 255, 255 */
messi1 2:e033aab5daad 154 #define Orange 0xFD20 /* 255, 165, 0 */
messi1 2:e033aab5daad 155 #define GreenYellow 0xAFE5 /* 173, 255, 47 */
messi1 2:e033aab5daad 156 #define Pink 0xF81F
messi1 2:e033aab5daad 157
messi1 0:6e810b5b40a3 158 enum DisplayMode{
messi1 0:6e810b5b40a3 159 //reset the above effect and turn the data to ON at the corresponding gray level.
messi1 0:6e810b5b40a3 160 NormalDisplay = 0xA4,
messi1 0:6e810b5b40a3 161 //forces the entire display to be at "GS63"
messi1 0:6e810b5b40a3 162 DisplayOn = 0xA5,
messi1 0:6e810b5b40a3 163 //forces the entire display to be at gray level "GS0"
messi1 0:6e810b5b40a3 164 DisplayOff = 0xA6,
messi1 0:6e810b5b40a3 165 //swap the gray level of display data
messi1 0:6e810b5b40a3 166 InverseDisplay = 0xA7
messi1 0:6e810b5b40a3 167 };
messi1 0:6e810b5b40a3 168
messi1 0:6e810b5b40a3 169 enum DisplayPower{
messi1 0:6e810b5b40a3 170 DimMode = 0xAC,
messi1 0:6e810b5b40a3 171 SleepMode = 0xAE,
messi1 0:6e810b5b40a3 172 NormalMode = 0xAF
messi1 0:6e810b5b40a3 173 };
messi1 0:6e810b5b40a3 174
messi1 0:6e810b5b40a3 175 enum ScollingDirection{
messi1 0:6e810b5b40a3 176 Horizontal = 0x00,
messi1 0:6e810b5b40a3 177 Vertical = 0x01,
messi1 0:6e810b5b40a3 178 Diagonal = 0x02
messi1 0:6e810b5b40a3 179 };
messi1 0:6e810b5b40a3 180
messi1 0:6e810b5b40a3 181
messi1 3:af00512c9694 182 class SSD1331 : public mbed::Stream, public virtual SGL
messi1 3:af00512c9694 183 {
messi1 3:af00512c9694 184 public:
messi1 3:af00512c9694 185 SSD1331(PinName cs, PinName rst, PinName dc, PinName mosi, PinName miso, PinName sclk);
messi1 5:9de43186f5ea 186
messi1 3:af00512c9694 187 virtual void drawPixel(uint8_t x, uint8_t y, uint16_t color);
messi1 4:1707ca53e7d5 188 virtual void drawLine(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint16_t color);
messi1 5:9de43186f5ea 189 void drawFrame(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint16_t outColor, uint16_t fillColor);
messi1 5:9de43186f5ea 190 void copyArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2);
messi1 5:9de43186f5ea 191 void dimArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1);
messi1 5:9de43186f5ea 192 void clearArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1);
messi1 3:af00512c9694 193 void setScolling(ScollingDirection direction, uint8_t rowAddr, uint8_t rowNum, uint8_t timeInterval);
messi1 3:af00512c9694 194 void enableScolling(bool enable);
messi1 3:af00512c9694 195 void setDisplayMode(DisplayMode mode);
messi1 3:af00512c9694 196 void setDisplayPower(DisplayPower power);
messi1 3:af00512c9694 197
messi1 3:af00512c9694 198 protected:
messi1 3:af00512c9694 199 // Stream implementation functions
messi1 3:af00512c9694 200 virtual int _putc( int c );
messi1 3:af00512c9694 201 virtual int _getc();
messi1 3:af00512c9694 202
messi1 3:af00512c9694 203 private:
messi1 5:9de43186f5ea 204 void init(void);
messi1 3:af00512c9694 205 void sendCmd(uint8_t cmd);
messi1 3:af00512c9694 206 void sendCmd(uint8_t cmd, uint8_t arg1);
messi1 3:af00512c9694 207 void sendCmd(uint8_t cmd, uint8_t arg1, uint8_t arg2);
messi1 3:af00512c9694 208 void sendCmd(uint8_t *cmd, uint8_t count);
messi1 3:af00512c9694 209 void sendData(uint16_t data);
messi1 3:af00512c9694 210
messi1 3:af00512c9694 211 private:
messi1 3:af00512c9694 212 mbed::DigitalOut _cs;
messi1 3:af00512c9694 213 mbed::DigitalOut _dc;
messi1 3:af00512c9694 214 mbed::SPI _spiPort;
messi1 0:6e810b5b40a3 215 };
messi1 0:6e810b5b40a3 216
messi1 0:6e810b5b40a3 217 #endif