mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-28 02:33:58 -04:00
AP_HAL_ChibiOS: add support for bank selection call outside SPI driver
This commit is contained in:
parent
4cdb4b74f3
commit
3ddd1d484a
@ -125,6 +125,7 @@ SPIDevice::SPIDevice(SPIBus &_bus, SPIDesc &_device_desc)
|
|||||||
asprintf(&pname, "SPI:%s:%u:%u",
|
asprintf(&pname, "SPI:%s:%u:%u",
|
||||||
device_desc.name,
|
device_desc.name,
|
||||||
(unsigned)bus.bus, (unsigned)device_desc.device);
|
(unsigned)bus.bus, (unsigned)device_desc.device);
|
||||||
|
AP_HAL::SPIDevice::setup_bankselect_callback(device_desc.bank_select_cb);
|
||||||
//printf("SPI device %s on %u:%u at speed %u mode %u\n",
|
//printf("SPI device %s on %u:%u at speed %u mode %u\n",
|
||||||
// device_desc.name,
|
// device_desc.name,
|
||||||
// (unsigned)bus.bus, (unsigned)device_desc.device,
|
// (unsigned)bus.bus, (unsigned)device_desc.device,
|
||||||
|
@ -51,7 +51,8 @@ struct SPIDesc {
|
|||||||
uint32_t _mode, uint32_t _lowspeed, uint32_t _highspeed)
|
uint32_t _mode, uint32_t _lowspeed, uint32_t _highspeed)
|
||||||
: name(_name), bus(_bus), device(_device),
|
: name(_name), bus(_bus), device(_device),
|
||||||
pal_line(_pal_line), mode(_mode),
|
pal_line(_pal_line), mode(_mode),
|
||||||
lowspeed(_lowspeed), highspeed(_highspeed)
|
lowspeed(_lowspeed), highspeed(_highspeed),
|
||||||
|
bank_select_cb(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,6 +63,7 @@ struct SPIDesc {
|
|||||||
uint32_t mode;
|
uint32_t mode;
|
||||||
uint32_t lowspeed;
|
uint32_t lowspeed;
|
||||||
uint32_t highspeed;
|
uint32_t highspeed;
|
||||||
|
AP_HAL::Device::BankSelectCb bank_select_cb;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -82,6 +84,25 @@ public:
|
|||||||
bool transfer_fullduplex(const uint8_t *send, uint8_t *recv,
|
bool transfer_fullduplex(const uint8_t *send, uint8_t *recv,
|
||||||
uint32_t len) override;
|
uint32_t len) override;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Links the bank select callback to the spi bus, so that even when
|
||||||
|
used outside of the driver bank selection can be done.
|
||||||
|
*/
|
||||||
|
void setup_bankselect_callback(BankSelectCb bank_select) override {
|
||||||
|
device_desc.bank_select_cb = bank_select;
|
||||||
|
AP_HAL::SPIDevice::setup_bankselect_callback(bank_select);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Ensure to deregister bankselect callback in destructor of user
|
||||||
|
that could potentially be deleted. otherewise the orphaned functor
|
||||||
|
can be called causing memory corruption.
|
||||||
|
*/
|
||||||
|
void deregister_bankselect_callback() override {
|
||||||
|
device_desc.bank_select_cb = nullptr;
|
||||||
|
AP_HAL::SPIDevice::deregister_bankselect_callback();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* send N bytes of clock pulses without taking CS. This is used
|
* send N bytes of clock pulses without taking CS. This is used
|
||||||
* when initialising microSD interfaces over SPI
|
* when initialising microSD interfaces over SPI
|
||||||
|
Loading…
Reference in New Issue
Block a user