Test for STM32F4

Dependents:   Nucleo_SSD1331

Fork of RGB_OLED_SSD1331 by Juergen M

Committer:
messi1
Date:
Tue Nov 10 22:51:46 2015 +0000
Revision:
0:6e810b5b40a3
Child:
1:b55525d2db34
Init version

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 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
messi1 0:6e810b5b40a3 60 #ifndef _SSD1331_H_
messi1 0:6e810b5b40a3 61 #define _SSD1331_H_
messi1 0:6e810b5b40a3 62 #include "DigitalOut.h"
messi1 0:6e810b5b40a3 63 #include "PinNames.h"
messi1 0:6e810b5b40a3 64 #include "SGL.h"
messi1 0:6e810b5b40a3 65
messi1 0:6e810b5b40a3 66 namespace mbed
messi1 0:6e810b5b40a3 67 {
messi1 0:6e810b5b40a3 68 class DigitalOut;
messi1 0:6e810b5b40a3 69 class SPI;
messi1 0:6e810b5b40a3 70 }
messi1 0:6e810b5b40a3 71
messi1 0:6e810b5b40a3 72
messi1 0:6e810b5b40a3 73 #define RGB_OLED_WIDTH 96
messi1 0:6e810b5b40a3 74 #define RGB_OLED_HEIGHT 64
messi1 0:6e810b5b40a3 75
messi1 0:6e810b5b40a3 76 #define CMD_DRAW_LINE 0x21
messi1 0:6e810b5b40a3 77 #define CMD_DRAW_RECTANGLE 0x22
messi1 0:6e810b5b40a3 78 #define CMD_COPY_WINDOW 0x23
messi1 0:6e810b5b40a3 79 #define CMD_DIM_WINDOW 0x24
messi1 0:6e810b5b40a3 80 #define CMD_CLEAR_WINDOW 0x25
messi1 0:6e810b5b40a3 81 #define CMD_FILL_WINDOW 0x26
messi1 0:6e810b5b40a3 82 #define DISABLE_FILL 0x00
messi1 0:6e810b5b40a3 83 #define ENABLE_FILL 0x01
messi1 0:6e810b5b40a3 84 #define CMD_CONTINUOUS_SCROLLING_SETUP 0x27
messi1 0:6e810b5b40a3 85 #define CMD_DEACTIVE_SCROLLING 0x2E
messi1 0:6e810b5b40a3 86 #define CMD_ACTIVE_SCROLLING 0x2F
messi1 0:6e810b5b40a3 87
messi1 0:6e810b5b40a3 88 #define CMD_SET_COLUMN_ADDRESS 0x15
messi1 0:6e810b5b40a3 89 #define CMD_SET_ROW_ADDRESS 0x75
messi1 0:6e810b5b40a3 90 #define CMD_SET_CONTRAST_A 0x81
messi1 0:6e810b5b40a3 91 #define CMD_SET_CONTRAST_B 0x82
messi1 0:6e810b5b40a3 92 #define CMD_SET_CONTRAST_C 0x83
messi1 0:6e810b5b40a3 93 #define CMD_MASTER_CURRENT_CONTROL 0x87
messi1 0:6e810b5b40a3 94 #define CMD_SET_PRECHARGE_SPEED_A 0x8A
messi1 0:6e810b5b40a3 95 #define CMD_SET_PRECHARGE_SPEED_B 0x8B
messi1 0:6e810b5b40a3 96 #define CMD_SET_PRECHARGE_SPEED_C 0x8C
messi1 0:6e810b5b40a3 97 #define CMD_SET_REMAP 0xA0
messi1 0:6e810b5b40a3 98 #define CMD_SET_DISPLAY_START_LINE 0xA1
messi1 0:6e810b5b40a3 99 #define CMD_SET_DISPLAY_OFFSET 0xA2
messi1 0:6e810b5b40a3 100 #define CMD_NORMAL_DISPLAY 0xA4
messi1 0:6e810b5b40a3 101 #define CMD_ENTIRE_DISPLAY_ON 0xA5
messi1 0:6e810b5b40a3 102 #define CMD_ENTIRE_DISPLAY_OFF 0xA6
messi1 0:6e810b5b40a3 103 #define CMD_INVERSE_DISPLAY 0xA7
messi1 0:6e810b5b40a3 104 #define CMD_SET_MULTIPLEX_RATIO 0xA8
messi1 0:6e810b5b40a3 105 #define CMD_DIM_MODE_SETTING 0xAB
messi1 0:6e810b5b40a3 106 #define CMD_SET_MASTER_CONFIGURE 0xAD
messi1 0:6e810b5b40a3 107 #define CMD_DIM_MODE_DISPLAY_ON 0xAC
messi1 0:6e810b5b40a3 108 #define CMD_DISPLAY_OFF 0xAE
messi1 0:6e810b5b40a3 109 #define CMD_NORMAL_BRIGHTNESS_DISPLAY_ON 0xAF
messi1 0:6e810b5b40a3 110 #define CMD_POWER_SAVE_MODE 0xB0
messi1 0:6e810b5b40a3 111 #define CMD_PHASE_PERIOD_ADJUSTMENT 0xB1
messi1 0:6e810b5b40a3 112 #define CMD_DISPLAY_CLOCK_DIV 0xB3
messi1 0:6e810b5b40a3 113 #define CMD_SET_GRAy_SCALE_TABLE 0xB8
messi1 0:6e810b5b40a3 114 #define CMD_ENABLE_LINEAR_GRAY_SCALE_TABLE 0xB9
messi1 0:6e810b5b40a3 115 #define CMD_SET_PRECHARGE_VOLTAGE 0xBB
messi1 0:6e810b5b40a3 116 #define CMD_SET_V_VOLTAGE 0xBE
messi1 0:6e810b5b40a3 117
messi1 0:6e810b5b40a3 118 #define RGB(R,G,B) (((R>>3)<<11) | ((G>>2)<<5) | (B>>3))
messi1 0:6e810b5b40a3 119
messi1 0:6e810b5b40a3 120 #define LOW 0
messi1 0:6e810b5b40a3 121 #define HIGH 1
messi1 0:6e810b5b40a3 122
messi1 0:6e810b5b40a3 123 enum Color{
messi1 0:6e810b5b40a3 124 COLOR_BLACK = RGB( 0, 0, 0), // black
messi1 0:6e810b5b40a3 125 COLOR_GREY = RGB(192,192,192), // grey
messi1 0:6e810b5b40a3 126 COLOR_WHITE = RGB(255,255,255), // white
messi1 0:6e810b5b40a3 127 COLOR_RED = RGB(255, 0, 0), // red
messi1 0:6e810b5b40a3 128 COLOR_PINK = RGB(255,192,203), // pink
messi1 0:6e810b5b40a3 129 COLOR_YELLOW = RGB(255,255, 0), // yellow
messi1 0:6e810b5b40a3 130 COLOR_GOLDEN = RGB(255,215, 0), // golden
messi1 0:6e810b5b40a3 131 COLOR_BROWN = RGB(128, 42, 42), // brown
messi1 0:6e810b5b40a3 132 COLOR_BLUE = RGB( 0, 0,255), // blue
messi1 0:6e810b5b40a3 133 COLOR_CYAN = RGB( 0,255,255), // cyan
messi1 0:6e810b5b40a3 134 COLOR_GREEN = RGB( 0,255, 0), // green
messi1 0:6e810b5b40a3 135 COLOR_PURPLE = RGB(160, 32,240), // purple
messi1 0:6e810b5b40a3 136 };
messi1 0:6e810b5b40a3 137
messi1 0:6e810b5b40a3 138 enum DisplayMode{
messi1 0:6e810b5b40a3 139 //reset the above effect and turn the data to ON at the corresponding gray level.
messi1 0:6e810b5b40a3 140 NormalDisplay = 0xA4,
messi1 0:6e810b5b40a3 141 //forces the entire display to be at "GS63"
messi1 0:6e810b5b40a3 142 DisplayOn = 0xA5,
messi1 0:6e810b5b40a3 143 //forces the entire display to be at gray level "GS0"
messi1 0:6e810b5b40a3 144 DisplayOff = 0xA6,
messi1 0:6e810b5b40a3 145 //swap the gray level of display data
messi1 0:6e810b5b40a3 146 InverseDisplay = 0xA7
messi1 0:6e810b5b40a3 147 };
messi1 0:6e810b5b40a3 148
messi1 0:6e810b5b40a3 149 enum DisplayPower{
messi1 0:6e810b5b40a3 150 DimMode = 0xAC,
messi1 0:6e810b5b40a3 151 SleepMode = 0xAE,
messi1 0:6e810b5b40a3 152 NormalMode = 0xAF
messi1 0:6e810b5b40a3 153 };
messi1 0:6e810b5b40a3 154
messi1 0:6e810b5b40a3 155 enum ScollingDirection{
messi1 0:6e810b5b40a3 156 Horizontal = 0x00,
messi1 0:6e810b5b40a3 157 Vertical = 0x01,
messi1 0:6e810b5b40a3 158 Diagonal = 0x02
messi1 0:6e810b5b40a3 159 };
messi1 0:6e810b5b40a3 160
messi1 0:6e810b5b40a3 161
messi1 0:6e810b5b40a3 162 class SSD1331 : public virtual SGL {
messi1 0:6e810b5b40a3 163 public:
messi1 0:6e810b5b40a3 164 SSD1331(PinName cs, PinName dc, PinName mosi, PinName sck);
messi1 0:6e810b5b40a3 165 void init(void);
messi1 0:6e810b5b40a3 166 virtual void drawPixel(uint16_t x, uint16_t y, uint16_t color);
messi1 0:6e810b5b40a3 167 virtual void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
messi1 0:6e810b5b40a3 168 void drawFrame(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t outColor, uint16_t fillColor);
messi1 0:6e810b5b40a3 169 void copyWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,uint16_t x2, uint16_t y2);
messi1 0:6e810b5b40a3 170 void dimWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
messi1 0:6e810b5b40a3 171 void clearWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
messi1 0:6e810b5b40a3 172 void setScolling(ScollingDirection direction, uint8_t rowAddr, uint8_t rowNum, uint8_t timeInterval);
messi1 0:6e810b5b40a3 173 void enableScolling(bool enable);
messi1 0:6e810b5b40a3 174 void setDisplayMode(DisplayMode mode);
messi1 0:6e810b5b40a3 175 void setDisplayPower(DisplayPower power);
messi1 0:6e810b5b40a3 176 private:
messi1 0:6e810b5b40a3 177 void _sendCmd(uint8_t cmd);
messi1 0:6e810b5b40a3 178
messi1 0:6e810b5b40a3 179 private:
messi1 0:6e810b5b40a3 180 mbed::DigitalOut* _cs;
messi1 0:6e810b5b40a3 181 mbed::DigitalOut* _dc;
messi1 0:6e810b5b40a3 182 mbed::SPI* _spiPort;
messi1 0:6e810b5b40a3 183 };
messi1 0:6e810b5b40a3 184
messi1 0:6e810b5b40a3 185 #endif