#include "TYW_stdint.h"

#ifndef SGMCD1020Q_H
#define SGMCD1020Q_H

#include "Simulated_SPI_1_Master.h"
#include "Dio.h"

/* SGMCD1020Q 寄存器地址定义 */
#define SGMCD_REG_SPI_CHECK          0x00
#define SGMCD_REG_DEVICE_CONFIG      0x02
#define SGMCD_REG_TRISTATE_SP        0x04
#define SGMCD_REG_TRISTATE_SG        0x06
#define SGMCD_REG_WETTING_CURRENT_SP 0x08
#define SGMCD_REG_WETTING_CURRENT_SG0 0x0A
#define SGMCD_REG_WETTING_CURRENT_SG1 0x0C
#define SGMCD_REG_CONT_WETTING_SP    0x16
#define SGMCD_REG_CONT_WETTING_SG    0x18
#define SGMCD_REG_INT_ENABLE_SP      0x1A
#define SGMCD_REG_INT_ENABLE_SG      0x1C
#define SGMCD_REG_LPM_CONFIG         0x1E
#define SGMCD_REG_WAKEUP_ENABLE_SP   0x20
#define SGMCD_REG_WAKEUP_ENABLE_SG   0x22
#define SGMCD_REG_COMPARATOR_ONLY_SP 0x24
#define SGMCD_REG_COMPARATOR_ONLY_SG 0x26
#define SGMCD_REG_LPM_THRESHOLD_SP   0x28
#define SGMCD_REG_LPM_THRESHOLD_SG   0x2A
#define SGMCD_REG_POLLING_CURRENT_SP 0x2C
#define SGMCD_REG_POLLING_CURRENT_SG 0x2E
#define SGMCD_REG_ENTER_LPM          0x39
#define SGMCD_REG_AMUX_CONTROL       0x3A
#define SGMCD_REG_READ_SWITCH_STATUS 0x3E
#define SGMCD_REG_FAULT_STATUS       0x42
#define SGMCD_REG_INTERRUPT_REQUEST  0x47
#define SGMCD_REG_RESET              0x49

/* 湿润电流级别定义 */
#define WETTING_CURRENT_2MA   0x00
#define WETTING_CURRENT_8MA   0x02
#define WETTING_CURRENT_12MA  0x04
#define WETTING_CURRENT_16MA  0x06

/* 设备选择 */
typedef enum {
    SGMCD_DEVICE_1 = 0,
    SGMCD_DEVICE_2,
    SGMCD_DEVICE_3
} SGMCD_DeviceType;

/* 函数声明 */
void SGMCD1020Q_Init(void);
void SGMCD1020Q_SelectDevice(SGMCD_DeviceType device);
uint32_t SGMCD1020Q_SPI_Transfer(uint32_t data);
uint32_t SGMCD1020Q_ReadRegister(uint8_t regAddr);
void SGMCD1020Q_WriteRegister(uint8_t regAddr, uint32_t data);
uint32_t SGMCD1020Q_ReadSwitchStatus(void);
void SGMCD1020Q_SetWettingCurrent(uint8_t channel, uint8_t currentLevel);
void SGMCD1020Q_EnableInterrupt(uint8_t channel, uint8_t enable);
void SGMCD1020Q_EnterLowPowerMode(void);
void SGMCD1020Q_Reset(void);
uint32_t SGMCD1020Q_ReadFaultStatus(void);

#endif /* SGMCD1020Q_H */

