projects
/
bertos.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
First version of new i2c bitbang API.
[bertos.git]
/
bertos
/
drv
/
i2c.h
diff --git
a/bertos/drv/i2c.h
b/bertos/drv/i2c.h
index ec193c66a8a51c76f46a26fe4e06789bfad3eed5..f527f359d19d375998633260ba90453e65ea600a 100644
(file)
--- a/
bertos/drv/i2c.h
+++ b/
bertos/drv/i2c.h
@@
-134,10
+134,13
@@
bool i2c_recv(void *_buf, size_t count);
*
*/
#define I2C_OK 0
*
*/
#define I2C_OK 0
-#define I2C_START_ERR BV(0)
+#define I2C_ERR BV(3)
+#define I2C_ARB_LOST BV(2)
+#define I2C_START_TIMEOUT BV(0)
#define I2C_NO_ACK BV(1)
#define I2C_NO_ACK BV(1)
+
#define I2C_NOSTOP 0
#define I2C_STOP BV(0)
#define I2C_START_R BV(1)
#define I2C_NOSTOP 0
#define I2C_STOP BV(0)
#define I2C_START_R BV(1)
@@
-145,6
+148,7
@@
bool i2c_recv(void *_buf, size_t count);
#define I2C_TEST_START(flag) ((flag) & I2C_START_R)
#define I2C_TEST_START(flag) ((flag) & I2C_START_R)
+#define I2C_TEST_STOP(flag) ((flag) & I2C_STOP)
struct I2cHardware;
struct I2c;
struct I2cHardware;
struct I2c;
@@
-176,32
+180,32
@@
typedef struct I2c
#include CPU_HEADER(i2c)
#include CPU_HEADER(i2c)
-INLINE void i2c_start
_r(I2c *i2c, uint16_t slave_addr, size_t size, int flags
)
+INLINE void i2c_start
(I2c *i2c, uint16_t slave_addr, size_t size
)
{
{
- ASSERT(i2c);
ASSERT(i2c->vt);
ASSERT(i2c->vt->start);
ASSERT(i2c->vt);
ASSERT(i2c->vt->start);
- ASSERT(i2c->xfer_size == 0);
- i2c->flags = flags | I2C_START_R;
+ if (!i2c->errors)
+ ASSERT(i2c->xfer_size == 0);
+
i2c->errors = 0;
i2c->xfer_size = size;
i2c->vt->start(i2c, slave_addr);
}
i2c->errors = 0;
i2c->xfer_size = size;
i2c->vt->start(i2c, slave_addr);
}
-INLINE void i2c_start_
w
(I2c *i2c, uint16_t slave_addr, size_t size, int flags)
+INLINE void i2c_start_
r
(I2c *i2c, uint16_t slave_addr, size_t size, int flags)
{
ASSERT(i2c);
{
ASSERT(i2c);
-
ASSERT(i2c->vt)
;
-
ASSERT(i2c->vt->start
);
- ASSERT(i2c->xfer_size == 0);
+
i2c->flags = flags | I2C_START_R
;
+
i2c_start(i2c, slave_addr, size
);
+}
+INLINE void i2c_start_w(I2c *i2c, uint16_t slave_addr, size_t size, int flags)
+{
+ ASSERT(i2c);
i2c->flags = flags & ~I2C_START_R;
i2c->flags = flags & ~I2C_START_R;
- i2c->errors = 0;
- i2c->xfer_size = size;
-
- i2c->vt->start(i2c, slave_addr);
+ i2c_start(i2c, slave_addr, size);
}
INLINE uint8_t i2c_get(I2c *i2c)
}
INLINE uint8_t i2c_get(I2c *i2c)
@@
-210,12
+214,16
@@
INLINE uint8_t i2c_get(I2c *i2c)
ASSERT(i2c->vt);
ASSERT(i2c->vt->get);
ASSERT(i2c->vt);
ASSERT(i2c->vt->get);
- ASSERT(i2c->xfer_size
>= 1
);
+ ASSERT(i2c->xfer_size);
ASSERT(I2C_TEST_START(i2c->flags) == I2C_START_R);
if (!i2c->errors)
ASSERT(I2C_TEST_START(i2c->flags) == I2C_START_R);
if (!i2c->errors)
- return i2c->vt->get(i2c);
+ {
+ uint8_t data = i2c->vt->get(i2c);
+ i2c->xfer_size--;
+ return data;
+ }
else
return 0xFF;
}
else
return 0xFF;
}
@@
-226,12
+234,15
@@
INLINE void i2c_put(I2c *i2c, uint8_t data)
ASSERT(i2c->vt);
ASSERT(i2c->vt->put);
ASSERT(i2c->vt);
ASSERT(i2c->vt->put);
- ASSERT(i2c->xfer_size
>= 1
);
+ ASSERT(i2c->xfer_size);
ASSERT(I2C_TEST_START(i2c->flags) == I2C_START_W);
if (!i2c->errors)
ASSERT(I2C_TEST_START(i2c->flags) == I2C_START_W);
if (!i2c->errors)
+ {
i2c->vt->put(i2c, data);
i2c->vt->put(i2c, data);
+ i2c->xfer_size--;
+ }
}
INLINE void i2c_send(I2c *i2c, const void *_buf, size_t count)
}
INLINE void i2c_send(I2c *i2c, const void *_buf, size_t count)