LCDGFX LCD display driver  1.2.0
Lightweight graphics library for SSD1306, SSD1325, SSD1327, SSD1331, SSD1351, SH1106, SH1107, IL9163, ST7735, ST7789, ILI9341, PCD8544 displays over I2C/SPI
custom_interface.h
Go to the documentation of this file.
1 /*
2  MIT License
3 
4  Copyright (c) 2017-2020, Alexey Dynda
5 
6  Permission is hereby granted, free of charge, to any person obtaining a copy
7  of this software and associated documentation files (the "Software"), to deal
8  in the Software without restriction, including without limitation the rights
9  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  copies of the Software, and to permit persons to whom the Software is
11  furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in all
14  copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  SOFTWARE.
23 */
28 #pragma once
29 
30 #include <stdint.h>
31 
32 #ifdef __cplusplus
33 
38 template <int N> class _ICustom
39 {
40 public:
44  explicit _ICustom(int8_t dc = -1)
45  : m_dc(dc)
46  {
47  if ( getDc() >= 0 )
48  {
49  lcd_registerGpioEvent(getDc(), onDcChange, this);
50  }
51  }
52 
56  virtual ~_ICustom()
57  {
58  if ( getDc() >= 0 )
59  {
60  lcd_unregisterGpioEvent(getDc());
61  }
62  }
63 
67  virtual void begin()
68  {
69  }
70 
74  virtual void end()
75  {
76  }
77 
81  virtual void start()
82  {
83  }
84 
88  virtual void stop()
89  {
90  }
91 
96  void send(uint8_t data)
97  {
98  m_buffer[m_data_size] = data;
99  m_data_size++;
100  if ( m_data_size == sizeof(m_buffer) )
101  {
102  forceTransfer();
103  }
104  }
105 
114  void sendBuffer(const uint8_t *buffer, uint16_t size)
115  {
116  while ( size )
117  {
118  send(*buffer);
119  size--;
120  buffer++;
121  }
122  }
123 
124 protected:
128  virtual void transferToHw(const uint8_t *buffer, uint16_t size) = 0;
129 
135  {
136  transferToHw(m_buffer, m_data_size);
137  m_data_size = 0;
138  }
139 
143  int8_t getDc()
144  {
145  return m_dc;
146  }
147 
148 private:
149  uint8_t m_buffer[N];
150  uint16_t m_data_size = 0;
151  int8_t m_dc = -1;
152 
153  static void onDcChange(void *arg)
154  {
155  _ICustom *obj = reinterpret_cast<_ICustom *>(arg);
156  obj->forceTransfer();
157  }
158 };
159 
160 #endif
void forceTransfer()
Call this method to transfer data to hardware.
int8_t getDc()
Returns number of D/C pin if used, or -1.
virtual void transferToHw(const uint8_t *buffer, uint16_t size)=0
This function must implement actual sending of data to hardware interface.
virtual void start()
Starts communication with the display over custom interface.
virtual ~_ICustom()
Destroys instance of custom basic interface.
This is basic class for custom user-defined interfaces This is template, which accepts maximum number...
_ICustom(int8_t dc=-1)
Creates instance of custom basic interface.
virtual void end()
Deinitializes basic class for custom interface.
virtual void stop()
Ends communication with the display over custom interface.
void sendBuffer(const uint8_t *buffer, uint16_t size)
Sends bytes to custom interface.
void send(uint8_t data)
Sends byte to custom interface.
virtual void begin()
Initializes basic class for custom interface.