2015-09-07 05:58:20 -03:00
|
|
|
|
|
|
|
#ifndef __AP_HAL_PX4_I2CDRIVER_H__
|
|
|
|
#define __AP_HAL_PX4_I2CDRIVER_H__
|
|
|
|
|
|
|
|
#include "AP_HAL_PX4.h"
|
|
|
|
#include <AP_HAL_Empty/AP_HAL_Empty.h>
|
|
|
|
#include <AP_HAL_Empty/AP_HAL_Empty_Private.h>
|
|
|
|
|
|
|
|
class PX4::PX4I2CDriver : public AP_HAL::I2CDriver {
|
|
|
|
public:
|
|
|
|
PX4I2CDriver(void);
|
|
|
|
|
2015-11-30 16:18:25 -04:00
|
|
|
void begin() override {}
|
|
|
|
void end() override {}
|
|
|
|
void setTimeout(uint16_t ms) override {}
|
|
|
|
void setHighSpeed(bool active) override {}
|
|
|
|
|
|
|
|
// main transfer function
|
|
|
|
bool do_transfer(uint8_t address, const uint8_t *send, uint32_t send_len, uint8_t *recv, uint32_t recv_len) override;
|
2015-09-07 05:58:20 -03:00
|
|
|
|
|
|
|
/* write: for i2c devices which do not obey register conventions */
|
2015-11-30 16:18:25 -04:00
|
|
|
uint8_t write(uint8_t addr, uint8_t len, uint8_t* data) override;
|
2015-09-07 05:58:20 -03:00
|
|
|
|
|
|
|
/* writeRegister: write a single 8-bit value to a register */
|
2015-11-30 16:18:25 -04:00
|
|
|
uint8_t writeRegister(uint8_t addr, uint8_t reg, uint8_t val) override;
|
2015-09-07 05:58:20 -03:00
|
|
|
|
|
|
|
/* writeRegisters: write bytes to contigious registers */
|
2015-11-30 16:18:25 -04:00
|
|
|
uint8_t writeRegisters(uint8_t addr, uint8_t reg, uint8_t len, uint8_t* data) override;
|
2015-09-07 05:58:20 -03:00
|
|
|
|
|
|
|
/* read: for i2c devices which do not obey register conventions */
|
2015-11-30 16:18:25 -04:00
|
|
|
uint8_t read(uint8_t addr, uint8_t len, uint8_t* data) override;
|
2015-09-07 05:58:20 -03:00
|
|
|
|
|
|
|
/* readRegister: read from a device register - writes the register,
|
|
|
|
* then reads back an 8-bit value. */
|
2015-11-30 16:18:25 -04:00
|
|
|
uint8_t readRegister(uint8_t addr, uint8_t reg, uint8_t* data) override;
|
2015-09-07 05:58:20 -03:00
|
|
|
|
|
|
|
/* readRegister: read contigious device registers - writes the first
|
|
|
|
* register, then reads back multiple bytes */
|
2015-11-30 16:18:25 -04:00
|
|
|
uint8_t readRegisters(uint8_t addr, uint8_t reg, uint8_t len, uint8_t* data) override;
|
2015-09-07 05:58:20 -03:00
|
|
|
|
2015-11-30 16:18:25 -04:00
|
|
|
uint8_t lockup_count() override { return 0; }
|
2015-09-07 05:58:20 -03:00
|
|
|
|
2015-11-30 16:18:25 -04:00
|
|
|
AP_HAL::Semaphore* get_semaphore() override { return &semaphore; }
|
2015-09-07 05:58:20 -03:00
|
|
|
|
|
|
|
private:
|
|
|
|
// we use an empty semaphore as the underlying I2C class already has a semaphore
|
2015-12-07 15:01:34 -04:00
|
|
|
Empty::Semaphore semaphore;
|
2015-09-07 05:58:20 -03:00
|
|
|
PX4_I2C *px4_i2c = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __AP_HAL_PX4_I2CDRIVER_H__
|