diff options
Diffstat (limited to 'shared')
-rw-r--r-- | shared/bool.h | 9 | ||||
-rw-r--r-- | shared/io.h | 59 | ||||
-rw-r--r-- | shared/protocol.h | 56 |
3 files changed, 70 insertions, 54 deletions
diff --git a/shared/bool.h b/shared/bool.h new file mode 100644 index 0000000..9ea97f7 --- /dev/null +++ b/shared/bool.h @@ -0,0 +1,9 @@ +#pragma once + +#include <stdint.h> + +/** @file bool.h */ + +typedef uint8_t bool; +#define false 0 /* NOLINT */ +#define true 1 /* NOLINT */ diff --git a/shared/io.h b/shared/io.h new file mode 100644 index 0000000..584ad1e --- /dev/null +++ b/shared/io.h @@ -0,0 +1,59 @@ +#pragma once + +#include <stdio.h> + +#include "bool.h" + +#pragma pack(push, 1) + +/** momentary button input struct */ +typedef struct { + bool pressed; +} w2_s_i_push; + +/** qtr contrast sensor input struct */ +typedef struct { + uint16_t range; +} w2_s_i_contrast; + +/** distance sensor input struct */ +typedef struct { + uint16_t detection; +} w2_s_i_distance; + +/** battery input struct */ +typedef struct { + uint16_t charge_level; +} w2_s_i_battery; + +/** motor output struct */ +typedef struct { + int16_t speed; +} w2_s_o_motor; + +/** underside led output struct */ +typedef struct { + bool on; +} w2_s_o_led; + +/** lcd output struct */ +typedef struct { + char text[16]; +} w2_s_o_display; + +/** struct containing all i/o */ +typedef struct { + w2_s_i_push button[5]; + w2_s_i_contrast qtr[5]; + w2_s_i_distance front_distance; + w2_s_i_distance side_distance; + w2_s_i_battery battery; + + w2_s_o_motor motor_left; + w2_s_o_motor motor_right; + w2_s_o_led led_red; + w2_s_o_led led_green; + w2_s_o_display lcd; +} w2_s_io_all; + +#pragma pack(pop) diff --git a/shared/protocol.h b/shared/protocol.h index 05cde03..2e1e4ea 100644 --- a/shared/protocol.h +++ b/shared/protocol.h @@ -6,11 +6,9 @@ #include <stdlib.h> #include "bin.h" +#include "bool.h" #include "consts.h" - -typedef uint8_t bool; -#define false 0 /* NOLINT */ -#define true 1 /* NOLINT */ +#include "io.h" #define W2_SERIAL_START_BYTE 0xff @@ -54,56 +52,6 @@ typedef enum { #pragma pack(push, 1) -/** momentary button input struct */ -typedef struct { - bool pressed; -} w2_s_i_push; - -/** qtr contrast sensor input struct */ -typedef struct { - uint16_t range; -} w2_s_i_contrast; - -/** distance sensor input struct */ -typedef struct { - uint16_t detection; -} w2_s_i_distance; - -/** battery input struct */ -typedef struct { - uint16_t charge_level; -} w2_s_i_battery; - -/** motor output struct */ -typedef struct { - int16_t speed; -} w2_s_o_motor; - -/** underside led output struct */ -typedef struct { - bool on; -} w2_s_o_led; - -/** lcd output struct */ -typedef struct { - char text[16]; -} w2_s_o_display; - -/** struct containing all i/o */ -typedef struct { - w2_s_i_push button[5]; - w2_s_i_contrast qtr[5]; - w2_s_i_distance front_distance; - w2_s_i_distance side_distance; - w2_s_i_battery battery; - - w2_s_o_motor motor_left; - w2_s_o_motor motor_right; - w2_s_o_led led_red; - w2_s_o_led led_green; - w2_s_o_display lcd; -} w2_s_io_all; - typedef struct { uint8_t opcode; uint8_t id; |