LCDGFX LCD display driver  1.0.5
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-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 */
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 
47 #ifdef __cplusplus
48 #include "arduino/arduino_spi.h"
49 #include "arduino/arduino_wire.h"
50 #include "avr/spi_avr.h"
51 #include "avr/i2c_twi.h"
52 #include "avr/spi_usi.h"
53 #include "avr/i2c_embedded.h"
54 #include "esp/esp32_i2c.h"
55 #include "esp/esp32_spi.h"
56 #include "esp/esp8266_i2c.h"
57 #include "esp/esp8266_spi.h"
58 #endif
59 
60 #elif defined(__AVR__) && !defined(ARDUINO)
61 #include "avr/io.h"
62 #ifdef __cplusplus
63 #include "avr/spi_avr.h"
64 #include "avr/i2c_twi.h"
65 #include "avr/spi_usi.h"
66 #include "avr/i2c_embedded.h"
67 #endif
68 #elif defined(__XTENSA__) && !defined(ARDUINO)
69 #include "esp/io.h"
70 #ifdef __cplusplus
71 #include "esp/esp32_i2c.h"
72 #include "esp/esp32_spi.h"
73 #include "esp/esp8266_i2c.h"
74 #include "esp/esp8266_spi.h"
75 #endif
76 #elif defined(STM32F1) || defined(STM32F2) || defined(STM32F4)
77 #include "stm32/io.h"
78 #elif defined(__linux__) || defined(__APPLE__)
79 #include "linux/io.h"
80 #ifdef __cplusplus
81 #include "linux/linux_i2c.h"
82 #include "linux/linux_spi.h"
83 #include "linux/sdl_i2c.h"
84 #include "linux/sdl_spi.h"
85 #endif
86 #elif defined(__MINGW32__)
87 #include "mingw/io.h"
88 #ifdef __cplusplus
89 #include "linux/sdl_i2c.h"
90 #include "linux/sdl_spi.h"
91 #endif
92 #else
93 #warning "Platform is not supported. Use template to add support"
94 #endif
95 
96 #include <stdint.h>
97 
98 #ifndef LCDINT_TYPES_DEFINED
99 
100 #define LCDINT_TYPES_DEFINED
101 
102 typedef int lcdint_t;
104 typedef unsigned int lcduint_t;
105 #endif
106 
108 #define ssd1306_swap_data(a, b, type) { type t = a; a = b; b = t; }
109 
111 // HAL Layer functions
113 
114 #ifndef DOXYGEN_SHOULD_SKIP_THIS
115 #define ARDUINO_COMPAT
116 #endif
117 
118 #if defined(ARDUINO)
119 
120 #define LCD_LOW LOW
121 #define LCD_HIGH HIGH
122 #define LCD_GPIO_INPUT INPUT
123 #define LCD_GPIO_OUTPUT OUTPUT
124 #define LCD_PROGMEM PROGMEM
125 
126 #define lcd_gpioRead digitalRead
127 #define lcd_gpioMode pinMode
128 #define lcd_adcRead analogRead
129 
130 #ifdef __cplusplus
131 extern "C" {
132 #endif
133 
134 #ifndef DOXYGEN_SHOULD_SKIP_THIS
135 void lcd_registerGpioEvent(int pin, void (*on_pin_change)(void *), void *arg);
136 void lcd_unregisterGpioEvent(int pin);
137 #endif
138 
139 void lcd_gpioWrite(int pin, int level);
140 
141 #ifdef __cplusplus
142 }
143 #endif
144 
145 
146 #define lcd_pgmReadByte pgm_read_byte
147 #define lcd_eepromReadWord eeprom_read_word
148 #define lcd_eepromWriteWord eeprom_write_word
149 
150 #define lcd_millis millis
151 #define lcd_micros micros
152 #define lcd_delay delay
153 #define lcd_delayUs delayMicroseconds
154 
155 #define lcd_random random
156 #define lcd_randomSeed randomSeed
157 
158 #else
159 
161 #define LCD_LOW 0
162 
163 #define LCD_HIGH 1
164 
165 #define LCD_GPIO_INPUT 0
166 
167 #define LCD_GPIO_OUTPUT 1
168 // LCD_PROMEM is platform specific definition
169 #ifndef LCD_PROGMEM
170 
171 #define LCD_PROGMEM PROGMEM
172 #endif
173 
174 #ifdef __cplusplus
175 extern "C" {
176 #endif
177 
183 void lcd_gpioMode(int pin, int mode);
184 
190 int lcd_gpioRead(int pin);
191 
197 void lcd_gpioWrite(int pin, int level);
198 
199 #ifndef DOXYGEN_SHOULD_SKIP_THIS
200 void lcd_registerGpioEvent(int pin, void (*on_pin_change)(void *), void *arg);
201 void lcd_unregisterGpioEvent(int pin);
202 #endif
203 
210 int lcd_adcRead(int pin);
211 
215 uint32_t lcd_millis(void);
216 
220 uint32_t lcd_micros(void);
221 
226 void lcd_randomSeed(int seed);
227 
234 void attachInterrupt(int pin, void (*interrupt)(), int level);
235 
240 void lcd_delay(unsigned long ms);
241 
246 void lcd_delayUs(unsigned long us);
247 
254 uint8_t lcd_pgmReadByte(const void *ptr);
255 
261 uint16_t lcd_eepromReadWord(const void *ptr);
262 
268 void lcd_eepromWriteWord(const void *ptr, uint16_t val);
269 
270 #ifdef __cplusplus
271 }
272 #endif
273 
274 #ifdef __cplusplus
275 
280 int lcd_random(int max);
281 
287 int lcd_random(int min, int max);
288 #endif
289 
290 #ifdef ARDUINO_COMPAT
291 
292 #define LOW LCD_LOW
293 
294 #define HIGH LCD_HIGH
295 
296 #define INPUT LCD_GPIO_INPUT
297 
298 #define OUTPUT LCD_GPIO_OUTPUT
299 #ifndef PROGMEM
300 
301 #define PROGMEM LCD_PROGMEM
302 #endif
303 
305 #define digitalRead lcd_gpioRead
306 
307 #define digitalWrite lcd_gpioWrite
308 
309 #define pinMode lcd_gpioMode
310 
311 #define analogRead lcd_adcRead
312 
313 #if !defined(__AVR__)
314 
315 #define pgm_read_byte lcd_pgmReadByte
316 
317 #define eeprom_read_word lcd_eepromReadWord
318 
319 #define eeprom_write_word lcd_eepromWriteWord
320 #endif
321 
323 #define millis lcd_millis
324 
325 #define micros lcd_micros
326 
327 #define delay lcd_delay
328 
329 #define delayMicroseconds lcd_delayUs
330 
332 #define random lcd_random
333 
334 #define randomSeed lcd_randomSeed
335 
336 #endif
337 
338 #endif
339 
340 
341 
342 #ifdef __cplusplus
343 
345 // I2C PLATFORM
347 
348 #if defined(CONFIG_ARDUINO_I2C_AVAILABLE) && defined(CONFIG_ARDUINO_I2C_ENABLE)
349 
352 class PlatformI2c: public ArduinoI2c
353 {
354 public:
360  : ArduinoI2c(config.scl, config.sda, config.addr) {}
361 };
362 
363 #elif defined(CONFIG_TWI_I2C_AVAILABLE) && defined(CONFIG_TWI_I2C_ENABLE)
364 
368 class PlatformI2c: public TwiI2c
369 {
370 public:
375  PlatformI2c(const SPlatformI2cConfig &config)
376  : TwiI2c(config.addr) {}
377 };
378 
379 #elif defined(CONFIG_LINUX_I2C_AVAILABLE) && defined(CONFIG_LINUX_I2C_ENABLE)
380 
381 #if defined(SDL_EMULATION)
382 
385 class PlatformI2c: public SdlI2c
386 {
387 public:
392  PlatformI2c(const SPlatformI2cConfig &config)
393  : SdlI2c(config.scl, config.sda, config.addr) {}
394 };
395 #else
396 
399 class PlatformI2c: public LinuxI2c
400 {
401 public:
406  PlatformI2c(const SPlatformI2cConfig &config)
407  : LinuxI2c( config.busId, config.addr ) {}
408 };
409 #endif
410 
411 #elif defined(CONFIG_ESP32_I2C_AVAILABLE) && defined(CONFIG_ESP32_I2C_ENABLE)
412 
416 class PlatformI2c: public EspI2c
417 {
418 public:
423  PlatformI2c(const SPlatformI2cConfig &config)
424  : EspI2c( config.busId, config.addr, config.scl, config.sda, 400000) {}
425 };
426 
427 #elif defined(CONFIG_ESP8266_I2C_AVAILABLE) && defined(CONFIG_ESP8266_I2C_ENABLE)
428 
432 class PlatformI2c: public EspI2c
433 {
434 public:
439  PlatformI2c(const SPlatformI2cConfig &config)
440  : EspI2c( config.busId, config.addr, config.scl, config.sda, 400000) {}
441 };
442 
443 #elif defined(CONFIG_SOFTWARE_I2C_AVAILABLE) && defined(CONFIG_SOFTWARE_I2C_ENABLE)
444 
448 class PlatformI2c: public SoftwareI2c
449 {
450 public:
455  PlatformI2c(const SPlatformI2cConfig &config)
456  : SoftwareI2c(config.scl, config.sda, config.addr) {}
457 };
458 
459 #else
460 
461 #error "Platform not supported"
462 
463 #endif
464 
466 // SPI PLATFORM
468 
469 #if defined(CONFIG_AVR_SPI_AVAILABLE) && defined(CONFIG_AVR_SPI_ENABLE)
470 
474 class PlatformSpi: public AvrSpi
475 {
476 public:
482  : AvrSpi( config.cs, config.dc, config.frequency ) {}
483 };
484 
485 #elif defined(CONFIG_ARDUINO_SPI_AVAILABLE) && defined(CONFIG_ARDUINO_SPI_ENABLE)
486 
490 class PlatformSpi: public ArduinoSpi
491 {
492 public:
497  PlatformSpi(const SPlatformSpiConfig &config)
498  : ArduinoSpi(config.cs, config.dc, config.frequency) {}
499 };
500 
501 #elif defined(CONFIG_LINUX_SPI_AVAILABLE) && defined(CONFIG_LINUX_SPI_ENABLE)
502 
503 #if defined(SDL_EMULATION)
504 
507 class PlatformSpi: public SdlSpi
508 {
509 public:
514  PlatformSpi(const SPlatformSpiConfig &config)
515  : SdlSpi(config.dc) {}
516 };
517 #else
518 
521 class PlatformSpi: public LinuxSpi
522 {
523 public:
528  PlatformSpi(const SPlatformSpiConfig &config)
529  : LinuxSpi( config.busId, config.devId, config.dc, config.frequency ) {}
530 };
531 #endif
532 
533 #elif defined(CONFIG_ESP32_SPI_AVAILABLE) && defined(CONFIG_ESP32_SPI_ENABLE)
534 
537 class PlatformSpi: public EspSpi
538 {
539 public:
544  PlatformSpi(const SPlatformSpiConfig &config)
545  : EspSpi( config.busId, config.cs, config.dc, config.scl, config.sda, config.frequency ) {}
546 };
547 
548 #elif defined(CONFIG_ESP8266_SPI_AVAILABLE) && defined(CONFIG_ESP8266_SPI_ENABLE)
549 
552 class PlatformSpi: public EspSpi
553 {
554 public:
559  PlatformSpi(const SPlatformSpiConfig &config)
560  : EspSpi( config.busId, config.cs, config.dc, config.scl, config.sda, config.frequency ) {}
561 };
562 
563 #elif defined(CONFIG_USI_SPI_AVAILABLE) && defined(CONFIG_USI_SPI_ENABLE)
564 
568 class PlatformSpi: public UsiSpi
569 {
570 public:
575  PlatformSpi(const SPlatformSpiConfig &config)
576  : UsiSpi( config.cs, config.dc ) {}
577 };
578 
579 #else
580 
581 #error "Platform not supported"
582 
583 #endif
584 
585 #include "custom_interface.h"
586 
587 #endif
588 
593 #endif
594 
595 
void lcd_randomSeed(int seed)
int lcd_gpioRead(int pin)
void attachInterrupt(int pin, void(*interrupt)(), int level)
Definition: i2c_twi.h:36
void lcd_gpioWrite(int pin, int level)
uint32_t lcd_micros(void)
int lcdint_t
Definition: io.h:102
PlatformSpi(const SPlatformSpiConfig &config)
Definition: io.h:481
#define max(a, b)
Definition: canvas_types.h:47
uint8_t lcd_pgmReadByte(const void *ptr)
unsigned int lcduint_t
Definition: io.h:104
void lcd_eepromWriteWord(const void *ptr, uint16_t val)
void lcd_gpioMode(int pin, int mode)
Definition: spi_usi.h:41
void lcd_delayUs(unsigned long us)
uint32_t frequency
Definition: interface.h:107
uint32_t lcd_millis(void)
int lcd_random(int max)
PlatformI2c(const SPlatformI2cConfig &config)
Definition: io.h:359
Definition: spi_avr.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)