2 * Copyright (c) 2019 G.camp,
4 * Contact: Jin Seog Bang <seog814@gmail.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #include <peripheral_io.h>
24 #define SSD1306_ADDR 0x03c /* Address of SSD1306 OLED */
28 peripheral_i2c_h sensor_h;
31 void resource_close_OLED(void)
33 if (!resource_sensor_s1.opened)
36 _I("OLED display is finishing...");
37 peripheral_i2c_close(resource_sensor_s1.sensor_h);
38 resource_sensor_s1.opened = 0;
41 int resource_OLED_initial(int i2c_bus)
43 int ret = PERIPHERAL_ERROR_NONE;
45 unsigned char buff_count ;
46 unsigned char page_count;
47 unsigned char buf[10] = { 0, };
48 unsigned char tcbuf[10] = { 0, };
49 unsigned char tmbuf[30] = { 0xae, 0xd5, 0x80, 0xa8, 0x3f,
50 0xd3, 0x00, 0x40, 0x8d, 0x14,
51 0x20, 0x00, 0xda, 0x12, 0x81,
52 0x9f, 0xd9, 0x22, 0xdb, 0x40,
55 if (!resource_sensor_s1.opened) {
57 ret = peripheral_i2c_open(i2c_bus, SSD1306_ADDR, &resource_sensor_s1.sensor_h);
58 if (ret != PERIPHERAL_ERROR_NONE) {
59 _E("i2c open error OLED1 : %s", get_error_message(ret));
63 resource_sensor_s1.opened = 1;
67 // buf[0] = 0x00; // OLED control command
68 // buf[1] = 0xae; // OLED command
71 for (buff_count = 0; buff_count < 24; buff_count++)
75 buf[1] = tmbuf[buff_count];
77 ret = peripheral_i2c_write(resource_sensor_s1.sensor_h, buf, 2);
78 if (ret != PERIPHERAL_ERROR_NONE) {
79 _E("i2c write error OLED : %s", get_error_message(ret));
82 write = 0; //write = 1;???
85 _I("iic OLED control initial .. step ");
92 for (buff_count = 0; buff_count < 2; buff_count++)
96 buf[1] = tcbuf[buff_count];
97 ret = peripheral_i2c_write(resource_sensor_s1.sensor_h, buf, 2);
98 if (ret != PERIPHERAL_ERROR_NONE) {
99 _E("i2c write error OLED 1: %s", get_error_message(ret));
103 write = 0; //write = 1;???
107 _I("iic OLED control pageaddr .. step ");
114 for (buff_count = 0; buff_count < 3; buff_count++)
118 buf[1] = tcbuf[buff_count];
119 ret = peripheral_i2c_write(resource_sensor_s1.sensor_h, buf, 2);
120 if (ret != PERIPHERAL_ERROR_NONE) {
121 _E("i2c write error OLED 2: %s", get_error_message(ret));
124 write = 0; //write = 1;???
128 _I("iic OLED control columnaddr .. step ");
135 for (buff_count = 0; buff_count < 3; buff_count++)
139 buf[1] = tcbuf[buff_count];
140 ret = peripheral_i2c_write(resource_sensor_s1.sensor_h, buf, 2);
141 if (ret != PERIPHERAL_ERROR_NONE) {
142 _E("i2c write error OLED 3: %s", get_error_message(ret));
145 write = 0; //write = 1;???
148 _I("iic OLED control pageaddr .. step ");
152 for (page_count = 0; page_count < 8; page_count ++)
154 tcbuf[0] = (0xb0 + page_count);
158 buf[1] = tcbuf[buff_count];
159 ret = peripheral_i2c_write(resource_sensor_s1.sensor_h, buf, 2);
160 if (ret != PERIPHERAL_ERROR_NONE) {
161 _E("i2c write error OLED 4: %s", get_error_message(ret));
164 write = 0; //write = 1;???
166 _I("iic OLED control pageaddr .. step ");
169 for (buff_count = 0; buff_count < 128; buff_count++)
175 ret = peripheral_i2c_write(resource_sensor_s1.sensor_h, buf, 2);
176 if (ret != PERIPHERAL_ERROR_NONE) {
177 _E("i2c write error OLED 5 : %s", get_error_message(ret));
180 write = 0; //write = 1;???
182 _I("iic OLED data .. step ");
191 int resource_OLED_disp_logo(int i2c_bus)
193 int ret = PERIPHERAL_ERROR_NONE;
194 static int write = 0;
195 unsigned char buff_count ;
196 unsigned char page_count;
197 unsigned char buf[10] = { 0, };
198 unsigned char tcbuf[10] = { 0, };
199 unsigned char font_G_l[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
200 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
201 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
203 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
204 0x00, 0x1f, 0x20, 0x20, 0x20, 0x20, 0x1f, 0x00, // G font
205 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, // - font
206 0x00, 0x1f, 0x20, 0x20, 0x20, 0x20, 0x10, 0x00, // C font
207 0x00, 0x3f, 0x01, 0x01, 0x01, 0x01, 0x3f, 0x00, // A font
208 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, // M font
209 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // P font
210 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
211 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
212 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
214 unsigned char font_G_h[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
215 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
216 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
217 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
219 0x00, 0xf8, 0x04, 0x04, 0x84, 0x84, 0x88, 0x00,
220 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00,
221 0x00, 0xf8, 0x04, 0x04, 0x04, 0x04, 0x08, 0x00,
222 0x00, 0xc0, 0x30, 0x0c, 0x0c, 0x30, 0xc0, 0x00,
223 0x00, 0xfc, 0x08, 0x70, 0x70, 0x08, 0xfc, 0x00,
224 0x00, 0xfc, 0x84, 0x84, 0x84, 0x84, 0x78, 0x00,
225 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
226 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
227 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
228 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
230 // resource_write_led(5, 1);
236 for (buff_count = 0; buff_count < 3; buff_count++)
240 buf[1] = tcbuf[buff_count];
241 ret = peripheral_i2c_write(resource_sensor_s1.sensor_h, buf, 2);
242 if (ret != PERIPHERAL_ERROR_NONE) {
243 _E("i2c write error OLED 2: %s", get_error_message(ret));
246 write = 0; //write = 1;???
249 _I("iic OLED control columnaddr .. step ");
252 tcbuf[0] = (0xb0 + page_count);
256 buf[1] = tcbuf[buff_count];
257 ret = peripheral_i2c_write(resource_sensor_s1.sensor_h, buf, 2);
258 if (ret != PERIPHERAL_ERROR_NONE) {
259 _E("i2c write error OLED 6: %s", get_error_message(ret));
262 write = 0; //write = 1;???
264 _I("iic OLED logo disp high pageaddr .. step ");
267 for (buff_count = 0; buff_count < 135; buff_count++)
271 buf[1] = font_G_h[buff_count];
273 ret = peripheral_i2c_write(resource_sensor_s1.sensor_h, buf, 2);
274 if (ret != PERIPHERAL_ERROR_NONE) {
275 _E("i2c write error OLED 7 : %s", get_error_message(ret));
278 write = 0; //write = 1;???
280 _I("iic OLED logo font high data .. step ");
287 for (buff_count = 0; buff_count < 3; buff_count++)
291 buf[1] = tcbuf[buff_count];
292 ret = peripheral_i2c_write(resource_sensor_s1.sensor_h, buf, 2);
293 if (ret != PERIPHERAL_ERROR_NONE) {
294 _E("i2c write error OLED 2: %s", get_error_message(ret));
297 write = 0; //write = 1;???
300 _I("iic OLED control columnaddr .. step ");
303 tcbuf[0] = (0xb0 + page_count );
307 buf[1] = tcbuf[buff_count];
308 ret = peripheral_i2c_write(resource_sensor_s1.sensor_h, buf, 2);
309 if (ret != PERIPHERAL_ERROR_NONE) {
310 _E("i2c write error OLED 6: %s", get_error_message(ret));
313 write = 0; //write = 1;???
315 _I("iic OLED logo disp low pageaddr .. step ");
317 for (buff_count = 0; buff_count < 135; buff_count++)
321 buf[1] = font_G_l[buff_count];
323 ret = peripheral_i2c_write(resource_sensor_s1.sensor_h, buf, 2);
324 if (ret != PERIPHERAL_ERROR_NONE) {
325 _E("i2c write error OLED 7 : %s", get_error_message(ret));
328 write = 0; //write = 1;???
330 _I("iic OLED logo font high data .. step ");