/* * ports.h * * Created on: Mar 21, 2023 * Author: Keith.Lloyd */ #ifndef PORTS_H_ #define PORTS_H_ typedef struct ACCESSORY_s ACCESSORY_t; typedef int (*AccessoryHandler_t)(ACCESSORY_t *accy); typedef enum { ID_BROADCAST = -1, ID_ERROR = 0, //0V should never happen. Error condition ID_TX_SINGLE_DIRECT, //Transmitter accessory ID_TX_DUAL_DIRECT, //Transmitter accessory ID_TX_TBD1, // ID_CLAMP2, // ID_CLAMP, //Receiver Clamp ID_TBD1, // ID_DIGITAL, //Digital Accessory - Use for EMS boot in future ID_FAULT_PROBE, //Fault Probe ID_TBD2, // ID_TBD3, // ID_NONE, //No accessory connected ID_NUM }ACCY_ID_t; typedef enum { PORT_STATE_DEINIT = -1, PORT_STATE_INIT = 0, PORT_STATE_STANDBY = 1, PORT_STATE_RUNNING = 2, } PortState_t; typedef enum { ACCY_PORT_INDUCTION = 0, ACCY_PORT_1 = 1, ACCY_PORT_2 = 2, NUM_PORTS } AccessoryPortId_t; typedef enum { CHANNEL_A = 0, CHANNEL_B, NUM_CHANNELS } AccyChannelId_t; typedef struct { AccyChannelId_t id; bool connected; } AccessoryChannel_t; struct ACCESSORY_s { bool isConnected; //Accessory is connected ACCY_ID_t connected; //Currently connected accessory ACCY_ID_t lastDetected; //accessory detected last scan uint32_t consecutiveScans; //number of consecutive scans of same accessory float *idVoltage; PortState_t state; bool initState; AccessoryHandler_t handler; AccessoryChannel_t channels[NUM_CHANNELS]; AccyChannelId_t activeChannel; uint32_t stateTimer; AccessoryPortId_t portId; }; #define DELAY_100MS 10 #define DELAY_ONE_SECOND 100 #define AC_NUM_SCANS_TO_CONNECT 3 //require 3 consecutive scans to connect to accessory #define A1_SLCT 0b00000000 #define A2_SLCT 0b00010000 #define B1_SLCT 0b00001000 #define B2_SLCT 0b00011000 #define TOP_SR 0 //0 #define MID_SR 1 #define BOTTOM_SR 2 //1 #define LF false #define HF true typedef enum { ONE, TWO, THREE, FOUR }OUTPUT_SELECT_t; void ACCY_Init(void); bool ACCY_isKnown(ACCY_ID_t id); void ACCY_Update(void); void ACCY_Update1(void); void ACCY_Update2(void); void Read_Tx_Ports(void); // check for whats plugged in at the ports. void Tx_ConfigureFrequency(void); void ACCY_Connect1(ACCY_ID_t id); void ACCY_Connect2(ACCY_ID_t id); bool ACCY_IsConnected(uint8_t port); ACCY_ID_t ACCY_GetConnectedAccessory(uint8_t port); ACCY_ID_t ACCY_GetActive(void); void Select_Output_Port(void); // Mutually exclusive output port selector void Enable_BC(void); void Disable_DC(void); void Disable_BC(void); void Disconnect(uint8_t port); // called when you disconnect uint32_t Search_BC_Frequency(void); uint32_t Search_Frequency(uint32_t pattern); bool Is_Clamp_Detected(void); void Cycled_Freq_Change_BC(uint8_t value); void Reset_Power_Gain(void); void ACCY_service(void); bool ACCY_Connect(ACCESSORY_t *accy, ACCY_ID_t id); void ACCY_setActive(ACCESSORY_t *accy, AccyChannelId_t channel); void ACCY_next(void); #endif /* PORTS_H_ */