Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: azonenberg/stm32-cpp
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 04ad3a71b64c
Choose a base ref
...
head repository: azonenberg/stm32-cpp
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c12c4478e6a6
Choose a head ref
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on Jul 7, 2020

  1. Copy the full SHA
    c12c447 View commit details
Showing with 21 additions and 1 deletion.
  1. +2 −1 devices/inc/stm32f031.h
  2. +17 −0 src/peripheral/SPI.cpp
  3. +2 −0 src/peripheral/SPI.h
3 changes: 2 additions & 1 deletion devices/inc/stm32f031.h
Original file line number Diff line number Diff line change
@@ -172,7 +172,8 @@ enum spi_cr1_bits
SPI_INTERNAL_CS = 0x0100,
SPI_LSB_FIRST = 0x0080,
SPI_ENABLE = 0x0040,
SPI_MASTER = 0x0004
SPI_MASTER = 0x0004,
SPI_CPOL = 0x0002
};

enum spi_sr_bits
17 changes: 17 additions & 0 deletions src/peripheral/SPI.cpp
Original file line number Diff line number Diff line change
@@ -120,3 +120,20 @@ void SPI::WaitForWrites()
while(!(m_lane->SR & SPI_TX_EMPTY))
{}
}

/**
@brief Set the SPI clock inversion mode (CPOL)
*/
void SPI::SetClockInvert(bool invert)
{
//Disable the peripheral
m_lane->CR1 &= ~SPI_ENABLE;

if(invert)
m_lane->CR1 |= SPI_CPOL;
else
m_lane->CR1 &= ~SPI_CPOL;

//Re-enable it
m_lane->CR1 |= SPI_ENABLE;
}
2 changes: 2 additions & 0 deletions src/peripheral/SPI.h
Original file line number Diff line number Diff line change
@@ -38,6 +38,8 @@ class SPI
void BlockingWrite(uint8_t data);
void WaitForWrites();

void SetClockInvert(bool invert);

protected:
volatile spi_t* m_lane;
bool m_fullDuplex;