projects
/
bertos.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add reg definition for adc driver.
[bertos.git]
/
bertos
/
drv
/
pcf8574.c
diff --git
a/bertos/drv/pcf8574.c
b/bertos/drv/pcf8574.c
index c4477efce2df8c9d39c41048c315e82c41e81129..7c5cf164b30b132c3c86c647a526566fd5a22ce6 100644
(file)
--- a/
bertos/drv/pcf8574.c
+++ b/
bertos/drv/pcf8574.c
@@
-40,25
+40,30
@@
* each pin as input or output, see datasheet on how this
* is achieved.
*
* each pin as input or output, see datasheet on how this
* is achieved.
*
- * \version $Id: ft245rl.c 22301 2008-09-09 16:53:17Z batt $
* \author Francesco Sacchi <batt@develer.com>
*/
#include "pcf8574.h"
* \author Francesco Sacchi <batt@develer.com>
*/
#include "pcf8574.h"
+
+#include "cfg/cfg_i2c.h"
+
#include <cfg/module.h>
#include <cfg/module.h>
+
#include <drv/i2c.h>
/**
* Read PCF8574 \a pcf bit status.
* \return the pins status or EOF on errors.
*/
#include <drv/i2c.h>
/**
* Read PCF8574 \a pcf bit status.
* \return the pins status or EOF on errors.
*/
-int pcf8574_get
(
Pcf8574 *pcf)
+int pcf8574_get
_2(I2c *i2c,
Pcf8574 *pcf)
{
{
- if (!i2c_start_r(PCF8574ID | ((pcf->addr << 1) & 0xF7)))
- return EOF;
+ i2c_start_r(i2c, PCF8574ID | ((pcf->addr << 1) & 0xF7), 1, I2C_STOP);
+
+ int data = i2c_getc(i2c);
+
+ if (i2c_error(i2c))
+ data = EOF;
- int data = i2c_get(false);
- i2c_stop();
return data;
}
return data;
}
@@
-66,20
+71,26
@@
int pcf8574_get(Pcf8574 *pcf)
* Write to PCF8574 \a pcf port \a data.
* \return true if ok, false on errors.
*/
* Write to PCF8574 \a pcf port \a data.
* \return true if ok, false on errors.
*/
-bool pcf8574_put
(
Pcf8574 *pcf, uint8_t data)
+bool pcf8574_put
_3(I2c *i2c,
Pcf8574 *pcf, uint8_t data)
{
{
- bool res = i2c_start_w(PCF8574ID | ((pcf->addr << 1) & 0xF7)) && i2c_put(data);
- i2c_stop();
- return res;
+ i2c_start_w(i2c, PCF8574ID | ((pcf->addr << 1) & 0xF7), 1, I2C_STOP);
+ i2c_putc(i2c, data);
+
+ if (i2c_error(i2c))
+ return false;
+
+ return true;
}
/**
* Init a PCF8574 on the bus with addr \a addr.
* \return true if device is found, false otherwise.
*/
}
/**
* Init a PCF8574 on the bus with addr \a addr.
* \return true if device is found, false otherwise.
*/
-bool pcf8574_init
(
Pcf8574 *pcf, pcf8574_addr addr)
+bool pcf8574_init
_3(I2c *i2c,
Pcf8574 *pcf, pcf8574_addr addr)
{
{
-
MOD_CHECK
(i2c);
+
ASSERT
(i2c);
pcf->addr = addr;
pcf->addr = addr;
- return pcf8574_get(pcf) != EOF;
+
+ return (pcf8574_get(i2c, pcf) != EOF);
}
}
+