LCDGFX LCD display driver  2.0.1
This library is developed to control SSD1306/SSD1325/SSD1327/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays
io.h
Go to the documentation of this file.
1 /*
2  MIT License
3 
4  Copyright (c) 2018-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 
29 #ifndef _LCD_HAL_IO_H_
30 #define _LCD_HAL_IO_H_
31 
41 #include "UserSettings.h"
42 #include "interface.h"
43 
44 #if defined(ARDUINO)
45 #include "arduino/io.h"
46 #ifdef __cplusplus
47 #include "arduino/arduino_spi.h"
48 #include "arduino/arduino_wire.h"
49 #include "avr/avr_spi.h"
50 #include "avr/avr_twi.h"
51 #include "avr/ssd1306_spi_usi.h"
53 #include "esp/esp32_i2c.h"
54 #include "esp/esp32_spi.h"
55 #endif
56 #elif defined(__AVR__) && !defined(ARDUINO)
57 #include "avr/io.h"
58 #ifdef __cplusplus
59 #include "avr/avr_spi.h"
60 #include "avr/avr_twi.h"
61 #include "avr/ssd1306_spi_usi.h"
63 #endif
64 #elif defined(__XTENSA__) && !defined(ARDUINO)
65 #include "esp/io.h"
66 #ifdef __cplusplus
67 #include "esp/esp32_i2c.h"
68 #include "esp/esp32_spi.h"
69 #endif
70 #elif defined(STM32F1) || defined(STM32F2) || defined(STM32F4)
71 #include "stm32/io.h"
72 #elif defined(__linux__)
73 #include "linux/io.h"
74 #ifdef __cplusplus
75 #include "linux/linux_i2c.h"
76 #include "linux/linux_spi.h"
77 #include "linux/sdl_i2c.h"
78 #include "linux/sdl_spi.h"
79 #endif
80 #elif defined(__MINGW32__)
81 #include "mingw/io.h"
82 #ifdef __cplusplus
83 #include "linux/sdl_i2c.h"
84 #include "linux/sdl_spi.h"
85 #endif
86 #else
87 #warning "Platform is not supported. Use template to add support"
88 #endif
89 
90 #include <stdint.h>
91 
92 #ifndef LCDINT_TYPES_DEFINED
93 
94 #define LCDINT_TYPES_DEFINED
95 
96 typedef int lcdint_t;
98 typedef unsigned int lcduint_t;
99 #endif
100 
102 #define ssd1306_swap_data(a, b, type) { type t = a; a = b; b = t; }
103 
105 // HAL Layer functions
107 
108 #ifndef DOXYGEN_SHOULD_SKIP_THIS
109 #define ARDUINO_COMPAT
110 #endif
111 
112 #if defined(ARDUINO)
113 
114 #define LCD_LOW LOW
115 #define LCD_HIGH HIGH
116 #define LCD_GPIO_INPUT INPUT
117 #define LCD_GPIO_OUTPUT OUTPUT
118 #define LCD_PROGMEM PROGMEM
119 
120 #define lcd_gpioRead digitalRead
121 #define lcd_gpioWrite digitalWrite
122 #define lcd_gpioMode pinMode
123 #define lcd_adcRead analogRead
124 
125 #define lcd_pgmReadByte pgm_read_byte
126 #define lcd_eepromReadWord eeprom_read_word
127 #define lcd_eepromWriteWord eeprom_write_word
128 
129 #define lcd_millis millis
130 #define lcd_micros micros
131 #define lcd_delay delay
132 #define lcd_delayUs delayMicroseconds
133 
134 #define lcd_random random
135 #define lcd_randomSeed randomSeed
136 
137 #else
138 
140 #define LCD_LOW 0
141 
142 #define LCD_HIGH 1
143 
144 #define LCD_GPIO_INPUT 0
145 
146 #define LCD_GPIO_OUTPUT 1
147 // LCD_PROMEM is platform specific definition
148 #ifndef LCD_PROGMEM
149 
150 #define LCD_PROGMEM PROGMEM
151 #endif
152 
153 #ifdef __cplusplus
154 extern "C" {
155 #endif
156 
162 void lcd_gpioMode(int pin, int mode);
163 
169 int lcd_gpioRead(int pin);
170 
176 void lcd_gpioWrite(int pin, int level);
177 
184 int lcd_adcRead(int pin);
185 
189 uint32_t lcd_millis(void);
190 
194 uint32_t lcd_micros(void);
195 
200 void lcd_randomSeed(int seed);
201 
208 void attachInterrupt(int pin, void (*interrupt)(), int level);
209 
214 void lcd_delay(unsigned long ms);
215 
220 void lcd_delayUs(unsigned long us);
221 
228 uint8_t lcd_pgmReadByte(const void *ptr);
229 
235 uint16_t lcd_eepromReadWord(const void *ptr);
236 
242 void lcd_eepromWriteWord(const void *ptr, uint16_t val);
243 
244 #ifdef __cplusplus
245 }
246 #endif
247 
248 #ifdef __cplusplus
249 
254 int lcd_random(int max);
255 
261 int lcd_random(int min, int max);
262 #endif
263 
264 #ifdef ARDUINO_COMPAT
265 
266 #define LOW LCD_LOW
267 
268 #define HIGH LCD_HIGH
269 
270 #define INPUT LCD_GPIO_INPUT
271 
272 #define OUTPUT LCD_GPIO_OUTPUT
273 #ifndef PROGMEM
274 
275 #define PROGMEM LCD_PROGMEM
276 #endif
277 
279 #define digitalRead lcd_gpioRead
280 
281 #define digitalWrite lcd_gpioWrite
282 
283 #define pinMode lcd_gpioMode
284 
285 #define analogRead lcd_adcRead
286 
287 #if !defined(__AVR__)
288 
289 #define pgm_read_byte lcd_pgmReadByte
290 
291 #define eeprom_read_word lcd_eepromReadWord
292 
293 #define eeprom_write_word lcd_eepromWriteWord
294 #endif
295 
297 #define millis lcd_millis
298 
299 #define micros lcd_micros
300 
301 #define delay lcd_delay
302 
303 #define delayMicroseconds lcd_delayUs
304 
306 #define random lcd_random
307 
308 #define randomSeed lcd_randomSeed
309 
310 #endif
311 
312 #endif
313 
314 
315 
316 #ifdef __cplusplus
317 
319 // I2C PLATFORM
321 
322 #if defined(CONFIG_ARDUINO_I2C_AVAILABLE) && defined(CONFIG_ARDUINO_I2C_ENABLE)
323 
326 class PlatformI2c: public ArduinoI2c
327 {
328 public:
334  : ArduinoI2c(config.scl, config.sda, config.addr) {}
335 };
336 
337 #elif defined(CONFIG_TWI_I2C_AVAILABLE) && defined(CONFIG_TWI_I2C_ENABLE)
338 
342 class PlatformI2c: public TwiI2c
343 {
344 public:
349  PlatformI2c(const SPlatformI2cConfig &config)
350  : TwiI2c(config.addr) {}
351 };
352 
353 #elif defined(CONFIG_LINUX_I2C_AVAILABLE) && defined(CONFIG_LINUX_I2C_ENABLE)
354 
355 #if defined(SDL_EMULATION)
356 
359 class PlatformI2c: public SdlI2c
360 {
361 public:
366  PlatformI2c(const SPlatformI2cConfig &config)
367  : SdlI2c(config.scl, config.sda, config.addr) {}
368 };
369 #else
370 
373 class PlatformI2c: public LinuxI2c
374 {
375 public:
380  PlatformI2c(const SPlatformI2cConfig &config)
381  : LinuxI2c( config.busId, config.addr ) {}
382 };
383 #endif
384 
385 #elif defined(CONFIG_ESP32_I2C_AVAILABLE) && defined(CONFIG_ESP32_I2C_ENABLE)
386 
390 class PlatformI2c: public EspI2c
391 {
392 public:
397  PlatformI2c(const SPlatformI2cConfig &config)
398  : EspI2c( config.busId, config.addr, config.scl, config.sda, 400000) {}
399 };
400 
401 #elif defined(CONFIG_SOFTWARE_I2C_AVAILABLE) && defined(CONFIG_SOFTWARE_I2C_ENABLE)
402 
406 class PlatformI2c: public SoftwareI2c
407 {
408 public:
413  PlatformI2c(const SPlatformI2cConfig &config)
414  : SoftwareI2c(config.scl, config.sda, config.addr) {}
415 };
416 
417 #else
418 
419 #error "Platform not supported"
420 
421 #endif
422 
424 // SPI PLATFORM
426 
427 #if defined(CONFIG_AVR_SPI_AVAILABLE) && defined(CONFIG_AVR_SPI_ENABLE)
428 
432 class PlatformSpi: public AvrSpi
433 {
434 public:
440  : AvrSpi( config.cs, config.dc, config.frequency ) {}
441 };
442 
443 #elif defined(CONFIG_ARDUINO_SPI_AVAILABLE) && defined(CONFIG_ARDUINO_SPI_ENABLE)
444 
448 class PlatformSpi: public ArduinoSpi
449 {
450 public:
455  PlatformSpi(const SPlatformSpiConfig &config)
456  : ArduinoSpi(config.cs, config.dc, config.frequency) {}
457 };
458 
459 #elif defined(CONFIG_LINUX_SPI_AVAILABLE) && defined(CONFIG_LINUX_SPI_ENABLE)
460 
461 #if defined(SDL_EMULATION)
462 
465 class PlatformSpi: public SdlSpi
466 {
467 public:
472  PlatformSpi(const SPlatformSpiConfig &config)
473  : SdlSpi(config.dc) {}
474 };
475 #else
476 
479 class PlatformSpi: public LinuxSpi
480 {
481 public:
486  PlatformSpi(const SPlatformSpiConfig &config)
487  : LinuxSpi( config.busId, config.devId, config.dc, config.frequency ) {}
488 };
489 #endif
490 
491 #elif defined(CONFIG_ESP32_SPI_AVAILABLE) && defined(CONFIG_ESP32_SPI_ENABLE)
492 
495 class PlatformSpi: public EspSpi
496 {
497 public:
502  PlatformSpi(const SPlatformSpiConfig &config)
503  : EspSpi( config.busId, config.cs, config.dc, config.scl, config.sda, config.frequency ) {}
504 };
505 
506 #elif defined(CONFIG_USI_SPI_AVAILABLE) && defined(CONFIG_USI_SPI_ENABLE)
507 
511 class PlatformSpi: public UsiSpi
512 {
513 public:
518  PlatformSpi(const SPlatformSpiConfig &config)
519  : UsiSpi( config.cs, config.dc ) {}
520 };
521 
522 #else
523 
524 #error "Platform not supported"
525 
526 #endif
527 
528 
529 
530 extern "C" {
531 #endif // end ifdef __cplusplus
532 
533 // !!! PLATFORM I2C IMPLEMENTATION OPTIONAL !!!
534 
538 typedef struct
539 {
540  int8_t sda;
541  int8_t scl;
543 
558 void ssd1306_platform_i2cInit(int8_t busId, uint8_t addr, ssd1306_platform_i2cConfig_t * cfg);
559 
560 // !!! PLATFORM SPI IMPLEMENTATION OPTIONAL !!!
561 
578 void ssd1306_platform_spiInit(int8_t busId, int8_t cesPin, int8_t dcPin);
579 
580 #ifdef __cplusplus
581 }
582 #endif
583 
588 #endif
589 
590 
void lcd_randomSeed(int seed)
int lcd_gpioRead(int pin)
int8_t scl
clock pin
Definition: io.h:541
void attachInterrupt(int pin, void(*interrupt)(), int level)
void ssd1306_platform_spiInit(int8_t busId, int8_t cesPin, int8_t dcPin)
Initializes spi interface for platform being used.
Definition: avr_twi.h:36
void lcd_gpioWrite(int pin, int level)
uint32_t lcd_micros(void)
int lcdint_t
Definition: io.h:96
PlatformSpi(const SPlatformSpiConfig &config)
Definition: io.h:439
#define max(a, b)
Definition: canvas_types.h:47
uint8_t lcd_pgmReadByte(const void *ptr)
unsigned int lcduint_t
Definition: io.h:98
void lcd_eepromWriteWord(const void *ptr, uint16_t val)
void lcd_gpioMode(int pin, int mode)
void ssd1306_platform_i2cInit(int8_t busId, uint8_t addr, ssd1306_platform_i2cConfig_t *cfg)
Initializes i2c interface for platform being used.
void lcd_delayUs(unsigned long us)
int8_t sda
data pin
Definition: io.h:540
uint32_t frequency
Definition: interface.h:120
uint32_t lcd_millis(void)
int lcd_random(int max)
PlatformI2c(const SPlatformI2cConfig &config)
Definition: io.h:333
Definition: avr_spi.h:36
#define min(a, b)
Definition: canvas_types.h:42
uint16_t lcd_eepromReadWord(const void *ptr)
int lcd_adcRead(int pin)
void lcd_delay(unsigned long ms)