pcf8574.c

Go to the documentation of this file.
00001 
00047 #include "pcf8574.h"
00048 #include <cfg/module.h>
00049 #include <drv/i2c.h>
00050 
00055 int pcf8574_get(Pcf8574 *pcf)
00056 {
00057     if (!i2c_start_r(PCF8574ID | ((pcf->addr << 1) & 0xF7)))
00058         return EOF;
00059 
00060     int data = i2c_get(false);
00061     i2c_stop();
00062     return data;
00063 }
00064 
00069 bool pcf8574_put(Pcf8574 *pcf, uint8_t data)
00070 {
00071     bool res = i2c_start_w(PCF8574ID | ((pcf->addr << 1) & 0xF7)) && i2c_put(data);
00072     i2c_stop();
00073     return res;
00074 }
00075 
00080 bool pcf8574_init(Pcf8574 *pcf, pcf8574_addr addr)
00081 {
00082     MOD_CHECK(i2c);
00083     pcf->addr = addr;
00084     return pcf8574_get(pcf) != EOF;
00085 }