mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-02 14:13:42 -04:00
7ac51f60d0
This commit changes the way libraries headers are included in source files: - If the header is in the same directory the source belongs to, so the notation '#include ""' is used with the path relative to the directory containing the source. - If the header is outside the directory containing the source, then we use the notation '#include <>' with the path relative to libraries folder. Some of the advantages of such approach: - Only one search path for libraries headers. - OSs like Windows may have a better lookup time.
66 lines
2.0 KiB
C++
66 lines
2.0 KiB
C++
|
|
#ifndef __AP_HAL_EMPTY_SPIDRIVER_H__
|
|
#define __AP_HAL_EMPTY_SPIDRIVER_H__
|
|
|
|
#include "AP_HAL_Linux.h"
|
|
#include "Semaphores.h"
|
|
|
|
// Most platforms won't need to declare the spidev bus offset
|
|
#ifndef LINUX_SPIDEV_BUS_OFFSET
|
|
#define LINUX_SPIDEV_BUS_OFFSET 0
|
|
#endif
|
|
|
|
#define LINUX_SPI_MAX_BUSES 3
|
|
|
|
// Fake CS pin to indicate in-kernel handling
|
|
#define SPI_CS_KERNEL -1
|
|
|
|
class Linux::LinuxSPIDeviceDriver : public AP_HAL::SPIDeviceDriver {
|
|
public:
|
|
friend class Linux::LinuxSPIDeviceManager;
|
|
LinuxSPIDeviceDriver(uint16_t bus, uint16_t subdev, enum AP_HAL::SPIDevice type, uint8_t mode, uint8_t bitsPerWord, int16_t cs_pin, uint32_t lowspeed, uint32_t highspeed);
|
|
void init();
|
|
AP_HAL::Semaphore *get_semaphore();
|
|
void transaction(const uint8_t *tx, uint8_t *rx, uint16_t len);
|
|
|
|
void cs_assert();
|
|
void cs_release();
|
|
uint8_t transfer (uint8_t data);
|
|
void transfer (const uint8_t *data, uint16_t len);
|
|
void set_bus_speed(enum bus_speed speed);
|
|
void set_state(State state) override { _state = state; }
|
|
State get_state() override { return _state; }
|
|
|
|
private:
|
|
uint16_t _bus;
|
|
uint16_t _subdev;
|
|
int16_t _cs_pin;
|
|
AP_HAL::DigitalSource *_cs;
|
|
uint8_t _mode;
|
|
uint8_t _bitsPerWord;
|
|
State _state = State::UNKNOWN;
|
|
uint32_t _lowspeed;
|
|
uint32_t _highspeed;
|
|
uint32_t _speed;
|
|
enum AP_HAL::SPIDevice _type;
|
|
int _fd; // Per-device FD.
|
|
};
|
|
|
|
class Linux::LinuxSPIDeviceManager : public AP_HAL::SPIDeviceManager {
|
|
public:
|
|
void init(void *);
|
|
AP_HAL::SPIDeviceDriver* device(enum AP_HAL::SPIDevice);
|
|
|
|
static AP_HAL::Semaphore *get_semaphore(uint16_t bus);
|
|
|
|
static void cs_assert(enum AP_HAL::SPIDevice type);
|
|
static void cs_release(enum AP_HAL::SPIDevice type);
|
|
static void transaction(LinuxSPIDeviceDriver &driver, const uint8_t *tx, uint8_t *rx, uint16_t len);
|
|
|
|
private:
|
|
static LinuxSPIDeviceDriver _device[];
|
|
static LinuxSemaphore _semaphore[LINUX_SPI_MAX_BUSES];
|
|
};
|
|
|
|
#endif // __AP_HAL_LINUX_SPIDRIVER_H__
|