![]() |
Kinetis Bootloader
2.0.0
Common bootloader for Kinetis devices
|
Collaboration diagram for LPI2C Master Driver:Data Structures | |
| struct | lpi2c_master_config_t |
| Structure with settings to initialize the LPI2C master module. More... | |
| struct | lpi2c_master_config_t.hostRequest |
| struct | lpi2c_data_match_config_t |
| LPI2C master data match config struct. More... | |
| struct | lpi2c_master_transfer_t |
| Non-blocking transfer descriptor structure. More... | |
| struct | lpi2c_master_handle_t |
| Driver handle for master non-blocking APIs. More... | |
Typedefs | |
| typedef void(* | lpi2c_master_transfer_callback_t) (LPI2C_Type *base, lpi2c_master_handle_t *handle, status_t completionStatus, void *userData) |
| Master completion callback function pointer type. More... | |
Initialization and deinitialization | |
| void | LPI2C_MasterGetDefaultConfig (lpi2c_master_config_t *masterConfig) |
| Provides a default configuration for the LPI2C master peripheral. More... | |
| void | LPI2C_MasterInit (LPI2C_Type *base, const lpi2c_master_config_t *masterConfig, uint32_t sourceClock_Hz) |
| Initializes the LPI2C master peripheral. More... | |
| void | LPI2C_MasterDeinit (LPI2C_Type *base) |
| Deinitializes the LPI2C master peripheral. More... | |
| void | LPI2C_MasterConfigureDataMatch (LPI2C_Type *base, const lpi2c_data_match_config_t *config) |
| Configure LPI2C master data match feature. More... | |
| static void | LPI2C_MasterReset (LPI2C_Type *base) |
| Perform software reset. More... | |
| static void | LPI2C_MasterEnable (LPI2C_Type *base, bool enable) |
| Enables or disables the LPI2C module as master. More... | |
Status | |
| static uint32_t | LPI2C_MasterGetStatusFlags (LPI2C_Type *base) |
| Gets the LPI2C master status flags. More... | |
| static void | LPI2C_MasterClearStatusFlags (LPI2C_Type *base, uint32_t statusMask) |
| Clears the LPI2C master status flag state. More... | |
Interrupts | |
| static void | LPI2C_MasterEnableInterrupts (LPI2C_Type *base, uint32_t interruptMask) |
| Enable LPI2C master interrupt requests. More... | |
| static void | LPI2C_MasterDisableInterrupts (LPI2C_Type *base, uint32_t interruptMask) |
| Disable LPI2C master interrupt requests. More... | |
| static uint32_t | LPI2C_MasterGetEnabledInterrupts (LPI2C_Type *base) |
| Returns the set of currently enabled LPI2C master interrupt requests. More... | |
DMA control | |
| static void | LPI2C_MasterEnableDMA (LPI2C_Type *base, bool enableTx, bool enableRx) |
| Enables or disables LPI2C master DMA requests. More... | |
| static uint32_t | LPI2C_MasterGetTxFifoAddress (LPI2C_Type *base) |
| Gets LPI2C master transmit data register address for DMA transfer. More... | |
| static uint32_t | LPI2C_MasterGetRxFifoAddress (LPI2C_Type *base) |
| Gets LPI2C master receive data register address for DMA transfer. More... | |
FIFO control | |
| static void | LPI2C_MasterSetWatermarks (LPI2C_Type *base, size_t txWords, size_t rxWords) |
| Set the watermarks for LPI2C master FIFOs. More... | |
| static void | LPI2C_MasterGetFifoCounts (LPI2C_Type *base, size_t *rxCount, size_t *txCount) |
| Get the current number of words in the LPI2C master FIFOs. More... | |
Bus operations | |
| void | LPI2C_MasterSetBaudRate (LPI2C_Type *base, uint32_t sourceClock_Hz, uint32_t baudRate_Hz) |
| Sets the I2C bus frequency for master transactions. More... | |
| static bool | LPI2C_MasterGetBusIdleState (LPI2C_Type *base) |
| Return whether the bus is idle. More... | |
| status_t | LPI2C_MasterStart (LPI2C_Type *base, uint8_t address, lpi2c_direction_t dir) |
| Sends a START signal and slave address on the I2C bus. More... | |
| static status_t | LPI2C_MasterRepeatedStart (LPI2C_Type *base, uint8_t address, lpi2c_direction_t dir) |
| Sends a repeated START signal and slave address on the I2C bus. More... | |
| status_t | LPI2C_MasterSend (LPI2C_Type *base, const void *txBuff, size_t txSize) |
| Performs a polling send transfer on the I2C bus. More... | |
| status_t | LPI2C_MasterReceive (LPI2C_Type *base, void *rxBuff, size_t rxSize) |
| Performs a polling receive transfer on the I2C bus. More... | |
| status_t | LPI2C_MasterStop (LPI2C_Type *base) |
| Sends a STOP signal on the I2C bus. More... | |
Non-blocking | |
| void | LPI2C_MasterCreateHandle (LPI2C_Type *base, lpi2c_master_handle_t *handle, lpi2c_master_transfer_callback_t callback, void *userData) |
| Create a new handle for the LPI2C master non-blocking APIs. More... | |
| status_t | LPI2C_MasterTransferNonBlocking (LPI2C_Type *base, lpi2c_master_handle_t *handle, lpi2c_master_transfer_t *transfer) |
| Performs a non-blocking transaction on the I2C bus. More... | |
| status_t | LPI2C_MasterGetTransferCount (LPI2C_Type *base, lpi2c_master_handle_t *handle, size_t *count) |
| Returns number of bytes transferred so far. More... | |
| void | LPI2C_MasterAbortTransfer (LPI2C_Type *base, lpi2c_master_handle_t *handle) |
| Terminates a non-blocking LPI2C master transmission early. More... | |
IRQ handler | |
| void | LPI2C_MasterHandleInterrupt (LPI2C_Type *base, lpi2c_master_handle_t *handle) |
| Reusable routine to handle master interrupts. More... | |
| struct lpi2c_master_config_t |
Structure with settings to initialize the LPI2C master module.
This structure holds configuration settings for the LPI2C peripheral. To initialize this structure to reasonable defaults, call the LPI2C_MasterGetDefaultConfig() function and pass a pointer to your config struct instance.
The config struct can be made const so it resides in flash.
| Data Fields | ||
|---|---|---|
| uint32_t | baudRate_Hz |
Desired baud rate in Hertz. |
| uint32_t | busIdleTimeout_ns |
Bus idle timeout in nanoseconds. Set to 0 to disable. |
| bool | debugEnable |
Enable transfers to continue when halted in debug mode. |
| bool | enableDoze |
Whether master is enabled in doze mode. |
| bool | enableMaster |
Whether to enable master mode. |
| struct lpi2c_master_config_t | hostRequest |
Host request options. |
| bool | ignoreAck |
Whether to ignore ack/nack. |
| lpi2c_master_pin_config_t | pinConfig |
The pin configuration option. |
| uint32_t | pinLowTimeout_ns |
Pin low timeout in nanoseconds. Set to 0 to disable. |
| uint8_t | sclGlitchFilterWidth_ns |
Width in nanoseconds of glitch filter on SCL pin. Set to 0 to disable. |
| uint8_t | sdaGlitchFilterWidth_ns |
Width in nanoseconds of glitch filter on SDA pin. Set to 0 to disable. |
| struct lpi2c_master_config_t.hostRequest |
| Data Fields | ||
|---|---|---|
| bool | enable |
Enable host request. |
| lpi2c_host_request_polarity_t | polarity |
Host request pin polarity. |
| lpi2c_host_request_source_t | source |
Host request source. |
| struct lpi2c_data_match_config_t |
LPI2C master data match config struct.
| Data Fields | ||
|---|---|---|
| uint32_t | match0 |
Match value 0. |
| uint32_t | match1 |
Match value 1. |
| lpi2c_data_match_config_mode_t | matchMode |
Data match configuration setting. |
| bool | rxDataMatchOnly |
When set to true, received data is ignored until a successful match. |
| struct _lpi2c_master_transfer |
Non-blocking transfer descriptor structure.
This structure is used to pass transaction parameters to the LPI2C_MasterTransferNonBlocking() API.
| Data Fields | ||
|---|---|---|
| void * | data |
Pointer to data to transfer. |
| size_t | dataSize |
Number of bytes to transfer. |
| lpi2c_direction_t | direction |
Either kLPI2C_Read or kLPI2C_Write. |
| uint32_t | flags |
Bit mask of options for the transfer. See enum _lpi2c_master_transfer_flags for available options. Set to 0 or kLPI2C_TransferDefaultFlag for normal transfers. |
| uint16_t | slaveAddress |
The 7-bit slave address. |
| uint32_t | subaddress |
Subaddress. Transferred MSB first. |
| size_t | subaddressSize |
Length of subaddress to send in bytes. Maximum size is 4 bytes. |
| struct _lpi2c_master_handle |
Driver handle for master non-blocking APIs.
| Data Fields | ||
|---|---|---|
| uint8_t * | buf |
Buffer pointer for current state. |
| uint16_t | commandBuffer[7] |
LPI2C command sequence. |
| lpi2c_master_transfer_callback_t | completionCallback |
Callback function pointer. |
| uint16_t | remainingBytes |
Remaining byte count in current state. |
| uint8_t | state |
Transfer state machine current state. |
| lpi2c_master_transfer_t | transfer |
Copy of the current transfer info. |
| void * | userData |
Application data passed to callback. |
| typedef void(* lpi2c_master_transfer_callback_t) (LPI2C_Type *base, lpi2c_master_handle_t *handle, status_t completionStatus, void *userData) |
Master completion callback function pointer type.
This callback is used only for the non-blocking master transfer API. Specify the callback you wish to use in the call to LPI2C_MasterCreateHandle().
| base | The LPI2C peripheral base address. |
| completionStatus | Either #kStatus_Success or an error code describing how the transfer completed. |
| userData | Arbitrary pointer-sized value passed from the application. |
| enum _lpi2c_master_flags |
LPI2C master peripheral flags.
The following status register flags can be cleared:
All flags except kLPI2C_MasterBusyFlag and kLPI2C_MasterBusBusyFlag can be enabled as interrupts.
Transfer option flags.
LPI2C master data match configuration modes.
| enum lpi2c_direction_t |
LPI2C pin configuration.
| void LPI2C_MasterAbortTransfer | ( | LPI2C_Type * | base, |
| lpi2c_master_handle_t * | handle | ||
| ) |
Terminates a non-blocking LPI2C master transmission early.
| base | The LPI2C peripheral base address. |
| handle | Pointer to the LPI2C master driver handle. |
| #kStatus_Success | A transaction was successfully aborted. |
| kStatus_LPI2C_Idle | There is not a non-blocking transaction currently in progress. |
|
inlinestatic |
Clears the LPI2C master status flag state.
The following status register flags can be cleared:
Attempts to clear other flags will have no effect.
| base | The LPI2C peripheral base address. |
| statusMask | A bitmask of status flags that are to be cleared. The mask is composed of _lpi2c_master_flags enumerators OR'd together. You may pass the result of a previous call to LPI2C_MasterGetStatusFlags(). |
| void LPI2C_MasterConfigureDataMatch | ( | LPI2C_Type * | base, |
| const lpi2c_data_match_config_t * | config | ||
| ) |
Configure LPI2C master data match feature.
| base | The LPI2C peripheral base address. |
| config | Settings for the data match feature. |
| void LPI2C_MasterCreateHandle | ( | LPI2C_Type * | base, |
| lpi2c_master_handle_t * | handle, | ||
| lpi2c_master_transfer_callback_t | callback, | ||
| void * | userData | ||
| ) |
Create a new handle for the LPI2C master non-blocking APIs.
The creation of a handle is for use with the non-blocking APIs. Once a handle is created, there is not a corresponding destroy handle. If the user wants to terminate a transfer, the LPI2C_MasterAbortTransfer() API shall be called.
| base | The LPI2C peripheral base address. | |
| [out] | handle | Pointer to the LPI2C master driver handle. |
| callback | User provided pointer to the asynchronous callback function. | |
| userData | User provided pointer to the application callback data. |
| void LPI2C_MasterDeinit | ( | LPI2C_Type * | base | ) |
Deinitializes the LPI2C master peripheral.
This function will disable the LPI2C master peripheral and gates the clock. It also performs a software reset to restore the peripheral to reset conditions.
| base | The LPI2C peripheral base address. |
|
inlinestatic |
Disable LPI2C master interrupt requests.
All flags except kLPI2C_MasterBusyFlag and kLPI2C_MasterBusBusyFlag can be enabled as interrupts.
| base | The LPI2C peripheral base address. |
| interruptMask | Bit mask of interrupts to disable. See _lpi2c_master_flags for the set of constants that should be OR'd together to form the bit mask. |
|
inlinestatic |
Enables or disables the LPI2C module as master.
| base | The LPI2C peripheral base address. |
| enable | Pass true to enable or false to disable the specified LPI2C as master. |
|
inlinestatic |
Enables or disables LPI2C master DMA requests.
| base | The LPI2C peripheral base address. |
| enableTx | Enable flag for transmit DMA request. Pass true for enable, false for disable. |
| enableRx | Enable flag for receive DMA request. Pass true for enable, false for disable. |
|
inlinestatic |
Enable LPI2C master interrupt requests.
All flags except kLPI2C_MasterBusyFlag and kLPI2C_MasterBusBusyFlag can be enabled as interrupts.
| base | The LPI2C peripheral base address. |
| interruptMask | Bit mask of interrupts to enable. See _lpi2c_master_flags for the set of constants that should be OR'd together to form the bit mask. |
|
inlinestatic |
Return whether the bus is idle.
Requires the master mode to be enabled.
| base | The LPI2C peripheral base address. |
| true | Bus is busy. |
| false | Bus is idle. |
| void LPI2C_MasterGetDefaultConfig | ( | lpi2c_master_config_t * | masterConfig | ) |
Provides a default configuration for the LPI2C master peripheral.
This function will provide the following default configuration for the LPI2C master peripheral:
After calling this function, you can override any settings in order to customize the configuration, prior to initializing the master driver with LPI2C_MasterInit().
| [out] | masterConfig | User provided configuration structure for default values. Refer to lpi2c_master_config_t. |
|
inlinestatic |
Returns the set of currently enabled LPI2C master interrupt requests.
| base | The LPI2C peripheral base address. |
|
inlinestatic |
Get the current number of words in the LPI2C master FIFOs.
| base | The LPI2C peripheral base address. | |
| [out] | txCount | Pointer through which the current number of words in the transmit FIFO will be returned. Pass NULL if this value is not required. |
| [out] | rxCount | Pointer through which the current number of words in the receive FIFO will be returned. Pass NULL if this value is not required. |
|
inlinestatic |
Gets LPI2C master receive data register address for DMA transfer.
| base | The LPI2C peripheral base address. |
|
inlinestatic |
Gets the LPI2C master status flags.
A bit mask with the state of all LPI2C master status flags is returned. For each flag, the corresponding bit in the return value will be set if the flag is asserted.
| base | The LPI2C peripheral base address. |
| status_t LPI2C_MasterGetTransferCount | ( | LPI2C_Type * | base, |
| lpi2c_master_handle_t * | handle, | ||
| size_t * | count | ||
| ) |
Returns number of bytes transferred so far.
| base | The LPI2C peripheral base address. | |
| handle | Pointer to the LPI2C master driver handle. | |
| [out] | count | Number of bytes transferred so far by the non-blocking transaction. |
| #kStatus_Success | |
| #kStatus_NoTransferInProgress | There is not a non-blocking transaction currently in progress. |
|
inlinestatic |
Gets LPI2C master transmit data register address for DMA transfer.
| base | The LPI2C peripheral base address. |
| void LPI2C_MasterHandleInterrupt | ( | LPI2C_Type * | base, |
| lpi2c_master_handle_t * | handle | ||
| ) |
Reusable routine to handle master interrupts.
| base | The LPI2C peripheral base address. |
| handle | Pointer to the LPI2C master driver handle. |
| void LPI2C_MasterInit | ( | LPI2C_Type * | base, |
| const lpi2c_master_config_t * | masterConfig, | ||
| uint32_t | sourceClock_Hz | ||
| ) |
Initializes the LPI2C master peripheral.
This function enables the peripheral clock and initializes the LPI2C master peripheral as described by the user provided configuration. A software reset is performed prior to configuration.
| base | The LPI2C peripheral base address. |
| masterConfig | User provided peripheral configuration. Use LPI2C_MasterGetDefaultConfig() to get a set of defaults that you can override. |
| sourceClock_Hz | Frequency in Hertz of the LPI2C functional clock. Used to calculate the baud rate divisors, filter widths, and timeout periods. |
| status_t LPI2C_MasterReceive | ( | LPI2C_Type * | base, |
| void * | rxBuff, | ||
| size_t | rxSize | ||
| ) |
Performs a polling receive transfer on the I2C bus.
| base | The LPI2C peripheral base address. |
| rxBuff | The pointer to the data to be transferred. |
| rxSize | The length in bytes of the data to be transferred. |
| #kStatus_Success | Data was received successfully. |
| kStatus_LPI2C_Busy | Another master is currently utilizing the bus. |
| kStatus_LPI2C_Nak | The slave device sent a NAK in response to a byte. |
| kStatus_LPI2C_FifoError | Fifo underrun or overrun. |
| kStatus_LPI2C_ArbitrationLost | Arbitration lost error. |
| kStatus_LPI2C_PinLowTimeout | SCL or SDA were held low longer than the timeout. |
|
inlinestatic |
Sends a repeated START signal and slave address on the I2C bus.
This function is used to send a Repeated START signal when a transfer is already in progress. Like LPI2C_MasterStart(), it also sends the specified 7-bit address.
| base | The LPI2C peripheral base address. |
| address | 7-bit slave device address, in bits [6:0]. |
| dir | Master transfer direction, either kLPI2C_Read or kLPI2C_Write. This parameter is used to set the R/w bit (bit 0) in the transmitted slave address. |
| #kStatus_Success | Repeated START signal and address were successfully enqueued in the transmit FIFO. |
| kStatus_LPI2C_Busy | Another master is currently utilizing the bus. |
|
inlinestatic |
Perform software reset.
Restores the LPI2C master peripheral to reset conditions.
| base | The LPI2C peripheral base address. |
| status_t LPI2C_MasterSend | ( | LPI2C_Type * | base, |
| const void * | txBuff, | ||
| size_t | txSize | ||
| ) |
Performs a polling send transfer on the I2C bus.
Sends up to txSize number of bytes to the previously addressed slave device. The slave may reply with a NAK to any byte in order to terminate the transfer early. If this happens, this function will return kStatus_LPI2C_Nak.
| base | The LPI2C peripheral base address. |
| txBuff | The pointer to the data to be transferred. |
| txSize | The length in bytes of the data to be transferred. |
| #kStatus_Success | Data was sent successfully. |
| kStatus_LPI2C_Busy | Another master is currently utilizing the bus. |
| kStatus_LPI2C_Nak | The slave device sent a NAK in response to a byte. |
| kStatus_LPI2C_FifoError | Fifo underrun or overrun. |
| kStatus_LPI2C_ArbitrationLost | Arbitration lost error. |
| kStatus_LPI2C_PinLowTimeout | SCL or SDA were held low longer than the timeout. |
| void LPI2C_MasterSetBaudRate | ( | LPI2C_Type * | base, |
| uint32_t | sourceClock_Hz, | ||
| uint32_t | baudRate_Hz | ||
| ) |
Sets the I2C bus frequency for master transactions.
The LPI2C master is automatically disabled and re-enabled as necessary to configure the baud rate. Do not call this function during a transfer, or the transfer will be aborted.
| base | The LPI2C peripheral base address. |
| sourceClock_Hz | LPI2C functional clock frequency in Hertz. |
| baudRate_Hz | Requested bus frequency in Hertz. |
|
inlinestatic |
Set the watermarks for LPI2C master FIFOs.
| base | The LPI2C peripheral base address. |
| txWords | Transmit FIFO watermark value in words. The kLPI2C_MasterTxReadyFlag flag is set whenever the number of words in the transmit FIFO is equal or less than txWords. Writing a value equal or greater than the FIFO size will be truncated. |
| rxWords | Receive FIFO watermark value in words. The kLPI2C_MasterRxReadyFlag flag is set whenever the number of words in the receive FIFO is greater than rxWords. Writing a value equal or greater than the FIFO size will be truncated. |
| status_t LPI2C_MasterStart | ( | LPI2C_Type * | base, |
| uint8_t | address, | ||
| lpi2c_direction_t | dir | ||
| ) |
Sends a START signal and slave address on the I2C bus.
This function is used to initiate a new master mode transfer. First, the bus state is checked to ensure that another master is not occupying the bus. Then a START signal is transmitted, followed by the 7-bit address specified in the address parameter. Note that this function does not actually wait until the START and address are successfully sent on the bus before returning.
| base | The LPI2C peripheral base address. |
| address | 7-bit slave device address, in bits [6:0]. |
| dir | Master transfer direction, either kLPI2C_Read or kLPI2C_Write. This parameter is used to set the R/w bit (bit 0) in the transmitted slave address. |
| #kStatus_Success | START signal and address were successfully enqueued in the transmit FIFO. |
| kStatus_LPI2C_Busy | Another master is currently utilizing the bus. |
| status_t LPI2C_MasterStop | ( | LPI2C_Type * | base | ) |
Sends a STOP signal on the I2C bus.
This function does not return until the STOP signal is seen on the bus, or an error occurrs.
| base | The LPI2C peripheral base address. |
| #kStatus_Success | The STOP signal was successfully sent on the bus and the transaction terminated. |
| kStatus_LPI2C_Busy | Another master is currently utilizing the bus. |
| kStatus_LPI2C_Nak | The slave device sent a NAK in response to a byte. |
| kStatus_LPI2C_FifoError | Fifo underrun or overrun. |
| kStatus_LPI2C_ArbitrationLost | Arbitration lost error. |
| kStatus_LPI2C_PinLowTimeout | SCL or SDA were held low longer than the timeout. |
| status_t LPI2C_MasterTransferNonBlocking | ( | LPI2C_Type * | base, |
| lpi2c_master_handle_t * | handle, | ||
| lpi2c_master_transfer_t * | transfer | ||
| ) |
Performs a non-blocking transaction on the I2C bus.
| base | The LPI2C peripheral base address. |
| handle | Pointer to the LPI2C master driver handle. |
| transfer | The pointer to the transfer descriptor. |
| #kStatus_Success | The transaction was started successfully. |
| kStatus_LPI2C_Busy | Either another master is currently utilizing the bus, or a non-blocking transaction is already in progress. |