spi: do not deselect other chip-selects

And make sure on reset & init everything is deselected.

Reduces CPU load on a pixhawk cube by almost 1%.
This commit is contained in:
Beat Küng 2020-03-19 16:06:38 +01:00 committed by Daniel Agar
parent 1612f4c2ed
commit 7ea8dff8db
3 changed files with 6 additions and 39 deletions

View File

@ -300,27 +300,16 @@ __EXPORT int fmuk66_spi_bus_initialize(void)
static inline void kinetis_spixselect(const px4_spi_bus_t *bus, struct spi_dev_s *dev, uint32_t devid, bool selected)
{
int matched_dev_idx = -1;
for (int i = 0; i < SPI_BUS_MAX_DEVICES; ++i) {
if (bus->devices[i].cs_gpio == 0) {
break;
}
if (devid == bus->devices[i].devid) {
matched_dev_idx = i;
} else {
// Making sure the other peripherals are not selected
kinetis_gpiowrite(bus->devices[i].cs_gpio, 1);
// SPI select is active low, so write !selected to select the device
kinetis_gpiowrite(bus->devices[i].cs_gpio, !selected);
}
}
// different devices might use the same CS, so make sure to configure the one we want last
if (matched_dev_idx != -1) {
// SPI select is active low, so write !selected to select the device
kinetis_gpiowrite(bus->devices[matched_dev_idx].cs_gpio, !selected);
}
}
void kinetis_spi0select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)

View File

@ -241,27 +241,16 @@ __EXPORT int imxrt1062_spi_bus_initialize(void)
static inline void imxrt_spixselect(const px4_spi_bus_t *bus, struct spi_dev_s *dev, uint32_t devid, bool selected)
{
int matched_dev_idx = -1;
for (int i = 0; i < SPI_BUS_MAX_DEVICES; ++i) {
if (bus->devices[i].cs_gpio == 0) {
break;
}
if (devid == bus->devices[i].devid) {
matched_dev_idx = i;
} else {
// Making sure the other peripherals are not selected
imxrt_gpio_write(bus->devices[i].cs_gpio, 1);
// SPI select is active low, so write !selected to select the device
imxrt_gpio_write(bus->devices[i].cs_gpio, !selected);
}
}
// different devices might use the same CS, so make sure to configure the one we want last
if (matched_dev_idx != -1) {
// SPI select is active low, so write !selected to select the device
imxrt_gpio_write(bus->devices[matched_dev_idx].cs_gpio, !selected);
}
}
#if defined(CONFIG_IMXRT_LPSPI1)

View File

@ -184,27 +184,16 @@ __EXPORT void stm32_spiinitialize()
static inline void stm32_spixselect(const px4_spi_bus_t *bus, struct spi_dev_s *dev, uint32_t devid, bool selected)
{
int matched_dev_idx = -1;
for (int i = 0; i < SPI_BUS_MAX_DEVICES; ++i) {
if (bus->devices[i].cs_gpio == 0) {
break;
}
if (devid == bus->devices[i].devid) {
matched_dev_idx = i;
} else {
// Making sure the other peripherals are not selected
stm32_gpiowrite(bus->devices[i].cs_gpio, 1);
// SPI select is active low, so write !selected to select the device
stm32_gpiowrite(bus->devices[i].cs_gpio, !selected);
}
}
// different devices might use the same CS, so make sure to configure the one we want last
if (matched_dev_idx != -1) {
// SPI select is active low, so write !selected to select the device
stm32_gpiowrite(bus->devices[matched_dev_idx].cs_gpio, !selected);
}
}