diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2014-02-13 16:45:48 +0100 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2014-02-13 16:45:48 +0100 |
commit | 9a5753f23fb7d55a7a72c8cf9846cc72349c65de (patch) | |
tree | 81ffaf7f1f5673880fa17546cc8ff3dae08345b9 /i2c.h | |
parent | ab0e37395d2390727248361f00f37109fd6bde9c (diff) | |
download | hourglass-9a5753f23fb7d55a7a72c8cf9846cc72349c65de.tar.gz hourglass-9a5753f23fb7d55a7a72c8cf9846cc72349c65de.tar.bz2 hourglass-9a5753f23fb7d55a7a72c8cf9846cc72349c65de.zip |
Split up main.c
Diffstat (limited to 'i2c.h')
-rw-r--r-- | i2c.h | 51 |
1 files changed, 51 insertions, 0 deletions
@@ -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 */ |