~ruther/CTU-FEE-B0B35APO-Semestral-project

ref: 612a284d28b5cfb66a922ec130c5eb01433a550a CTU-FEE-B0B35APO-Semestral-project/lib-pheripherals/include/display_utils.h -rw-r--r-- 3.0 KiB
612a284d — František Boháček fix: update list 3 years ago
                                                                                
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
119
120
121
122
#ifndef __DISPLAY_UTILS_H__
#define __DISPLAY_UTILS_H__

#include <stdint.h>
#include <stdbool.h>

#define DISPLAY_MAX_RED 31u
#define DISPLAY_MAX_GREEN 63u
#define DISPLAY_MAX_BLUE 31u

#define DISPLAY_WIDTH 480
#define DISPLAY_HEIGHT 320

typedef union {
  struct {
    uint8_t b : 5;
    uint8_t g : 6;
    uint8_t r : 5;
  } __attribute__((__packed__)) fields;
  uint16_t bits;
} __attribute__((__packed__)) display_pixel_t;

typedef struct {
  uint8_t red;
  uint8_t green;
  uint8_t blue;
} __attribute__((__packed__)) raw_pixel_onebit_t;

typedef struct {
  uint16_t red;
  uint16_t green;
  uint16_t blue;
} __attribute__((__packed__)) raw_pixel_t;

typedef struct {
  void* base_address;
} display_data_t;

typedef struct {
  display_pixel_t pixels[DISPLAY_HEIGHT * DISPLAY_WIDTH];
  display_data_t data;
} display_t;

extern const display_pixel_t BLACK_PIXEL;
extern const display_pixel_t WHITE_PIXEL;

extern const raw_pixel_t DISPLAY_PIXEL_MAX;

/**
 * @brief Make display_pixel_t from raw_pixel_onebit_t
 * 
 * @param pixel pixel to convert
 * @param max maximum rgb values (brightness) of raw pixel to calculate display pixel value from
 * @return display_pixel_t 
 */
display_pixel_t raw_pixel_onebit_convert_to_display(raw_pixel_onebit_t pixel,
                                             raw_pixel_onebit_t max);

/**
 * @brief Make display_pixel_t from raw_pixel_t
 * 
 * @param pixel pixel to convert
 * @param max maximum rgb values (brightness) of raw pixel to calculate display pixel value from
 * @return display_pixel_t 
 */
display_pixel_t raw_pixel_convert_to_display(raw_pixel_t pixel, raw_pixel_t max);

/**
 * @brief Call initialize display sequence and return its data
 * @note With COMPUTER macro this will initialize SDL window
 * 
 * @param data Data along with memory address where display is stored
 * @return display_t 
 */
display_t display_init(display_data_t data);

/**
 * @brief Clear the screen and call destroy sequence
 * @note With COMPUTER macro this will close SDL window
 * 
 * @param display 
 */
void display_deinit(display_t *display);

/**
 * @brief Render data in display_t structure on the display
 * @note With COMPUTER macro this will render data on SDL window
 * 
 * @param display 
 */
void display_render(display_t *display);

/**
 * @brief Clear display data in memory and optionally render it
 * 
 * @param display
 * @param render whether to render or only clear data in memory 
 */
void display_clear(display_t *display, bool render);

/**
 * @brief Return display pixel set in memory on given position
 * 
 * @param display 
 * @param x x coordinate of pixel
 * @param y y coordinate of pixel
 * @return display_pixel_t pixel on given position
 */
display_pixel_t display_get_pixel(display_t *display, uint16_t x, uint16_t y);

/**
 * @brief Set pixel in memory on given position
 * 
 * @param display 
 * @param x x coordinate of pixel
 * @param y y coordinate of pixel
 * @param pixel pixel to set
 */
void display_set_pixel(display_t *display, uint16_t x, uint16_t y,
                       display_pixel_t pixel);

#endif // __DISPLAY_UTILS_H__
Do not follow this link