Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 1 | #pragma once |
2 | #include "main.h" |
||
3 | |||
4 | #if !defined LCD_DELAY_CNT |
||
5 | #error need to define LCD delay counter ticking in microseconds |
||
6 | #endif |
||
7 | |||
8 | enum lcdType_t |
||
9 | { |
||
10 | LCD_8X1, ///< 8 chars, 1 column |
||
11 | LCD_10X1, |
||
12 | LCD_16X1, |
||
13 | LCD_20X1, |
||
14 | LCD_40X1, |
||
15 | LCD_8X2, |
||
16 | LCD_10X2, |
||
17 | LCD_16X2, |
||
18 | LCD_20X2, |
||
19 | LCD_40X2 |
||
20 | |||
21 | }; |
||
22 | |||
23 | class ioline_t |
||
24 | { |
||
25 | public: |
||
26 | ioline_t(GPIO_TypeDef *gpio, uint16_t pin) : gpio(gpio), pin(pin){}; |
||
27 | |||
28 | ioline_t() : gpio(nullptr), pin(0){}; |
||
29 | |||
30 | ioline_t &operator=(ioline_t const &data) |
||
31 | { |
||
32 | this->gpio = data.gpio; |
||
33 | this->pin = data.pin; |
||
34 | return *this; |
||
35 | }; |
||
36 | |||
37 | GPIO_TypeDef *gpio; // GPIO pin port |
||
38 | uint16_t pin; // GPIO pin number |
||
39 | }; |
||
40 | |||
41 | |||
42 | |||
43 | /// \brief Describe the bits of the databus for the LCD |
||
44 | struct lcdDataLines_t |
||
45 | { |
||
46 | lcdDataLines_t(ioline_t d0_, ioline_t d1_, ioline_t d2_, ioline_t d3_) |
||
47 | { |
||
48 | m_bits[0] = d0_; |
||
49 | m_bits[1] = d1_; |
||
50 | m_bits[2] = d2_; |
||
51 | m_bits[3] = d3_; |
||
52 | } |
||
53 | ioline_t &operator[](int i_) { return m_bits[i_]; }; |
||
54 | |||
55 | private: |
||
56 | ioline_t m_bits[4]; |
||
57 | }; |
||
58 | |||
59 | class lcdInterface_t |
||
60 | { |
||
61 | public: |
||
62 | lcdInterface_t(lcdType_t type_, ///< LCD type code |
||
63 | ioline_t rsBit_, ///< LCD register select bit |
||
64 | ioline_t wrBit_, ///< LCD register write bit |
||
65 | ioline_t eBit_, ///< LCD enable bit |
||
66 | lcdDataLines_t dBits_ ///< LCD data bits |
||
67 | ) |
||
68 | : m_lcdType(type_), m_rsBit(rsBit_), m_wrBit(wrBit_), m_eBit(eBit_), m_dBits(dBits_), m_timeouts(0){}; |
||
69 | |||
70 | uint8_t displayXsize() const; |
||
71 | |||
72 | uint8_t displayYsize() const; |
||
73 | |||
74 | void writeData(uint8_t data_); |
||
75 | |||
76 | /// \brief write top 4 bits of the control register with the top 4 bits of data_ |
||
77 | void writeCtrl4(uint8_t data_); |
||
78 | |||
79 | void writeCtrl(uint8_t data_); |
||
80 | |||
81 | /// \brief write a control value then wait for it to complete |
||
82 | void writeCtrlWait(uint8_t data_); |
||
83 | |||
84 | uint8_t readData(); |
||
85 | |||
86 | uint8_t readCtrl(); |
||
87 | |||
88 | lcdType_t lcdType() { return m_lcdType; }; |
||
89 | |||
90 | /// \brief Set cursor position. |
||
91 | void gotoxy(uint8_t x_, uint8_t y_); |
||
92 | |||
93 | // \brief Start the polled timer for high speed signals. |
||
94 | void init(); |
||
95 | |||
96 | // \brief maintaining data on the bus |
||
97 | void pulseE(); |
||
98 | |||
99 | private: |
||
100 | /// \brief write low order 4 bits to data bus |
||
101 | void writeData4(uint8_t data_); |
||
102 | /// \brief read low order 4 bits from data bus |
||
103 | uint8_t readData4(); |
||
104 | |||
105 | /// \brief write full 8 bits to data bus |
||
106 | void writeData8(uint8_t data_); |
||
107 | |||
108 | /// \brief read full 8 bits from data bus |
||
109 | uint8_t readData8(); |
||
110 | |||
111 | /// \brief poll/wait while hardware reports busy |
||
112 | void pollBusy(); |
||
113 | |||
114 | /// \brief Set the GPIO mode |
||
115 | void setLineMode(ioline_t line, unsigned mode); |
||
116 | |||
117 | /// \brief delay for microseconds |
||
118 | void polledDelay(unsigned microsec); |
||
119 | |||
120 | lcdType_t const m_lcdType; |
||
121 | |||
122 | ioline_t const m_rsBit; |
||
123 | |||
124 | ioline_t const m_wrBit; |
||
125 | |||
126 | ioline_t const m_eBit; |
||
127 | |||
128 | /// \brief gpio information |
||
129 | lcdDataLines_t m_dBits; |
||
130 | |||
131 | /// \brief a count of the number of failures |
||
132 | uint32_t m_timeouts; |
||
133 | }; |