123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- #pragma once
- #include <inttypes.h>
- #include <vector>
- #include <AP_HAL/HAL.h>
- #include <AP_HAL/SPIDevice.h>
- namespace Linux {
- class SPIBus;
- class SPIDesc;
- class SPIDevice : public AP_HAL::SPIDevice {
- public:
- SPIDevice(SPIBus &bus, SPIDesc &device_desc);
- virtual ~SPIDevice();
-
-
- bool set_speed(AP_HAL::Device::Speed speed) override;
-
- bool transfer(const uint8_t *send, uint32_t send_len,
- uint8_t *recv, uint32_t recv_len) override;
-
- bool transfer_fullduplex(const uint8_t *send, uint8_t *recv,
- uint32_t len) override;
-
- AP_HAL::Semaphore *get_semaphore() override;
-
- AP_HAL::Device::PeriodicHandle register_periodic_callback(
- uint32_t period_usec, AP_HAL::Device::PeriodicCb) override;
-
- bool adjust_periodic_callback(
- AP_HAL::Device::PeriodicHandle h, uint32_t period_usec) override;
- protected:
- SPIBus &_bus;
- SPIDesc &_desc;
- AP_HAL::DigitalSource *_cs;
- uint32_t _speed;
-
- void _cs_assert();
-
- void _cs_release();
- };
- class SPIDeviceManager : public AP_HAL::SPIDeviceManager {
- public:
- friend class SPIDevice;
- static SPIDeviceManager *from(AP_HAL::SPIDeviceManager *spi_mgr)
- {
- return static_cast<SPIDeviceManager*>(spi_mgr);
- }
- SPIDeviceManager()
- {
-
- _buses.reserve(3);
- }
-
- AP_HAL::OwnPtr<AP_HAL::SPIDevice> get_device(const char *name) override;
-
- void teardown();
-
- uint8_t get_count() override;
-
- const char *get_device_name(uint8_t idx) override;
- protected:
- void _unregister(SPIBus &b);
- AP_HAL::OwnPtr<AP_HAL::SPIDevice> _create_device(SPIBus &b, SPIDesc &device_desc) const;
- std::vector<SPIBus*> _buses;
- static const uint8_t _n_device_desc;
- static SPIDesc _device[];
- };
- }
|