Rpi-hw  0.7.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
pcd8544.hpp
1 /*
2  Title --- display/pcd8544.hpp
3 
4  Copyright (C) 2013 Giacomo Trudu - wicker25[at]gmail[dot]com
5 
6  This file is part of Rpi-hw.
7 
8  Rpi-hw is free software: you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation version 3 of the License.
11 
12  Rpi-hw is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with Rpi-hw. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 
22 #ifndef _RPI_HW_DISPLAY_PCD8544_HPP_
23 #define _RPI_HW_DISPLAY_PCD8544_HPP_
24 
25 #include <vector>
26 
27 #include <rpi-hw/types.hpp>
28 #include <rpi-hw/exception.hpp>
29 #include <rpi-hw/math.hpp>
30 #include <rpi-hw/utils.hpp>
31 #include <rpi-hw/time.hpp>
32 
33 #include <rpi-hw/designer.hpp>
34 
35 #include <rpi-hw/iface/output.hpp>
36 #include <rpi-hw/iface/shift-out.hpp>
37 
38 namespace rpihw { // Begin main namespace
39 
40 namespace display { // Begin displays namespace
41 
42 /*!
43  @class pcd8544
44  @brief Philips PCD8544 LCD controller.
45 
46  @example display/pcd8544.cpp
47 */
48 class pcd8544 : public designer< int8_t, bool, 1 > {
49 
50 public:
51 
52  //! The controller command set.
53  enum Commands {
54 
55  DISPLAY = 0x08, //!< Display control.
56  FUNC = 0x20, //!< Function set.
57  YADDR = 0x40, //!< Set Y address of RAM.
58  XADDR = 0x80, //!< Set Y address of RAM.
59 
60  TEMP = 0x04, //!< Temperature control.
61  BIAS = 0x10, //!< Bias system.
62  VOP = 0x80 //!< Set Vop.
63  };
64 
65  //! The controller command set (bit flags).
66  enum Settings {
67 
68  DISPLAY_E = 0x01, //!< Sets display configuration.
69  DISPLAY_D = 0x04, //!< Sets display configuration.
70 
71  FUNC_H = 0x01, //!< Extended instruction set.
72  FUNC_V = 0x02, //!< Entry mode.
73  FUNC_PD = 0x04, //!< Power down control.
74 
75  BIAS_BS0 = 0x01, //!< Set bias system.
76  BIAS_BS1 = 0x02, //!< Set bias system.
77  BIAS_BS2 = 0x04 //!< Set bias system.
78  };
79 
80  //! The size of the display.
81  enum DisplaySize {
82 
83  LCD_WIDTH = 84,
84  LCD_HEIGHT = 48
85  };
86 
87  //! The size of the DDRAM.
88  enum RamSize {
89 
90  DDRAM_WIDTH = LCD_WIDTH,
91  DDRAM_HEIGHT = LCD_HEIGHT / 8,
92  DDRAM_SIZE = DDRAM_WIDTH * DDRAM_HEIGHT
93  };
94 
95  //! The controller data pins.
96  enum DataPin {
97 
98  DIN = 0, //!< Serial data input.
99  SCLK = 1, //!< Input for the clock signal.
100  DC = 0, //!< Data/Command mode select.
101  RST = 1, //!< External rst input.
102  SCE = 2 //!< Chip Enable (CS/SS).
103  };
104 
105  //! The display colors.
106  enum Color {
107 
108  BLACK = 0,
109  WHITE = 1
110  };
111 
112  /*!
113  @brief Constructor method (4-bit mode).
114  @param[in] sclk The GPIO pin connected to the sclk pin.
115  @param[in] sdin The GPIO pin connected to the sda pin.
116  @param[in] dc The GPIO pin connected to the dorc pin.
117  @param[in] sce The GPIO pin connected to the cs pin.
118  @param[in] rst The GPIO pin connected to the rst pin.
119  */
120  pcd8544( uint8_t sclk, uint8_t sdin, uint8_t dc, uint8_t sce, uint8_t rst );
121 
122  //! Destructor method.
123  virtual ~pcd8544();
124 
125  /*!
126  @brief Initializes the display.
127  @param[in] contrast The contrast of the display.
128  @param[in] inverse Invert the colors of the display.
129  */
130  void init( uint8_t contrast = 80, bool inverse = false );
131 
132  /*!
133  @brief Sends a command to the display.
134  @param[in] data The command.
135  */
136  void cmd( uint8_t data );
137 
138  /*!
139  @brief Sends a data to the display.
140  @param[in] data The 8-bit data to be sended.
141  */
142  void sendData( uint8_t data );
143 
144  /*!
145  @brief Sets the contrast of the display.
146  @param[in] value The contrast of the display.
147  */
148  void setContrast( uint8_t value );
149 
150  /*!
151  @brief Sets the foreground color.
152  @param[in] color The new foreground color.
153  */
154  void setColor( bool color );
155 
156  /*!
157  @brief Gets the current foreground color.
158  @return The foreground color.
159  */
160  bool getColor() const;
161 
162  /*!
163  @brief Sets the color of a pixel.
164  @param[in] x The horizontal position of the pixel.
165  @param[in] y The vertical position of the pixel.
166  @param[in] color The new pixel color.
167  */
168  void setPixel( int8_t x, int8_t y, bool color );
169 
170  /*!
171  @brief Returns the color of a pixel.
172  @param[in] x The horizontal position of the pixel.
173  @param[in] y The vertical position of the pixel.
174  @return The pixel color.
175  */
176  bool getPixel( int8_t x, int8_t y ) const;
177 
178  /*!
179  @brief Redraws the display.
180  @return The number of updated blocks.
181  */
182  uint16_t redraw();
183 
184  //! Clears the display.
185  void clear();
186 
187 protected:
188 
189  //! Output interface to the control pins.
191 
192  //! Shift-out interface to the data pins.
194 
195  //! Data buffer.
196  std::vector< uint8_t > m_buffer;
197 
198  //! Buffer of updates.
199  std::vector< bool > m_updates;
200 
201  /*!
202  @brief Updates the bounding box.
203  @param[in] left The left side of the bounding box.
204  @param[in] top The top side of the bounding box.
205  @param[in] right The right side of the bounding box.
206  @param[in] bottom The bottom side of the bounding box.
207  */
208  void updateBoundingBox( uint8_t left, uint8_t top, uint8_t right, uint8_t bottom );
209 
210  /*!
211  @brief Sets the color of a pixel.
212  @param[in] x The horizontal position of the pixel.
213  @param[in] y The vertical position of the pixel.
214  @param[in] color An iterator to the color data.
215  */
216  virtual void drawPixel( int8_t x, int8_t y, color_iterator< bool > color );
217 };
218 
219 } // End of displays namespace
220 
221 } // End of main namespace
222 
223 
224 // Include inline methods
225 #include <rpi-hw/display/pcd8544-inl.hpp>
226 
227 #endif /* _RPI_HW_DISPLAY_PCD8544_HPP_ */
void setColor(bool color)
Sets the foreground color.
Definition: pcd8544-inl.hpp:30
Output interface.
Definition: output.hpp:43
Input for the clock signal.
Definition: pcd8544.hpp:99
Set Y address of RAM.
Definition: pcd8544.hpp:58
Set Y address of RAM.
Definition: pcd8544.hpp:57
Shift-out interface.
Definition: shift-out.hpp:41
Commands
The controller command set.
Definition: pcd8544.hpp:53
virtual void drawPixel(int8_t x, int8_t y, color_iterator< bool > color)
Sets the color of a pixel.
typename std::vector< T >::const_iterator color_iterator
Color iterator.
Definition: types.hpp:45
void init(uint8_t contrast=80, bool inverse=false)
Initializes the display.
DataPin
The controller data pins.
Definition: pcd8544.hpp:96
iface::shiftOut * m_data
Shift-out interface to the data pins.
Definition: pcd8544.hpp:193
void sendData(uint8_t data)
Sends a data to the display.
std::vector< uint8_t > m_buffer
Data buffer.
Definition: pcd8544.hpp:196
DisplaySize
The size of the display.
Definition: pcd8544.hpp:81
bool getColor() const
Gets the current foreground color.
Definition: pcd8544-inl.hpp:37
External rst input.
Definition: pcd8544.hpp:101
virtual ~pcd8544()
Destructor method.
Sets display configuration.
Definition: pcd8544.hpp:69
void updateBoundingBox(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom)
Updates the bounding box.
Serial data input.
Definition: pcd8544.hpp:98
iface::output * m_control
Output interface to the control pins.
Definition: pcd8544.hpp:190
std::vector< bool > m_updates
Buffer of updates.
Definition: pcd8544.hpp:199
The graphic designer.
Definition: designer.hpp:44
Sets display configuration.
Definition: pcd8544.hpp:68
Color
The display colors.
Definition: pcd8544.hpp:106
void setPixel(int8_t x, int8_t y, bool color)
Sets the color of a pixel.
Definition: pcd8544-inl.hpp:44
Philips PCD8544 LCD controller.
Definition: pcd8544.hpp:48
Temperature control.
Definition: pcd8544.hpp:60
RamSize
The size of the DDRAM.
Definition: pcd8544.hpp:88
Chip Enable (CS/SS).
Definition: pcd8544.hpp:102
uint16_t redraw()
Redraws the display.
void cmd(uint8_t data)
Sends a command to the display.
Extended instruction set.
Definition: pcd8544.hpp:71
void clear()
Clears the display.
Power down control.
Definition: pcd8544.hpp:73
void setContrast(uint8_t value)
Sets the contrast of the display.
Data/Command mode select.
Definition: pcd8544.hpp:100
Settings
The controller command set (bit flags).
Definition: pcd8544.hpp:66
pcd8544(uint8_t sclk, uint8_t sdin, uint8_t dc, uint8_t sce, uint8_t rst)
Constructor method (4-bit mode).
bool getPixel(int8_t x, int8_t y) const
Returns the color of a pixel.