Skip to content

Better I2C driver abstraction? #17

@opsound

Description

@opsound

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions