From 05c8b0af602b222d00c227560682158333b726a2 Mon Sep 17 00:00:00 2001 From: sicarius Date: Sun, 11 Feb 2007 19:03:00 +0000 Subject: Added lot's of code-files used during work --- source/AVR_Studio/Soccer/hal/i2c.h | 69 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 source/AVR_Studio/Soccer/hal/i2c.h (limited to 'source/AVR_Studio/Soccer/hal/i2c.h') 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 + +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 + -- cgit v1.2.3