/** * \brief Select the given device on the SPI bus. * * Set device specific setting and call board chip select. * * \param p_spi Base address of the SPI instance. * \param device SPI device. * */ void spi_select_device(Spi *p_spi, struct spi_device *device) { if (spi_get_peripheral_select_decode_setting(p_spi)) { if (device->id < MAX_NUM_WITH_DECODER) { spi_set_peripheral_chip_select_value(p_spi, device->id); } } else { if (device->id < MAX_NUM_WITHOUT_DECODER) { spi_set_peripheral_chip_select_value(p_spi, (~(1 << device->id))); } } }
/** * \brief Select the given device on the SPI bus. * * Set device specific setting and call board chip select. * * \param p_spi Base address of the SPI instance. * \param device SPI device. * */ void spi_select_device(Spi *p_spi, const struct spi_device *device) { if (spi_get_peripheral_select_decode_setting(p_spi)) { if (device->id < MAX_NUM_WITH_DECODER) { spi_set_peripheral_chip_select_value(p_spi, device->id); } } else { if (device->id < MAX_NUM_WITHOUT_DECODER) { spi_set_peripheral_chip_select_value(p_spi, (~(1 << device->id))); } } // Enable the CS line digitalWrite(device->cs, LOW); }