mirror of https://github.com/ArduPilot/ardupilot
AP_HAL_ChibiOS: add mechanism to set register rw register using device name for SPI
This commit is contained in:
parent
e26ffc4ec5
commit
76d6170ec9
|
@ -126,6 +126,7 @@ SPIDevice::SPIDevice(SPIBus &_bus, SPIDesc &_device_desc)
|
|||
device_desc.name,
|
||||
(unsigned)bus.bus, (unsigned)device_desc.device);
|
||||
AP_HAL::SPIDevice::setup_bankselect_callback(device_desc.bank_select_cb);
|
||||
AP_HAL::SPIDevice::set_register_rw_callback(device_desc.register_rw_cb);
|
||||
//printf("SPI device %s on %u:%u at speed %u mode %u\n",
|
||||
// device_desc.name,
|
||||
// (unsigned)bus.bus, (unsigned)device_desc.device,
|
||||
|
@ -441,6 +442,24 @@ SPIDeviceManager::get_device(const char *name)
|
|||
return AP_HAL::OwnPtr<AP_HAL::SPIDevice>(new SPIDevice(*busp, desc));
|
||||
}
|
||||
|
||||
void SPIDeviceManager::set_register_rw_callback(const char* name, AP_HAL::Device::RegisterRWCb cb)
|
||||
{
|
||||
/* Find the bus description in the table */
|
||||
uint8_t i;
|
||||
for (i = 0; i<ARRAY_SIZE(device_table); i++) {
|
||||
if (strcmp(device_table[i].name, name) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == ARRAY_SIZE(device_table)) {
|
||||
return;
|
||||
}
|
||||
|
||||
device_table[i].register_rw_cb = cb;
|
||||
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAL_SPI_CHECK_CLOCK_FREQ
|
||||
|
||||
/*
|
||||
|
|
|
@ -52,7 +52,7 @@ struct SPIDesc {
|
|||
: name(_name), bus(_bus), device(_device),
|
||||
pal_line(_pal_line), mode(_mode),
|
||||
lowspeed(_lowspeed), highspeed(_highspeed),
|
||||
bank_select_cb(nullptr)
|
||||
bank_select_cb(nullptr), register_rw_cb(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,7 @@ struct SPIDesc {
|
|||
uint32_t lowspeed;
|
||||
uint32_t highspeed;
|
||||
AP_HAL::Device::BankSelectCb bank_select_cb;
|
||||
AP_HAL::Device::RegisterRWCb register_rw_cb;
|
||||
};
|
||||
|
||||
|
||||
|
@ -160,6 +161,8 @@ public:
|
|||
|
||||
AP_HAL::OwnPtr<AP_HAL::SPIDevice> get_device(const char *name) override;
|
||||
|
||||
void set_register_rw_callback(const char* name, AP_HAL::Device::RegisterRWCb cb) override;
|
||||
|
||||
private:
|
||||
static SPIDesc device_table[];
|
||||
SPIBus *buses;
|
||||
|
|
Loading…
Reference in New Issue