Yuji Notsu
/
MARMEX_OB_oled__HelloWorld
This program is for operating OLED module of MAPLE Board and mbed1768
NokiaLCD/NokiaLCD.h@0:53adaf7199b6, 2013-01-03 (annotated)
- Committer:
- y_notsu
- Date:
- Thu Jan 03 13:12:04 2013 +0000
- Revision:
- 0:53adaf7199b6
This program is for OLED module of MAPLE Board and mbed1768.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
y_notsu | 0:53adaf7199b6 | 1 | /* mbed NokiaLCD Library, for a 130x130 Nokia colour LCD |
y_notsu | 0:53adaf7199b6 | 2 | * Copyright (c) 2007-2010, sford |
y_notsu | 0:53adaf7199b6 | 3 | * |
y_notsu | 0:53adaf7199b6 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
y_notsu | 0:53adaf7199b6 | 5 | * of this software and associated documentation files (the "Software"), to deal |
y_notsu | 0:53adaf7199b6 | 6 | * in the Software without restriction, including without limitation the rights |
y_notsu | 0:53adaf7199b6 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
y_notsu | 0:53adaf7199b6 | 8 | * copies of the Software, and to permit persons to whom the Software is |
y_notsu | 0:53adaf7199b6 | 9 | * furnished to do so, subject to the following conditions: |
y_notsu | 0:53adaf7199b6 | 10 | * |
y_notsu | 0:53adaf7199b6 | 11 | * The above copyright notice and this permission notice shall be included in |
y_notsu | 0:53adaf7199b6 | 12 | * all copies or substantial portions of the Software. |
y_notsu | 0:53adaf7199b6 | 13 | * |
y_notsu | 0:53adaf7199b6 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
y_notsu | 0:53adaf7199b6 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
y_notsu | 0:53adaf7199b6 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
y_notsu | 0:53adaf7199b6 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
y_notsu | 0:53adaf7199b6 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
y_notsu | 0:53adaf7199b6 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
y_notsu | 0:53adaf7199b6 | 20 | * THE SOFTWARE. |
y_notsu | 0:53adaf7199b6 | 21 | */ |
y_notsu | 0:53adaf7199b6 | 22 | |
y_notsu | 0:53adaf7199b6 | 23 | #ifndef MBED_NOKIALCD_H |
y_notsu | 0:53adaf7199b6 | 24 | #define MBED_NOKIALCD_H |
y_notsu | 0:53adaf7199b6 | 25 | |
y_notsu | 0:53adaf7199b6 | 26 | #include "mbed.h" |
y_notsu | 0:53adaf7199b6 | 27 | |
y_notsu | 0:53adaf7199b6 | 28 | /** An interface for the 130x130 Nokia Mobile phone screens |
y_notsu | 0:53adaf7199b6 | 29 | * |
y_notsu | 0:53adaf7199b6 | 30 | * @code |
y_notsu | 0:53adaf7199b6 | 31 | * #include "mbed.h" |
y_notsu | 0:53adaf7199b6 | 32 | * #include "NokiaLCD.h" |
y_notsu | 0:53adaf7199b6 | 33 | * |
y_notsu | 0:53adaf7199b6 | 34 | * NokiaLCD lcd(p5, p7, p8, p9, NokiaLCD::6610); // mosi, sclk, cs, rst, type |
y_notsu | 0:53adaf7199b6 | 35 | * |
y_notsu | 0:53adaf7199b6 | 36 | * int main() { |
y_notsu | 0:53adaf7199b6 | 37 | * lcd.printf("Hello World!"); |
y_notsu | 0:53adaf7199b6 | 38 | * } |
y_notsu | 0:53adaf7199b6 | 39 | * @endcode |
y_notsu | 0:53adaf7199b6 | 40 | */ |
y_notsu | 0:53adaf7199b6 | 41 | class NokiaLCD : public Stream { |
y_notsu | 0:53adaf7199b6 | 42 | |
y_notsu | 0:53adaf7199b6 | 43 | public: |
y_notsu | 0:53adaf7199b6 | 44 | /** LCD panel format */ |
y_notsu | 0:53adaf7199b6 | 45 | enum LCDType { |
y_notsu | 0:53adaf7199b6 | 46 | LCD6100 /**< Nokia 6100, as found on sparkfun board (default) */ |
y_notsu | 0:53adaf7199b6 | 47 | , LCD6610 /**< Nokia 6610, as found on olimex board */ |
y_notsu | 0:53adaf7199b6 | 48 | , PCF8833 |
y_notsu | 0:53adaf7199b6 | 49 | }; |
y_notsu | 0:53adaf7199b6 | 50 | |
y_notsu | 0:53adaf7199b6 | 51 | /** Create and Nokia LCD interface, using a SPI and two DigitalOut interfaces |
y_notsu | 0:53adaf7199b6 | 52 | * |
y_notsu | 0:53adaf7199b6 | 53 | * @param mosi SPI data out |
y_notsu | 0:53adaf7199b6 | 54 | * @param sclk SPI clock |
y_notsu | 0:53adaf7199b6 | 55 | * @param cs Chip Select (DigitalOut) |
y_notsu | 0:53adaf7199b6 | 56 | * @param rst Reset (DigitalOut) |
y_notsu | 0:53adaf7199b6 | 57 | * @param type The LCDType to select driver chip variants |
y_notsu | 0:53adaf7199b6 | 58 | */ |
y_notsu | 0:53adaf7199b6 | 59 | NokiaLCD(PinName mosi, PinName sclk, PinName cs, PinName rst, LCDType type = LCD6100); |
y_notsu | 0:53adaf7199b6 | 60 | |
y_notsu | 0:53adaf7199b6 | 61 | #if DOXYGEN_ONLY |
y_notsu | 0:53adaf7199b6 | 62 | /** Write a character to the LCD |
y_notsu | 0:53adaf7199b6 | 63 | * |
y_notsu | 0:53adaf7199b6 | 64 | * @param c The character to write to the display |
y_notsu | 0:53adaf7199b6 | 65 | */ |
y_notsu | 0:53adaf7199b6 | 66 | int putc(int c); |
y_notsu | 0:53adaf7199b6 | 67 | |
y_notsu | 0:53adaf7199b6 | 68 | /** Write a formated string to the LCD |
y_notsu | 0:53adaf7199b6 | 69 | * |
y_notsu | 0:53adaf7199b6 | 70 | * @param format A printf-style format string, followed by the |
y_notsu | 0:53adaf7199b6 | 71 | * variables to use in formating the string. |
y_notsu | 0:53adaf7199b6 | 72 | */ |
y_notsu | 0:53adaf7199b6 | 73 | int printf(const char* format, ...); |
y_notsu | 0:53adaf7199b6 | 74 | #endif |
y_notsu | 0:53adaf7199b6 | 75 | |
y_notsu | 0:53adaf7199b6 | 76 | /** Locate to a screen column and row |
y_notsu | 0:53adaf7199b6 | 77 | * |
y_notsu | 0:53adaf7199b6 | 78 | * @param column The horizontal position from the left, indexed from 0 |
y_notsu | 0:53adaf7199b6 | 79 | * @param row The vertical position from the top, indexed from 0 |
y_notsu | 0:53adaf7199b6 | 80 | */ |
y_notsu | 0:53adaf7199b6 | 81 | void locate(int column, int row); |
y_notsu | 0:53adaf7199b6 | 82 | |
y_notsu | 0:53adaf7199b6 | 83 | /** Clear the screen and locate to 0,0 */ |
y_notsu | 0:53adaf7199b6 | 84 | void cls(); |
y_notsu | 0:53adaf7199b6 | 85 | |
y_notsu | 0:53adaf7199b6 | 86 | /** Set a pixel on te screen |
y_notsu | 0:53adaf7199b6 | 87 | * |
y_notsu | 0:53adaf7199b6 | 88 | * @param x horizontal position from left |
y_notsu | 0:53adaf7199b6 | 89 | * @param y vertical position from top |
y_notsu | 0:53adaf7199b6 | 90 | * @param colour 24-bit colour in format 0x00RRGGBB |
y_notsu | 0:53adaf7199b6 | 91 | */ |
y_notsu | 0:53adaf7199b6 | 92 | void pixel(int x, int y, int colour); |
y_notsu | 0:53adaf7199b6 | 93 | |
y_notsu | 0:53adaf7199b6 | 94 | /** Fill an area of the screen |
y_notsu | 0:53adaf7199b6 | 95 | * |
y_notsu | 0:53adaf7199b6 | 96 | * @param x horizontal position from left |
y_notsu | 0:53adaf7199b6 | 97 | * @param y vertical position from top |
y_notsu | 0:53adaf7199b6 | 98 | * @param width width in pixels |
y_notsu | 0:53adaf7199b6 | 99 | * @param height height in pixels |
y_notsu | 0:53adaf7199b6 | 100 | * @param colour 24-bit colour in format 0x00RRGGBB |
y_notsu | 0:53adaf7199b6 | 101 | */ |
y_notsu | 0:53adaf7199b6 | 102 | void fill(int x, int y, int width, int height, int colour); |
y_notsu | 0:53adaf7199b6 | 103 | |
y_notsu | 0:53adaf7199b6 | 104 | void blit(int x, int y, int width, int height, const int* colour); |
y_notsu | 0:53adaf7199b6 | 105 | void bitblit(int x, int y, int width, int height, const char* bitstream); |
y_notsu | 0:53adaf7199b6 | 106 | |
y_notsu | 0:53adaf7199b6 | 107 | int width(); |
y_notsu | 0:53adaf7199b6 | 108 | int height(); |
y_notsu | 0:53adaf7199b6 | 109 | int columns(); |
y_notsu | 0:53adaf7199b6 | 110 | int rows(); |
y_notsu | 0:53adaf7199b6 | 111 | |
y_notsu | 0:53adaf7199b6 | 112 | void reset(); |
y_notsu | 0:53adaf7199b6 | 113 | |
y_notsu | 0:53adaf7199b6 | 114 | /** Set the foreground colour |
y_notsu | 0:53adaf7199b6 | 115 | * |
y_notsu | 0:53adaf7199b6 | 116 | * @param c 24-bit colour |
y_notsu | 0:53adaf7199b6 | 117 | */ |
y_notsu | 0:53adaf7199b6 | 118 | void foreground(int c); |
y_notsu | 0:53adaf7199b6 | 119 | |
y_notsu | 0:53adaf7199b6 | 120 | /** Set the background colour |
y_notsu | 0:53adaf7199b6 | 121 | * |
y_notsu | 0:53adaf7199b6 | 122 | * @param c 24-bit colour |
y_notsu | 0:53adaf7199b6 | 123 | */ |
y_notsu | 0:53adaf7199b6 | 124 | void background(int c); |
y_notsu | 0:53adaf7199b6 | 125 | |
y_notsu | 0:53adaf7199b6 | 126 | protected: |
y_notsu | 0:53adaf7199b6 | 127 | virtual void _window(int x, int y, int width, int height); |
y_notsu | 0:53adaf7199b6 | 128 | virtual void _putp(int colour); |
y_notsu | 0:53adaf7199b6 | 129 | |
y_notsu | 0:53adaf7199b6 | 130 | void command(int value); |
y_notsu | 0:53adaf7199b6 | 131 | void data(int value); |
y_notsu | 0:53adaf7199b6 | 132 | |
y_notsu | 0:53adaf7199b6 | 133 | void newline(); |
y_notsu | 0:53adaf7199b6 | 134 | virtual int _putc(int c); |
y_notsu | 0:53adaf7199b6 | 135 | virtual int _getc() { |
y_notsu | 0:53adaf7199b6 | 136 | return 0; |
y_notsu | 0:53adaf7199b6 | 137 | } |
y_notsu | 0:53adaf7199b6 | 138 | void putp(int v); |
y_notsu | 0:53adaf7199b6 | 139 | void window(int x, int y, int width, int height); |
y_notsu | 0:53adaf7199b6 | 140 | |
y_notsu | 0:53adaf7199b6 | 141 | SPI _spi; |
y_notsu | 0:53adaf7199b6 | 142 | DigitalOut _rst; |
y_notsu | 0:53adaf7199b6 | 143 | DigitalOut _cs; |
y_notsu | 0:53adaf7199b6 | 144 | |
y_notsu | 0:53adaf7199b6 | 145 | LCDType _type; |
y_notsu | 0:53adaf7199b6 | 146 | int _row, _column, _rows, _columns, _foreground, _background, _width, _height; |
y_notsu | 0:53adaf7199b6 | 147 | }; |
y_notsu | 0:53adaf7199b6 | 148 | |
y_notsu | 0:53adaf7199b6 | 149 | #endif |
y_notsu | 0:53adaf7199b6 | 150 | |
y_notsu | 0:53adaf7199b6 | 151 |