Haron foo
/
Q_nolkiaJapanese_3_tryBaikaku
MaryOB
Moled.h@0:4ef525e32ebc, 2011-07-18 (annotated)
- Committer:
- s_s_s
- Date:
- Mon Jul 18 01:30:20 2011 +0000
- Revision:
- 0:4ef525e32ebc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
s_s_s | 0:4ef525e32ebc | 1 | /* mbed NokiaLCD Library, for a 130x130 Nokia colour LCD |
s_s_s | 0:4ef525e32ebc | 2 | * Copyright (c) 2007-2010, sford |
s_s_s | 0:4ef525e32ebc | 3 | * |
s_s_s | 0:4ef525e32ebc | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
s_s_s | 0:4ef525e32ebc | 5 | * of this software and associated documentation files (the "Software"), to deal |
s_s_s | 0:4ef525e32ebc | 6 | * in the Software without restriction, including without limitation the rights |
s_s_s | 0:4ef525e32ebc | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
s_s_s | 0:4ef525e32ebc | 8 | * copies of the Software, and to permit persons to whom the Software is |
s_s_s | 0:4ef525e32ebc | 9 | * furnished to do so, subject to the following conditions: |
s_s_s | 0:4ef525e32ebc | 10 | * |
s_s_s | 0:4ef525e32ebc | 11 | * The above copyright notice and this permission notice shall be included in |
s_s_s | 0:4ef525e32ebc | 12 | * all copies or substantial portions of the Software. |
s_s_s | 0:4ef525e32ebc | 13 | * |
s_s_s | 0:4ef525e32ebc | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
s_s_s | 0:4ef525e32ebc | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
s_s_s | 0:4ef525e32ebc | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
s_s_s | 0:4ef525e32ebc | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
s_s_s | 0:4ef525e32ebc | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
s_s_s | 0:4ef525e32ebc | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
s_s_s | 0:4ef525e32ebc | 20 | * THE SOFTWARE. |
s_s_s | 0:4ef525e32ebc | 21 | */ |
s_s_s | 0:4ef525e32ebc | 22 | |
s_s_s | 0:4ef525e32ebc | 23 | #ifndef MoledH |
s_s_s | 0:4ef525e32ebc | 24 | #define MoledH |
s_s_s | 0:4ef525e32ebc | 25 | |
s_s_s | 0:4ef525e32ebc | 26 | #include "mbed.h" |
s_s_s | 0:4ef525e32ebc | 27 | |
s_s_s | 0:4ef525e32ebc | 28 | /** An interface for the 130x130 Nokia Mobile phone screens |
s_s_s | 0:4ef525e32ebc | 29 | * |
s_s_s | 0:4ef525e32ebc | 30 | * @code |
s_s_s | 0:4ef525e32ebc | 31 | * #include "mbed.h" |
s_s_s | 0:4ef525e32ebc | 32 | * #include "Moled.h" |
s_s_s | 0:4ef525e32ebc | 33 | * |
s_s_s | 0:4ef525e32ebc | 34 | * Moled lcd(p5, p7, p8, p9); // mosi, sclk, cs, rst |
s_s_s | 0:4ef525e32ebc | 35 | * |
s_s_s | 0:4ef525e32ebc | 36 | * int main() { |
s_s_s | 0:4ef525e32ebc | 37 | * lcd.printf("Hello World!"); |
s_s_s | 0:4ef525e32ebc | 38 | * } |
s_s_s | 0:4ef525e32ebc | 39 | */ |
s_s_s | 0:4ef525e32ebc | 40 | class Moled : public Stream { |
s_s_s | 0:4ef525e32ebc | 41 | |
s_s_s | 0:4ef525e32ebc | 42 | public: |
s_s_s | 0:4ef525e32ebc | 43 | /** Create and Nokia LCD interface, using a SPI and two DigitalOut interfaces |
s_s_s | 0:4ef525e32ebc | 44 | * |
s_s_s | 0:4ef525e32ebc | 45 | * @param mosi SPI data out |
s_s_s | 0:4ef525e32ebc | 46 | * @param sclk SPI clock |
s_s_s | 0:4ef525e32ebc | 47 | * @param cs Chip Select (DigitalOut) |
s_s_s | 0:4ef525e32ebc | 48 | * @param rst Reset (DigitalOut) |
s_s_s | 0:4ef525e32ebc | 49 | * @param type The LCDType to select driver chip variants |
s_s_s | 0:4ef525e32ebc | 50 | */ |
s_s_s | 0:4ef525e32ebc | 51 | Moled(PinName mosi, PinName sclk, PinName cs, PinName rst, PinName power); |
s_s_s | 0:4ef525e32ebc | 52 | /** General parameters for MARMEX_OB_oled */ |
s_s_s | 0:4ef525e32ebc | 53 | enum { |
s_s_s | 0:4ef525e32ebc | 54 | ROWS = 15, /**< # of rows (lines) for displaying characters */ |
s_s_s | 0:4ef525e32ebc | 55 | COLS = 16, /**< # of columns (width) for displaying characters */ |
s_s_s | 0:4ef525e32ebc | 56 | WIDTH = 128, /**< screen width [pixels] */ |
s_s_s | 0:4ef525e32ebc | 57 | HEIGHT = 128, /**< screen height [pixels] */ |
s_s_s | 0:4ef525e32ebc | 58 | SPI_FREQUENCY = 20000000 /**< SPI (sclk) SPI_FREQUENCY */ |
s_s_s | 0:4ef525e32ebc | 59 | }; |
s_s_s | 0:4ef525e32ebc | 60 | |
s_s_s | 0:4ef525e32ebc | 61 | /** Constants for power() function */ |
s_s_s | 0:4ef525e32ebc | 62 | enum { |
s_s_s | 0:4ef525e32ebc | 63 | OFF = 0, /**< : to turning-OFF */ |
s_s_s | 0:4ef525e32ebc | 64 | ON /**< : to turning-ON */ |
s_s_s | 0:4ef525e32ebc | 65 | }; |
s_s_s | 0:4ef525e32ebc | 66 | |
s_s_s | 0:4ef525e32ebc | 67 | #if DOXYGEN_ONLY |
s_s_s | 0:4ef525e32ebc | 68 | /** Write a character to the LCD |
s_s_s | 0:4ef525e32ebc | 69 | * |
s_s_s | 0:4ef525e32ebc | 70 | * @param c The character to write to the display |
s_s_s | 0:4ef525e32ebc | 71 | */ |
s_s_s | 0:4ef525e32ebc | 72 | int putc(int c); |
s_s_s | 0:4ef525e32ebc | 73 | |
s_s_s | 0:4ef525e32ebc | 74 | /** Write a formated string to the LCD |
s_s_s | 0:4ef525e32ebc | 75 | * |
s_s_s | 0:4ef525e32ebc | 76 | * @param format A printf-style format string, followed by the |
s_s_s | 0:4ef525e32ebc | 77 | * variables to use in formating the string. |
s_s_s | 0:4ef525e32ebc | 78 | */ |
s_s_s | 0:4ef525e32ebc | 79 | int printf(const char* format, ...); |
s_s_s | 0:4ef525e32ebc | 80 | #endif |
s_s_s | 0:4ef525e32ebc | 81 | |
s_s_s | 0:4ef525e32ebc | 82 | /** Locate to a screen column and row |
s_s_s | 0:4ef525e32ebc | 83 | * |
s_s_s | 0:4ef525e32ebc | 84 | * @param column The horizontal position from the left, indexed from 0 |
s_s_s | 0:4ef525e32ebc | 85 | * @param row The vertical position from the top, indexed from 0 |
s_s_s | 0:4ef525e32ebc | 86 | */ |
s_s_s | 0:4ef525e32ebc | 87 | void locate(int column, int row); |
s_s_s | 0:4ef525e32ebc | 88 | |
s_s_s | 0:4ef525e32ebc | 89 | /** font size |
s_s_s | 0:4ef525e32ebc | 90 | * void Moled::fontsize(int yoko,int tate){ |
s_s_s | 0:4ef525e32ebc | 91 | * |
s_s_s | 0:4ef525e32ebc | 92 | * @param yoko The vertical multiply factor |
s_s_s | 0:4ef525e32ebc | 93 | * @param tate The horizotal multiply factor |
s_s_s | 0:4ef525e32ebc | 94 | */ |
s_s_s | 0:4ef525e32ebc | 95 | void fontsize(int yoko,int tate); |
s_s_s | 0:4ef525e32ebc | 96 | |
s_s_s | 0:4ef525e32ebc | 97 | |
s_s_s | 0:4ef525e32ebc | 98 | /** Clear the screen and locate to 0,0 */ |
s_s_s | 0:4ef525e32ebc | 99 | void cls(); |
s_s_s | 0:4ef525e32ebc | 100 | |
s_s_s | 0:4ef525e32ebc | 101 | void pixel(int x, int y, int colour); |
s_s_s | 0:4ef525e32ebc | 102 | void fill(int x, int y, int width, int height, int colour); |
s_s_s | 0:4ef525e32ebc | 103 | |
s_s_s | 0:4ef525e32ebc | 104 | void blit(int x, int y, int width, int height, const int* colour); |
s_s_s | 0:4ef525e32ebc | 105 | void bitblit(int x, int y, int width, int height, const char* bitstream); |
s_s_s | 0:4ef525e32ebc | 106 | |
s_s_s | 0:4ef525e32ebc | 107 | int width(); |
s_s_s | 0:4ef525e32ebc | 108 | int height(); |
s_s_s | 0:4ef525e32ebc | 109 | int columns(); |
s_s_s | 0:4ef525e32ebc | 110 | int rows(); |
s_s_s | 0:4ef525e32ebc | 111 | |
s_s_s | 0:4ef525e32ebc | 112 | void reset(); |
s_s_s | 0:4ef525e32ebc | 113 | |
s_s_s | 0:4ef525e32ebc | 114 | void foreground(int c); |
s_s_s | 0:4ef525e32ebc | 115 | void background(int c); |
s_s_s | 0:4ef525e32ebc | 116 | |
s_s_s | 0:4ef525e32ebc | 117 | private: //protected: |
s_s_s | 0:4ef525e32ebc | 118 | /** Command list for the OLED controller */ |
s_s_s | 0:4ef525e32ebc | 119 | enum { |
s_s_s | 0:4ef525e32ebc | 120 | SET_DISPLAY_MODE_ALL_OFF = 0xA4, |
s_s_s | 0:4ef525e32ebc | 121 | SET_COMMAND_LOCK = 0xFD, |
s_s_s | 0:4ef525e32ebc | 122 | SET_SLEEP_MODE_ON = 0xAE, |
s_s_s | 0:4ef525e32ebc | 123 | FRONT_CLOCK_DRIVER_OSC_FREQ = 0xB3, |
s_s_s | 0:4ef525e32ebc | 124 | SET_MUX_RATIO = 0xCA, |
s_s_s | 0:4ef525e32ebc | 125 | SET_DISPAY_OFFSET = 0xA2, |
s_s_s | 0:4ef525e32ebc | 126 | SET_DISPAY_START_LINE = 0xA1, |
s_s_s | 0:4ef525e32ebc | 127 | SET_REMAP_COLOR_DEPTH = 0xA0, |
s_s_s | 0:4ef525e32ebc | 128 | SET_GPIO = 0xB5, |
s_s_s | 0:4ef525e32ebc | 129 | FUNCTION_SELECTION = 0xAB, |
s_s_s | 0:4ef525e32ebc | 130 | SET_SEGMENT_LOW_VOLTAGE = 0xB4, |
s_s_s | 0:4ef525e32ebc | 131 | SET_CONTRAST_CURRENT_FOR_COLOR_ABC = 0xC1, |
s_s_s | 0:4ef525e32ebc | 132 | MASTER_CONTRAST_CURRENT_CONTROL = 0xC7, |
s_s_s | 0:4ef525e32ebc | 133 | LOOKUP_TABLE_FOR_GRAYSCALE_PULSE_WIDTH = 0xB8, |
s_s_s | 0:4ef525e32ebc | 134 | SET_RESET_PRECHARGE_PERIOD = 0xB1, |
s_s_s | 0:4ef525e32ebc | 135 | ENHANCE_DRIVING_SCHEME_CAPABILITY = 0xB2, |
s_s_s | 0:4ef525e32ebc | 136 | SET_PRECHARGE_VOLTAGE = 0xBB, |
s_s_s | 0:4ef525e32ebc | 137 | SET_SECOND_PRECHARGE_VOLTAGE = 0xB6, |
s_s_s | 0:4ef525e32ebc | 138 | SET_VCOMH_VOLTAGE = 0xBE, |
s_s_s | 0:4ef525e32ebc | 139 | SET_DISPLAY_MODE_RESET = 0xA6, |
s_s_s | 0:4ef525e32ebc | 140 | SET_COLUMN_ADDRESS = 0x15, |
s_s_s | 0:4ef525e32ebc | 141 | SET_ROW_ADDRESS = 0x75, |
s_s_s | 0:4ef525e32ebc | 142 | WRITE_RAM_COMMAND = 0x5C, |
s_s_s | 0:4ef525e32ebc | 143 | SET_SLEEP_MODE_OFF = 0xAF |
s_s_s | 0:4ef525e32ebc | 144 | }; |
s_s_s | 0:4ef525e32ebc | 145 | protected: |
s_s_s | 0:4ef525e32ebc | 146 | |
s_s_s | 0:4ef525e32ebc | 147 | virtual void _window(int x, int y, int width, int height); |
s_s_s | 0:4ef525e32ebc | 148 | virtual void _putp(int colour); |
s_s_s | 0:4ef525e32ebc | 149 | |
s_s_s | 0:4ef525e32ebc | 150 | void command(int value); |
s_s_s | 0:4ef525e32ebc | 151 | void data(int value); |
s_s_s | 0:4ef525e32ebc | 152 | |
s_s_s | 0:4ef525e32ebc | 153 | void newline(); |
s_s_s | 0:4ef525e32ebc | 154 | virtual int _putc(int c); |
s_s_s | 0:4ef525e32ebc | 155 | virtual int _getc() { |
s_s_s | 0:4ef525e32ebc | 156 | return 0; |
s_s_s | 0:4ef525e32ebc | 157 | } |
s_s_s | 0:4ef525e32ebc | 158 | void putp(int v); |
s_s_s | 0:4ef525e32ebc | 159 | void window(int x, int y, int width, int height); |
s_s_s | 0:4ef525e32ebc | 160 | //void power( unsigned char sw ); |
s_s_s | 0:4ef525e32ebc | 161 | |
s_s_s | 0:4ef525e32ebc | 162 | SPI _spi; |
s_s_s | 0:4ef525e32ebc | 163 | DigitalOut _rst; |
s_s_s | 0:4ef525e32ebc | 164 | DigitalOut _cs; |
s_s_s | 0:4ef525e32ebc | 165 | DigitalOut _power; |
s_s_s | 0:4ef525e32ebc | 166 | |
s_s_s | 0:4ef525e32ebc | 167 | //LCDType _type; |
s_s_s | 0:4ef525e32ebc | 168 | int _row, _column, _rows, _columns, _foreground, _background, _width, _height; |
s_s_s | 0:4ef525e32ebc | 169 | int _yokosize, _tatesize; |
s_s_s | 0:4ef525e32ebc | 170 | |
s_s_s | 0:4ef525e32ebc | 171 | unsigned int findface(unsigned short c); |
s_s_s | 0:4ef525e32ebc | 172 | }; |
s_s_s | 0:4ef525e32ebc | 173 | |
s_s_s | 0:4ef525e32ebc | 174 | #endif //Moled |
s_s_s | 0:4ef525e32ebc | 175 | |
s_s_s | 0:4ef525e32ebc | 176 |