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