#ifndef LAMP_FRAME_STAGE_H
#define LAMP_FRAME_STAGE_H
#include "lamp_guard.h"
#include "lamp_i2c_read.h"
#include "lamp_i2c_write.h"
#define LAMP_FRAME_CHANNELS 61u
typedef struct {uint32_t calibration_id;uint8_t iref[61];bool physically_qualified;} lamp_current_profile;
typedef enum {LFS_IDLE,LFS_WRITE_BEGIN,LFS_WRITE_WAIT,LFS_READ_BEGIN,LFS_READ_WAIT,LFS_WAKE,LFS_DONE,LFS_FAILED} lamp_frame_stage_state;
typedef struct {
 lamp_i2c_write writer;lamp_i2c_read reader;
 lamp_frame_stage_state state;uint32_t started,last_poll,wake_started,calibration_id;
 uint64_t session_id;uint16_t index;uint8_t pwm[61],iref[61];
} lamp_frame_stage;
/* Authorized logical image only. Caller must hold physical OE high and power
 * request low for every poll, pause diagnostics at a completed bank, and never
 * enable output on write ACK alone. Qualified current profile must come from
 * actual hardware/optical calibration, never a command packet.
 * 174 explicit matches include all 11 unused channels zeroed. */
bool lamp_frame_stage_begin(lamp_frame_stage *,const lg_guard *,const lamp_current_profile *,uint32_t now);
void lamp_frame_stage_poll(lamp_frame_stage *,const lg_guard *,const lamp_current_profile *,uint32_t now);
void lamp_frame_stage_abort(lamp_frame_stage *);
bool lamp_frame_stage_done(const lamp_frame_stage *,const lg_guard *,const lamp_current_profile *,uint32_t now);
#endif
