A class library for OLED on MARMEX_OB board. MARY拡張のMARMEX_OB基板のOLEDをmbed+MAPLE基板で動かすためのライブラリです.このサンプルではMAPLEに用意されているMARMEXスロットの1番に搭載したOLEDを制御するようになっています.詳細はCode&APIからソースやAPI詳細をご覧ください

Dependencies:   mbed NokiaLCD

Committer:
nxpfan
Date:
Thu Apr 07 23:32:35 2011 +0000
Revision:
1:a0ac2743f855
Parent:
0:a19b70a76e66

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxpfan 0:a19b70a76e66 1 /** MARMEX_OB OLED screen drawing library
nxpfan 0:a19b70a76e66 2 *
nxpfan 0:a19b70a76e66 3 * @class MARMEX_OB_oled
nxpfan 0:a19b70a76e66 4 * @author tedd
nxpfan 1:a0ac2743f855 5 * @version 0.51
nxpfan 1:a0ac2743f855 6 * @date 08-Apr-2011
nxpfan 0:a19b70a76e66 7 *
nxpfan 0:a19b70a76e66 8 * Released under the MIT License: http://mbed.org/license/mit
nxpfan 0:a19b70a76e66 9 *
nxpfan 0:a19b70a76e66 10 * MARMEX_OB_oled OLED screen drawing library for mbed
nxpfan 0:a19b70a76e66 11 * This code has been written based on sample code and advises
nxpfan 0:a19b70a76e66 12 * from Ochiai-san (Marutsu-Elec). Thank you!
nxpfan 0:a19b70a76e66 13 *
nxpfan 0:a19b70a76e66 14 * SPI mode:
nxpfan 0:a19b70a76e66 15 * 9bit or 8bit SPI mode can be selected by disabling/enabling "#define MARMEX_OB_SPI_8BIT_MODE".
nxpfan 0:a19b70a76e66 16 * See source code in this (MARMEX_OB_oled.h) file.
nxpfan 0:a19b70a76e66 17 */
nxpfan 0:a19b70a76e66 18
nxpfan 0:a19b70a76e66 19 #ifndef MBED_MARMEX_OB_OLED
nxpfan 0:a19b70a76e66 20 #define MBED_MARMEX_OB_OLED
nxpfan 0:a19b70a76e66 21
nxpfan 0:a19b70a76e66 22 #include "mbed.h"
nxpfan 0:a19b70a76e66 23 #include "NokiaLCD.h"
nxpfan 0:a19b70a76e66 24
nxpfan 0:a19b70a76e66 25 /** @def MARMEX_OB_SPI_8BIT_MODE
nxpfan 0:a19b70a76e66 26 *
nxpfan 0:a19b70a76e66 27 * MARMEX_OB_oled_oled OLED screen SPI access length setting
nxpfan 0:a19b70a76e66 28 * Enabling "MARMEX_OB_SPI_8BIT_MODE" makes 9bit SPI access by 8bit * 2 times.
nxpfan 0:a19b70a76e66 29 * This may be useful if other 8bit access SPI device on same SPI bus.
nxpfan 0:a19b70a76e66 30 *
nxpfan 0:a19b70a76e66 31 * If disabled (just coment out the "#define MARMEX_OB_SPI_8BIT_MODE"), SPI access willbe done by 9 bit format.
nxpfan 0:a19b70a76e66 32 */
nxpfan 0:a19b70a76e66 33 //#define MARMEX_OB_SPI_8BIT_MODE
nxpfan 0:a19b70a76e66 34
nxpfan 0:a19b70a76e66 35 /** MARMEX_OB_oled OLED screen drawing class
nxpfan 0:a19b70a76e66 36 *
nxpfan 0:a19b70a76e66 37 * This is a driver code for MARMEX_OB_oled board OLED screen.
nxpfan 0:a19b70a76e66 38 * This class inherits NokiaLCD class of mbed.org.
nxpfan 0:a19b70a76e66 39 * To use this class, import the NokiaLCD class from here..
nxpfan 0:a19b70a76e66 40 * http://mbed.org/users/simon/libraries/NokiaLCD/
nxpfan 0:a19b70a76e66 41 *
nxpfan 0:a19b70a76e66 42 * Example:
nxpfan 0:a19b70a76e66 43 * @code
nxpfan 1:a0ac2743f855 44 * #include "mbed.h"
nxpfan 1:a0ac2743f855 45 * #include "MARMEX_OB_oled.h"
nxpfan 1:a0ac2743f855 46 *
nxpfan 1:a0ac2743f855 47 * // oled1 is for MARMEX_OB_oled board on MAPLE slot 1
nxpfan 1:a0ac2743f855 48 * // oled1 is for MARMEX_OB_oled board on MAPLE slot 2
nxpfan 1:a0ac2743f855 49 *
nxpfan 1:a0ac2743f855 50 * MARMEX_OB_oled oled1( p5, p7, p8, p30, p11 ); // mosi, sclk, cs, rst, power_control
nxpfan 1:a0ac2743f855 51 * //MARMEX_OB_oled oled2( p5, p7, p26, p21, p17 ); // mosi, sclk, cs, rst, power_control
nxpfan 1:a0ac2743f855 52 *
nxpfan 1:a0ac2743f855 53 *
nxpfan 1:a0ac2743f855 54 * int main() {
nxpfan 1:a0ac2743f855 55 * oled1.background( 0x000000 );
nxpfan 1:a0ac2743f855 56 * oled1.cls();
nxpfan 1:a0ac2743f855 57 *
nxpfan 1:a0ac2743f855 58 * int colorbar_width = MARMEX_OB_oled::WIDTH / 8;
nxpfan 1:a0ac2743f855 59 *
nxpfan 1:a0ac2743f855 60 * for ( int i = 0; i < 8; i++ )
nxpfan 1:a0ac2743f855 61 * oled1.fill( colorbar_width * i, 0, colorbar_width, MARMEX_OB_oled::HEIGHT, ((i & 0x4) ? 0xFF0000 : 0x000000) | ((i & 0x2) ? 0x00FF00 : 0x000000) | ((i & 0x1) ? 0x0000FF : 0x000000) );
nxpfan 1:a0ac2743f855 62 *
nxpfan 1:a0ac2743f855 63 * oled1.fill( 50, 50, 64, 64, 0xCCCCCC );;
nxpfan 1:a0ac2743f855 64 *
nxpfan 1:a0ac2743f855 65 * oled1.locate( 0, 3 );
nxpfan 1:a0ac2743f855 66 * oled1.printf( "Hello World!" );
nxpfan 1:a0ac2743f855 67 * oled1.locate( 0, 4 );
nxpfan 1:a0ac2743f855 68 * oled1.printf( "SPI = %s", MERMEX_OB_SPI_MODE_STR );
nxpfan 1:a0ac2743f855 69 *
nxpfan 1:a0ac2743f855 70 * for (int i = 0; i < MARMEX_OB_oled::WIDTH; i++ ) {
nxpfan 1:a0ac2743f855 71 * oled1.pixel( i, 80 + sin( (float)i / 5.0 ) * 10, 0x000000 );
nxpfan 1:a0ac2743f855 72 * }
nxpfan 1:a0ac2743f855 73 * } * @endcode
nxpfan 0:a19b70a76e66 74 */
nxpfan 0:a19b70a76e66 75
nxpfan 0:a19b70a76e66 76 class MARMEX_OB_oled : public NokiaLCD {
nxpfan 0:a19b70a76e66 77
nxpfan 0:a19b70a76e66 78 public:
nxpfan 0:a19b70a76e66 79
nxpfan 0:a19b70a76e66 80 /** General parameters for MARMEX_OB_oled */
nxpfan 0:a19b70a76e66 81 enum {
nxpfan 0:a19b70a76e66 82 ROWS = 15, /**< # of rows (lines) for displaying characters */
nxpfan 0:a19b70a76e66 83 COLS = 16, /**< # of columns (width) for displaying characters */
nxpfan 0:a19b70a76e66 84 WIDTH = 128, /**< screen width [pixels] */
nxpfan 0:a19b70a76e66 85 HEIGHT = 128, /**< screen height [pixels] */
nxpfan 0:a19b70a76e66 86 SPI_FREQUENCY = 20000000 /**< SPI (sclk) SPI_FREQUENCY */
nxpfan 0:a19b70a76e66 87 };
nxpfan 0:a19b70a76e66 88
nxpfan 0:a19b70a76e66 89 /** Constants for power() function */
nxpfan 0:a19b70a76e66 90 enum {
nxpfan 0:a19b70a76e66 91 OFF = 0, /**< : to turning-OFF */
nxpfan 0:a19b70a76e66 92 ON /**< : to turning-ON */
nxpfan 0:a19b70a76e66 93 };
nxpfan 0:a19b70a76e66 94
nxpfan 0:a19b70a76e66 95 /** Create a MARMEX_OB_oled object connected to specified SPI and DigitalOut pins
nxpfan 0:a19b70a76e66 96 *
nxpfan 0:a19b70a76e66 97 * @param mosi SPI-MOSI pin (for MAPLE board, use p5)
nxpfan 0:a19b70a76e66 98 * @param sclk SPI-SCLK pin (for MAPLE board, use p8)
nxpfan 0:a19b70a76e66 99 * @param cs chip select signal (for MAPLE board, use p8(slot1), p26(slot2))
nxpfan 0:a19b70a76e66 100 * @param rst reset signal (for MAPLE board, use p30(slot1), p21(slot2))
nxpfan 0:a19b70a76e66 101 * @param power_pin backlight power control signal (for MAPLE board, use p11(slot1), p17(slot2))
nxpfan 0:a19b70a76e66 102 *
nxpfan 0:a19b70a76e66 103 * Example of MARMEX_OB_oled on MAPLE board:
nxpfan 0:a19b70a76e66 104 * @code
nxpfan 0:a19b70a76e66 105 * #include "mbed.h"
nxpfan 0:a19b70a76e66 106 * #include "MARMEX_OB_oled.h"
nxpfan 0:a19b70a76e66 107 *
nxpfan 0:a19b70a76e66 108 * MARMEX_OB_oled oled_on_maple_slot1( p5, p7, p8, p30, p11 ); // mosi, sclk, cs, rst, power_control
nxpfan 0:a19b70a76e66 109 * MARMEX_OB_oled oled_on_maple_slot2( p5, p7, p26, p21, p17 ); // mosi, sclk, cs, rst, power_control
nxpfan 0:a19b70a76e66 110 * ...
nxpfan 0:a19b70a76e66 111 * ..
nxpfan 0:a19b70a76e66 112 * @endcode
nxpfan 0:a19b70a76e66 113 */
nxpfan 0:a19b70a76e66 114
nxpfan 0:a19b70a76e66 115 MARMEX_OB_oled( PinName mosi, PinName sclk, PinName cs, PinName rst, PinName power_pin ) : NokiaLCD( mosi, sclk, cs, rst, NokiaLCD::LCD6100 ), _power_pin( power_pin ) {
nxpfan 0:a19b70a76e66 116 power( ON );
nxpfan 0:a19b70a76e66 117 reset();
nxpfan 0:a19b70a76e66 118 }
nxpfan 0:a19b70a76e66 119
nxpfan 0:a19b70a76e66 120 #if DOXYGEN_ONLY
nxpfan 0:a19b70a76e66 121 /** Write a character to the LCD
nxpfan 0:a19b70a76e66 122 *
nxpfan 0:a19b70a76e66 123 * @param c The character to write to the display
nxpfan 0:a19b70a76e66 124 */
nxpfan 0:a19b70a76e66 125 int putc( int c );
nxpfan 0:a19b70a76e66 126
nxpfan 0:a19b70a76e66 127 /** Write a formated string to the LCD
nxpfan 0:a19b70a76e66 128 *
nxpfan 0:a19b70a76e66 129 * @param format A printf-style format string, followed by the
nxpfan 0:a19b70a76e66 130 * variables to use in formating the string.
nxpfan 0:a19b70a76e66 131 *
nxpfan 0:a19b70a76e66 132 * !!! 16th character in the string will be disappeared
nxpfan 0:a19b70a76e66 133 * !!! This problem is due to difference of screen size NokiaLCD library and its internal mechanism...
nxpfan 0:a19b70a76e66 134 */
nxpfan 0:a19b70a76e66 135 int printf( const char* format, ... );
nxpfan 0:a19b70a76e66 136
nxpfan 0:a19b70a76e66 137 /** Set the foreground colour
nxpfan 0:a19b70a76e66 138 *
nxpfan 0:a19b70a76e66 139 * @param c 24-bit colour
nxpfan 0:a19b70a76e66 140 */
nxpfan 0:a19b70a76e66 141 void foreground(int c);
nxpfan 0:a19b70a76e66 142
nxpfan 0:a19b70a76e66 143 /** Set the background colour
nxpfan 0:a19b70a76e66 144 *
nxpfan 0:a19b70a76e66 145 * @param c 24-bit colour
nxpfan 0:a19b70a76e66 146 */
nxpfan 0:a19b70a76e66 147 void background(int c);
nxpfan 0:a19b70a76e66 148
nxpfan 0:a19b70a76e66 149 #endif
nxpfan 0:a19b70a76e66 150
nxpfan 0:a19b70a76e66 151 /** reset MARMEX_OB_oled
nxpfan 0:a19b70a76e66 152 *
nxpfan 0:a19b70a76e66 153 * Executes hardware reset and initialize.
nxpfan 0:a19b70a76e66 154 * See MARMEX_OB_oled manual for the initialization sequence and values
nxpfan 0:a19b70a76e66 155 * For gamma correction table, using math function to make the code simple
nxpfan 0:a19b70a76e66 156 */
nxpfan 0:a19b70a76e66 157
nxpfan 0:a19b70a76e66 158 void reset( void ) {
nxpfan 0:a19b70a76e66 159
nxpfan 0:a19b70a76e66 160 #define GAMMA_LUT_SIZE 63
nxpfan 0:a19b70a76e66 161 unsigned char gamma_LUT[ GAMMA_LUT_SIZE ];
nxpfan 0:a19b70a76e66 162
nxpfan 0:a19b70a76e66 163 for ( int i = 0; i < GAMMA_LUT_SIZE; i++ )
nxpfan 0:a19b70a76e66 164 gamma_LUT[ i ] = (unsigned char)(powf( ((float)i / 62.0), (1.0 / 0.58) ) * 178.0 + 2.0);
nxpfan 0:a19b70a76e66 165
nxpfan 0:a19b70a76e66 166 // setup the SPI interface and bring display out of reset
nxpfan 0:a19b70a76e66 167 _cs = 1;
nxpfan 0:a19b70a76e66 168 _rst = 0;
nxpfan 0:a19b70a76e66 169 #ifdef MARMEX_OB_SPI_8BIT_MODE
nxpfan 0:a19b70a76e66 170 _spi.format( 8 );
nxpfan 0:a19b70a76e66 171 #else
nxpfan 0:a19b70a76e66 172 _spi.format( 9 );
nxpfan 0:a19b70a76e66 173 #endif
nxpfan 0:a19b70a76e66 174
nxpfan 0:a19b70a76e66 175 _spi.frequency( SPI_FREQUENCY );
nxpfan 0:a19b70a76e66 176 wait_ms( 1 );
nxpfan 0:a19b70a76e66 177 _rst = 1;
nxpfan 0:a19b70a76e66 178 wait_ms( 1 );
nxpfan 0:a19b70a76e66 179
nxpfan 0:a19b70a76e66 180 _cs = 0;
nxpfan 0:a19b70a76e66 181
nxpfan 0:a19b70a76e66 182 command( SET_DISPLAY_MODE_ALL_OFF );
nxpfan 0:a19b70a76e66 183 command( SET_COMMAND_LOCK );
nxpfan 0:a19b70a76e66 184 data( 0x12 );
nxpfan 0:a19b70a76e66 185
nxpfan 0:a19b70a76e66 186 command( SET_COMMAND_LOCK );
nxpfan 0:a19b70a76e66 187 data( 0xb1 );
nxpfan 0:a19b70a76e66 188
nxpfan 0:a19b70a76e66 189 command( SET_SLEEP_MODE_ON );
nxpfan 0:a19b70a76e66 190
nxpfan 0:a19b70a76e66 191 command( FRONT_CLOCK_DRIVER_OSC_FREQ );
nxpfan 0:a19b70a76e66 192 data( 0xF1 );
nxpfan 0:a19b70a76e66 193
nxpfan 0:a19b70a76e66 194 command( SET_MUX_RATIO );
nxpfan 0:a19b70a76e66 195 data( 0x7F );
nxpfan 0:a19b70a76e66 196
nxpfan 0:a19b70a76e66 197 command( SET_DISPAY_OFFSET );
nxpfan 0:a19b70a76e66 198 data( 0x00 );
nxpfan 0:a19b70a76e66 199
nxpfan 0:a19b70a76e66 200 command( SET_DISPAY_START_LINE );
nxpfan 0:a19b70a76e66 201 data( 0x00 );
nxpfan 0:a19b70a76e66 202
nxpfan 0:a19b70a76e66 203 command( SET_REMAP_COLOR_DEPTH );
nxpfan 0:a19b70a76e66 204 data( 0x74 );
nxpfan 0:a19b70a76e66 205
nxpfan 0:a19b70a76e66 206 command( SET_GPIO );
nxpfan 0:a19b70a76e66 207 data( 0x00);
nxpfan 0:a19b70a76e66 208
nxpfan 0:a19b70a76e66 209 command( FUNCTION_SELECTION );
nxpfan 0:a19b70a76e66 210 data( 0x01 );
nxpfan 0:a19b70a76e66 211
nxpfan 0:a19b70a76e66 212 command( SET_SEGMENT_LOW_VOLTAGE );
nxpfan 0:a19b70a76e66 213 data( 0xA0 );
nxpfan 0:a19b70a76e66 214 data( 0xB5 );
nxpfan 0:a19b70a76e66 215 data( 0x55 );
nxpfan 0:a19b70a76e66 216
nxpfan 0:a19b70a76e66 217 command( SET_CONTRAST_CURRENT_FOR_COLOR_ABC );
nxpfan 0:a19b70a76e66 218 data( 0xC8 );
nxpfan 0:a19b70a76e66 219 data( 0x80 );
nxpfan 0:a19b70a76e66 220 data( 0xC8 );
nxpfan 0:a19b70a76e66 221
nxpfan 0:a19b70a76e66 222 command( MASTER_CONTRAST_CURRENT_CONTROL );
nxpfan 0:a19b70a76e66 223 data( 0x0F );
nxpfan 0:a19b70a76e66 224
nxpfan 0:a19b70a76e66 225 command( LOOKUP_TABLE_FOR_GRAYSCALE_PULSE_WIDTH );
nxpfan 0:a19b70a76e66 226 for ( int i = 0; i < GAMMA_LUT_SIZE; i++ )
nxpfan 0:a19b70a76e66 227 data( gamma_LUT[ i ] );
nxpfan 0:a19b70a76e66 228
nxpfan 0:a19b70a76e66 229 command( SET_RESET_PRECHARGE_PERIOD );
nxpfan 0:a19b70a76e66 230 data( 0x32 );
nxpfan 0:a19b70a76e66 231
nxpfan 0:a19b70a76e66 232 command( ENHANCE_DRIVING_SCHEME_CAPABILITY );
nxpfan 0:a19b70a76e66 233 data( 0x04 );
nxpfan 0:a19b70a76e66 234 data( 0x00 );
nxpfan 0:a19b70a76e66 235 data( 0x00 );
nxpfan 0:a19b70a76e66 236
nxpfan 0:a19b70a76e66 237 command( SET_PRECHARGE_VOLTAGE );
nxpfan 0:a19b70a76e66 238 data( 0x17 );
nxpfan 0:a19b70a76e66 239
nxpfan 0:a19b70a76e66 240 command( SET_SECOND_PRECHARGE_VOLTAGE );
nxpfan 0:a19b70a76e66 241 data( 0x01 );
nxpfan 0:a19b70a76e66 242
nxpfan 0:a19b70a76e66 243 command( SET_VCOMH_VOLTAGE );
nxpfan 0:a19b70a76e66 244 data( 0x05 );
nxpfan 0:a19b70a76e66 245
nxpfan 0:a19b70a76e66 246 command( SET_DISPLAY_MODE_RESET );
nxpfan 0:a19b70a76e66 247
nxpfan 0:a19b70a76e66 248 #if 0
nxpfan 0:a19b70a76e66 249 command( SET_COLUMN_ADDRESS );
nxpfan 0:a19b70a76e66 250 data( 0x00 );
nxpfan 0:a19b70a76e66 251 data( 0x7F );
nxpfan 0:a19b70a76e66 252
nxpfan 0:a19b70a76e66 253 command( SET_ROW_ADDRESS );
nxpfan 0:a19b70a76e66 254 data( 0x00 );
nxpfan 0:a19b70a76e66 255 data( 0x7F);
nxpfan 0:a19b70a76e66 256
nxpfan 0:a19b70a76e66 257 command( WRITE_RAM_COMMAND );
nxpfan 0:a19b70a76e66 258 for ( int i = 0; i < WIDTH * HEIGHT; i++ )
nxpfan 0:a19b70a76e66 259 data( 0x00 );
nxpfan 0:a19b70a76e66 260 #endif
nxpfan 0:a19b70a76e66 261 _cs = 1;
nxpfan 0:a19b70a76e66 262
nxpfan 0:a19b70a76e66 263 cls();
nxpfan 0:a19b70a76e66 264 wait_ms( 200 );
nxpfan 0:a19b70a76e66 265
nxpfan 0:a19b70a76e66 266 command( SET_SLEEP_MODE_OFF );
nxpfan 0:a19b70a76e66 267 }
nxpfan 0:a19b70a76e66 268
nxpfan 0:a19b70a76e66 269 /** Clear the screen and locate to 0,0 */
nxpfan 0:a19b70a76e66 270
nxpfan 0:a19b70a76e66 271 void cls( void ) {
nxpfan 0:a19b70a76e66 272 fill( 0, 0, WIDTH , HEIGHT, _background );
nxpfan 0:a19b70a76e66 273 _row = 0;
nxpfan 0:a19b70a76e66 274 _column = 0;
nxpfan 0:a19b70a76e66 275 }
nxpfan 0:a19b70a76e66 276
nxpfan 0:a19b70a76e66 277 /** Set a pixel on te screen
nxpfan 0:a19b70a76e66 278 *
nxpfan 0:a19b70a76e66 279 * @param x horizontal position from left
nxpfan 0:a19b70a76e66 280 * @param y vertical position from top
nxpfan 0:a19b70a76e66 281 * @param colour 24-bit colour in format 0x00RRGGBB
nxpfan 0:a19b70a76e66 282 */
nxpfan 0:a19b70a76e66 283
nxpfan 0:a19b70a76e66 284 virtual void pixel( int x, int y, int colour ) {
nxpfan 0:a19b70a76e66 285 _cs = 0;
nxpfan 0:a19b70a76e66 286 _window( x, y, 1, 1 );
nxpfan 0:a19b70a76e66 287 _putp( colour );
nxpfan 0:a19b70a76e66 288 _cs = 1;
nxpfan 0:a19b70a76e66 289 }
nxpfan 0:a19b70a76e66 290
nxpfan 0:a19b70a76e66 291 /** Fill an area of the screen
nxpfan 0:a19b70a76e66 292 *
nxpfan 0:a19b70a76e66 293 * @param x horizontal position from left
nxpfan 0:a19b70a76e66 294 * @param y vertical position from top
nxpfan 0:a19b70a76e66 295 * @param width width in pixels
nxpfan 0:a19b70a76e66 296 * @param height height in pixels
nxpfan 0:a19b70a76e66 297 * @param colour 24-bit colour in format 0x00RRGGBB
nxpfan 0:a19b70a76e66 298 */
nxpfan 0:a19b70a76e66 299
nxpfan 0:a19b70a76e66 300 void fill( int x, int y, int width, int height, int colour ) {
nxpfan 0:a19b70a76e66 301 _cs = 0;
nxpfan 0:a19b70a76e66 302 _window( x, y, width, height );
nxpfan 0:a19b70a76e66 303
nxpfan 0:a19b70a76e66 304 for (int i = 0; i < width * height; i++ ) {
nxpfan 0:a19b70a76e66 305 _putp( colour );
nxpfan 0:a19b70a76e66 306 }
nxpfan 0:a19b70a76e66 307
nxpfan 0:a19b70a76e66 308 _window( 0, 0, WIDTH, HEIGHT );
nxpfan 0:a19b70a76e66 309 _cs = 1;
nxpfan 0:a19b70a76e66 310 }
nxpfan 0:a19b70a76e66 311
nxpfan 0:a19b70a76e66 312 void blit( int x, int y, int width, int height, const int* colour ) {
nxpfan 0:a19b70a76e66 313 _cs = 0;
nxpfan 0:a19b70a76e66 314 _window( x, y, width, height );
nxpfan 0:a19b70a76e66 315
nxpfan 0:a19b70a76e66 316 for (int i = 0; i < width * height; i++ ) {
nxpfan 0:a19b70a76e66 317 _putp( colour[i] );
nxpfan 0:a19b70a76e66 318 }
nxpfan 0:a19b70a76e66 319 _window( 0, 0, WIDTH, HEIGHT );
nxpfan 0:a19b70a76e66 320 _cs = 1;
nxpfan 0:a19b70a76e66 321 }
nxpfan 0:a19b70a76e66 322
nxpfan 0:a19b70a76e66 323 void bitblit( int x, int y, int width, int height, const char* bitstream ) {
nxpfan 0:a19b70a76e66 324 _cs = 0;
nxpfan 0:a19b70a76e66 325 _window( x, y, width, height );
nxpfan 0:a19b70a76e66 326
nxpfan 0:a19b70a76e66 327 for (int i = 0; i < height * width; i++ ) {
nxpfan 0:a19b70a76e66 328 int byte = i / 8;
nxpfan 0:a19b70a76e66 329 int bit = i % 8;
nxpfan 0:a19b70a76e66 330 int colour = ((bitstream[ byte ] << bit) & 0x80) ? _foreground : _background;
nxpfan 0:a19b70a76e66 331 _putp( colour );
nxpfan 0:a19b70a76e66 332 }
nxpfan 0:a19b70a76e66 333 _window( 0, 0, _width, _height );
nxpfan 0:a19b70a76e66 334 _cs = 1;
nxpfan 0:a19b70a76e66 335 }
nxpfan 0:a19b70a76e66 336
nxpfan 0:a19b70a76e66 337 /** Screen width
nxpfan 0:a19b70a76e66 338 *
nxpfan 0:a19b70a76e66 339 * @return screen width [pixel]
nxpfan 0:a19b70a76e66 340 */
nxpfan 0:a19b70a76e66 341 int width() {
nxpfan 0:a19b70a76e66 342 return WIDTH;
nxpfan 0:a19b70a76e66 343 }
nxpfan 0:a19b70a76e66 344
nxpfan 0:a19b70a76e66 345 /** Screen height
nxpfan 0:a19b70a76e66 346 *
nxpfan 0:a19b70a76e66 347 * @return screen height [pixel]
nxpfan 0:a19b70a76e66 348 */
nxpfan 0:a19b70a76e66 349 int height() {
nxpfan 0:a19b70a76e66 350 return HEIGHT;
nxpfan 0:a19b70a76e66 351 }
nxpfan 0:a19b70a76e66 352 /** Columns
nxpfan 0:a19b70a76e66 353 *
nxpfan 0:a19b70a76e66 354 * @return screen columns
nxpfan 0:a19b70a76e66 355 */
nxpfan 0:a19b70a76e66 356 int columns() {
nxpfan 0:a19b70a76e66 357 return COLS;
nxpfan 0:a19b70a76e66 358 }
nxpfan 0:a19b70a76e66 359
nxpfan 0:a19b70a76e66 360 /** Rows
nxpfan 0:a19b70a76e66 361 *
nxpfan 0:a19b70a76e66 362 * @return screen rows
nxpfan 0:a19b70a76e66 363 */
nxpfan 0:a19b70a76e66 364 int rows() {
nxpfan 0:a19b70a76e66 365 return ROWS;
nxpfan 0:a19b70a76e66 366 }
nxpfan 0:a19b70a76e66 367
nxpfan 0:a19b70a76e66 368 /** Power switch for OLED backlight
nxpfan 0:a19b70a76e66 369 *
nxpfan 0:a19b70a76e66 370 * @param sw argument can be MARMEX_OB_oled::ON or MARMEX_OB_oled::OFF
nxpfan 0:a19b70a76e66 371 */
nxpfan 0:a19b70a76e66 372
nxpfan 0:a19b70a76e66 373 void power( unsigned char sw ) {
nxpfan 0:a19b70a76e66 374 _power_pin = sw;
nxpfan 0:a19b70a76e66 375 }
nxpfan 0:a19b70a76e66 376
nxpfan 0:a19b70a76e66 377 private:
nxpfan 0:a19b70a76e66 378 /** Command list for the OLED controller */
nxpfan 0:a19b70a76e66 379 enum {
nxpfan 0:a19b70a76e66 380 SET_DISPLAY_MODE_ALL_OFF = 0xA4,
nxpfan 0:a19b70a76e66 381 SET_COMMAND_LOCK = 0xFD,
nxpfan 0:a19b70a76e66 382 SET_SLEEP_MODE_ON = 0xAE,
nxpfan 0:a19b70a76e66 383 FRONT_CLOCK_DRIVER_OSC_FREQ = 0xB3,
nxpfan 0:a19b70a76e66 384 SET_MUX_RATIO = 0xCA,
nxpfan 0:a19b70a76e66 385 SET_DISPAY_OFFSET = 0xA2,
nxpfan 0:a19b70a76e66 386 SET_DISPAY_START_LINE = 0xA1,
nxpfan 0:a19b70a76e66 387 SET_REMAP_COLOR_DEPTH = 0xA0,
nxpfan 0:a19b70a76e66 388 SET_GPIO = 0xB5,
nxpfan 0:a19b70a76e66 389 FUNCTION_SELECTION = 0xAB,
nxpfan 0:a19b70a76e66 390 SET_SEGMENT_LOW_VOLTAGE = 0xB4,
nxpfan 0:a19b70a76e66 391 SET_CONTRAST_CURRENT_FOR_COLOR_ABC = 0xC1,
nxpfan 0:a19b70a76e66 392 MASTER_CONTRAST_CURRENT_CONTROL = 0xC7,
nxpfan 0:a19b70a76e66 393 LOOKUP_TABLE_FOR_GRAYSCALE_PULSE_WIDTH = 0xB8,
nxpfan 0:a19b70a76e66 394 SET_RESET_PRECHARGE_PERIOD = 0xB1,
nxpfan 0:a19b70a76e66 395 ENHANCE_DRIVING_SCHEME_CAPABILITY = 0xB2,
nxpfan 0:a19b70a76e66 396 SET_PRECHARGE_VOLTAGE = 0xBB,
nxpfan 0:a19b70a76e66 397 SET_SECOND_PRECHARGE_VOLTAGE = 0xB6,
nxpfan 0:a19b70a76e66 398 SET_VCOMH_VOLTAGE = 0xBE,
nxpfan 0:a19b70a76e66 399 SET_DISPLAY_MODE_RESET = 0xA6,
nxpfan 0:a19b70a76e66 400 SET_COLUMN_ADDRESS = 0x15,
nxpfan 0:a19b70a76e66 401 SET_ROW_ADDRESS = 0x75,
nxpfan 0:a19b70a76e66 402 WRITE_RAM_COMMAND = 0x5C,
nxpfan 0:a19b70a76e66 403 SET_SLEEP_MODE_OFF = 0xAF
nxpfan 0:a19b70a76e66 404 };
nxpfan 0:a19b70a76e66 405
nxpfan 0:a19b70a76e66 406 #ifdef MARMEX_OB_SPI_8BIT_MODE
nxpfan 0:a19b70a76e66 407 void command( int value ) {
nxpfan 0:a19b70a76e66 408 int tmp = value & 0x00ff;
nxpfan 0:a19b70a76e66 409 _cs = 0;
nxpfan 0:a19b70a76e66 410 _spi.write( tmp >> 1 );
nxpfan 0:a19b70a76e66 411 _spi.write( tmp << 7 );
nxpfan 0:a19b70a76e66 412 _cs = 1;
nxpfan 0:a19b70a76e66 413 }
nxpfan 0:a19b70a76e66 414
nxpfan 0:a19b70a76e66 415 void data( int value ) {
nxpfan 0:a19b70a76e66 416 int tmp = value & 0x00ff;
nxpfan 0:a19b70a76e66 417 tmp |= 0x0100;
nxpfan 0:a19b70a76e66 418 _cs = 0;
nxpfan 0:a19b70a76e66 419 _spi.write( tmp >> 1 );
nxpfan 0:a19b70a76e66 420 _spi.write( tmp << 7 );
nxpfan 0:a19b70a76e66 421 _cs = 1;
nxpfan 0:a19b70a76e66 422 }
nxpfan 0:a19b70a76e66 423 #else
nxpfan 0:a19b70a76e66 424 void command( int value ) {
nxpfan 0:a19b70a76e66 425 _cs = 0;
nxpfan 0:a19b70a76e66 426 _spi.write( value & 0xFF );
nxpfan 0:a19b70a76e66 427 _cs = 1;
nxpfan 0:a19b70a76e66 428 }
nxpfan 0:a19b70a76e66 429
nxpfan 0:a19b70a76e66 430 void data(int value) {
nxpfan 0:a19b70a76e66 431 _cs = 0;
nxpfan 0:a19b70a76e66 432 _spi.write( value | 0x100 );
nxpfan 0:a19b70a76e66 433 _cs = 1;
nxpfan 0:a19b70a76e66 434 }
nxpfan 0:a19b70a76e66 435 #endif
nxpfan 0:a19b70a76e66 436
nxpfan 0:a19b70a76e66 437 virtual void _window( int x, int y, int width, int height ) {
nxpfan 0:a19b70a76e66 438 int x1 = x + 0;
nxpfan 0:a19b70a76e66 439 int y1 = y + 0;
nxpfan 0:a19b70a76e66 440 int x2 = x1 + width - 1;
nxpfan 0:a19b70a76e66 441 int y2 = y1 + height - 1;
nxpfan 0:a19b70a76e66 442
nxpfan 0:a19b70a76e66 443 command( SET_COLUMN_ADDRESS );
nxpfan 0:a19b70a76e66 444 data( x1 );
nxpfan 0:a19b70a76e66 445 data( x2 );
nxpfan 0:a19b70a76e66 446 command( SET_ROW_ADDRESS );
nxpfan 0:a19b70a76e66 447 data( y1 );
nxpfan 0:a19b70a76e66 448 data( y2 );
nxpfan 0:a19b70a76e66 449 command( WRITE_RAM_COMMAND );
nxpfan 0:a19b70a76e66 450 }
nxpfan 0:a19b70a76e66 451
nxpfan 0:a19b70a76e66 452 void window( int x, int y, int width, int height ) {
nxpfan 0:a19b70a76e66 453 _cs = 0;
nxpfan 0:a19b70a76e66 454 _window( x, y, width, height );
nxpfan 0:a19b70a76e66 455 _cs = 1;
nxpfan 0:a19b70a76e66 456 }
nxpfan 0:a19b70a76e66 457
nxpfan 1:a0ac2743f855 458 virtual void _putp( int colour ) {
nxpfan 0:a19b70a76e66 459 int cnv = 0;
nxpfan 0:a19b70a76e66 460
nxpfan 0:a19b70a76e66 461 cnv = (colour >> 8) & 0xf800;
nxpfan 0:a19b70a76e66 462 cnv |= (colour >> 5) & 0x07e0;
nxpfan 0:a19b70a76e66 463 cnv |= (colour >> 3) & 0x001f;
nxpfan 0:a19b70a76e66 464
nxpfan 0:a19b70a76e66 465 data( cnv >> 8);
nxpfan 0:a19b70a76e66 466 data( cnv );
nxpfan 0:a19b70a76e66 467 }
nxpfan 0:a19b70a76e66 468
nxpfan 0:a19b70a76e66 469 DigitalOut _power_pin;
nxpfan 0:a19b70a76e66 470 }
nxpfan 0:a19b70a76e66 471 ;
nxpfan 0:a19b70a76e66 472
nxpfan 0:a19b70a76e66 473 #ifdef MARMEX_OB_SPI_8BIT_MODE
nxpfan 0:a19b70a76e66 474 #define MERMEX_OB_SPI_MODE_STR "8bit mode"
nxpfan 0:a19b70a76e66 475 #else
nxpfan 0:a19b70a76e66 476 #define MERMEX_OB_SPI_MODE_STR "9bit mode"
nxpfan 0:a19b70a76e66 477 #endif
nxpfan 0:a19b70a76e66 478 #endif // MBED_MARMEX_OB_OLED
nxpfan 0:a19b70a76e66 479
nxpfan 1:a0ac2743f855 480 /*
nxpfan 1:a0ac2743f855 481 * history:
nxpfan 1:a0ac2743f855 482 * 0.5 (2011-Apr-07) : initial published version
nxpfan 1:a0ac2743f855 483 * 0.51 (2011-Apr-08) : a. "virtual" had been added on "_putp()" function definition to surpress warning when compiling (is this correct way?)
nxpfan 1:a0ac2743f855 484 * b. sample code (for Doxygen) is changed from new "main.cpp (ver 0.51)"
nxpfan 1:a0ac2743f855 485 */