aboutsummaryrefslogtreecommitdiff
path: root/i2c.h
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2014-02-13 16:45:48 +0100
committerLars-Dominik Braun <lars@6xq.net>2014-02-13 16:45:48 +0100
commit9a5753f23fb7d55a7a72c8cf9846cc72349c65de (patch)
tree81ffaf7f1f5673880fa17546cc8ff3dae08345b9 /i2c.h
parentab0e37395d2390727248361f00f37109fd6bde9c (diff)
downloadhourglass-9a5753f23fb7d55a7a72c8cf9846cc72349c65de.tar.gz
hourglass-9a5753f23fb7d55a7a72c8cf9846cc72349c65de.tar.bz2
hourglass-9a5753f23fb7d55a7a72c8cf9846cc72349c65de.zip
Split up main.c
Diffstat (limited to 'i2c.h')
-rw-r--r--i2c.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/i2c.h b/i2c.h
new file mode 100644
index 0000000..1381663
--- /dev/null
+++ b/i2c.h
@@ -0,0 +1,51 @@
+#ifndef TW_H
+#define TW_H
+
+typedef enum {
+ TWM_INVALID = 0,
+ TWM_WRITE,
+ TWM_READ_MULTI,
+} twMode;
+
+typedef enum {
+ TWST_WAIT = 0,
+ TWST_OK = 1,
+ TWST_ERR = 2,
+} twStatus;
+
+#include <stdint.h>
+
+typedef struct {
+ twMode mode;
+ uint8_t address;
+ uint8_t subaddress;
+ uint8_t data;
+ uint8_t step;
+ /* read data store */
+ uint8_t *retData;
+ /* number of bytes to be read */
+ uint8_t count;
+ /* current byte */
+ uint8_t i;
+ twStatus status;
+} twReq;
+
+extern volatile twReq twr;
+
+/* i2c device addresses */
+#define L3GD20 0b11010100
+#define L3GD20_WHOAMI 0xf
+#define L3GD20_CTRLREG1 0x20
+#define LIS302DL 0b00111000
+#define LIS302DL_WHOAMI 0xf
+#define LIS302DL_CTRLREG1 0x20
+
+#include <stdbool.h>
+
+void twInit ();
+bool twWrite (const uint8_t address, const uint8_t subaddress,
+ const uint8_t data);
+bool twReadMulti (const uint8_t address, const uint8_t subaddress,
+ uint8_t * const retData, const uint8_t count);
+
+#endif /* TW_H */