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

platform.c
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 #include "ssd1306_hal/io.h"
26
27 // TODO: DON'T FORGET ADD YOUR PLATFORM FILE TO MAKEFILE
28
29 #if defined(YOUR_PLATFORM)
30
31 #include "intf/ssd1306_interface.h"
33 // !!! PLATFORM I2C IMPLEMENTATION OPTIONAL !!!
34 #if defined(CONFIG_PLATFORM_I2C_AVAILABLE) && defined(CONFIG_PLATFORM_I2C_ENABLE)
35 static uint8_t s_i2c_addr = 0x3C;
36
37 static void platform_i2c_start(void)
38 {
39 // ... Open i2c channel for your device with specific s_i2c_addr
40 }
41
42 static void platform_i2c_stop(void)
43 {
44 // ... Complete i2c communication
45 }
46
47 static void platform_i2c_send(uint8_t data)
48 {
49 // ... Send byte to i2c communication channel
50 }
51
52 static void platform_i2c_close(void)
53 {
54 // ... free all i2c resources here
55 }
56
57 static void platform_i2c_send_buffer(const uint8_t *data, uint16_t len)
58 {
59 // ... Send len bytes to i2c communication channel here
60 }
61
62 void ssd1306_platform_i2cInit(int8_t busId, uint8_t addr, ssd1306_platform_i2cConfig_t * cfg)
63 {
64 if (addr) s_i2c_addr = addr;
65 ssd1306_intf.spi = 0;
66 ssd1306_intf.start = &platform_i2c_start;
67 ssd1306_intf.stop = &platform_i2c_stop;
68 ssd1306_intf.send = &platform_i2c_send;
69 ssd1306_intf.close = &platform_i2c_close;
70 ssd1306_intf.send_buffer = &platform_i2c_send_buffer;
71 // init your interface here
72 //...
73 }
74 #endif
75
77 // !!! PLATFORM SPI IMPLEMENTATION OPTIONAL !!!
78 #if defined(CONFIG_PLATFORM_SPI_AVAILABLE) && defined(CONFIG_PLATFORM_SPI_ENABLE)
79
80 #include "intf/spi/ssd1306_spi.h"
81
82 static void platform_spi_start(void)
83 {
84 // ... Open spi channel for your device with specific s_ssd1306_cs, s_ssd1306_dc
85 }
86
87 static void platform_spi_stop(void)
88 {
89 // ... Complete spi communication
90 }
91
92 static void platform_spi_send(uint8_t data)
93 {
94 // ... Send byte to spi communication channel
95 }
96
97 static void platform_spi_close(void)
98 {
99 // ... free all spi resources here
100 }
101
102 static void platform_spi_send_buffer(const uint8_t *data, uint16_t len)
103 {
104 // ... Send len bytes to spi communication channel here
105 }
106
107 void ssd1306_platform_spiInit(int8_t busId,
108 int8_t cesPin,
109 int8_t dcPin)
110 {
111 if (cesPin>=0) s_ssd1306_cs = cesPin;
112 if (dcPin>=0) s_ssd1306_dc = dcPin;
113 ssd1306_intf.spi = 1;
114 ssd1306_intf.start = &platform_spi_start;
115 ssd1306_intf.stop = &platform_spi_stop;
116 ssd1306_intf.send = &platform_spi_send;
117 ssd1306_intf.close = &platform_spi_close;
118 ssd1306_intf.send_buffer = &platform_spi_send_buffer;
119 // init your interface here
120 //...
121 }
122 #endif
123
124 #endif // YOUR_PLATFORM
s_ssd1306_dc
int8_t s_ssd1306_dc
Definition: ssd1306_spi.c:34
ssd1306_platform_i2cConfig_t
Definition: io.h:80
ssd1306_platform_spiInit
void ssd1306_platform_spiInit(int8_t busId, int8_t cesPin, int8_t dcPin)
Initializes spi interface for platform being used.
ssd1306_interface_t::send
void(* send)(uint8_t data)
Definition: ssd1306_interface.h:70
ssd1306_interface_t::stop
void(* stop)(void)
Definition: ssd1306_interface.h:65
io.h
ssd1306_platform_i2cInit
void ssd1306_platform_i2cInit(int8_t busId, uint8_t addr, ssd1306_platform_i2cConfig_t *cfg)
Initializes i2c interface for platform being used.
ssd1306_spi.h
ssd1306_interface_t::start
void(* start)(void)
Definition: ssd1306_interface.h:61
ssd1306_interface_t::close
void(* close)(void)
deinitializes internal resources, allocated for interface.
Definition: ssd1306_interface.h:88
ssd1306_intf
ssd1306_interface_t ssd1306_intf
Definition: ssd1306_interface.c:31
ssd1306_interface.h
ssd1306_interface_t::spi
uint8_t spi
Definition: ssd1306_interface.h:57
ssd1306_interface_t::send_buffer
void(* send_buffer)(const uint8_t *buffer, uint16_t size)
Sends bytes to SSD1306 device.
Definition: ssd1306_interface.h:80
s_ssd1306_cs
int8_t s_ssd1306_cs
Definition: ssd1306_spi.c:33