-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphics.h
More file actions
118 lines (102 loc) · 3.56 KB
/
Copy pathgraphics.h
File metadata and controls
118 lines (102 loc) · 3.56 KB
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
116
117
118
/**
* @file graphics.h
* @brief SSD1306 OLED graphics display APIs header.
* @author Luyao Han (luyaohan1001@gmail.com)
* @date 12-21-2022
*/
#ifndef GRAPHICS_H
#define GRAPHICS_H
#include "datalink.h"
#define OLED_CANVAS_WIDTH_PIXELS 128
#define OLED_CANVAS_HEIGHT_PIXELS 64
#define BITS_PER_BYTE 8
#define OLED_COLUMN_LENGTH OLED_CANVAS_WIDTH_PIXELS
#define OLED_COLUMN_MIN 0
#define OLED_COLUMN_MAX OLED_CANVAS_WIDTH_PIXELS - 1
#define OLED_PAGE_LENGTH (OLED_CANVAS_HEIGHT_PIXELS / BITS_PER_BYTE)
#define OLED_PAGE_MIN 0
#define OLED_PAGE_MAX (OLED_CANVAS_HEIGHT_PIXELS / BITS_PER_BYTE) - 1
#define DEFAULT_TEXT_LENGTH 256
/**
* @struct Pixel location on the screen.
* @param line The horizontal line (page).
* @param position The vertical position (column).
* @note Page and columns are formal terms defined in SSD1306 datasheet, Figure
* 10-3. In this program we have renamed them respectively line and
* position as more intuitive names. The screen is 128x64 pixels.
* However, since data are written in slices (one byte) at a time, there are 64
* / 8 = 8 lines.
*
* Visualize:
* ------- 128 positions / columns --------
* |||||||| |||||||| ||||....... |||||||| ||||||||
* -
* -
* -
* 8 lines/pages -
* -
* -
* -
* -
*/
typedef struct {
uint8_t line; /* Valid range 0 - 7 */
uint8_t position; /* Valid range 0 - 127 */
} oled_cursor_coordinate_t;
/**
* @brief Struct used to book-keep parameters for the oled graphics.
* @param cursor_coordinate Keeps track of the coordinate of current cursor.
* @param display_text Buffers/keeps track of the current text on the
* oled_screen.
*/
typedef struct {
oled_cursor_coordinate_t cursor_coordinate;
char display_text[DEFAULT_TEXT_LENGTH];
} oled_graphics_params_t;
/**
* @brief Enum type defining options when printing to a new line (page).
* @param START_OF_NEW_LINE For example, when printing a sentence, it is
* expected to be printed to the start of the new line.
* @param SAME_CURSOR_POSITION For exapmle, when printing an image, it is
* expected to be printed to the same cursor position.
*/
typedef enum { START_OF_NEW_LINE, SAME_CURSOR_POSITION } oled_new_line_options;
/**
* @brief Print single char to the oled screen.
* @param ascii_char ASCII character to put.
* @return None.
*/
void oled_putc(unsigned char c);
/**
* @brief printf on oled with variadic arguments to print on the oled screen.
* @param format Format supplied including string and/or parameters.
* @return None.
*/
void oled_printf(const char *format, ...);
/**
* @brief Change to a new line on the OLED screen.
* @param oled_new_line_options
* START_OF_NEW_LINE to print to the start of the new line.
* SAME_CURSOR_POSITION to print the next line the same cursor position.
* @return None.
*/
void oled_new_line(oled_new_line_options new_line_option);
/**
* @brief Set the cursor position, i.e. the start location to print.
* @param cursor_coordinate The pixel coordinate to set the cursor to.
*/
void oled_set_cursor(oled_cursor_coordinate_t cursor_coordinate);
/**
* @brief Fill the entire screen with byte pattern.
* @param pattern Byte pattern to fill.
* @return None.
*/
void oled_fill_all(uint8_t pattern);
/**
* @brief Draw a dinosaur on the oled screen.
* @param cursor_coordinate Set to this coordinate as the start pixel drawing
* the dinosaur.
* @return None.
*/
void oled_draw_dino_map(oled_cursor_coordinate_t cursor_coordinate);
#endif /* GRAPHICS_H */