#ifndef DRILL_CONFIG_ASYNC_H
#define DRILL_CONFIG_ASYNC_H
#include <stdbool.h>
#include <stdint.h>
typedef enum { DC_IDLE, DC_SLEEP, DC_WAKE, DC_SUBMIT, DC_RECEIVE, DC_READY, DC_FAILED } dc_state;
typedef enum { DC_NONE, DC_ARGUMENT, DC_INTERLOCK, DC_TIME, DC_IO, DC_STATUS, DC_READBACK } dc_error;
typedef struct {
 void *ctx;
 bool (*off_ok)(void *); /* MCU off configuration, NOT measured bridge-off proof */
 bool (*fault_high)(void *);
 bool (*awake)(void *,bool);
 bool (*submit)(void *,uint16_t,uint32_t);
 bool (*receive)(void *,uint16_t *,uint32_t);
 bool (*io_failed)(void *);
 void (*stop)(void *); /* abort transport, hard-off outputs, then sleep */
} dc_hal;
typedef struct {
 dc_state state; dc_error error; uint32_t last,origin,phase;
 uint8_t step,header,data; bool npor_required;
} dc_runtime;
/* One foreground owner; zero initialization required. No automatic retry.
 * permission means bench startup supply/pull-ups/clock qualified externally.
 * This never authorizes PWM, RUN, charger, or motor motion. */
bool dc_begin(dc_runtime *,const dc_hal *,uint32_t,bool permission);
void dc_poll(dc_runtime *,const dc_hal *,uint32_t);
#endif
