summaryrefslogtreecommitdiffstats
path: root/source/AVR_Studio/Soccer/hal/i2c.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/AVR_Studio/Soccer/hal/i2c.h')
-rwxr-xr-xsource/AVR_Studio/Soccer/hal/i2c.h69
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
+