LPC11U_LPC13U_CodeBase icon indicating copy to clipboard operation
LPC11U_LPC13U_CodeBase copied to clipboard

Better I2C driver abstraction?

Open opsound opened this issue 11 years ago • 0 comments

Would it be better to abstract away access to I2CWriteLength, I2CReadLength, I2CMasterBuffer, I2CSlaveBuffer? It seems like manipulation of these global variables creates a lot of coupling in between the I2C driver and any modules that use it.

For example, something along the lines of...

#include <string.h> // For memcpy

uint32_t i2cWrite(uint8_t *buffer, uint8_t len)
{
   I2CWriteLength = len;
   I2CReadLength = 0;

   memcpy(I2CMasterBuffer, buffer, len);

   return i2cEngine();
}

uint32_t i2cWriteRead(uint8_t *w_buffer, uint8_t w_len,
                      uint8_t *r_buffer, uint8_t r_len)
{
   I2CWriteLength = w_len;
   I2CReadLength = r_len;

   memcpy(I2CMasterBuffer, w_buffer, w_len);

   uint32_t ret = i2cEngine();

   memcpy(r_buffer, I2CSlaveBuffer, r_len);

   return ret;
}

opsound avatar Feb 25 '14 22:02 opsound