Files
pcf8574_driver/cm_pcf8574_driver.c
Christian L. V. Madsen a13b50e47f test
2024-08-17 13:42:34 +02:00

79 lines
1.5 KiB
C

/*
* cm_pcf8574_driver.c
*
* Created on: 29. jan. 2024
* Author: Chris
*/
#include "cm_pcf8574_driver.h"
#include <stddef.h>
#define NUM_OF_RETRYS 3
static int checkInst(cm_pcf8574_t *inst){
if(inst->i2c_transfer_evt == NULL)return CM_PCF8574_NOK;
if(inst->i2c_inst == NULL)return CM_PCF8574_NOK;
return CM_PCF8574_OK;
}
int cm_pcf8574_RegTransEvt(cm_pcf8574_t *inst, void *i2c_inst, setGet_I2C_Event_fpt i2c_transfer_evt){
if(inst == NULL) return CM_PCF8574_NOK;
inst->i2c_inst = i2c_inst;
inst->i2c_transfer_evt = i2c_transfer_evt;
return CM_PCF8574_OK;
}
/*// No need to do this.. because I2C driver does this for us..
int cm_pcf8574_IsDeviceActive(cm_pcf8574_t *inst){
if(checkInst(inst)) return CM_PCF8574_NOK;
uint8_t tx_buf[1] = {0};
uint8_t ret = 0;
for(uint8_t retry_ctr = 0; retry_ctr < NUM_OF_RETRYS; retry_ctr++){
ret = inst->i2c_transfer_evt(inst->i2c_inst, (uint8_t*)&tx_buf, 2, CM_PCF8574_I2C_GET);
if(ret == 0)return 0;
}
return ret;
}*/
int cm_pcf8574_SetPort(cm_pcf8574_t *inst, uint8_t port_val){
if(checkInst(inst)) return CM_PCF8574_NOK;
//inst->Port_1 = (cm_io_port_t)port_val;
return inst->i2c_transfer_evt(inst->i2c_inst, (uint8_t*)&port_val, sizeof(inst->Port_1), CM_PCF8574_I2C_SET);
return 0;
}
// ret = inst->i2c_transfer_evt(inst->i2c_transfer_inst, (uint8_t*)&tx_buf, 2, LTR390_I2C_SET);
int cm_pcf8574_Init(cm_pcf8574_t *inst){
if(checkInst(inst)) return CM_PCF8574_NOK;
//return cm_pcf8574_IsDeviceActive(inst);
return 0;
}