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
+2 -13
View File
@@ -300,26 +300,15 @@ __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) 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) { for (int i = 0; i < SPI_BUS_MAX_DEVICES; ++i) {
if (bus->devices[i].cs_gpio == 0) { if (bus->devices[i].cs_gpio == 0) {
break; break;
} }
if (devid == bus->devices[i].devid) { 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);
}
}
// 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 // SPI select is active low, so write !selected to select the device
kinetis_gpiowrite(bus->devices[matched_dev_idx].cs_gpio, !selected); kinetis_gpiowrite(bus->devices[i].cs_gpio, !selected);
}
} }
} }
+2 -13
View File
@@ -241,26 +241,15 @@ __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) 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) { for (int i = 0; i < SPI_BUS_MAX_DEVICES; ++i) {
if (bus->devices[i].cs_gpio == 0) { if (bus->devices[i].cs_gpio == 0) {
break; break;
} }
if (devid == bus->devices[i].devid) { 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);
}
}
// 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 // SPI select is active low, so write !selected to select the device
imxrt_gpio_write(bus->devices[matched_dev_idx].cs_gpio, !selected); imxrt_gpio_write(bus->devices[i].cs_gpio, !selected);
}
} }
} }
@@ -184,26 +184,15 @@ __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) 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) { for (int i = 0; i < SPI_BUS_MAX_DEVICES; ++i) {
if (bus->devices[i].cs_gpio == 0) { if (bus->devices[i].cs_gpio == 0) {
break; break;
} }
if (devid == bus->devices[i].devid) { 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);
}
}
// 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 // SPI select is active low, so write !selected to select the device
stm32_gpiowrite(bus->devices[matched_dev_idx].cs_gpio, !selected); stm32_gpiowrite(bus->devices[i].cs_gpio, !selected);
}
} }
} }