#ifndef PCA9554_H
#define PCA9554_H

#ifdef __cplusplus
extern "C" {
#endif

#include "driver/i2c_master.h"

typedef enum {
    PCA9554_REG_INPUT  = 0x00u,                   /* input register address              */
    PCA9554_REG_OUTPUT = 0x01u,                   /* output register address             */
    PCA9554_REG_POLAR  = 0x02u,                   /* polarity inverse register           */
    PCA9554_REG_CFG    = 0x03u                    /* configuration register              */
} pca9554_register_t;

typedef enum {
    PCA9554_PORT_P0 = 0,
    PCA9554_PORT_P1 = 1, 
    PCA9554_PORT_P2 = 2, 
    PCA9554_PORT_P3 = 3,
    PCA9554_PORT_P4 = 4, 
    PCA9554_PORT_P5 = 5, 
    PCA9554_PORT_P6 = 6, 
    PCA9554_PORT_P7 = 7 
} pca9554_port_t;

typedef enum {
    PCA9554_DIR_OUTPUT = 0,
    PCA9554_DIR_INPUT  = 1
} pca9554_direction_t;

typedef enum {
    PCA9554_LOGIC_LOW  = 0,
    PCA9554_LOGIC_HIGH = 1
    
} pca9554_logic_t;

i2c_master_dev_handle_t  pca9554_device_create(i2c_master_bus_handle_t bus_handle,const uint8_t dev_addr, const uint32_t dev_speed); 
void                     pca9554_config_io(i2c_master_dev_handle_t dev_handle, uint8_t data);
void                     pca9554_pin_set_direction(i2c_master_dev_handle_t dev_handle, pca9554_port_t pin, pca9554_direction_t direction);
void                     pca9554_pin_set_inverse(i2c_master_dev_handle_t dev_handle, pca9554_port_t pin);
void                     pca9554_pin_clear_inverse(i2c_master_dev_handle_t dev_handle, pca9554_port_t pin);
void                     pca9554_pin_set_logic(i2c_master_dev_handle_t dev_handle, pca9554_port_t pin, pca9554_logic_t logic);
pca9554_logic_t          pca9554_pin_get_logic(i2c_master_dev_handle_t dev_handle, pca9554_port_t pin);
esp_err_t                pca9554_device_remove(i2c_master_dev_handle_t dev_handle);
void                     pca9554_write_output(i2c_master_dev_handle_t dev_handle, uint8_t data);
uint8_t                  pca9554_read_input(i2c_master_dev_handle_t dev_handle);

#ifdef __cplusplus
}
#endif

#endif