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#include <hi_types_base.h> 200a7ce71fSopenharmony_ci#include <hi_i2c.h> 210a7ce71fSopenharmony_ci 220a7ce71fSopenharmony_ci#define OLED_ADDRESS 0x78 // 默认地址为0x78 230a7ce71fSopenharmony_ci#define OLED_ADDRESS_WRITE_CMD 0x00 // 0000000 写命令 240a7ce71fSopenharmony_ci#define OLED_ADDRESS_WRITE_DATA 0x40 // 0100 0000(0x40) 250a7ce71fSopenharmony_ci#define HI_I2C_IDX_BAUDRATE 400000 // 400k 260a7ce71fSopenharmony_ci/* delay */ 270a7ce71fSopenharmony_ci#define SLEEP_1_MS 1 280a7ce71fSopenharmony_ci#define SLEEP_10_MS 10 290a7ce71fSopenharmony_ci#define SLEEP_20_MS 20 300a7ce71fSopenharmony_ci#define SLEEP_30_MS 30 310a7ce71fSopenharmony_ci#define SLEEP_50_MS 50 320a7ce71fSopenharmony_ci#define SLEEP_100_MS 100 330a7ce71fSopenharmony_ci#define SLEEP_1S 1000 340a7ce71fSopenharmony_ci#define SLEEP_6_S 6000 350a7ce71fSopenharmony_ci#define DELAY_5_MS 5000 360a7ce71fSopenharmony_ci#define DELAY_10_MS 10000 370a7ce71fSopenharmony_ci#define DELAY_100_MS 100000 380a7ce71fSopenharmony_ci#define DELAY_250_MS 250000 390a7ce71fSopenharmony_ci#define DELAY_500_MS 500000 400a7ce71fSopenharmony_ci#define DELAY_1_S 1000000 410a7ce71fSopenharmony_ci#define DELAY_5_S 5000000 420a7ce71fSopenharmony_ci#define DELAY_6_S 6000000 430a7ce71fSopenharmony_ci#define DELAY_10_S 10000000 440a7ce71fSopenharmony_ci#define DELAY_30_S 30000000 450a7ce71fSopenharmony_ci#define DEFAULT_TYPE ((hi_u8)0) 460a7ce71fSopenharmony_ci#define INIT_TIME_COUNT ((hi_u8)1) 470a7ce71fSopenharmony_ci#define TIME_PERIOD_COUNT 10 480a7ce71fSopenharmony_ci/* pwm duty */ 490a7ce71fSopenharmony_ci#define PWM_LOW_DUTY 1 500a7ce71fSopenharmony_ci#define PWM_SLOW_DUTY 1000 510a7ce71fSopenharmony_ci#define PWM_SMALL_DUTY 4000 520a7ce71fSopenharmony_ci#define PWM_LITTLE_DUTY 10000 530a7ce71fSopenharmony_ci#define PWM_DUTY 20000 540a7ce71fSopenharmony_ci#define PWM_MIDDLE_DUTY 40000 550a7ce71fSopenharmony_ci#define PWM_FULL_DUTY 65530 560a7ce71fSopenharmony_ci/* oled init */ 570a7ce71fSopenharmony_ci#define OLED_CLEAN_SCREEN ((hi_u8)0x00) 580a7ce71fSopenharmony_ci/* ssd1306 register cmd */ 590a7ce71fSopenharmony_ci#define DISPLAY_OFF 0xAE 600a7ce71fSopenharmony_ci#define SET_LOW_COLUMN_ADDRESS 0x00 610a7ce71fSopenharmony_ci#define SET_HIGH_COLUMN_ADDRESS 0x10 620a7ce71fSopenharmony_ci#define SET_START_LINE_ADDRESS 0x40 630a7ce71fSopenharmony_ci#define SET_PAGE_ADDRESS 0xB0 640a7ce71fSopenharmony_ci#define CONTRACT_CONTROL 0x81 650a7ce71fSopenharmony_ci#define FULL_SCREEN 0xFF 660a7ce71fSopenharmony_ci#define SET_SEGMENT_REMAP 0xA1 670a7ce71fSopenharmony_ci#define NORMAL 0xA6 680a7ce71fSopenharmony_ci#define SET_MULTIPLEX 0xA8 690a7ce71fSopenharmony_ci#define DUTY 0x3F 700a7ce71fSopenharmony_ci#define SCAN_DIRECTION 0xC8 710a7ce71fSopenharmony_ci#define DISPLAY_OFFSET 0xD3 720a7ce71fSopenharmony_ci#define DISPLAY_TYPE 0x00 730a7ce71fSopenharmony_ci#define OSC_DIVISION 0xD5 740a7ce71fSopenharmony_ci#define DIVISION 0x80 750a7ce71fSopenharmony_ci#define COLOR_MODE_OFF 0xD8 760a7ce71fSopenharmony_ci#define COLOR 0x05 770a7ce71fSopenharmony_ci#define PRE_CHARGE_PERIOD 0xD9 780a7ce71fSopenharmony_ci#define PERIOD 0xF1 790a7ce71fSopenharmony_ci#define PIN_CONFIGURATION 0xDA 800a7ce71fSopenharmony_ci#define CONFIGURATION 0x12 810a7ce71fSopenharmony_ci#define SET_VCOMH 0xDB 820a7ce71fSopenharmony_ci#define VCOMH 0x30 830a7ce71fSopenharmony_ci#define SET_CHARGE_PUMP_ENABLE 0x8D 840a7ce71fSopenharmony_ci#define PUMP_ENABLE 0x14 850a7ce71fSopenharmony_ci#define TURN_ON_OLED_PANEL 0xAF 860a7ce71fSopenharmony_ci 870a7ce71fSopenharmony_ci#define IOT_IO_NAME_GPIO9 (9) 880a7ce71fSopenharmony_ci#define IOT_GPIO_IDX_9 (9) 890a7ce71fSopenharmony_ci 900a7ce71fSopenharmony_citypedef struct { 910a7ce71fSopenharmony_ci /* Pointer to the buffer storing data to send */ 920a7ce71fSopenharmony_ci unsigned char *sendBuf; 930a7ce71fSopenharmony_ci /* Length of data to send */ 940a7ce71fSopenharmony_ci unsigned int sendLen; 950a7ce71fSopenharmony_ci /* Pointer to the buffer for storing data to receive */ 960a7ce71fSopenharmony_ci unsigned char *receiveBuf; 970a7ce71fSopenharmony_ci /* Length of data received */ 980a7ce71fSopenharmony_ci unsigned int receiveLen; 990a7ce71fSopenharmony_ci} IotI2cData; 1000a7ce71fSopenharmony_ci 1010a7ce71fSopenharmony_citypedef enum { 1020a7ce71fSopenharmony_ci IOT_I2C_IDX_0, 1030a7ce71fSopenharmony_ci TOT_I2C_IDX_1, 1040a7ce71fSopenharmony_ci} IotI2cIdx; 1050a7ce71fSopenharmony_ci 1060a7ce71fSopenharmony_ci 1070a7ce71fSopenharmony_cistatic unsigned int I2cWriteByte(unsigned char regAddr, unsigned char cmd); 1080a7ce71fSopenharmony_cistatic unsigned int WriteCmd(unsigned char cmd); 1090a7ce71fSopenharmony_cistatic unsigned int WriteData(unsigned char i2cData); 1100a7ce71fSopenharmony_ciunsigned int OledInit(void); 1110a7ce71fSopenharmony_civoid OledSetPosition(unsigned char x, unsigned char y); 1120a7ce71fSopenharmony_civoid OledFillScreen(unsigned char fiiData); 1130a7ce71fSopenharmony_civoid OledShowChar(unsigned char x, unsigned char y, unsigned char chr, unsigned char charSize); 1140a7ce71fSopenharmony_civoid OledShowStr(unsigned char x, unsigned char y, unsigned char *chr, unsigned char charSize); 1150a7ce71fSopenharmony_ci#endif