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