Test for STM32F4

Dependents:   Nucleo_SSD1331

Fork of RGB_OLED_SSD1331 by Juergen M

Committer:
messi1
Date:
Sun Nov 15 23:07:48 2015 +0000
Revision:
7:5250c825c7bb
Parent:
6:06c211302c93
Child:
8:ff74bd4d94d6
Fixed 16bit collor transmission to the spi port according to the datasheet page32

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 LOW 0
messi1 0:6e810b5b40a3 118 #define HIGH 1
messi1 0:6e810b5b40a3 119
messi1 7:5250c825c7bb 120
messi1 7:5250c825c7bb 121 /* some 16bit RGB color definitions */
messi1 7:5250c825c7bb 122 enum Color{
messi1 7:5250c825c7bb 123 Black = 0x0000, /* 0, 0, 0 */
messi1 7:5250c825c7bb 124 Navy = 0x000F, /* 0, 0, 128 */
messi1 7:5250c825c7bb 125 DarkGreen = 0x03E0, /* 0, 128, 0 */
messi1 7:5250c825c7bb 126 DarkCyan = 0x03EF, /* 0, 128, 128 */
messi1 7:5250c825c7bb 127 Maroon = 0x7800, /* 128, 0, 0 */
messi1 7:5250c825c7bb 128 Purple = 0x780F, /* 128, 0, 128 */
messi1 7:5250c825c7bb 129 Olive = 0x7BE0, /* 128, 128, 0 */
messi1 7:5250c825c7bb 130 LightGrey = 0xC618, /* 192, 192, 192 */
messi1 7:5250c825c7bb 131 DarkGrey = 0x7BEF, /* 128, 128, 128 */
messi1 7:5250c825c7bb 132 Blue = 0x001F, /* 0, 0, 255 */
messi1 7:5250c825c7bb 133 Green = 0x07E0, /* 0, 255, 0 */
messi1 7:5250c825c7bb 134 Cyan = 0x07FF, /* 0, 255, 255 */
messi1 7:5250c825c7bb 135 Red = 0xF800, /* 255, 0, 0 */
messi1 7:5250c825c7bb 136 Magenta = 0xF81F, /* 255, 0, 255 */
messi1 7:5250c825c7bb 137 Yellow = 0xFFE0, /* 255, 255, 0 */
messi1 7:5250c825c7bb 138 White = 0xFFFF, /* 255, 255, 255 */
messi1 7:5250c825c7bb 139 Orange = 0xFD20, /* 255, 165, 0 */
messi1 7:5250c825c7bb 140 GreenYellow = 0xAFE5, /* 173, 255, 47 */
messi1 7:5250c825c7bb 141 Pink = 0xF81F
messi1 0:6e810b5b40a3 142 };
messi1 0:6e810b5b40a3 143
messi1 0:6e810b5b40a3 144 enum DisplayMode{
messi1 0:6e810b5b40a3 145 //reset the above effect and turn the data to ON at the corresponding gray level.
messi1 0:6e810b5b40a3 146 NormalDisplay = 0xA4,
messi1 0:6e810b5b40a3 147 //forces the entire display to be at "GS63"
messi1 0:6e810b5b40a3 148 DisplayOn = 0xA5,
messi1 0:6e810b5b40a3 149 //forces the entire display to be at gray level "GS0"
messi1 0:6e810b5b40a3 150 DisplayOff = 0xA6,
messi1 0:6e810b5b40a3 151 //swap the gray level of display data
messi1 0:6e810b5b40a3 152 InverseDisplay = 0xA7
messi1 0:6e810b5b40a3 153 };
messi1 0:6e810b5b40a3 154
messi1 0:6e810b5b40a3 155 enum DisplayPower{
messi1 0:6e810b5b40a3 156 DimMode = 0xAC,
messi1 0:6e810b5b40a3 157 SleepMode = 0xAE,
messi1 0:6e810b5b40a3 158 NormalMode = 0xAF
messi1 0:6e810b5b40a3 159 };
messi1 0:6e810b5b40a3 160
messi1 0:6e810b5b40a3 161 enum ScollingDirection{
messi1 0:6e810b5b40a3 162 Horizontal = 0x00,
messi1 0:6e810b5b40a3 163 Vertical = 0x01,
messi1 0:6e810b5b40a3 164 Diagonal = 0x02
messi1 0:6e810b5b40a3 165 };
messi1 0:6e810b5b40a3 166
messi1 0:6e810b5b40a3 167
messi1 3:af00512c9694 168 class SSD1331 : public mbed::Stream, public virtual SGL
messi1 3:af00512c9694 169 {
messi1 3:af00512c9694 170 public:
messi1 3:af00512c9694 171 SSD1331(PinName cs, PinName rst, PinName dc, PinName mosi, PinName miso, PinName sclk);
messi1 5:9de43186f5ea 172
messi1 3:af00512c9694 173 virtual void drawPixel(uint8_t x, uint8_t y, uint16_t color);
messi1 4:1707ca53e7d5 174 virtual void drawLine(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint16_t color);
messi1 5:9de43186f5ea 175 void drawFrame(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint16_t outColor, uint16_t fillColor);
messi1 5:9de43186f5ea 176 void copyArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2);
messi1 5:9de43186f5ea 177 void dimArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1);
messi1 5:9de43186f5ea 178 void clearArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1);
messi1 6:06c211302c93 179 void moveArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2);
messi1 3:af00512c9694 180 void setScolling(ScollingDirection direction, uint8_t rowAddr, uint8_t rowNum, uint8_t timeInterval);
messi1 3:af00512c9694 181 void enableScolling(bool enable);
messi1 3:af00512c9694 182 void setDisplayMode(DisplayMode mode);
messi1 3:af00512c9694 183 void setDisplayPower(DisplayPower power);
messi1 3:af00512c9694 184
messi1 3:af00512c9694 185 protected:
messi1 3:af00512c9694 186 // Stream implementation functions
messi1 3:af00512c9694 187 virtual int _putc( int c );
messi1 3:af00512c9694 188 virtual int _getc();
messi1 3:af00512c9694 189
messi1 3:af00512c9694 190 private:
messi1 5:9de43186f5ea 191 void init(void);
messi1 3:af00512c9694 192 void sendCmd(uint8_t cmd);
messi1 3:af00512c9694 193 void sendCmd(uint8_t cmd, uint8_t arg1);
messi1 3:af00512c9694 194 void sendCmd(uint8_t cmd, uint8_t arg1, uint8_t arg2);
messi1 3:af00512c9694 195 void sendCmd(uint8_t *cmd, uint8_t count);
messi1 3:af00512c9694 196 void sendData(uint16_t data);
messi1 3:af00512c9694 197
messi1 3:af00512c9694 198 private:
messi1 3:af00512c9694 199 mbed::DigitalOut _cs;
messi1 3:af00512c9694 200 mbed::DigitalOut _dc;
messi1 3:af00512c9694 201 mbed::SPI _spiPort;
messi1 0:6e810b5b40a3 202 };
messi1 0:6e810b5b40a3 203
messi1 0:6e810b5b40a3 204 #endif