LCDGFX LCD display driver  1.0.2
This library is developed to control SSD1306/SSD1325/SSD1327/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays
lcd_common.inl
1 /*
2  MIT License
3 
4  Copyright (c) 2019, 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 */
24 
25 #define CMD_DELAY 0xFF
26 
27 template <class I>
28 void _configureSpiDisplay(I& intf, const uint8_t *config, uint8_t configSize)
29 {
30  uint8_t command = 1;
31  int8_t args;
32  intf.commandStart();
33  for( uint8_t i=0; i<configSize; i++)
34  {
35  uint8_t data = pgm_read_byte(&config[i]);
36  if ( command )
37  {
38  if ( command == CMD_DELAY )
39  {
40  command = 1;
41  lcd_delay( data == 0xFF ? 500: data );
42  }
43  else
44  {
45  intf.send(data);
46  command = 0;
47  args = -1;
48  }
49  }
50  else
51  {
52  if (args < 0)
53  {
54  if ( data >= 128 )
55  {
56  command = data;
57  }
58  else if ( data > 0 )
59  {
60  args = data;
61  intf.spiDataMode(1);
62  }
63  else
64  {
65  command = 1;
66  }
67  }
68  else
69  {
70  args--;
71  intf.send(data);
72  if ( !args )
73  {
74  command = 1;
75  intf.spiDataMode(0);
76  }
77  }
78  }
79  }
80  intf.stop();
81 }
82 
83 
84 template <class I>
85 void _configureSpiDisplayCmdModeOnly(I& intf, const uint8_t *config, uint8_t configSize)
86 {
87  uint8_t command = 1;
88  int8_t args;
89  intf.commandStart();
90  for( uint8_t i=0; i<configSize; i++)
91  {
92  uint8_t data = pgm_read_byte(&config[i]);
93  if ( command )
94  {
95  if ( command == CMD_DELAY )
96  {
97  command = 1;
98  lcd_delay( data == 0xFF ? 500: data );
99  }
100  else
101  {
102  intf.send(data);
103  command = 0;
104  args = -1;
105  }
106  }
107  else
108  {
109  if (args < 0)
110  {
111  if ( data >= 128 )
112  {
113  command = data;
114  }
115  else if ( data > 0 )
116  {
117  args = data;
118  }
119  else
120  {
121  command = 1;
122  }
123  }
124  else
125  {
126  args--;
127  intf.send(data);
128  if ( !args )
129  {
130  command = 1;
131  }
132  }
133  }
134  }
135  intf.stop();
136 }
137 
void lcd_delay(unsigned long ms)