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