Arduino-LCD
LCD library for Arduino
SR3W.h
Go to the documentation of this file.
1 
18 #ifndef LCD_ADAPTER_SR3W_H
19 #define LCD_ADAPTER_SR3W_H
20 
21 #include "LCD.h"
22 #include "Driver/HD44780.h"
23 #include "GPIO.h"
24 
75 namespace LCD {
76 template<BOARD::pin_t SDA_PIN, BOARD::pin_t SCL_PIN, BOARD::pin_t EN_PIN>
77 class SR3W : public HD44780::Adapter {
78 public:
82  SR3W() :
83  HD44780::Adapter(),
84  m_port()
85  {
86  m_sda.output();
87  m_scl.output();
88  m_en.output();
89  }
90 
96  virtual bool setup()
97  {
98  return (false);
99  }
100 
106  virtual void write4b(uint8_t data)
107  {
108  m_port.data = data;
109  data = m_port;
110  uint8_t mask = 0x20;
111  do {
112  m_sda = data & mask;
113  m_scl.toggle();
114  mask >>= 1;
115  m_scl.toggle();
116  } while (mask);
117  m_en.toggle();
118  m_en.toggle();
119  }
120 
126  virtual void write8b(uint8_t data)
127  {
128  write4b(data >> 4);
129  write4b(data);
130  delayMicroseconds(SHORT_EXEC_TIME);
131  }
132 
139  virtual void set_mode(uint8_t flag)
140  {
141  m_port.rs = flag;
142  }
143 
149  virtual void set_backlight(uint8_t flag)
150  {
151  m_port.bt = flag;
152  }
153 
154 protected:
156  static const uint16_t SHORT_EXEC_TIME = 32;
157 
159  union port_t {
160  uint8_t as_uint8;
161  struct {
162  uint8_t data:4;
163  uint8_t rs:1;
164  uint8_t bt:1;
165  uint8_t app2:1;
166  uint8_t app1:1;
167  };
168  operator uint8_t() { return (as_uint8); }
169  port_t() { as_uint8 = 0; }
170  };
171 
173  GPIO<SDA_PIN> m_sda;
174  GPIO<SCL_PIN> m_scl;
175  GPIO<EN_PIN> m_en;
176 };
177 };
178 #endif
static const uint16_t SHORT_EXEC_TIME
Definition: SR3W.h:156
uint8_t app2
Application bit#2 (Q6).
Definition: SR3W.h:165
uint8_t rs
Command/Data select (Q4).
Definition: SR3W.h:163
virtual bool setup()
Definition: SR3W.h:96
Definition: Debug.h:28
virtual void set_mode(uint8_t flag)
Definition: SR3W.h:139
uint8_t bt
Back-light control (Q5).
Definition: SR3W.h:164
port_t m_port
Port setting.
Definition: SR3W.h:172
GPIO< SDA_PIN > m_sda
Serial data output.
Definition: SR3W.h:173
Definition: SR3W.h:77
uint8_t data
Data port (Q0..Q3).
Definition: SR3W.h:162
virtual void write8b(uint8_t data)
Definition: SR3W.h:126
uint8_t as_uint8
Unsigned byte access.
Definition: SR3W.h:160
uint8_t app1
Application bit#1 (Q7).
Definition: SR3W.h:166
GPIO< SCL_PIN > m_scl
Serial clock.
Definition: SR3W.h:174
SR3W()
Definition: SR3W.h:82
virtual void write4b(uint8_t data)
Definition: SR3W.h:106
virtual void set_backlight(uint8_t flag)
Definition: SR3W.h:149
GPIO< EN_PIN > m_en
Starts data read/write.
Definition: SR3W.h:175