|
Hierodule 1.6.2
Utility module set for STM32 MCUs
|
Elements of the module that are not confined to the scope of the compilation unit. Perfectly corresponds to the module's header file, except the IRQ handlers. More...
Data Structures | |
| struct | HIERODULE_I2C_Wrapper |
| Struct that keeps variables for the data buffers, a pointer to the I2C peripheral, the slave address and pointers to the transmission end callback routines. More... | |
Enumerations | |
| enum | HIERODULE_I2C_Status { HIERODULE_I2C_Status_IDLE , HIERODULE_I2C_Status_MTX_SB , HIERODULE_I2C_Status_MTX_ADR , HIERODULE_I2C_Status_MTX , HIERODULE_I2C_Status_SRX , HIERODULE_I2C_Status_MRX_SB , HIERODULE_I2C_Status_MRX_ADR , HIERODULE_I2C_Status_MRX , HIERODULE_I2C_Status_STX } |
| I2C wrapper status enumeration. More... | |
Functions | |
| uint8_t | HIERODULE_I2C_GetNextByte (HIERODULE_I2C_Wrapper *Wrapper) |
| Fetches the next byte in the SRX ring buffer. | |
| HIERODULE_I2C_Wrapper ** | HIERODULE_I2C_InitWrapper (I2C_TypeDef *_I2C, uint16_t SRX_BufferSize, void(*SRX_Handler)(void), void(*MTX_Handler)(void), void(*STX_Handler)(void), void(*MRX_Handler)(void)) |
| Initializes a wrapper for the specified I2C peripheral. | |
| void | HIERODULE_I2C_ReleaseWrapper (HIERODULE_I2C_Wrapper *Wrapper) |
| Frees the memory allocated to an I2C wrapper. | |
| void | HIERODULE_I2C_MasterTransmit (HIERODULE_I2C_Wrapper *Wrapper, uint8_t SlaveAddress, uint8_t *MTX_Buffer, uint32_t Size) |
| Puts the peripheral in master transmitter mode and handles the transmission. | |
| void | HIERODULE_I2C_MasterReceive (HIERODULE_I2C_Wrapper *Wrapper, uint8_t SlaveAddress, uint8_t *MRX_Buffer, uint32_t Size) |
| Puts the peripheral in master receiver mode and handles the transmission. | |
| void | I2C1_EV_IRQHandler (void) |
| I2C1 IRQ implementation. Requires the device specific macro __STM32F103xB_H or __STM32F401xC_H to be defined. | |
| void | I2C2_EV_IRQHandler (void) |
| I2C2 IRQ implementation. Requires the device specific macro __STM32F103xB_H or __STM32F401xC_H to be defined. | |
| void | I2C1_IRQHandler (void) |
| I2C1 IRQ implementation. Requires the device specific macro __STM32F030x6_H to be defined. | |
| void | I2C3_EV_IRQHandler (void) |
| I2C3 IRQ implementation. Requires the device specific macro __STM32F401xC_H to be defined. | |
Consists of general I2C comm routines, a I2C wrapper initalizer and typedefs for module routines.
Device-specific macro constants and type definitions are imported with an include directive to main.h, where the device driver headers are assumed to be included.
stddef.h and stdlib.h also included for NULL and malloc/free, respectively.
| enum HIERODULE_I2C_Status |
Notice that different devices may not follow the same status succession.
Definition at line 42 of file hierodule_i2c.h.
| uint8_t HIERODULE_I2C_GetNextByte | ( | HIERODULE_I2C_Wrapper * | Wrapper | ) |
| Wrapper | Pointer to the I2C wrapper. |
SRX_New and SRX_Index are also updated on call, to revolve the ring buffer, so as to say.
Definition at line 397 of file hierodule_i2c.c.
References Wrapper.
| HIERODULE_I2C_Wrapper ** HIERODULE_I2C_InitWrapper | ( | I2C_TypeDef * | _I2C, |
| uint16_t | SRX_BufferSize, | ||
| void(* | SRX_Handler )(void), | ||
| void(* | MTX_Handler )(void), | ||
| void(* | STX_Handler )(void), | ||
| void(* | MRX_Handler )(void) ) |
| _I2C | I2C peripheral of the wrapper. |
| SRX_BufferSize | Length of the SRX ring buffer array. |
| SRX_Handler | Pointer to the callback routine for slave receiver mode. |
| MTX_Handler | Pointer to the callback routine for master transmitter mode. |
| STX_Handler | Pointer to the callback routine for slave transmitter mode. |
| MRX_Handler | Pointer to the callback routine for master receiver mode. |
The buffers get a new addresses allocated to them.
The SRX ring buffer is filled with null characters.
Also configures the peripheral's control register and calculates the I2C clock period.
The wrapper pointer gets a new address allocated, to be freed at some future point via HIERODULE_I2C_ReleaseWrapper, hence the reason a pointer is used for the wrapper; likewise, a double pointer is used to return it by reference.
Device specific checks are performed for the I2C peripheral specified.
Definition at line 421 of file hierodule_i2c.c.
References ACK_Next(), EnableClockStretching(), HIERODULE_I2C_Status_IDLE, I2C1_Wrapper, I2C2_Wrapper, I2C3_Wrapper, and Wrapper.
| void HIERODULE_I2C_MasterReceive | ( | HIERODULE_I2C_Wrapper * | Wrapper, |
| uint8_t | SlaveAddress, | ||
| uint8_t * | MRX_Buffer, | ||
| uint32_t | Size ) |
| Wrapper | Pointer to the I2C wrapper. |
| SlaveAddress | Target device address. |
| MRX_Buffer | Byte array where the received data will be saved. |
| Size | Number of bytes to be received. |
Transmission won't commence if Size is zero.
Definition at line 583 of file hierodule_i2c.c.
References DisableClockStretching(), HIERODULE_I2C_Status_MRX, HIERODULE_I2C_Status_MRX_SB, NACK_Next(), Start(), and Wrapper.
| void HIERODULE_I2C_MasterTransmit | ( | HIERODULE_I2C_Wrapper * | Wrapper, |
| uint8_t | SlaveAddress, | ||
| uint8_t * | MTX_Buffer, | ||
| uint32_t | Size ) |
| Wrapper | Pointer to the I2C wrapper. |
| SlaveAddress | Target device address. |
| MTX_Buffer | Byte array to be transmitted. |
| Size | Number of bytes to be transmitted. |
Transmission won't commence if Size is zero.
Definition at line 554 of file hierodule_i2c.c.
References DisableClockStretching(), HIERODULE_I2C_Status_MTX, HIERODULE_I2C_Status_MTX_SB, Start(), and Wrapper.
| void HIERODULE_I2C_ReleaseWrapper | ( | HIERODULE_I2C_Wrapper * | Wrapper | ) |
| Wrapper | Pointer to the I2C wrapper. |
Buffer addresses are also freed.
Using a released I2C wrapper or its fields may result in unexpected behavior.
Keep in mind this clears up the I2C wrapper pointer in this file scope; it is recommended to free your double pointer to the wrapper, likewise.
Definition at line 534 of file hierodule_i2c.c.
References Wrapper.
|
extern |
Self-explanatory code, nothing to elaborate.
Definition at line 806 of file hierodule_i2c.c.
References I2C1_Wrapper, and I2C_IRQ_Handler().
|
extern |
Self-explanatory code, nothing to elaborate.
Definition at line 830 of file hierodule_i2c.c.
References I2C1_Wrapper, and I2C_IRQ_Handler().
|
extern |
Self-explanatory code, nothing to elaborate.
Definition at line 817 of file hierodule_i2c.c.
References I2C2_Wrapper, and I2C_IRQ_Handler().
|
extern |
Self-explanatory code, nothing to elaborate.
Definition at line 845 of file hierodule_i2c.c.
References I2C3_Wrapper, and I2C_IRQ_Handler().