Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
LPI2C Slave peripheral driver

Overview

This section describes the programming interface of the I2C slave mode Peripheral driver.

Data Structures

struct  lpi2c_slave_state_t
 Runtime state of the LPI2C Slave driver. More...
 
struct  lpi2c_slave_user_config_t
 Defines the structure to initialize the LPI2C Slave module. More...
 

Typedefs

typedef void(* lpi2c_slave_callback_t )(uint8_t instance, lpi2c_slave_event_t slaveEvent, void *userData)
 LPI2C slave callback function.
 

Enumerations

enum  lpi2c_slave_event_t {
  kLPI2CSlaveTxReq = 0x02u,
  kLPI2CSlaveRxReq = 0x04u,
  kLPI2CSlaveTxNAK = 0x08u,
  kLPI2CSlaveTxEmpty = 0x10u,
  kLPI2CSlaveRxFull = 0x20u,
  kLPI2CSlaveAbort = 0x40u
}
 Internal driver state information. More...
 

Variables

LPI2C_Type *const g_lpi2cBase [LPI2C_INSTANCE_COUNT]
 Table of base addresses for LPI2C instances. More...
 

LPI2C Slave

void LPI2C_DRV_SlaveInit (uint32_t instance, const lpi2c_slave_user_config_t *userConfigPtr, lpi2c_slave_state_t *slave)
 Initializes the LPI2C module. More...
 
void LPI2C_DRV_SlaveDeinit (uint32_t instance)
 Shuts down the LPI2C slave driver. More...
 
lpi2c_slave_state_tLPI2C_DRV_SlaveGetHandler (uint32_t instance)
 Gets the LPI2C slave run-time state structure. More...
 
lpi2c_status_t LPI2C_DRV_SlaveSendData (uint32_t instance, const uint8_t *txBuff, uint32_t txSize)
 Sends/transmits data by using a non-blocking method. More...
 
lpi2c_status_t LPI2C_DRV_SlaveSendDataBlocking (uint32_t instance, const uint8_t *txBuff, uint32_t txSize, uint32_t timeout_ms)
 Sends (transmits) data by using a blocking method. More...
 
lpi2c_status_t LPI2C_DRV_SlaveReceiveData (uint32_t instance, uint8_t *rxBuff, uint32_t rxSize)
 Receives the data by using a non-blocking method. More...
 
lpi2c_status_t LPI2C_DRV_SlaveReceiveDataBlocking (uint32_t instance, uint8_t *rxBuff, uint32_t rxSize, uint32_t timeout_ms)
 Receives data by using a blocking method. More...
 
lpi2c_status_t LPI2C_DRV_SlaveGetReceiveStatus (uint32_t instance, uint32_t *bytesRemaining)
 Gets the current status of the LPI2C slave driver. More...
 
lpi2c_status_t LPI2C_DRV_SlaveGetTransmitStatus (uint32_t instance, uint32_t *bytesRemaining)
 Gets the current status of the LPI2C slave driver. More...
 
lpi2c_status_t LPI2C_DRV_SlaveAbortReceiveData (uint32_t instance, uint32_t *rxSize)
 Terminates a non-blocking receive of the LPI2C slave early. More...
 
lpi2c_status_t LPI2C_DRV_SlaveAbortSendData (uint32_t instance, uint32_t *txSize)
 Terminates a non-blocking send of the LPI2C slave early. More...
 
static bool LPI2C_DRV_SlaveIsBusBusy (uint32_t instance)
 Gets the current status of the LPI2C slave bus. More...
 
static lpi2c_status_t LPI2C_DRV_SlaveSendDataPolling (uint32_t instance, const uint8_t *txBuff, uint32_t txSize)
 Sends out multiple bytes of data using a polling method. More...
 
static lpi2c_status_t LPI2C_DRV_SlaveReceiveDataPolling (uint32_t instance, uint8_t *rxBuff, uint32_t rxSize)
 Receives multiple bytes of data using a polling method. More...
 

Data Structure Documentation

struct lpi2c_slave_state_t

This structure holds data used by the LPI2C Slave Peripheral driver to communicate between the transfer function and the interrupt handler. The interrupt handler also uses this information to keep track of its progress.

Data Fields

lpi2c_status_t status
 The slave LPI2C status. More...
 
volatile uint32_t txSize
 Size of the transmit buffer. More...
 
volatile uint32_t rxSize
 Size of the receive buffer. More...
 
const uint8_t * txBuff
 Pointer to transmit Buffer. More...
 
uint8_t * rxBuff
 Pointer to receive Buffer. More...
 
bool isTxBusy
 True if the driver is sending data. More...
 
bool isRxBusy
 True if the driver is receiving data. More...
 
bool isTxBlocking
 True if transmit is blocking transaction. More...
 
bool isRxBlocking
 True if receive is blocking transaction. More...
 
event_t irqEvent
 Use to wait for ISR to complete transmit and receive. More...
 
bool slaveListening
 True if slave is in listening mode. More...
 
lpi2c_slave_callback_t slaveCallback
 Pointer to user callback function. More...
 
void * callbackParam
 Pointer to user callback parameter. More...
 

Field Documentation

lpi2c_status_t lpi2c_slave_state_t::status
volatile uint32_t lpi2c_slave_state_t::txSize
volatile uint32_t lpi2c_slave_state_t::rxSize
const uint8_t* lpi2c_slave_state_t::txBuff
uint8_t* lpi2c_slave_state_t::rxBuff
bool lpi2c_slave_state_t::isTxBusy
bool lpi2c_slave_state_t::isRxBusy
bool lpi2c_slave_state_t::isTxBlocking
bool lpi2c_slave_state_t::isRxBlocking
event_t lpi2c_slave_state_t::irqEvent
bool lpi2c_slave_state_t::slaveListening
lpi2c_slave_callback_t lpi2c_slave_state_t::slaveCallback
void* lpi2c_slave_state_t::callbackParam
struct lpi2c_slave_user_config_t
Note
once slaveListening mode is selected, all send/receive blocking/non-blocking functions will be invalid.

Data Fields

uint16_t address
 Slave's 7-bit or 10-bit address. More...
 
bool slaveListening
 The slave configuration mode.
 
lpi2c_slave_callback_t slaveCallback
 The slave callback function.
 
void * callbackParam
 The slave callback data.
 

Field Documentation

uint16_t lpi2c_slave_user_config_t::address

If 10-bit address, the first 6 bits must be 011110 in binary.

Enumeration Type Documentation

Note
The contents of this structure are internal to the driver and should not be modified by users. Also, contents of the structure are subject to change in future releases.

Defines the type of flags for callback function

Enumerator
kLPI2CSlaveTxReq 

The slave LPI2C Transmitting Request event.

kLPI2CSlaveRxReq 

The slave LPI2C Receiving Request event.

kLPI2CSlaveTxNAK 

The slave LPI2C Transmitting NAK event.

kLPI2CSlaveTxEmpty 

The slave LPI2C Transmitting Buffer Empty event.

kLPI2CSlaveRxFull 

The slave LPI2C Receiving Buffer Full event.

kLPI2CSlaveAbort 

The slave LPI2C Slave abort transaction event.

Function Documentation

void LPI2C_DRV_SlaveInit ( uint32_t  instance,
const lpi2c_slave_user_config_t userConfigPtr,
lpi2c_slave_state_t slave 
)

Saves the application callback info, turns on the clock to the module, enables the device, and enables interrupts. Sets the LPI2C to slave mode. IOMUX should be handled in the init_hardware() function.

Parameters
instanceInstance number of the LPI2C module.
userConfigPtrPointer of the user configuration structure
slavePointer of the slave run-time structure.
void LPI2C_DRV_SlaveDeinit ( uint32_t  instance)

Clears the control register and turns off the clock to the module.

Parameters
instanceInstance number of the LPI2C module.
lpi2c_slave_state_t* LPI2C_DRV_SlaveGetHandler ( uint32_t  instance)

This function gets the LPI2C slave run-time state structure.

Parameters
instanceInstance number of the LPI2C module.
Returns
Pointer to LPI2C slave run-time state structure.
lpi2c_status_t LPI2C_DRV_SlaveSendData ( uint32_t  instance,
const uint8_t *  txBuff,
uint32_t  txSize 
)

This function returns immediately when the buffer pointer and length are set to the transfer buffer and transfer size. Check the status of LPI2C slave to find out whether the transmission is complete. Wait the kLPI2CSlaveStop or the kLPI2CSlaveTxDone to ensure that the transmission is ended.

Parameters
instanceInstance number of the LPI2C module.
txBuffThe pointer to sending the data buffer.
txSizeThe number of bytes which the user wants to send.
Returns
success (if LPI2C slave status is not error) or error code in others.
lpi2c_status_t LPI2C_DRV_SlaveSendDataBlocking ( uint32_t  instance,
const uint8_t *  txBuff,
uint32_t  txSize,
uint32_t  timeout_ms 
)

This function sets the buffer pointer and length to the transfer buffer and the transfer size and waits until the transmission is ended (NAK is detected).

Parameters
instanceInstance number of the LPI2C module.
txBuffThe pointer to sending the data buffer.
txSizeThe number of bytes which the user wants to send.
timeout_msThe maximum number of milliseconds to wait for transmit completed
Returns
success (if LPI2C slave status is not error) or error code in others.
lpi2c_status_t LPI2C_DRV_SlaveReceiveData ( uint32_t  instance,
uint8_t *  rxBuff,
uint32_t  rxSize 
)

This function returns immediately when the buffer pointer and length are set to the receive buffer and the receive size. Check the status of the LPI2C slave to find out whether the transmission is completed. Wait the kLPI2CSlaveStop or the kLPI2CSlaveRxDone to ensure that the transmission is ended.

Parameters
instanceInstance number of the LPI2C module.
rxBuffThe pointer to the received data buffer.
rxSizeThe number of bytes which the user wants to receive.
Returns
success (if LPI2C slave status is not error) or error code in others.
lpi2c_status_t LPI2C_DRV_SlaveReceiveDataBlocking ( uint32_t  instance,
uint8_t *  rxBuff,
uint32_t  rxSize,
uint32_t  timeout_ms 
)

This function sets the buffer pointer and length to the receive buffer and the receive size. Then, the function waits until the transmission has ended (all data is received or a STOP signal is detected).

Parameters
instanceInstance number of the LPI2C module.
rxBuffThe pointer to the received data buffer.
rxSizeThe number of bytes which the user wants to receive.
timeout_msThe maximum number of milliseconds to wait for receive completed
Returns
success (if LPI2C slave status is not error) or error code in others.
lpi2c_status_t LPI2C_DRV_SlaveGetReceiveStatus ( uint32_t  instance,
uint32_t *  bytesRemaining 
)
Parameters
instanceInstance number of the LPI2C module.
bytesRemainingThe number of remaining bytes that LPI2C transmits.
Returns
The current status of LPI2C instance: in progress (busy), complete (success) or idle (lpi2c bus is idle).
lpi2c_status_t LPI2C_DRV_SlaveGetTransmitStatus ( uint32_t  instance,
uint32_t *  bytesRemaining 
)
Parameters
instanceInstance number of the LPI2C module.
bytesRemainingThe number of remaining bytes that LPI2C transmits.
Returns
The current status of LPI2C instance: in progress (busy), complete (success) or idle (LPI2C bus is idle).
lpi2c_status_t LPI2C_DRV_SlaveAbortReceiveData ( uint32_t  instance,
uint32_t *  rxSize 
)

During an non-blocking receiving

Parameters
instanceInstance number of the LPI2C module.
rxSizeThe number of remaining bytes in LPI2C receive buffer.
Returns
kStatus_LPI2C_Success if success kStatus_LPI2C_NoReceiveInProgress if none receiving is available.
lpi2c_status_t LPI2C_DRV_SlaveAbortSendData ( uint32_t  instance,
uint32_t *  txSize 
)

During an non-blocking receiving

Parameters
instanceInstance number of the LPI2C module.
txSizeThe number of remaining bytes in LPI2C Tx Buffer.
Returns
kStatus_LPI2C_Success if success kStatus_LPI2C_NoReceiveInProgress if none receiving is available.
static bool LPI2C_DRV_SlaveIsBusBusy ( uint32_t  instance)
inlinestatic
Parameters
instanceInstance number of the LPI2C module.
Returns
True if the bus is busy False if the bus is idle
static lpi2c_status_t LPI2C_DRV_SlaveSendDataPolling ( uint32_t  instance,
const uint8_t *  txBuff,
uint32_t  txSize 
)
inlinestatic
Parameters
instanceInstance number of the LPI2C module.
txBuffThe buffer pointer which saves the data to be sent.
txSizeSize of data to be sent in bytes.
Returns
Error or success status returned by API.
static lpi2c_status_t LPI2C_DRV_SlaveReceiveDataPolling ( uint32_t  instance,
uint8_t *  rxBuff,
uint32_t  rxSize 
)
inlinestatic
Parameters
instanceInstance number of the LPI2C module.
rxBuffThe buffer pointer which saves the data to be received.
rxSizeSize of data need to be received in bytes.
Returns
Error or success status returned by the API.

Variable Documentation

LPI2C_Type* const g_lpi2cBase[LPI2C_INSTANCE_COUNT]