81 lines
2.9 KiB
C
81 lines
2.9 KiB
C
#ifndef __SSD1306_OLED_H
|
|
#define __SSD1306_OLED_H
|
|
|
|
#include "main.h"
|
|
|
|
// OLED引脚定义
|
|
#define SSD1306_SDA_PORT OLED_SDA_GPIO_Port
|
|
#define SSD1306_SDA_PIN OLED_SDA_Pin
|
|
#define SSD1306_SCK_PORT OLDE_SCK_GPIO_Port
|
|
#define SSD1306_SCK_PIN OLDE_SCK_Pin
|
|
|
|
// I2C地址
|
|
#define SSD1306_I2C_ADDRESS 0x78
|
|
// OLED显示参数
|
|
#define SSD1306_WIDTH 128
|
|
#define SSD1306_HEIGHT 64
|
|
// OLED颜色
|
|
#define SSD1306_WHITE 1
|
|
#define SSD1306_BLACK 0
|
|
|
|
// OLED命令定义
|
|
#define SSD1306_CMD_DISPLAY_OFF 0xAE
|
|
#define SSD1306_CMD_DISPLAY_ON 0xAF
|
|
#define SSD1306_CMD_SET_CONTRAST 0x81
|
|
#define SSD1306_CMD_DISPLAY_ALL_ON_RESUME 0xA4
|
|
#define SSD1306_CMD_DISPLAY_ALL_ON 0xA5
|
|
#define SSD1306_CMD_NORMAL_DISPLAY 0xA6
|
|
#define SSD1306_CMD_INVERT_DISPLAY 0xA7
|
|
#define SSD1306_CMD_SET_DISPLAY_OFFSET 0xD3
|
|
#define SSD1306_CMD_SET_COM_PINS 0xDA
|
|
#define SSD1306_CMD_SET_VCOM_DETECT 0xDB
|
|
#define SSD1306_CMD_SET_DISPLAY_CLOCK_DIV 0xD5
|
|
#define SSD1306_CMD_SET_PRECHARGE 0xD9
|
|
#define SSD1306_CMD_SET_MULTIPLEX 0xA8
|
|
#define SSD1306_CMD_SET_LOW_COLUMN 0x00
|
|
#define SSD1306_CMD_SET_HIGH_COLUMN 0x10
|
|
#define SSD1306_CMD_SET_START_LINE 0x40
|
|
#define SSD1306_CMD_MEMORY_MODE 0x20
|
|
#define SSD1306_CMD_COLUMN_ADDR 0x21
|
|
#define SSD1306_CMD_PAGE_ADDR 0x22
|
|
#define SSD1306_CMD_COM_SCAN_INC 0xC0
|
|
#define SSD1306_CMD_COM_SCAN_DEC 0xC8
|
|
#define SSD1306_CMD_SEG_REMAP 0xA0
|
|
#define SSD1306_CMD_CHARGE_PUMP 0x8D
|
|
#define SSD1306_CMD_SET_DC_DC_ENABLE 0x14
|
|
|
|
#define SDA_OUT() \
|
|
{ \
|
|
GPIO_SET_OUTPUT(SSD1306_SDA_PORT, SSD1306_SDA_PIN); \
|
|
}
|
|
|
|
#define SDA_IN() \
|
|
{ \
|
|
GPIO_SET_INPUT(SSD1306_SDA_PORT, SSD1306_SDA_PIN); \
|
|
}
|
|
|
|
// 函数声明
|
|
void ssd1306_init(void);
|
|
void ssd1306_logo(void);
|
|
void ssd1306_display_on(void);
|
|
void ssd1306_display_off(void);
|
|
void ssd1306_update_screen(void);
|
|
|
|
void ssd1306_fill(uint8_t color);
|
|
void ssd1306_clear(void);
|
|
void ssd1306_clear_buffer(void);
|
|
void ssd1306_draw_bmp(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, const uint8_t *bmp);
|
|
void ssd1306_f6x8_string(uint8_t x, uint8_t y, const uint8_t *ch);
|
|
void ssd1306_f6x8_number(uint8_t x, uint8_t y, float32 num, uint8_t dot_num);
|
|
void ssd1306_f6x8_string_number(uint8_t x, uint8_t y, const uint8_t *ch, uint8_t unit, float32 num);
|
|
void ssd1306_f8x16_string(uint8_t x, uint8_t y, const uint8_t *ch);
|
|
void ssd1306_f8x16_number(uint8_t x, uint8_t y, float32 num, uint8_t dot_num);
|
|
|
|
void ssd1306_draw_text_center(uint8_t y, const char *text);
|
|
void ssd1306_draw_progress_bar(uint8_t progress);
|
|
void ssd1306_fill_rect_angle(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t color);
|
|
void ssd1306_draw_rect_angle(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t color);
|
|
void ssd1306_draw_line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t color);
|
|
void ssd1306_draw_pixel(uint8_t x, uint8_t y, uint8_t color);
|
|
#endif // __SSD1306_OLED_H
|