From 9a5753f23fb7d55a7a72c8cf9846cc72349c65de Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Thu, 13 Feb 2014 16:45:48 +0100 Subject: Split up main.c --- i2c.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 i2c.h (limited to 'i2c.h') 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 + +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 + +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 */ -- cgit v1.2.3