The I2S hardware implementation on the STM32F4xx series is based on the special configuration of the SPI engine, although the usage and setup are different enough that I don't see a straightforward way to graft that configuration onto the existing pyb.SPI class without terribly mucking up the SPI API. Instead I am taking the approach of using the existing SPI implementation as a reference to build a new I2S class from scratch.
I will have some (many!) questions as I proceed with this, and once I have something minimally functional I will post a PR on github and move the discussion there. For now, I have a question about a code convention used frequently in spi.c that I don't really understand; I'm not sure if I should follow it completely or implement it in a way that makes more sense to me.
The shortest example I could see is in the spi_deinit() function:
Code: Select all
void spi_deinit(SPI_HandleTypeDef *spi) {
HAL_SPI_DeInit(spi);
if (0) {
#if MICROPY_HW_ENABLE_SPI1
} else if (spi->Instance == SPI1) {
__SPI1_FORCE_RESET();
__SPI1_RELEASE_RESET();
__SPI1_CLK_DISABLE();
#endif
#if MICROPY_HW_ENABLE_SPI2
} else if (spi->Instance == SPI2) {
__SPI2_FORCE_RESET();
__SPI2_RELEASE_RESET();
__SPI2_CLK_DISABLE();
#endif
#if MICROPY_HW_ENABLE_SPI3
} else if (spi->Instance == SPI3) {
__SPI3_FORCE_RESET();
__SPI3_RELEASE_RESET();
__SPI3_CLK_DISABLE();
#endif
}
}
What is the purpose of the empty 'if(0) { }' clause, if it always evaluates as false? The same convention also appears in the spi_init() function, but that is much more complex to serve as a clear illustration here.
Thanks!
Bryan