#ifndef __PROTO_H__ #define __PROTO_H__ #include #include #define PROTO_RESPONSE_TIMEOUT_MS 7 #define PROTO_UPDATE_INTERVAL_MS 50 enum proto_fsm { ST_START = 0, ST_TIME_SYNC, ST_FETCH_0, ST_FETCH_1, ST_UPDATE_DISPLAY, ST_WAITING, }; enum packet_type { PK_TIME_SYNC, PK_FETCH_ADC, PK_FETCH_RESPONSE, PK_DISPLAY_UPDATE, PK_BUTTON_STATE, }; struct proto_state { enum proto_fsm fsm; uint64_t last_start; ErrorCode error; uint64_t last_error; bool timeout[3]; const char *status_msg; const char *error_msg; uint8_t rx_buttons; bool rx_lid_open; bool rx_estop; int32_t adc_samples[2][2][512]; size_t adc_sp_wr_idx[2]; size_t adc_sp_rd_idx[2]; uint64_t adc_sample_timestamp[2]; uint32_t adc_sampling_interval[2]; uint32_t adc_sample_count[2]; }; enum proto_led_format { PROTO_LED_FMT_OFF = 0x00, PROTO_LED_FMT_DEC = 0x01, PROTO_LED_FMT_HEX = 0x02, PROTO_LED_FMT_DP_OFF = 0x00, PROTO_LED_FMT_DP_0 = 0x10, PROTO_LED_FMT_DP_1 = 0x30, PROTO_LED_FMT_DP_2 = 0x50, PROTO_LED_FMT_DP_3 = 0x70, PROTO_LED_FMT_DP_4 = 0x90, PROTO_LED_FMT_DP_5 = 0xb0, PROTO_LED_FMT_DP_6 = 0xd0, PROTO_LED_FMT_DP_7 = 0xf0, }; struct __attribute__((__packed__)) pkt_update_display { struct ll_pkt ll_pkt; char lcd[20*4]; uint32_t led[3]; uint8_t led_fmt[3]; }; enum proto_display_buttons { PROTO_DSP_BT_RED, /* Bottom left of display panel */ PROTO_DSP_BT_GREEN, /* Bottom right of display panel */ PROTO_DSP_BT_TOP, /* Top right of display panel, next to the LCD, above PROTO_DSP_BT_BOTTOM */ PROTO_DSP_BT_BOTTOM, /* Top right of display panel, next to the LCD, below PROTO_DSP_BT_TOP */ PROTO_DSP_BT_LID, /* lid switch, 1 when open */ PROTO_DSP_BT_ESTOP, /* lid switch, 1 when pressed */ }; struct __attribute__((__packed__)) pkt_button_state { struct ll_pkt ll_pkt; uint8_t buttons; }; struct __attribute__((__packed__)) pkt_time_sync { struct ll_pkt ll_pkt; uint64_t time; }; struct __attribute__((__packed__)) pkt_adc_data { struct ll_pkt ll_pkt; uint64_t timestamp; uint32_t sampling_interval_us; uint32_t sample_count; uint8_t samples[16][2][3]; }; extern struct proto_state st_proto; void proto_init(void); void proto_loop(void); #endif /* __PROTO_H__ */