make spi_init return baud rate set (#296)
This commit is contained in:
parent
5259693774
commit
4c83c10f01
@ -102,14 +102,14 @@ typedef enum {
|
||||
* Puts the SPI into a known state, and enable it. Must be called before other
|
||||
* functions.
|
||||
*
|
||||
* \param spi SPI instance specifier, either \ref spi0 or \ref spi1
|
||||
* \param baudrate Baudrate required in Hz
|
||||
* \note There is no guarantee that the baudrate requested can be achieved exactly; the nearest will be chosen
|
||||
* and returned
|
||||
*
|
||||
* \note There is no guarantee that the baudrate requested will be possible, the nearest will be chosen,
|
||||
* and this function does not return any indication of this. You can use the \ref spi_set_baudrate function
|
||||
* which will return the actual baudrate selected if this is important.
|
||||
* \param spi SPI instance specifier, either \ref spi0 or \ref spi1
|
||||
* \param baudrate Baudrate requested in Hz
|
||||
* \return the actual baud rate set
|
||||
*/
|
||||
void spi_init(spi_inst_t *spi, uint baudrate);
|
||||
uint spi_init(spi_inst_t *spi, uint baudrate);
|
||||
|
||||
/*! \brief Deinitialise SPI instances
|
||||
* \ingroup hardware_spi
|
||||
|
@ -18,11 +18,11 @@ static inline void spi_unreset(spi_inst_t *spi) {
|
||||
unreset_block_wait(spi == spi0 ? RESETS_RESET_SPI0_BITS : RESETS_RESET_SPI1_BITS);
|
||||
}
|
||||
|
||||
void spi_init(spi_inst_t *spi, uint baudrate) {
|
||||
uint spi_init(spi_inst_t *spi, uint baudrate) {
|
||||
spi_reset(spi);
|
||||
spi_unreset(spi);
|
||||
|
||||
(void) spi_set_baudrate(spi, baudrate);
|
||||
uint baud = spi_set_baudrate(spi, baudrate);
|
||||
spi_set_format(spi, 8, SPI_CPOL_0, SPI_CPHA_0, SPI_MSB_FIRST);
|
||||
// Always enable DREQ signals -- harmless if DMA is not listening
|
||||
hw_set_bits(&spi_get_hw(spi)->dmacr, SPI_SSPDMACR_TXDMAE_BITS | SPI_SSPDMACR_RXDMAE_BITS);
|
||||
@ -30,6 +30,7 @@ void spi_init(spi_inst_t *spi, uint baudrate) {
|
||||
|
||||
// Finally enable the SPI
|
||||
hw_set_bits(&spi_get_hw(spi)->cr1, SPI_SSPCR1_SSE_BITS);
|
||||
return baud;
|
||||
}
|
||||
|
||||
void spi_deinit(spi_inst_t *spi) {
|
||||
|
Loading…
Reference in New Issue
Block a user