10a7ce71fSopenharmony_ci/*
20a7ce71fSopenharmony_ci * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
30a7ce71fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
40a7ce71fSopenharmony_ci * you may not use this file except in compliance with the License.
50a7ce71fSopenharmony_ci * You may obtain a copy of the License at
60a7ce71fSopenharmony_ci *
70a7ce71fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
80a7ce71fSopenharmony_ci *
90a7ce71fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
100a7ce71fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
110a7ce71fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
120a7ce71fSopenharmony_ci * See the License for the specific language governing permissions and
130a7ce71fSopenharmony_ci * limitations under the License.
140a7ce71fSopenharmony_ci */
150a7ce71fSopenharmony_ci
160a7ce71fSopenharmony_ci#ifndef SSD1306_OLED_H
170a7ce71fSopenharmony_ci#define SSD1306_OLED_H
180a7ce71fSopenharmony_ci
190a7ce71fSopenharmony_ci#define SEND_CMD_LEN    (8)
200a7ce71fSopenharmony_ci
210a7ce71fSopenharmony_ci#define OLED_X_POSITION_0    (0)
220a7ce71fSopenharmony_ci#define OLED_X_POSITION_15   (15)
230a7ce71fSopenharmony_ci#define OLED_X_POSITION_16   (16)
240a7ce71fSopenharmony_ci#define OLED_X_POSITION_18   (18)
250a7ce71fSopenharmony_ci#define OLED_X_POSITION_40   (40)
260a7ce71fSopenharmony_ci#define OLED_X_POSITION_48   (48)
270a7ce71fSopenharmony_ci#define OLED_X_POSITION_56   (56)
280a7ce71fSopenharmony_ci#define OLED_X_POSITION_60   (60)
290a7ce71fSopenharmony_ci#define OLED_X_POSITION_81   (81)
300a7ce71fSopenharmony_ci#define OLED_X_POSITION_120  (120)
310a7ce71fSopenharmony_ci
320a7ce71fSopenharmony_ci#define OLED_Y_POSITION_0     ((unsigned char)0x0)
330a7ce71fSopenharmony_ci#define OLED_Y_POSITION_1     ((unsigned char)0x1)
340a7ce71fSopenharmony_ci#define OLED_Y_POSITION_2     ((unsigned char)0x2)
350a7ce71fSopenharmony_ci#define OLED_Y_POSITION_3     ((unsigned char)0x3)
360a7ce71fSopenharmony_ci#define OLED_Y_POSITION_4     ((unsigned char)0x4)
370a7ce71fSopenharmony_ci#define OLED_Y_POSITION_5     ((unsigned char)0x5)
380a7ce71fSopenharmony_ci#define OLED_Y_POSITION_6     ((unsigned char)0x6)
390a7ce71fSopenharmony_ci#define OLED_Y_POSITION_7     ((unsigned char)0x7)
400a7ce71fSopenharmony_ci
410a7ce71fSopenharmony_ci#define OLED_DISPLAY_STRING_TYPE_1   (1)
420a7ce71fSopenharmony_ci#define OLED_DISPLAY_STRING_TYPE_16  (16)
430a7ce71fSopenharmony_ci
440a7ce71fSopenharmony_ci#define OLED_ADDRESS                0x78 // 默认地址为0x78
450a7ce71fSopenharmony_ci#define OLED_ADDRESS_WRITE_CMD      0x00 // 0000000 写命令
460a7ce71fSopenharmony_ci#define OLED_ADDRESS_WRITE_DATA     0x40 // 0100 0000(0x40)
470a7ce71fSopenharmony_ci#define HI_I2C_IDX_BAUDRATE         400000 // 400k
480a7ce71fSopenharmony_ci/* delay */
490a7ce71fSopenharmony_ci#define SLEEP_1_MS                  1
500a7ce71fSopenharmony_ci#define SLEEP_10_MS                 10
510a7ce71fSopenharmony_ci#define SLEEP_20_MS                 20
520a7ce71fSopenharmony_ci#define SLEEP_30_MS                 30
530a7ce71fSopenharmony_ci#define SLEEP_50_MS                 50
540a7ce71fSopenharmony_ci#define SLEEP_100_MS                100
550a7ce71fSopenharmony_ci#define SLEEP_1S                    1000
560a7ce71fSopenharmony_ci#define SLEEP_6_S                   6000
570a7ce71fSopenharmony_ci#define DELAY_5_MS                  5000
580a7ce71fSopenharmony_ci#define DELAY_10_MS                 10000
590a7ce71fSopenharmony_ci#define DELAY_100_MS                100000
600a7ce71fSopenharmony_ci#define DELAY_250_MS                250000
610a7ce71fSopenharmony_ci#define DELAY_500_MS                500000
620a7ce71fSopenharmony_ci#define DELAY_1_S                   1000000
630a7ce71fSopenharmony_ci#define DELAY_5_S                   5000000
640a7ce71fSopenharmony_ci#define DELAY_6_S                   6000000
650a7ce71fSopenharmony_ci#define DELAY_10_S                  10000000
660a7ce71fSopenharmony_ci#define DELAY_30_S                  30000000
670a7ce71fSopenharmony_ci#define DEFAULT_TYPE                ((hi_u8)0)
680a7ce71fSopenharmony_ci#define INIT_TIME_COUNT             ((hi_u8)1)
690a7ce71fSopenharmony_ci#define TIME_PERIOD_COUNT           10
700a7ce71fSopenharmony_ci/* pwm duty */
710a7ce71fSopenharmony_ci#define PWM_LOW_DUTY                1
720a7ce71fSopenharmony_ci#define PWM_SLOW_DUTY               1000
730a7ce71fSopenharmony_ci#define PWM_SMALL_DUTY              4000
740a7ce71fSopenharmony_ci#define PWM_LITTLE_DUTY             10000
750a7ce71fSopenharmony_ci#define PWM_DUTY                    50
760a7ce71fSopenharmony_ci#define PWM_MIDDLE_DUTY             40000
770a7ce71fSopenharmony_ci#define PWM_FULL_DUTY               65530
780a7ce71fSopenharmony_ci/* oled init */
790a7ce71fSopenharmony_ci#define OLED_CLEAN_SCREEN           ((hi_u8)0x00)
800a7ce71fSopenharmony_ci/* ssd1306 register cmd */
810a7ce71fSopenharmony_ci#define DISPLAY_OFF                 0xAE
820a7ce71fSopenharmony_ci#define SET_LOW_COLUMN_ADDRESS      0x00
830a7ce71fSopenharmony_ci#define SET_HIGH_COLUMN_ADDRESS     0x10
840a7ce71fSopenharmony_ci#define SET_START_LINE_ADDRESS      0x40
850a7ce71fSopenharmony_ci#define SET_PAGE_ADDRESS            0xB0
860a7ce71fSopenharmony_ci#define CONTRACT_CONTROL            0x81
870a7ce71fSopenharmony_ci#define FULL_SCREEN                 0xFF
880a7ce71fSopenharmony_ci#define SET_SEGMENT_REMAP           0xA1
890a7ce71fSopenharmony_ci#define NORMAL                      0xA6
900a7ce71fSopenharmony_ci#define SET_MULTIPLEX               0xA8
910a7ce71fSopenharmony_ci#define DUTY                        0x3F
920a7ce71fSopenharmony_ci#define SCAN_DIRECTION              0xC8
930a7ce71fSopenharmony_ci#define DISPLAY_OFFSET              0xD3
940a7ce71fSopenharmony_ci#define DISPLAY_TYPE                0x00
950a7ce71fSopenharmony_ci#define OSC_DIVISION                0xD5
960a7ce71fSopenharmony_ci#define DIVISION                    0x80
970a7ce71fSopenharmony_ci#define COLOR_MODE_OFF              0xD8
980a7ce71fSopenharmony_ci#define COLOR                       0x05
990a7ce71fSopenharmony_ci#define PRE_CHARGE_PERIOD           0xD9
1000a7ce71fSopenharmony_ci#define PERIOD                      0xF1
1010a7ce71fSopenharmony_ci#define PIN_CONFIGURATION           0xDA
1020a7ce71fSopenharmony_ci#define CONFIGURATION               0x12
1030a7ce71fSopenharmony_ci#define SET_VCOMH                   0xDB
1040a7ce71fSopenharmony_ci#define VCOMH                       0x30
1050a7ce71fSopenharmony_ci#define SET_CHARGE_PUMP_ENABLE      0x8D
1060a7ce71fSopenharmony_ci#define PUMP_ENABLE                 0x14
1070a7ce71fSopenharmony_ci#define TURN_ON_OLED_PANEL          0xAF
1080a7ce71fSopenharmony_ci
1090a7ce71fSopenharmony_ci#define IOT_IO_NAME_GPIO9            (9)
1100a7ce71fSopenharmony_ci#define IOT_GPIO_IDX_9               (9)
1110a7ce71fSopenharmony_ci
1120a7ce71fSopenharmony_citypedef struct {
1130a7ce71fSopenharmony_ci    /** Pointer to the buffer storing data to send */
1140a7ce71fSopenharmony_ci    unsigned char *sendBuf;
1150a7ce71fSopenharmony_ci    /** Length of data to send */
1160a7ce71fSopenharmony_ci    unsigned int  sendLen;
1170a7ce71fSopenharmony_ci    /** Pointer to the buffer for storing data to receive */
1180a7ce71fSopenharmony_ci    unsigned char *receiveBuf;
1190a7ce71fSopenharmony_ci    /** Length of data received */
1200a7ce71fSopenharmony_ci    unsigned int  receiveLen;
1210a7ce71fSopenharmony_ci} IotI2cData;
1220a7ce71fSopenharmony_ci
1230a7ce71fSopenharmony_citypedef enum {
1240a7ce71fSopenharmony_ci    IOT_I2C_IDX_0,
1250a7ce71fSopenharmony_ci    TOT_I2C_IDX_1,
1260a7ce71fSopenharmony_ci} IotI2cIdx;
1270a7ce71fSopenharmony_ci
1280a7ce71fSopenharmony_ciunsigned int OledInit(void);
1290a7ce71fSopenharmony_civoid OledSetPosition(unsigned char x, unsigned char y);
1300a7ce71fSopenharmony_civoid OledFillScreen(unsigned char fiiData);
1310a7ce71fSopenharmony_civoid OledShowChar(unsigned char x, unsigned char y, unsigned char chr, unsigned char charSize);
1320a7ce71fSopenharmony_civoid OledShowStr(unsigned char x, unsigned char y, unsigned char *chr, unsigned char charSize);
1330a7ce71fSopenharmony_ci#endif