projects
/
bertos.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add documentation.
[bertos.git]
/
bertos
/
drv
/
i2c_bitbang.c
diff --git
a/bertos/drv/i2c_bitbang.c
b/bertos/drv/i2c_bitbang.c
index 71374e98583c343dcbaf67978eb09cfae45a6195..1d7e98d6819c0d7b86ec09829e3ca38cad274455 100644
(file)
--- a/
bertos/drv/i2c_bitbang.c
+++ b/
bertos/drv/i2c_bitbang.c
@@
-32,7
+32,7
@@
*
* \brief I2C bitbang driver (implementation)
*
*
* \brief I2C bitbang driver (implementation)
*
- * \version $Id
: adc.c 1604 2008-08-10 17:19:51Z bernie
$
+ * \version $Id$
* \author Francesco Sacchi <batt@develer.com>
*/
* \author Francesco Sacchi <batt@develer.com>
*/
@@
-43,21
+43,26
@@
#define LOG_FORMAT I2C_LOG_FORMAT
#include <cfg/log.h>
#define LOG_FORMAT I2C_LOG_FORMAT
#include <cfg/log.h>
+#include <cfg/macros.h>
#include <cfg/module.h>
#include <cfg/module.h>
+#include <drv/timer.h>
+#include <cpu/irq.h>
+
#include "hw/hw_i2c_bitbang.h"
#include "hw/hw_i2c_bitbang.h"
-INLINE bool i2c_start(void)
+INLINE bool i2c_
bitbang_
start(void)
{
SDA_HI;
SCL_HI;
I2C_HALFBIT_DELAY();
SDA_LO;
I2C_HALFBIT_DELAY();
{
SDA_HI;
SCL_HI;
I2C_HALFBIT_DELAY();
SDA_LO;
I2C_HALFBIT_DELAY();
+ ASSERT(!SDA_IN);
return !SDA_IN;
}
return !SDA_IN;
}
-void i2c_stop(void)
+void i2c_
bitbang_
stop(void)
{
SDA_LO;
SCL_HI;
{
SDA_LO;
SCL_HI;
@@
-65,7
+70,7
@@
void i2c_stop(void)
SDA_HI;
}
SDA_HI;
}
-bool i2c_put(uint8_t _data)
+bool i2c_
bitbang_
put(uint8_t _data)
{
/* Add ACK bit */
uint16_t data = (_data << 1) | 1;
{
/* Add ACK bit */
uint16_t data = (_data << 1) | 1;
@@
-89,7
+94,7
@@
bool i2c_put(uint8_t _data)
return ack;
}
return ack;
}
-bool i2c_start_w(uint8_t id)
+bool i2c_
bitbang_
start_w(uint8_t id)
{
id &= ~I2C_READBIT;
/*
{
id &= ~I2C_READBIT;
/*
@@
-99,9
+104,9
@@
bool i2c_start_w(uint8_t id)
* keep trying until the deveice responds with an ACK.
*/
ticks_t start = timer_clock();
* keep trying until the deveice responds with an ACK.
*/
ticks_t start = timer_clock();
- while (i2c_start())
+ while (i2c_
bitbang_
start())
{
{
- if (i2c_put(id))
+ if (i2c_
bitbang_
put(id))
return true;
else if (timer_clock() - start > ms_to_ticks(CONFIG_I2C_START_TIMEOUT))
{
return true;
else if (timer_clock() - start > ms_to_ticks(CONFIG_I2C_START_TIMEOUT))
{
@@
-114,12
+119,12
@@
bool i2c_start_w(uint8_t id)
return false;
}
return false;
}
-bool i2c_start_r(uint8_t id)
+bool i2c_
bitbang_
start_r(uint8_t id)
{
id |= I2C_READBIT;
{
id |= I2C_READBIT;
- if (i2c_start())
+ if (i2c_
bitbang_
start())
{
{
- if (i2c_put(id))
+ if (i2c_
bitbang_
put(id))
return true;
LOG_ERR("NACK on I2c start read\n");
return true;
LOG_ERR("NACK on I2c start read\n");
@@
-128,7
+133,7
@@
bool i2c_start_r(uint8_t id)
return false;
}
return false;
}
-int i2c_get(bool ack)
+int i2c_
bitbang_
get(bool ack)
{
uint8_t data = 0;
for (uint8_t i = 0x80; i != 0; i >>= 1)
{
uint8_t data = 0;
for (uint8_t i = 0x80; i != 0; i >>= 1)
@@
-164,8
+169,9
@@
MOD_DEFINE(i2c);
/**
* Initialize i2c module.
*/
/**
* Initialize i2c module.
*/
-void i2c_init(void)
+void i2c_
bitbang_
init(void)
{
{
+ MOD_CHECK(timer);
I2C_BITBANG_HW_INIT;
SDA_HI;
SCL_HI;
I2C_BITBANG_HW_INIT;
SDA_HI;
SCL_HI;