2012-08-20 15:37:46 -03:00
|
|
|
|
|
|
|
#ifndef __AP_HAL_SPI_DRIVER_H__
|
|
|
|
#define __AP_HAL_SPI_DRIVER_H__
|
|
|
|
|
|
|
|
#include "AP_HAL_Namespace.h"
|
|
|
|
|
2012-11-28 21:57:20 -04:00
|
|
|
|
|
|
|
class AP_HAL::SPIDeviceManager {
|
|
|
|
public:
|
2015-12-02 10:10:19 -04:00
|
|
|
virtual void init(void *) { }
|
|
|
|
virtual void init() { }
|
2015-09-14 15:44:29 -03:00
|
|
|
virtual AP_HAL::SPIDeviceDriver* device(enum AP_HAL::SPIDevice, uint8_t index = 0) = 0;
|
2012-11-28 21:57:20 -04:00
|
|
|
};
|
|
|
|
|
2012-08-30 20:25:35 -03:00
|
|
|
/**
|
2012-11-28 21:57:20 -04:00
|
|
|
* We still need an abstraction for performing bulk
|
2012-08-30 20:25:35 -03:00
|
|
|
* transfers to be portable to other platforms.
|
|
|
|
*/
|
|
|
|
|
2012-11-28 21:57:20 -04:00
|
|
|
class AP_HAL::SPIDeviceDriver {
|
2012-08-20 15:37:46 -03:00
|
|
|
public:
|
2012-11-28 21:57:20 -04:00
|
|
|
virtual void init() = 0;
|
|
|
|
virtual AP_HAL::Semaphore* get_semaphore() = 0;
|
2015-08-19 12:31:27 -03:00
|
|
|
virtual bool transaction(const uint8_t *tx, uint8_t *rx, uint16_t len) = 0;
|
2012-12-17 21:06:51 -04:00
|
|
|
|
2012-11-28 21:57:20 -04:00
|
|
|
virtual void cs_assert() = 0;
|
|
|
|
virtual void cs_release() = 0;
|
2012-08-30 20:25:35 -03:00
|
|
|
virtual uint8_t transfer (uint8_t data) = 0;
|
2013-01-12 07:10:00 -04:00
|
|
|
virtual void transfer (const uint8_t *data, uint16_t len) = 0;
|
2013-10-11 04:00:23 -03:00
|
|
|
|
|
|
|
/**
|
|
|
|
optional set_bus_speed() interface. This can be used by drivers
|
|
|
|
to request higher speed for sensor registers once the sensor is
|
|
|
|
initialised. This is used by the MPU6000 driver which can
|
|
|
|
handle 20MHz for sensor register reads, but only 1MHz for other
|
|
|
|
registers.
|
|
|
|
*/
|
|
|
|
enum bus_speed {
|
|
|
|
SPI_SPEED_LOW, SPI_SPEED_HIGH
|
|
|
|
};
|
|
|
|
|
2015-07-02 16:36:28 -03:00
|
|
|
enum class State : uint8_t {
|
|
|
|
UNKNOWN,
|
|
|
|
RUNNING,
|
|
|
|
FAILED,
|
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:23 -03:00
|
|
|
virtual void set_bus_speed(enum bus_speed speed) {}
|
2015-07-02 16:36:28 -03:00
|
|
|
virtual void set_state(State state) { };
|
|
|
|
virtual State get_state() { return State::UNKNOWN; }
|
2012-08-20 15:37:46 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __AP_HAL_SPI_DRIVER_H__
|
|
|
|
|