BeRTOS
pcf8574.c
Go to the documentation of this file.
00001 
00046 #include "pcf8574.h"
00047 
00048 #include "cfg/cfg_i2c.h"
00049 
00050 #include <cfg/module.h>
00051 
00052 #include <drv/i2c.h>
00053 
00058 int pcf8574_get_2(I2c *i2c, Pcf8574 *pcf)
00059 {
00060     i2c_start_r(i2c, PCF8574ID | ((pcf->addr << 1) & 0xF7), 1, I2C_STOP);
00061 
00062     int data = i2c_getc(i2c);
00063 
00064     if (i2c_error(i2c))
00065         data = EOF;
00066 
00067     return data;
00068 }
00069 
00074 bool pcf8574_put_3(I2c *i2c, Pcf8574 *pcf, uint8_t data)
00075 {
00076     i2c_start_w(i2c, PCF8574ID | ((pcf->addr << 1) & 0xF7), 1, I2C_STOP);
00077     i2c_putc(i2c, data);
00078 
00079     if (i2c_error(i2c))
00080         return false;
00081 
00082     return true;
00083 }
00084 
00089 bool pcf8574_init_3(I2c *i2c, Pcf8574 *pcf, pcf8574_addr addr)
00090 {
00091     ASSERT(i2c);
00092     pcf->addr = addr;
00093 
00094     return (pcf8574_get(i2c, pcf) != EOF);
00095 }
00096