diff options
author | sicarius <devnull@localhost> | 2007-02-11 20:03:00 +0100 |
---|---|---|
committer | sicarius <devnull@localhost> | 2007-02-11 20:03:00 +0100 |
commit | 05c8b0af602b222d00c227560682158333b726a2 (patch) | |
tree | 98a7eaa96222097b9d74343b37447820f9250efc /source/AVR_Studio/Soccer/hal/i2c.h | |
parent | 1a6b28b1c2a68cfccbe8f4ed9866aadf88db7085 (diff) | |
download | rc2007-soccer-05c8b0af602b222d00c227560682158333b726a2.tar rc2007-soccer-05c8b0af602b222d00c227560682158333b726a2.zip |
Added lot's of code-files used during work
Diffstat (limited to 'source/AVR_Studio/Soccer/hal/i2c.h')
-rwxr-xr-x | source/AVR_Studio/Soccer/hal/i2c.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/source/AVR_Studio/Soccer/hal/i2c.h b/source/AVR_Studio/Soccer/hal/i2c.h new file mode 100755 index 0000000..e983bf2 --- /dev/null +++ b/source/AVR_Studio/Soccer/hal/i2c.h @@ -0,0 +1,69 @@ +#ifndef _IC2_H_
+#define _I2C_H_
+
+//------------------------------------------------------------------
+// qfixI2C.h
+//
+// This class is used for low-level I2C communication.
+//
+// For TW_ constants see compat/twi.h
+//
+// Copyright 2005-2006 by KTB mechatronics GmbH
+// Author: Stefan Enderle, Florian Schrapp
+//------------------------------------------------------------------
+
+
+
+#include "../global.h"
+#include <compat/twi.h>
+
+const int ACTION_SEND = 1;
+const int ACTION_GET = 2;
+const int ACTION_UNKNOWN = 3;
+
+
+const uint8_t ERROR_NO_ACK = 1;
+const uint8_t ERROR_NO_START = 2;
+const uint8_t ERROR_NOT_SENT = 3; // send() could not send byte(s)
+
+
+
+class I2C
+{
+private:
+ uint8_t err;
+ uint8_t adr;
+
+ void sendStartSLA_W(uint8_t address);
+ void sendStartSLA_R(uint8_t address);
+ void sendByte(uint8_t data);
+ void sendStop();
+ void readByte(uint8_t& data);
+
+public:
+ I2C();
+ uint8_t error();
+
+// master side //
+
+ void send(uint8_t address, uint8_t data);
+ void send(uint8_t address, uint8_t* data, int length);
+ void get(uint8_t address, uint8_t* data, int length);
+
+// slave side //
+
+ void setSlaveAdress(uint8_t address);
+ bool isAction();
+ bool isActionSend(); // true if master sent something
+ bool isActionGet(); // true if master wants to get something
+ int receive(uint8_t* data); // if action is send, receive the bytes
+ void returnBytes(uint8_t* data, int len, bool lastOne);
+};
+
+
+
+
+
+
+#endif
+
|