COSA
An Object-Oriented Platform for Arduino Programming
LCD.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_LCD_HH
22 #define COSA_LCD_HH
23 
24 #include "Cosa/Types.h"
25 #include "Cosa/SPI.hh"
26 #include "Cosa/Keypad.hh"
27 #include "Cosa/IOStream.hh"
28 #include "Cosa/AnalogPin.hh"
29 
36 class LCD : public IOStream {
37 public:
38 
42  class Device : public IOStream::Device {
43  public:
45  enum TextMode {
48  } __attribute__((packed));
49 
53  Device() :
54  IOStream::Device(),
55  m_x(0),
56  m_y(0),
57  m_tab(4),
58  m_mode(0)
59  {}
60 
67  virtual bool begin() = 0;
68 
74  virtual bool end() = 0;
75 
80  virtual void backlight_on() {}
81 
86  virtual void backlight_off() {}
87 
93  virtual void display_contrast(uint8_t level)
94  {
95  UNUSED(level);
96  }
97 
102  virtual void display_on() = 0;
103 
108  virtual void display_off() = 0;
109 
114  virtual void display_normal() {}
115 
120  virtual void display_inverse() {}
121 
126  virtual void display_clear() = 0;
127 
133  void get_cursor(uint8_t& x, uint8_t& y) const
134  __attribute__((always_inline))
135  {
136  x = m_x;
137  y = m_y;
138  }
139 
146  virtual void set_cursor(uint8_t x, uint8_t y) = 0;
147 
152  uint8_t get_tab_step() const
153  {
154  return (m_tab);
155  }
156 
161  void set_tab_step(uint8_t step)
162  {
163  m_tab = step;
164  }
165 
172  __attribute__((always_inline))
173  {
174  TextMode previous = (TextMode) m_mode;
175  m_mode = mode;
176  return (previous);
177  }
178 
179  protected:
180  uint8_t m_x;
181  uint8_t m_y;
182  uint8_t m_tab;
183  uint8_t m_mode;
184  };
185 
190  class IO {
191  public:
196  virtual void begin() = 0;
197 
202  virtual void end() = 0;
203 
209  virtual void write(uint8_t data) = 0;
210 
217  virtual void write(const void* buf, size_t size) = 0;
218  };
219 
223  class Serial3W : public IO {
224  public:
231 #if !defined(BOARD_ATTINY)
235  m_sdin(sdin, 0),
236  m_sclk(sclk, 0),
237  m_sce(sce, 1)
238  {}
239 #else
243  m_sdin(sdin, 0),
244  m_sclk(sclk, 0),
245  m_sce(sce, 1)
246  {}
247 #endif
248 
253  virtual void begin()
254  {
255  m_sce.clear();
256  }
257 
262  virtual void end()
263  {
264  m_sce.set();
265  }
266 
273  virtual void write(uint8_t data)
274  {
275  m_sdin.write(data, m_sclk);
276  }
277 
285  virtual void write(const void* buf, size_t size)
286  {
287  uint8_t* dp = (uint8_t*) buf;
288  while (size--) m_sdin.write(*dp++, m_sclk);
289  }
290 
291  protected:
295  };
296 
300  class SPI3W : public IO, public SPI::Driver {
301  public:
307 #if !defined(BOARD_ATTINY)
308  SPI3W(Board::DigitalPin sce = Board::D9) : IO(), SPI::Driver(sce) {}
309 #else
310  SPI3W(Board::DigitalPin sce = Board::D3) : IO(), SPI::Driver(sce) {}
311 #endif
312 
317  virtual void begin()
318  {
319  spi.acquire(this);
320  spi.begin();
321  }
322 
327  virtual void end()
328  {
329  spi.end();
330  spi.release();
331  }
332 
339  virtual void write(uint8_t data)
340  {
341  spi.transfer(data);
342  }
343 
351  virtual void write(const void* buf, size_t size)
352  {
353  spi.write(buf, size);
354  }
355  };
356 
362  class Keypad : public ::Keypad {
363  public:
364  // Key index
365  enum {
366  NO_KEY = 0,
371  RIGHT_KEY
372  } __attribute__((packed));
373 
376  ::Keypad(scheduler, pin, m_map)
377  {}
378 
379  private:
381  static const uint16_t m_map[] PROGMEM;
382  };
383 };
384 
385 #endif
uint8_t m_y
Cursor position y.
Definition: LCD.hh:181
uint8_t transfer(uint8_t data)
Definition: SOFT_SPI.cpp:87
uint8_t m_x
Cursor position x.
Definition: LCD.hh:180
virtual void write(const void *buf, size_t size)
Definition: LCD.hh:285
virtual void begin()
Definition: LCD.hh:253
Definition: SPI.hh:57
virtual int write(const void *buf, size_t size)
void acquire(Driver *dev)
Definition: SOFT_SPI.cpp:43
virtual void display_inverse()
Definition: LCD.hh:120
virtual void end()
Definition: LCD.hh:327
virtual void display_off()=0
TextMode
Definition: LCD.hh:45
virtual void write(const void *buf, size_t size)
Definition: LCD.hh:351
virtual void backlight_off()
Definition: LCD.hh:86
virtual bool begin()=0
uint8_t m_tab
Tab step.
Definition: LCD.hh:182
virtual void set_cursor(uint8_t x, uint8_t y)=0
void set_tab_step(uint8_t step)
Definition: LCD.hh:161
OutputPin m_sdin
Serial data input.
Definition: LCD.hh:292
SPI3W(Board::DigitalPin sce=Board::D9)
Definition: LCD.hh:308
void get_cursor(uint8_t &x, uint8_t &y) const
Definition: LCD.hh:133
virtual void display_on()=0
virtual void write(uint8_t data)
Definition: LCD.hh:339
Serial3W(Board::DigitalPin sdin=Board::D6, Board::DigitalPin sclk=Board::D7, Board::DigitalPin sce=Board::D9)
Definition: LCD.hh:232
void write(const void *buf, size_t count)
Definition: SPI.hh:321
virtual void backlight_on()
Definition: LCD.hh:80
virtual void write(uint8_t data)
Definition: LCD.hh:273
void begin()
Definition: SPI.hh:216
virtual void display_clear()=0
virtual bool end()=0
void end()
Definition: SPI.hh:226
#define UNUSED(x)
Definition: ATmega328P.hh:31
virtual void display_contrast(uint8_t level)
Definition: LCD.hh:93
Definition: LCD.hh:190
OutputPin m_sclk
Serial clock input.
Definition: LCD.hh:293
OutputPin m_sce
Chip enable.
Definition: LCD.hh:294
virtual void begin()
Definition: LCD.hh:317
Keypad(Job::Scheduler *scheduler, Board::AnalogPin pin=Board::A0)
Definition: LCD.hh:375
uint8_t m_mode
Text mode.
Definition: LCD.hh:183
TextMode text_mode(TextMode mode)
Definition: LCD.hh:171
Definition: LCD.hh:36
SPI spi
Definition: SPI.cpp:29
virtual void display_normal()
Definition: LCD.hh:114
void release()
Definition: SOFT_SPI.cpp:64
Device()
Definition: LCD.hh:53
uint8_t get_tab_step() const
Definition: LCD.hh:152
virtual void end()
Definition: LCD.hh:262