mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-30 04:06:33 +08:00
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:
@@ -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)
|
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;
|
// SPI select is active low, so write !selected to select the device
|
||||||
|
kinetis_gpiowrite(bus->devices[i].cs_gpio, !selected);
|
||||||
} 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
|
|
||||||
kinetis_gpiowrite(bus->devices[matched_dev_idx].cs_gpio, !selected);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void kinetis_spi0select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
|
void kinetis_spi0select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
|
||||||
|
|||||||
@@ -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)
|
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;
|
// SPI select is active low, so write !selected to select the device
|
||||||
|
imxrt_gpio_write(bus->devices[i].cs_gpio, !selected);
|
||||||
} 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
|
|
||||||
imxrt_gpio_write(bus->devices[matched_dev_idx].cs_gpio, !selected);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_IMXRT_LPSPI1)
|
#if defined(CONFIG_IMXRT_LPSPI1)
|
||||||
|
|||||||
@@ -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)
|
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;
|
// SPI select is active low, so write !selected to select the device
|
||||||
|
stm32_gpiowrite(bus->devices[i].cs_gpio, !selected);
|
||||||
} 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
|
|
||||||
stm32_gpiowrite(bus->devices[matched_dev_idx].cs_gpio, !selected);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user