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