A "Hello" program for MARMEX_VB library. This application may work 40pin type mbed platforms ;) This application expects to have the MARMEX_VB module on a "MAPLE mini type-B (MARM03-BASE)" baseboard (slot2) with a MARMEX_OB module (on slot1)

Dependencies:   MARMEX_VB NokiaLCD mbed

Sample code for MARMEX-VB (MARY-VB) camera module.
/media/uploads/nxpfan/dsc_0497s.png

This is a very simple program just copies the data from camera to OELD.
/media/uploads/nxpfan/dsc_0513.jpg

Committer:
nxpfan
Date:
Mon Jun 16 14:04:33 2014 +0000
Revision:
1:715bb00d7008
Parent:
0:139f0c46d0fd
Child:
2:7294334432d4
optimization done for SPI operation: ChipSelect signal kept asserted during line data transfer.

Who changed what in which revision?

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