COSA
An Object-Oriented Platform for Arduino Programming
ERM1602_5.cpp
Go to the documentation of this file.
1 
21 #include "ERM1602_5.hh"
22 
26  Board::DigitalPin bt) :
27  m_sda(sda),
28  m_scl(scl, 1),
29  m_en(en, 1),
30  m_bt(bt, 1),
31  m_rs(0),
32  m_dirty(false)
33 {
34 }
35 
36 bool
38 {
39  return (true);
40 }
41 
42 void
43 ERM1602_5::write4b(uint8_t data)
44 {
45  write8b(data);
46 }
47 
48 void
49 ERM1602_5::write8b(uint8_t data)
50 {
51  m_en.clear();
52  flush();
53  if (m_rs) {
56  }
57  m_sda.write(data, m_scl);
58  m_en.set();
60 }
61 
62 void
63 ERM1602_5::write8n(const void* buf, size_t size)
64 {
65  if (UNLIKELY(size == 0)) return;
66  m_en.clear();
67  flush();
68  if (m_rs) {
71  }
72  const uint8_t* bp = (const uint8_t*) buf;
73  while (size--) {
74  m_sda.write(*bp++, m_scl);
75  if (size)
77  }
78  m_en.set();
80 }
81 
82 void
83 ERM1602_5::set_mode(uint8_t flag)
84 {
85  if (m_rs == flag) return;
86  m_rs = flag;
87  m_dirty = !m_dirty;
88 }
89 
90 void
92 {
93  m_bt.write(flag);
94 }
95 
96 void
98 {
99  if (!m_dirty) return;
101  if (m_rs) func |= HD44780::EXTENDED_SET;
102  m_sda.write(func, m_scl);
104  m_dirty = false;
105 }
106 
uint8_t m_dirty
Mark register select change required.
Definition: ERM1602_5.hh:124
virtual void write4b(uint8_t data)
Definition: ERM1602_5.cpp:43
void set() const
Definition: OutputPin.hh:85
virtual void set_backlight(uint8_t flag)
Definition: ERM1602_5.cpp:91
virtual void set_mode(uint8_t flag)
Definition: ERM1602_5.cpp:83
#define DELAY(us)
Definition: Types.h:280
virtual bool setup()
Definition: ERM1602_5.cpp:37
void write(int value) const
Definition: OutputPin.hh:236
uint8_t m_rs
Register select (0/instruction, 1/data).
Definition: ERM1602_5.hh:123
OutputPin m_en
Starts data read/write.
Definition: ERM1602_5.hh:121
static const uint16_t SHORT_EXEC_TIME
Definition: ERM1602_5.hh:117
OutputPin m_scl
Serial clock.
Definition: ERM1602_5.hh:120
Sets interface data length, line and font.
Definition: HD44780.hh:849
virtual void write8n(const void *buf, size_t size)
Definition: ERM1602_5.cpp:63
void flush()
Definition: ERM1602_5.cpp:97
Set display data length.
Definition: HD44780.hh:858
ERM1602_5(Board::DigitalPin sda=Board::D7, Board::DigitalPin scl=Board::D6, Board::DigitalPin en=Board::D5, Board::DigitalPin bt=Board::D4)
Definition: ERM1602_5.cpp:23
OutputPin m_bt
Back-light control (0/on, 1/off).
Definition: ERM1602_5.hh:122
void clear() const
Definition: OutputPin.hh:124
OutputPin m_sda
Serial data output.
Definition: ERM1602_5.hh:119
#define UNLIKELY(x)
Definition: Types.h:153
virtual void write8b(uint8_t data)
Definition: ERM1602_5.cpp:49