display recentest video in niconico.

Dependencies:   EthernetInterface GraphicOLED NokiaLCD mbed-rtos mbed picojson

Committer:
mia_0032
Date:
Wed Dec 17 13:19:28 2014 +0000
Revision:
1:19589c30cc74
Parent:
0:1e0d84ef27ec
fix comment.

Who changed what in which revision?

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