HAL_PX4: implement set_chip_select for SPI

This commit is contained in:
Andrew Tridgell 2016-11-18 20:55:06 +11:00
parent 60801314e0
commit 638e89bd1d
2 changed files with 16 additions and 1 deletions

View File

@ -174,7 +174,9 @@ void SPIDevice::do_transfer(uint8_t *send, uint8_t *recv, uint32_t len)
SPI_SETBITS(bus.dev, 8);
SPI_SELECT(bus.dev, device_desc.device, true);
SPI_EXCHANGE(bus.dev, send, recv, len);
SPI_SELECT(bus.dev, device_desc.device, false);
if (!cs_forced) {
SPI_SELECT(bus.dev, device_desc.device, false);
}
SPI_LOCK(bus.dev, false);
perf_end(perf);
if (use_irq_save) {
@ -224,6 +226,16 @@ bool SPIDevice::adjust_periodic_callback(AP_HAL::Device::PeriodicHandle h, uint3
return false;
}
/*
allow for control of SPI chip select pin
*/
bool SPIDevice::set_chip_select(bool set)
{
cs_forced = set;
SPI_SELECT(bus.dev, device_desc.device, set);
return true;
}
/*
return a SPIDevice given a string device name

View File

@ -82,12 +82,15 @@ public:
/* See AP_HAL::Device::adjust_periodic_callback() */
bool adjust_periodic_callback(AP_HAL::Device::PeriodicHandle h, uint32_t period_usec) override;
bool set_chip_select(bool set) override;
private:
SPIBus &bus;
SPIDesc &device_desc;
uint32_t frequency;
perf_counter_t perf;
char *pname;
bool cs_forced;
static void *spi_thread(void *arg);
};