SSD1306 OLED display driver 1.7.8 This library is developed to control SSD1306/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays

io.h
1 /*
2 MIT License
3
4 Copyright (c) 2018, 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 /*
26 * @file ssd1306_hal/template/io.h This is template file for new platform with detailed instructions
27 */
28
29 #ifndef _SSD1306_YOUR_PLATFORM_IO_H_
30 #define _SSD1306_YOUR_PLATFORM_IO_H_
31
32 //========================== I. Create directory for your platform ========
33 /* 1. Copy content of this folder to src/ssd1306_hal/<your_platform>/ folder */
34 /* 2. Replace YOUR_PLATFORM in these files with the one, you would like to use */
35 /* 3. Add #include "<your_platform>/io.h" to src/ssd1306_hal/io.h file */
36 /* (remember to add required #elif defined(X) lines) */
37 /* 4. Add platform.c file to SOURCES list in src/Makefile.src */
38 /* 5. Implement functions below and functions in platform.c file */
39
40 #define YOUR_PLATFORM
41 //========================== I. Include libraries =========================
42 /* 1. Include all required headers, specific for your platform here */
43 #include <stdint.h>
44 #include <stdlib.h>
45 #include <string.h>
46
47 /* If your platform already has these definitions, comment out lines below */
48 #define LOW 0
49 #define HIGH 1
50 #define INPUT 0
51 #define OUTPUT 1
52 /* Progmem attribute for data, located in Flash */
53 #define PROGMEM
54
55 //========================== II. Define options ===========================
56 /* 2. Uncomment all options, you have support for on your platform *
57 * Remember that you will need to implement low level intf/i2c or *
58 * intf/spi layers for your platform */
59
60 //#define CONFIG_SOFTWARE_I2C_AVAILABLE
61 //#define CONFIG_TWI_I2C_AVAILABLE
62 //#define CONFIG_AVR_SPI_AVAILABLE
63 //#define CONFIG_AVR_UART_AVAILABLE
64 //#define CONFIG_VGA_AVAILABLE
65 //#define CONFIG_PLATFORM_I2C_AVAILABLE
66 //#define CONFIG_PLATFORM_SPI_AVAILABLE
67
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71
72 //========================== III. Implement functions =====================
73 /* Implement functions below the way you like. You can make them non-static
74 * and implement the functions in platform.c file
75 */
76 // !!! MANDATORY. The library will not work without these functions !!!
77 static inline int digitalRead(int pin) // digitalRead()
78 {
79 return LOW;
80 }
81
82 static inline void digitalWrite(int pin, int level) // digitalWrite()
83 {
84 }
85
86 static inline void pinMode(int pin, int mode) // pinMode()
87 {
88 }
89
90 static inline int analogRead(int pin) // analogRead()
91 {
92 return 0;
93 }
94
95 static inline uint32_t millis(void) // millis()
96 {
97 return 0;
98 }
99
100 static inline uint32_t micros(void) // micros()
101 {
102 return 0;
103 };
104
105 static inline void delay(uint32_t ms) // delay()
106 {
107 }
108
109 static inline void delayMicroseconds(uint32_t us) // delayMicroseconds()
110 {
111 }
112
113 // !!! OPTIONAL !!!
114 static inline void randomSeed(int seed) // randomSeed() - can be skipped
115 {
116 }
117
118 static inline void attachInterrupt(int pin, void (*interrupt)(), int level) // attachInterrupt() - can be skipped
119 {
120 }
121
122 static inline uint8_t pgm_read_byte(const void *ptr) // pgm_read_byte() - can be left as is
123 {
124 return *((const uint8_t *)ptr);
125 }
126
127 static inline uint16_t eeprom_read_word(const void *ptr) // eeprom_read_word() - can be skipped
128 {
129 return 0;
130 }
131
132 static inline void eeprom_write_word(const void *ptr, uint16_t val) // eeprom_write_word() - can be skipped
133 {
134 }
135
136 static inline char *utoa(unsigned int num, char *str, int radix) // util utoa() - can be skipped
137 {
138 *str = '\0';
139 return str;
140 }
141
142
143 // !!! PLATFORM I2C IMPLEMENTATION OPTIONAL !!!
144 #if defined(CONFIG_PLATFORM_I2C_AVAILABLE) && defined(CONFIG_PLATFORM_I2C_ENABLE)
145 void ssd1306_platform_i2cInit(int8_t busId, uint8_t addr, int8_t arg);
146 #endif
147
148
149 // !!! PLATFORM SPI IMPLEMENTATION OPTIONAL !!!
150 #if defined(CONFIG_PLATFORM_SPI_AVAILABLE) && defined(CONFIG_PLATFORM_SPI_ENABLE)
151 void ssd1306_platform_spiInit(uint8_t busId,
152 uint8_t cesPin,
153 uint8_t dcPin);
154 #endif
155
156 #ifdef __cplusplus
157 }
158 #endif
159
160 #ifdef __cplusplus
161 static inline int random(int max) // random(n) - can be skipped if you don't use it
162 {
163 return 0;
164 }
165
166 static inline int random(int min, int max) // random(a,b) - can be skipped if you don't use it
167 {
168 return 0;
169 }
170 #endif
171
172 #endif
173
ssd1306_platform_i2cInit
void ssd1306_platform_i2cInit(int8_t busId, uint8_t addr, int8_t arg)
Initializes i2c interface for platform being used.
ssd1306_platform_spiInit
void ssd1306_platform_spiInit(int8_t busId, int8_t cesPin, int8_t dcPin)
Initializes spi interface for platform being used.
max
#define max(a, b)
Definition: nano_gfx_types.h:40
min
#define min(a, b)
Definition: nano_gfx_types.h:35