33#if ( (defined __STM32F103xB_H) || (defined __STM32F401xC_H) )
56 return (uint8_t)(
Wrapper->_SPI->DR);
67 SET_BIT(
Wrapper->_SPI->CR1, SPI_CR1_SPE);
79 CLEAR_BIT(
Wrapper->_SPI->CR1, SPI_CR1_SPE);
116 *((
volatile uint8_t*) &(
Wrapper->_SPI->DR)) = Byte;
132 uint32_t SPI_Address = (uint32_t)_SPI;
136 case ( (uint32_t)SPI1 ):
140 #if ( (defined __STM32F103xB_H) || (defined __STM32F401xC_H) )
141 case ( (uint32_t)SPI2 ):
146 #ifdef __STM32F401xC_H
147 case ( (uint32_t)SPI3 ):
159 (*Wrapper)->_SPI = _SPI;
162 (*Wrapper)->RX_New = 0;
164 (*Wrapper)->RX_BufferSize = RX_BufferSize;
165 (*Wrapper)->RX_Buffer = (uint8_t*)malloc( ((*Wrapper)->RX_BufferSize) *
sizeof(uint8_t));
166 for( uint16_t _rxb_init = 0 ; _rxb_init < (*Wrapper)->RX_BufferSize ; _rxb_init++ )
168 ((*Wrapper)->RX_Buffer)[_rxb_init] =
'\0';
171 (*Wrapper)->TC_Handler = TC_Handler;
173 (*Wrapper)->Mode = Mode;
175 if( (*Wrapper)->Mode == 1 )
177 SET_BIT((*Wrapper)->_SPI->CR2, SPI_CR2_TXEIE);
181 SET_BIT((*Wrapper)->_SPI->CR2, SPI_CR2_RXNEIE);
183 (*Wrapper)->TX_Counter = 0;
209 Wrapper->TX_Buffer = TX_Buffer;
234 if( READ_BIT(
Wrapper->_SPI->CR1, SPI_CR1_SPE) == (SPI_CR1_SPE) )
236 if( READ_BIT(
Wrapper->_SPI->SR, SPI_SR_TXE) == (SPI_SR_TXE) )
239 while( READ_BIT(
Wrapper->_SPI->SR, SPI_SR_TXE) != (SPI_SR_TXE) );
241 while( READ_BIT(
Wrapper->_SPI->SR, SPI_SR_RXNE) != (SPI_SR_RXNE) );
249 while( READ_BIT(
Wrapper->_SPI->SR, SPI_SR_BSY) == (SPI_SR_BSY) );
259 if( READ_BIT(
Wrapper->_SPI->SR, SPI_SR_RXNE) == (SPI_SR_RXNE) )
298#if ( (defined __STM32F103xB_H) || (defined __STM32F401xC_H) )
313#ifdef __STM32F401xC_H
static HIERODULE_SPI_Wrapper * SPI2_Wrapper
SPI wrapper pointer meant for SPI2. Requires the device specific macro __STM32F103xB_H or __STM32F401...
static HIERODULE_SPI_Wrapper * SPI1_Wrapper
SPI wrapper pointer meant for SPI1.
static HIERODULE_SPI_Wrapper * SPI3_Wrapper
SPI wrapper pointer meant for SPI3. Requires the device specific macro __STM32F401xC_H to be defined.
static uint8_t ReceiveData(HIERODULE_SPI_Wrapper *Wrapper)
Reads and returns the data register content of the SPI peripheral.
void SPI_IRQ_Handler(HIERODULE_SPI_Wrapper *Wrapper)
The base IRQ body to be used for all SPI IRQs.
void Enable(HIERODULE_SPI_Wrapper *Wrapper)
Enables the SPI peripheral.
static void Disable(HIERODULE_SPI_Wrapper *Wrapper)
Disables the SPI peripheral.
HIERODULE_SPI_Wrapper ** HIERODULE_SPI_InitWrapper(SPI_TypeDef *_SPI, uint8_t Mode, uint16_t RX_BufferSize, void(*TC_Handler)(void))
Initializes a wrapper for the specified SPI peripheral.
uint8_t HIERODULE_SPI_GetNextByte(HIERODULE_SPI_Wrapper *Wrapper)
Fetches the next byte in the RX ring buffer.
void HIERODULE_SPI_TransmitByte(HIERODULE_SPI_Wrapper *Wrapper, uint8_t Byte)
Writes a byte into the data register of the SPI peripheral.
void SPI2_IRQHandler(void)
SPI2 IRQ implementation. Requires the device specific macro __STM32F103xB_H or __STM32F401xC_H to be ...
void HIERODULE_SPI_TransmitPackage(HIERODULE_SPI_Wrapper *Wrapper, uint8_t *TX_Buffer, uint32_t Size)
Starts a transmission as the master.
void SPI3_IRQHandler(void)
SPI3 IRQ implementation. Requires the device specific macro __STM32F401xC_H to be defined.
void SPI1_IRQHandler(void)
SPI1 IRQ implementation.
void HIERODULE_SPI_ReleaseWrapper(HIERODULE_SPI_Wrapper *Wrapper)
Frees the memory allocated to an SPI wrapper.
HIERODULE_USB_Wrapper Wrapper
Extern declaration for the wrapper instance in the source file.
: Header file for the SPI module.
Struct that keeps variables for the data buffers, a pointer to the SPI peripheral,...
uint8_t * RX_Buffer
The ring buffer where the data received is appended.
uint32_t RX_New
Number of new bytes in the ring buffer.
uint16_t RX_BufferSize
Number of elements in the ring buffer.
void(* TC_Handler)(void)
Pointer to the callback function to be called on a completed transmission.
uint32_t RX_Index
Index of next-byte-to-be-received in the ring buffer.