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 #if defined(SSD1306_STM32_PLATFORM)
28
29 #include "intf/ssd1306_interface.h"
30 #include "stm32f1xx_hal.h"
31
32 // TODO: To add support. Any help is welcome
33
35 // !!! PLATFORM I2C IMPLEMENTATION OPTIONAL !!!
36 #if defined(CONFIG_PLATFORM_I2C_AVAILABLE) && defined(CONFIG_PLATFORM_I2C_ENABLE)
37 static uint8_t s_i2c_addr = 0x3C;
38
39 static void platform_i2c_start(void)
40 {
41 // ... Open i2c channel for your device with specific s_i2c_addr
42 }
43
44 static void platform_i2c_stop(void)
45 {
46 // ... Complete i2c communication
47 }
48
49 static void platform_i2c_send(uint8_t data)
50 {
51 // ... Send byte to i2c communication channel
52 }
53
54 static void platform_i2c_close(void)
55 {
56 // ... free all i2c resources here
57 }
58
59 static void platform_i2c_send_buffer(const uint8_t *data, uint16_t len)
60 {
61 // ... Send len bytes to i2c communication channel here
62 }
63
64 void ssd1306_platform_i2cInit(int8_t busId, uint8_t addr, ssd1306_platform_i2cConfig_t * cfg)
65 {
66 if (addr) s_i2c_addr = addr;
67 if (HAL_I2C_IsDeviceReady(&hi2c1, s_i2c_addr, 1, 20000) != HAL_OK)
68 {
69 return;
70 }
71 ssd1306_intf.spi = 0;
72 ssd1306_intf.start = &platform_i2c_start;
73 ssd1306_intf.stop = &platform_i2c_stop;
74 ssd1306_intf.send = &platform_i2c_send;
75 ssd1306_intf.close = &platform_i2c_close;
76 ssd1306_intf.send_buffer = &platform_i2c_send_buffer;
77 // init your interface here
78 //...
79 }
80 #endif
81
83 // !!! PLATFORM SPI IMPLEMENTATION OPTIONAL !!!
84 #if defined(CONFIG_PLATFORM_SPI_AVAILABLE) && defined(CONFIG_PLATFORM_SPI_ENABLE)
85
86 #include "intf/spi/ssd1306_spi.h"
87
88 static void platform_spi_start(void)
89 {
90 // ... Open spi channel for your device with specific s_ssd1306_cs, s_ssd1306_dc
91 }
92
93 static void platform_spi_stop(void)
94 {
95 // ... Complete spi communication
96 }
97
98 static void platform_spi_send(uint8_t data)
99 {
100 // ... Send byte to spi communication channel
101 }
102
103 static void platform_spi_close(void)
104 {
105 // ... free all spi resources here
106 }
107
108 static void platform_spi_send_buffer(const uint8_t *data, uint16_t len)
109 {
110 // ... Send len bytes to spi communication channel here
111 }
112
113 void ssd1306_platform_spiInit(int8_t busId,
114 int8_t cesPin,
115 int8_t dcPin)
116 {
117 if (cesPin>=0) s_ssd1306_cs = cesPin;
118 if (dcPin>=0) s_ssd1306_dc = dcPin;
119 ssd1306_intf.spi = 1;
120 ssd1306_intf.start = &platform_spi_start;
121 ssd1306_intf.stop = &platform_spi_stop;
122 ssd1306_intf.send = &platform_spi_send;
123 ssd1306_intf.close = &platform_spi_close;
124 ssd1306_intf.send_buffer = &platform_spi_send_buffer;
125 // init your interface here
126 //...
127 }
128 #endif
129
130 #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