-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathssd1306.h
115 lines (94 loc) · 3.08 KB
/
ssd1306.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* ssd1306.h
*
* Created on: 29 Jul 2022
* Author: kirsc
*/
#ifndef SSD1306_H_
#define SSD1306_H_
#include "DAVE.h"
#include <stddef.h>
#include <_ansi.h>
_BEGIN_STD_C
#include "ssd1306_conf.h"
#ifdef SSD1306_X_OFFSET
#define SSD1306_X_OFFSET_LOWER (SSD1306_X_OFFSET & 0x0F)
#define SSD1306_X_OFFSET_UPPER ((SSD1306_X_OFFSET >> 4) & 0x07)
#else
#define SSD1306_X_OFFSET_LOWER 0
#define SSD1306_X_OFFSET_UPPER 0
#endif
#include "ssd1306_fonts.h"
#define SSD1306_I2C_PORT hi2c1
#define SSD1306_I2C_ADDR 0x78
// SSD1306 OLED height in pixels
#ifndef SSD1306_HEIGHT
#define SSD1306_HEIGHT 64
#endif
// SSD1306 width in pixels
#ifndef SSD1306_WIDTH
#define SSD1306_WIDTH 128
#endif
#ifndef SSD1306_BUFFER_SIZE
#define SSD1306_BUFFER_SIZE SSD1306_WIDTH * SSD1306_HEIGHT / 8
#endif
// Enumeration for screen colors
typedef enum {
Black = 0x00, // Black color, no pixel
White = 0x01 // Pixel is set. Color depends on OLED
} SSD1306_COLOR;
typedef enum {
SSD1306_OK = 0x00,
SSD1306_ERR = 0x01 // Generic error.
} SSD1306_Error_t;
// Struct to store transformations
typedef struct {
uint16_t CurrentX;
uint16_t CurrentY;
uint8_t Initialized;
uint8_t DisplayOn;
} SSD1306_t;
typedef struct {
uint8_t x;
uint8_t y;
} SSD1306_VERTEX;
// Procedure definitions
void ssd1306_Init(void);
void ssd1306_Fill(SSD1306_COLOR color);
void ssd1306_UpdateScreen(void);
void ssd1306_DrawPixel(uint8_t x, uint8_t y, SSD1306_COLOR color);
char ssd1306_WriteChar(char ch, FontDef Font, SSD1306_COLOR color);
char ssd1306_WriteString(char* str, FontDef Font, SSD1306_COLOR color);
void ssd1306_SetCursor(uint8_t x, uint8_t y);
void ssd1306_Line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, SSD1306_COLOR color);
void ssd1306_DrawArc(uint8_t x, uint8_t y, uint8_t radius, uint16_t start_angle, uint16_t sweep, SSD1306_COLOR color);
void ssd1306_DrawCircle(uint8_t par_x, uint8_t par_y, uint8_t par_r, SSD1306_COLOR color);
void ssd1306_Polyline(const SSD1306_VERTEX *par_vertex, uint16_t par_size, SSD1306_COLOR color);
void ssd1306_DrawRectangle(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, SSD1306_COLOR color);
void ssd1306_DrawBitmap(uint8_t x, uint8_t y, const unsigned char* bitmap, uint8_t w, uint8_t h, SSD1306_COLOR color);
/*
* @brief Sets the contrast of the display.
* @param[in] value contrast to set.
* @note Contrast increases as the value increases.
* @note RESET = 7Fh.
*/
void ssd1306_SetContrast(const uint8_t value);
/**
* @brief Set Display ON/OFF.
* @param[in] on 0 for OFF, any for ON.
*/
void ssd1306_SetDisplayOn(const uint8_t on);
/**
* @brief Reads DisplayOn state.
* @return 0: OFF.
* 1: ON.
*/
uint8_t ssd1306_GetDisplayOn();
// Low-level procedures
void ssd1306_Reset(void);
void ssd1306_WriteCommand(uint8_t byte);
void ssd1306_WriteData(uint8_t* buffer, size_t buff_size);
SSD1306_Error_t ssd1306_FillBuffer(uint8_t* buf, uint32_t len);
void delay(uint32_t cnt);
_END_STD_C
#endif /* SSD1306_H_ */