BeRTOS
i2c.c
Go to the documentation of this file.
00001 
00038 #include "i2c.h"
00039 
00040 #include "cfg/cfg_i2c.h"
00041 
00042 #if !CONFIG_I2C_DISABLE_OLD_API
00043 
00044 I2c local_i2c_old_api;
00045 
00052 bool i2c_send(const void *_buf, size_t count)
00053 {
00054     const uint8_t *buf = (const uint8_t *)_buf;
00055 
00056     while (count--)
00057     {
00058         if (!i2c_put(*buf++))
00059             return false;
00060     }
00061     return true;
00062 }
00063 
00076 bool i2c_recv(void *_buf, size_t count)
00077 {
00078     uint8_t *buf = (uint8_t *)_buf;
00079 
00080     while (count--)
00081     {
00082         /*
00083          * The last byte read does not has an ACK
00084          * to stop communication.
00085          */
00086         int c = i2c_get(count);
00087 
00088         if (c == EOF)
00089             return false;
00090         else
00091             *buf++ = c;
00092     }
00093 
00094     return true;
00095 }
00096 #endif /* !CONFIG_I2C_DISABLE_OLD_API */
00097 
00098 void i2c_genericWrite(struct I2c *i2c, const void *_buf, size_t count)
00099 {
00100     const uint8_t *buf = (const uint8_t *)_buf;
00101 
00102     while (count--)
00103         i2c_putc(i2c, *buf++);
00104 }
00105 
00106 void i2c_genericRead(struct I2c *i2c, void *_buf, size_t count)
00107 {
00108     uint8_t *buf = (uint8_t *)_buf;
00109 
00110     while (count--)
00111         *buf++ = i2c_getc(i2c);
00112 }
00113