This is what I did in a similar case, this example is for writing the I²C driver:
struct IIC_BUS
{
int pin_index_sclk;
int pin_index_sdat;
};
void iic_init_bus( struct IIC_BUS* iic, int idx_sclk, int idx_sdat );
void iic_write( struct IIC_BUS* iic, uint8_t iicAddress, uint8_t* data, uint8_t length );
All indexes are declared in the application-specific header file to provide a quick look, for example:
#define MY_IIC_BUS_SCLK_PIN 12
#define MY_IIC_BUS_SCLK_PIN 13
#define OTHER_PIN 14
In this example, the I²C bus implementation is fully portable. It depends only on the API, which can write on chips by index.
Edit:
This driver is used as follows:
#include "iic.h"
#include "pin-declarations.h"
main()
{
struct IIC_BUS mybus;
iic_init_bus( &mybus, MY_IIC_BUS_SCLK_PIN, MY_IIC_BUS_SDAT_PIN );
iic_write( &mybus, 0x42, some_data_buffer, buffer_length );
}
Timbo source
share