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