OpenMPTL - STM32 (common)
C++ Microprocessor Template Library
Classes | Public Types | Static Public Member Functions | Static Public Attributes | List of all members
mptl::spi_stm32_common< _spi_no, system_clock_type > Class Template Reference

#include <spi.hpp>

Classes

struct  clock_phase
 
struct  clock_polarity
 
struct  data_direction
 
struct  frame_format
 

Public Types

using SPIx = SPI< spi_no >
 
using irq = irq::spi< spi_no >
 
using resources = rcc_spi_clock_resources< spi_no >
 
using master = reglist< regval< typename SPIx::CR1::MSTR, 1 >, regval< typename SPIx::CR1::SSI, 1 > >
 
using slave = regval< typename SPIx::CR1::MSTR, 0 >
 
using software_slave_management = regval< typename SPIx::CR1::SSM, 1 >
 
template<freq_t value>
using max_frequency = regval< typename SPIx::CR1::BR,(value==0 ? 0 :value >=clk_freq/2 ? 0 :value >=clk_freq/4 ? 1 :value >=clk_freq/8 ? 2 :value >=clk_freq/16 ? 3 :value >=clk_freq/32 ? 4 :value >=clk_freq/64 ? 5 :value >=clk_freq/128 ? 6 :7) >
 Maximum frequency (hz, 0=maximum available) More...
 
template<unsigned value>
using data_size = typename std::enable_if< value==8||value==16, regval< typename SPIx::CR1::DFF, value==16 ? 1 :0 > >::type
 8 bit or 16 bit data size More...
 

Static Public Member Functions

template<typename... Tp>
static void configure (void)
 Configure SPI register using Tp type traits. More...
 
template<typename... Tp>
static void reconfigure (void)
 Disable SPI, configure SPI register using Tp type traits, and enable SPI. More...
 
static void reset_crc (void)
 
static void enable (void)
 
static void disable (void)
 
static void wait_transmit_empty (void)
 
static void wait_receive_not_empty (void)
 
static void wait_not_busy (void)
 
static void send (uint16_t data)
 
static void send_blocking (uint16_t data)
 
static SPIx::DR::value_type receive (void)
 NOTE: return value depends on the data frame format (CR1::DFF, 8 or 16 bit) More...
 
static SPIx::DR::value_type receive_blocking (void)
 
static unsigned char writeread_blocking (uint16_t data)
 

Static Public Attributes

static constexpr unsigned spi_no = _spi_no
 
static constexpr unsigned clk_freq = (spi_no == 1 ? system_clock_type::pclk2_freq : system_clock_type::pclk1_freq )
 

Member Typedef Documentation

◆ data_size

template<unsigned _spi_no, typename system_clock_type >
template<unsigned value>
using mptl::spi_stm32_common< _spi_no, system_clock_type >::data_size = typename std::enable_if< value == 8 || value == 16, regval< typename SPIx::CR1::DFF, value == 16 ? 1 : 0 > >::type

◆ irq

template<unsigned _spi_no, typename system_clock_type >
using mptl::spi_stm32_common< _spi_no, system_clock_type >::irq = irq::spi<spi_no>

◆ master

template<unsigned _spi_no, typename system_clock_type >
using mptl::spi_stm32_common< _spi_no, system_clock_type >::master = reglist< regval< typename SPIx::CR1::MSTR, 1 >, regval< typename SPIx::CR1::SSI, 1 > >

◆ max_frequency

template<unsigned _spi_no, typename system_clock_type >
template<freq_t value>
using mptl::spi_stm32_common< _spi_no, system_clock_type >::max_frequency = regval< typename SPIx::CR1::BR, ( value == 0 ? 0 : value >= clk_freq / 2 ? 0 : value >= clk_freq / 4 ? 1 : value >= clk_freq / 8 ? 2 : value >= clk_freq / 16 ? 3 : value >= clk_freq / 32 ? 4 : value >= clk_freq / 64 ? 5 : value >= clk_freq / 128 ? 6 : 7 ) >

◆ resources

template<unsigned _spi_no, typename system_clock_type >
using mptl::spi_stm32_common< _spi_no, system_clock_type >::resources = rcc_spi_clock_resources<spi_no>

◆ slave

template<unsigned _spi_no, typename system_clock_type >
using mptl::spi_stm32_common< _spi_no, system_clock_type >::slave = regval< typename SPIx::CR1::MSTR, 0 >

◆ software_slave_management

template<unsigned _spi_no, typename system_clock_type >
using mptl::spi_stm32_common< _spi_no, system_clock_type >::software_slave_management = regval< typename SPIx::CR1::SSM, 1 >

◆ SPIx

template<unsigned _spi_no, typename system_clock_type >
using mptl::spi_stm32_common< _spi_no, system_clock_type >::SPIx = SPI<spi_no>

Member Function Documentation

◆ configure()

template<unsigned _spi_no, typename system_clock_type >
template<typename... Tp>
static void mptl::spi_stm32_common< _spi_no, system_clock_type >::configure ( void  )
inlinestatic

NOTE: make sure no communication is ongoing when calling this function.

◆ disable()

template<unsigned _spi_no, typename system_clock_type >
static void mptl::spi_stm32_common< _spi_no, system_clock_type >::disable ( void  )
inlinestatic

◆ enable()

template<unsigned _spi_no, typename system_clock_type >
static void mptl::spi_stm32_common< _spi_no, system_clock_type >::enable ( void  )
inlinestatic

◆ receive()

template<unsigned _spi_no, typename system_clock_type >
static SPIx::DR::value_type mptl::spi_stm32_common< _spi_no, system_clock_type >::receive ( void  )
inlinestatic

◆ receive_blocking()

template<unsigned _spi_no, typename system_clock_type >
static SPIx::DR::value_type mptl::spi_stm32_common< _spi_no, system_clock_type >::receive_blocking ( void  )
inlinestatic

◆ reconfigure()

template<unsigned _spi_no, typename system_clock_type >
template<typename... Tp>
static void mptl::spi_stm32_common< _spi_no, system_clock_type >::reconfigure ( void  )
inlinestatic

NOTE: make sure no communication is ongoing when calling this function.

◆ reset_crc()

template<unsigned _spi_no, typename system_clock_type >
static void mptl::spi_stm32_common< _spi_no, system_clock_type >::reset_crc ( void  )
inlinestatic

◆ send()

template<unsigned _spi_no, typename system_clock_type >
static void mptl::spi_stm32_common< _spi_no, system_clock_type >::send ( uint16_t  data)
inlinestatic

◆ send_blocking()

template<unsigned _spi_no, typename system_clock_type >
static void mptl::spi_stm32_common< _spi_no, system_clock_type >::send_blocking ( uint16_t  data)
inlinestatic

◆ wait_not_busy()

template<unsigned _spi_no, typename system_clock_type >
static void mptl::spi_stm32_common< _spi_no, system_clock_type >::wait_not_busy ( void  )
inlinestatic

◆ wait_receive_not_empty()

template<unsigned _spi_no, typename system_clock_type >
static void mptl::spi_stm32_common< _spi_no, system_clock_type >::wait_receive_not_empty ( void  )
inlinestatic

◆ wait_transmit_empty()

template<unsigned _spi_no, typename system_clock_type >
static void mptl::spi_stm32_common< _spi_no, system_clock_type >::wait_transmit_empty ( void  )
inlinestatic

◆ writeread_blocking()

template<unsigned _spi_no, typename system_clock_type >
static unsigned char mptl::spi_stm32_common< _spi_no, system_clock_type >::writeread_blocking ( uint16_t  data)
inlinestatic

Member Data Documentation

◆ clk_freq

template<unsigned _spi_no, typename system_clock_type >
constexpr unsigned mptl::spi_stm32_common< _spi_no, system_clock_type >::clk_freq = (spi_no == 1 ? system_clock_type::pclk2_freq : system_clock_type::pclk1_freq )
static

◆ spi_no

template<unsigned _spi_no, typename system_clock_type >
constexpr unsigned mptl::spi_stm32_common< _spi_no, system_clock_type >::spi_no = _spi_no
static

The documentation for this class was generated from the following file: