TR-mbed 1.0
Loading...
Searching...
No Matches
ui_types.h
Go to the documentation of this file.
1//
2// Created by bismarckkk on 2026/3/22.
3// Dynamic Edition
4//
5
6#ifndef UI_TYPES_H
7#define UI_TYPES_H
8
9// User Code Begin
10
11// Defines whether or not we want to manually handling updtaing or not (comment out if we want automatic handling)
12// #define MANUAL_DIRTY
13
14#if defined(__GNUC__) || defined(__CC_ARM)
15#define MESSAGE_PACKED __attribute__((packed))
16#include <stdint.h>
17#else
18#error "MESSAGE_PACKED not defined for this compiler"
19#endif
20
21// User Code End
22
23// Structures for various figures/numbers/strings
24
25typedef struct __attribute__((__packed__)) {
26 uint8_t figure_name[3];
27 uint32_t operate_type: 3;
28 uint32_t figure_type: 3;
29 uint32_t layer: 4;
30 uint32_t color: 4;
31 uint32_t font_size: 9;
32 uint32_t _b: 9;
33 uint32_t width: 10;
34 uint32_t start_x: 11;
35 uint32_t start_y: 11;
36 int32_t number;
37} MESSAGE_PACKED ui_interface_number_t;
38
39typedef struct __attribute__((__packed__)) {
40 uint8_t figure_name[3];
41 uint32_t operate_type: 3;
42 uint32_t figure_type: 3;
43 uint32_t layer: 4;
44 uint32_t color: 4;
45 uint32_t font_size: 9;
46 uint32_t str_length: 9;
47 uint32_t width: 10;
48 uint32_t start_x: 11;
49 uint32_t start_y: 11;
50 uint32_t _c: 10;
51 uint32_t _d: 11;
52 uint32_t _e: 11;
53 char string[30];
54} MESSAGE_PACKED ui_interface_string_t;
55
56#define PRIMITIVE_CAT(x, y) x ## y
57#define CAT(x, y) PRIMITIVE_CAT(x, y)
58
59// Creates generic figure interface struct (good for inheritance related functions)
60#define DEFINE_MESSAGE(name, p_a, p_b, p_c, p_d, p_e) \
61typedef struct __attribute__((__packed__)) { \
62 uint8_t figure_name[3]; \
63 uint32_t operate_type:3; \
64 uint32_t figure_type:3; \
65 uint32_t layer:4; \
66 uint32_t color:4; \
67 uint32_t PRIMITIVE_CAT(,p_a) :9; \
68 uint32_t PRIMITIVE_CAT(,p_b):9; \
69 uint32_t width:10; \
70 uint32_t start_x:11; \
71 uint32_t start_y:11; \
72 uint32_t PRIMITIVE_CAT(,p_c):10; \
73 uint32_t PRIMITIVE_CAT(,p_d):11; \
74 uint32_t PRIMITIVE_CAT(,p_e):11; \
75} MESSAGE_PACKED ui_interface_ ## name ##_t
76
77// Explicitly define figure types with right names
78DEFINE_MESSAGE(figure, _a, _b, _c, _d, _e);
79DEFINE_MESSAGE(line, _a, _b, _c, end_x, end_y);
80DEFINE_MESSAGE(rect, _a, _b, _c, end_x, end_y);
81DEFINE_MESSAGE(round, _a, _b, r, _d, _e);
82DEFINE_MESSAGE(ellipse, _a, _b, _c, rx, ry);
83DEFINE_MESSAGE(arc, start_angle, end_angle, _c, rx, ry);
84
85// Structure for frame header
86typedef struct __attribute__((__packed__)) {
87 uint8_t SOF;
88 uint16_t length;
89 uint8_t seq, crc8;
90 uint16_t cmd_id, sub_id;
91 uint16_t send_id, recv_id;
92} MESSAGE_PACKED ui_frame_header_t;
93
94// Structure for sending figure data in various sized packets
95typedef struct __attribute__((__packed__)) {
97ui_interface_figure_t data[1];
98uint16_t crc16;
99} MESSAGE_PACKED ui_1_frame_t;
100
101typedef struct __attribute__((__packed__)) {
102ui_frame_header_t header;
103ui_interface_figure_t data[2];
104uint16_t crc16;
105} MESSAGE_PACKED ui_2_frame_t;
106
107typedef struct __attribute__((__packed__)) {
108ui_frame_header_t header;
109ui_interface_figure_t data[5];
110uint16_t crc16;
111} MESSAGE_PACKED ui_5_frame_t;
112
113typedef struct __attribute__((__packed__)) {
114ui_frame_header_t header;
115ui_interface_figure_t data[7];
116uint16_t crc16;
117} MESSAGE_PACKED ui_7_frame_t;
118
119// Structure for sending string data in packets
120typedef struct __attribute__((__packed__)) {
121 ui_frame_header_t header;
123 uint16_t crc16;
124} MESSAGE_PACKED ui_string_frame_t;
125
126// Structure for deleting layers
127typedef struct __attribute__((__packed__)) {
128 ui_frame_header_t header;
129 uint8_t delete_type;
130 uint8_t layer;
131 uint16_t crc16;
132} MESSAGE_PACKED ui_delete_frame_t;
133
134#endif //UI_TYPES_H
MESSAGE_PACKED ui_7_frame_t
Definition ui_types.h:117
MESSAGE_PACKED ui_frame_header_t
Definition ui_types.h:92
MESSAGE_PACKED ui_delete_frame_t
Definition ui_types.h:132
MESSAGE_PACKED ui_interface_string_t
Definition ui_types.h:54
MESSAGE_PACKED ui_interface_number_t
Definition ui_types.h:37
MESSAGE_PACKED ui_2_frame_t
Definition ui_types.h:105
MESSAGE_PACKED ui_string_frame_t
Definition ui_types.h:124
struct __attribute__((__packed__))
Definition ui_types.h:25
MESSAGE_PACKED ui_5_frame_t
Definition ui_types.h:111
#define DEFINE_MESSAGE(name, p_a, p_b, p_c, p_d, p_e)
Definition ui_types.h:60
MESSAGE_PACKED ui_1_frame_t
Definition ui_types.h:99