Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/rp2_common/hardware_spi/include/hardware/spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/rp2_common/hardware_spi/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ 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);
spi_set_format(spi, 8, SPI_CPOL_0, SPI_CPHA_0, SPI_MSB_FIRST);

// 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) {
Expand Down