COSA
An Object-Oriented Platform for Arduino Programming
SainSmart_LCD2004.cpp
Go to the documentation of this file.
1 
21 #include "SainSmart_LCD2004.hh"
22 
23 bool
25 {
26  data_direction(0);
27  return (false);
28 }
29 
30 void
32 {
33  uint8_t buf[2];
34  m_port.data = data;
35  m_port.en = 1;
36  buf[0] = m_port;
37  m_port.en = 0;
38  buf[1] = m_port;
39  write(buf, sizeof(buf));
40 }
41 
42 void
44 {
45  uint8_t buf[4];
46  m_port.data = (data >> 4);
47  m_port.en = 1;
48  buf[0] = m_port;
49  m_port.en = 0;
50  buf[1] = m_port;
51  m_port.data = data;
52  m_port.en = 1;
53  buf[2] = m_port.as_uint8;
54  m_port.en = 0;
55  buf[3] = m_port.as_uint8;
56  write(buf, sizeof(buf));
57 }
58 
59 void
60 SainSmart_LCD2004::write8n(const void* buf, size_t size)
61 {
62  const uint8_t* bp = (const uint8_t*) buf;
63  while (size != 0) {
64  uint8_t tmp[TMP_MAX];
65  uint8_t n = (size > sizeof(tmp) / 4 ? sizeof(tmp) / 4 : size);
66  size -= n;
67  uint8_t m = n * 4;
68  for (uint8_t i = 0; i < m;) {
69  uint8_t data = *bp++;
70  m_port.data = (data >> 4);
71  m_port.en = 1;
72  tmp[i++] = m_port;
73  m_port.en = 0;
74  tmp[i++] = m_port;
75  m_port.data = data;
76  m_port.en = 1;
77  tmp[i++] = m_port;
78  m_port.en = 0;
79  tmp[i++] = m_port;
80  }
81  write(tmp, m);
82  }
83 }
84 
85 void
87 {
88  m_port.rs = flag;
89 }
90 
91 void
93 {
94  m_port.bt = flag;
96 }
97 
virtual void write8b(uint8_t data)
virtual void write8n(const void *buf, size_t size)
uint8_t en
Enable pulse (P2).
virtual void set_mode(uint8_t flag)
bool write(uint8_t pin, uint8_t value)
Definition: PCF8574.cpp:45
virtual bool setup()
port_t m_port
Port setting.
static const uint8_t TMP_MAX
uint8_t rs
Command/Data select (P0).
virtual void set_backlight(uint8_t flag)
bool data_direction(uint8_t ddr)
Definition: PCF8574.cpp:24
uint8_t data
Data port (P4..P7).
virtual void write4b(uint8_t data)
uint8_t bt
Back-light (P3).
uint8_t as_uint8
Unsigned byte access.