2012-08-20 15:38:09 -03:00
|
|
|
|
|
|
|
#ifndef __AP_HAL_AVR_I2C_DRIVER_H__
|
|
|
|
#define __AP_HAL_AVR_I2C_DRIVER_H__
|
|
|
|
|
|
|
|
#include <AP_HAL.h>
|
2012-08-21 18:11:24 -03:00
|
|
|
#include "AP_HAL_AVR_Namespace.h"
|
2012-08-20 15:38:09 -03:00
|
|
|
|
2012-08-24 19:32:38 -03:00
|
|
|
#define AVRI2CDRIVER_MAX_BUFFER_SIZE 32
|
|
|
|
|
2012-08-21 18:11:24 -03:00
|
|
|
class AP_HAL_AVR::AVRI2CDriver : public AP_HAL::I2CDriver {
|
2012-08-20 15:38:09 -03:00
|
|
|
public:
|
2013-01-04 20:19:38 -04:00
|
|
|
AVRI2CDriver(AP_HAL::Semaphore *sem) : _sem(sem) {}
|
2012-08-24 19:32:38 -03:00
|
|
|
|
|
|
|
void begin();
|
|
|
|
void end();
|
|
|
|
void setTimeout(uint16_t ms) { _timeoutDelay = ms; }
|
|
|
|
void setHighSpeed(bool active);
|
|
|
|
|
2012-11-27 18:22:06 -04:00
|
|
|
uint8_t write(uint8_t addr, uint8_t len, uint8_t* data);
|
2012-10-11 14:48:45 -03:00
|
|
|
uint8_t writeRegister(uint8_t addr, uint8_t reg, uint8_t val);
|
2012-08-24 19:32:38 -03:00
|
|
|
uint8_t writeRegisters(uint8_t addr, uint8_t reg,
|
|
|
|
uint8_t len, uint8_t* data);
|
2012-11-27 18:22:06 -04:00
|
|
|
uint8_t read(uint8_t addr, uint8_t len, uint8_t* data);
|
2012-10-11 14:48:45 -03:00
|
|
|
uint8_t readRegister(uint8_t addr, uint8_t reg, uint8_t* data);
|
2012-08-24 19:32:38 -03:00
|
|
|
uint8_t readRegisters(uint8_t addr, uint8_t reg,
|
|
|
|
uint8_t len, uint8_t* data);
|
|
|
|
uint8_t lockup_count() { return _lockup_count; }
|
|
|
|
|
2013-01-04 20:19:38 -04:00
|
|
|
AP_HAL::Semaphore* get_semaphore() { return _sem; }
|
|
|
|
|
2012-08-20 15:38:09 -03:00
|
|
|
private:
|
2012-08-24 19:32:38 -03:00
|
|
|
uint8_t _start();
|
|
|
|
uint8_t _stop();
|
|
|
|
uint8_t _sendAddress(uint8_t addr);
|
|
|
|
uint8_t _sendByte(uint8_t data);
|
|
|
|
uint8_t _receiveByte(bool ack);
|
|
|
|
void _handleLockup();
|
|
|
|
|
|
|
|
uint8_t _waitInterrupt();
|
|
|
|
uint8_t _waitStop();
|
|
|
|
|
|
|
|
uint8_t _lockup_count;
|
|
|
|
uint16_t _timeoutDelay;
|
2013-01-04 20:19:38 -04:00
|
|
|
|
|
|
|
AP_HAL::Semaphore *_sem;
|
2012-08-20 15:38:09 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __AP_HAL_AVR_I2C_DRIVER_H__
|
|
|
|
|