test

Dependencies:   FatFileSystem TextLCD mbed

Committer:
y_notsu
Date:
Tue Sep 18 07:24:22 2012 +0000
Revision:
0:2c37ad282618
test

Who changed what in which revision?

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