-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.h
95 lines (76 loc) · 2.62 KB
/
display.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
#ifndef DISPLAY_H
#define DISPLAY_H
#include <stdint.h>
#include <stdbool.h>
#include <zephyr/device.h>
// The pin configuration is the following:
// - Data In (Blue) -> PA_7 (pin A6) configured as SPI1_MOSI
// - Clock (Yellow) -> PA_1 (pin A1) configured as SPI1_SCK
// - Chip Select (Orange) -> PB_0 (pin D3) configured as SPI_NSS (logical not slave select)
// - Data Command (Green) -> PA_4 (pin A3) configured as GPIO
// - Reset (White) -> PA_0 (pin A0) configured as GPIO
// The width of the display in pixels.
#define DISPLAY_WIDTH 128
// THe height of the display in pixels. Divided into 8 rows.
#define DISPLAY_HEIGHT 64
// The stack size of the dracula thread.
#define DISPLAY_THREAD_STACK_SIZE 2048
// The thread priority of the dracula logic.
#define DISPLAY_THREAD_PRIORITY 4
/**
* @brief Invert all the pixels on the display.
* @param inverted If the pixels are inverted.
*/
void display_invert(const struct device *dev, bool inverted);
/**
* @brief Clear the display with zeroes.
*/
void display_clear();
/**
* @brief Set the contrast of the display.
*
* @param level The contrast level from 0 to 255.
*/
void display_set_contrast(const struct device *dev, uint8_t level);
/**
* @brief Write pixel data to the display.
*
* The display has 8 rows. Each row has 128 columns. Each row is 8 pixels tall.
* Each of the 8 bits in a byte written to the display sets the 8 pixel states
* from LSB to MSH at a given row and column.
*
* @param column_begin The starting column from 0 to 127 inclusive.
* @param column_end The end column from 0 to 127 inclusive.
* @param row_begin The starting row from 0 to 7 inclusive.
* @param row_end The end row from 0 to 7 inclusive.
* @param data Pointer to the buffer to write.
* @param n The number of bytes to write.
*
* @returns Zero on success or a non-zero error number on failure.
*/
int display_write(uint8_t column_begin, uint8_t column_end, uint8_t row_begin,
uint8_t row_end, const uint8_t *data, unsigned int n);
/**
* @brief A structure containing an image to display.
*/
struct Image {
/// The width of the display image.
unsigned char width;
/// The height of the display image.
unsigned char height;
/// The size of the image data buffer.
unsigned int size;
/// The image data buffer.
unsigned char *buffer;
};
/**
* @brief Display an image.
*
* @param image The image to display.
* @param x The x coordinate of the image.
* @param y The y coordinate of the image.
*
* @returns Zero on success or a non-zero error number on failure.
*/
int display_image(struct Image *image, unsigned int x, unsigned int y);
#endif // DISPLAY_H