33 #include "fsl_device_registers.h" 34 #include "fsl_common.h" 48 #define FSL_LPI2C_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) 106 typedef enum _lpi2c_direction {
112 typedef enum _lpi2c_master_pin_config {
127 typedef enum _lpi2c_host_request_source {
133 typedef enum _lpi2c_host_request_polarity {
147 typedef struct _lpi2c_master_config
168 typedef enum _lpi2c_data_match_config_mode {
183 typedef struct _lpi2c_match_config
206 lpi2c_master_handle_t *handle,
250 uint16_t commandBuffer[7];
295 typedef enum _lpi2c_slave_address_match {
310 typedef struct _lpi2c_slave_config
351 typedef enum _lpi2c_slave_transfer_event {
367 typedef struct _lpi2c_slave_transfer
414 #if defined(__cplusplus) 494 base->MCR = LPI2C_MCR_RST_MASK;
506 base->MCR = (base->MCR & ~LPI2C_MCR_MEN_MASK) | LPI2C_MCR_MEN(enable);
553 base->MSR = statusMask;
573 base->MIER |= interruptMask;
588 base->MIER &= ~interruptMask;
617 base->MDER = LPI2C_MDER_TDDE(enableTx) | LPI2C_MDER_RDDE(enableRx);
628 return (uint32_t)&base->MTDR;
639 return (uint32_t)&base->MRDR;
660 base->MFCR = LPI2C_MFCR_TXWATER(txWords) | LPI2C_MFCR_RXWATER(rxWords);
676 *txCount = (base->MFSR & LPI2C_MFSR_TXCOUNT_MASK) >> LPI2C_MFSR_TXCOUNT_SHIFT;
680 *rxCount = (base->MFSR & LPI2C_MFSR_RXCOUNT_MASK) >> LPI2C_MFSR_RXCOUNT_SHIFT;
712 return (base->MSR & LPI2C_MSR_BBF_MASK) >> LPI2C_MSR_BBF_SHIFT;
820 lpi2c_master_handle_t *handle,
835 lpi2c_master_handle_t *handle,
836 lpi2c_master_transfer_t *transfer);
951 base->SCR = LPI2C_SCR_RST_MASK;
963 base->SCR = (base->SCR & ~LPI2C_SCR_SEN_MASK) | LPI2C_SCR_SEN(enable);
1007 base->SSR = statusMask;
1027 base->SIER |= interruptMask;
1042 base->SIER &= ~interruptMask;
1072 base->SDER = (base->SDER & ~(LPI2C_SDER_AVDE_MASK | LPI2C_SDER_RDDE_MASK | LPI2C_SDER_TDDE_MASK)) |
1073 LPI2C_SDER_AVDE(enableAddressValid) | LPI2C_SDER_RDDE(enableRx) | LPI2C_SDER_TDDE(enableTx);
1092 return (base->SSR & LPI2C_SSR_BBF_MASK) >> LPI2C_SSR_BBF_SHIFT;
1107 base->STAR = LPI2C_STAR_TXNACK(!ackOrNack);
1121 return base->SASR & LPI2C_SASR_RADDR_MASK;
1164 lpi2c_slave_handle_t *handle,
1233 #if defined(__cplusplus) status_t LPI2C_SlaveGetTransferCount(LPI2C_Type *base, lpi2c_slave_handle_t *handle, size_t *count)
Get slave transfer status during a non-blocking transfer.
Definition: fsl_lpi2c.c:1329
Definition: fsl_lpi2c.h:357
status_t LPI2C_MasterStop(LPI2C_Type *base)
Sends a STOP signal on the I2C bus.
Definition: fsl_lpi2c.c:540
Definition: fsl_lpi2c.h:178
bool debugEnable
Definition: fsl_lpi2c.h:151
void LPI2C_MasterAbortTransfer(LPI2C_Type *base, lpi2c_master_handle_t *handle)
Terminates a non-blocking LPI2C master transmission early.
Definition: fsl_lpi2c.c:1001
status_t LPI2C_SlaveTransferNonBlocking(LPI2C_Type *base, lpi2c_slave_handle_t *handle, uint32_t eventMask)
Start accepting slave transfers.
Definition: fsl_lpi2c.c:1286
Definition: fsl_lpi2c.h:97
Definition: fsl_lpi2c.h:174
status_t completionStatus
Definition: fsl_lpi2c.h:373
lpi2c_host_request_source_t
LPI2C master host request selection.
Definition: fsl_lpi2c.h:127
lpi2c_data_match_config_mode_t
LPI2C master data match configuration modes.
Definition: fsl_lpi2c.h:168
static void LPI2C_SlaveReset(LPI2C_Type *base)
Perform software reset of the LPI2C slave peripheral.
Definition: fsl_lpi2c.h:949
uint32_t subaddress
Definition: fsl_lpi2c.h:235
static uint32_t LPI2C_SlaveGetStatusFlags(LPI2C_Type *base)
Gets the LPI2C slave status flags.
Definition: fsl_lpi2c.h:983
static bool LPI2C_SlaveGetBusIdleState(LPI2C_Type *base)
Return whether the bus is idle.
Definition: fsl_lpi2c.h:1090
LPI2C slave transfer structure.
Definition: fsl_lpi2c.h:367
void(* lpi2c_slave_transfer_callback_t)(LPI2C_Type *base, lpi2c_slave_transfer_t *transfer, void *userData)
Slave event callback function pointer type.
Definition: fsl_lpi2c.h:391
uint32_t match1
Definition: fsl_lpi2c.h:188
Definition: fsl_lpi2c.h:99
bool filterEnable
Definition: fsl_lpi2c.h:317
Definition: fsl_lpi2c.h:134
static void LPI2C_MasterReset(LPI2C_Type *base)
Perform software reset.
Definition: fsl_lpi2c.h:492
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.
Definition: fsl_lpi2c.h:748
lpi2c_slave_transfer_callback_t callback
Definition: fsl_lpi2c.h:404
Definition: fsl_lpi2c.h:102
Definition: fsl_lpi2c.h:58
void LPI2C_SlaveDeinit(LPI2C_Type *base)
Deinitializes the LPI2C slave peripheral.
Definition: fsl_lpi2c.c:1106
Definition: fsl_lpi2c.h:107
Definition: fsl_lpi2c.h:129
uint32_t baudRate_Hz
Definition: fsl_lpi2c.h:154
Definition: fsl_lpi2c.h:114
Definition: fsl_lpi2c.h:96
bool enableDoze
Definition: fsl_lpi2c.h:150
static uint32_t LPI2C_MasterGetTxFifoAddress(LPI2C_Type *base)
Gets LPI2C master transmit data register address for DMA transfer.
Definition: fsl_lpi2c.h:626
Definition: fsl_lpi2c.h:98
uint32_t clockHoldTime_ns
Definition: fsl_lpi2c.h:338
void LPI2C_MasterInit(LPI2C_Type *base, const lpi2c_master_config_t *masterConfig, uint32_t sourceClock_Hz)
Initializes the LPI2C master peripheral.
Definition: fsl_lpi2c.c:348
lpi2c_slave_transfer_event_t
Set of events sent to the callback for nonblocking slave transfers.
Definition: fsl_lpi2c.h:351
Definition: fsl_lpi2c.h:57
Definition: fsl_lpi2c.h:279
static void LPI2C_SlaveTransmitAck(LPI2C_Type *base, bool ackOrNack)
Transmit either an Ack or Nak on the I2C bus in response to a byte from the master.
Definition: fsl_lpi2c.h:1105
bool enableReceivedAddressRead
Definition: fsl_lpi2c.h:334
void LPI2C_SlaveGetDefaultConfig(lpi2c_slave_config_t *slaveConfig)
Provides a default configuration for the LPI2C slave peripheral.
Definition: fsl_lpi2c.c:1052
bool isBusy
Definition: fsl_lpi2c.h:400
Definition: fsl_lpi2c.h:353
bool rxDataMatchOnly
Definition: fsl_lpi2c.h:186
size_t dataSize
Definition: fsl_lpi2c.h:238
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.
Definition: fsl_lpi2c.c:898
Definition: fsl_lpi2c.h:121
void LPI2C_SlaveAbortTransfer(LPI2C_Type *base, lpi2c_slave_handle_t *handle)
Abort slave non-blocking transfers.
Definition: fsl_lpi2c.c:1351
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.
Definition: fsl_lpi2c.h:205
void LPI2C_MasterDeinit(LPI2C_Type *base)
Deinitializes the LPI2C master peripheral.
Definition: fsl_lpi2c.c:417
Definition: fsl_lpi2c.h:170
lpi2c_slave_transfer_t transfer
Definition: fsl_lpi2c.h:399
Definition: fsl_lpi2c.h:56
Definition: fsl_lpi2c.h:123
Definition: fsl_lpi2c.h:94
static void LPI2C_MasterEnableInterrupts(LPI2C_Type *base, uint32_t interruptMask)
Enable LPI2C master interrupt requests.
Definition: fsl_lpi2c.h:571
lpi2c_slave_address_match_t addressMatchMode
Definition: fsl_lpi2c.h:315
lpi2c_master_pin_config_t
LPI2C pin configuration.
Definition: fsl_lpi2c.h:112
status_t LPI2C_SlaveSend(LPI2C_Type *base, const void *txBuff, size_t txSize, size_t *actualTxSize)
Performs a polling send transfer on the I2C bus.
Definition: fsl_lpi2c.c:1149
void LPI2C_SlaveCreateHandle(LPI2C_Type *base, lpi2c_slave_handle_t *handle, lpi2c_slave_transfer_callback_t callback, void *userData)
Create a new handle for the LPI2C slave non-blocking APIs.
Definition: fsl_lpi2c.c:1253
static void LPI2C_SlaveEnable(LPI2C_Type *base, bool enable)
Enables or disables the LPI2C module as slave.
Definition: fsl_lpi2c.h:961
Definition: fsl_lpi2c.h:61
Definition: fsl_lpi2c.h:119
lpi2c_direction_t
Direction of master and slave transfers.
Definition: fsl_lpi2c.h:106
Definition: fsl_lpi2c.h:171
lpi2c_host_request_polarity_t
LPI2C master host request pin polarity configuration.
Definition: fsl_lpi2c.h:133
bool wasTransmit
Definition: fsl_lpi2c.h:401
Definition: fsl_lpi2c.h:219
_lpi2c_status
LPI2C status return codes.
Definition: fsl_lpi2c.h:51
uint8_t sclGlitchFilterWidth_ns
Definition: fsl_lpi2c.h:158
lpi2c_slave_address_match_t
LPI2C slave address match options.
Definition: fsl_lpi2c.h:295
Definition: fsl_lpi2c.h:59
size_t dataSize
Definition: fsl_lpi2c.h:372
Driver handle for master non-blocking APIs.
Definition: fsl_lpi2c.h:245
uint8_t receivedAddress
Definition: fsl_lpi2c.h:370
uint32_t busIdleTimeout_ns
Definition: fsl_lpi2c.h:155
uint8_t * data
Definition: fsl_lpi2c.h:371
Definition: fsl_lpi2c.h:176
Definition: fsl_lpi2c.h:115
uint8_t address0
Definition: fsl_lpi2c.h:313
static uint32_t LPI2C_SlaveGetEnabledInterrupts(LPI2C_Type *base)
Returns the set of currently enabled LPI2C slave interrupt requests.
Definition: fsl_lpi2c.h:1051
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.
Definition: fsl_lpi2c.c:644
Definition: fsl_lpi2c.h:220
status_t LPI2C_SlaveReceive(LPI2C_Type *base, void *rxBuff, size_t rxSize, size_t *actualRxSize)
Performs a polling receive transfer on the I2C bus.
Definition: fsl_lpi2c.c:1201
uint32_t sdaGlitchFilterWidth_ns
Definition: fsl_lpi2c.h:335
lpi2c_direction_t direction
Definition: fsl_lpi2c.h:234
static void LPI2C_SlaveEnableDMA(LPI2C_Type *base, bool enableAddressValid, bool enableRx, bool enableTx)
Enable or disable LPI2C slave peripheral DMA requests.
Definition: fsl_lpi2c.h:1070
Definition: fsl_lpi2c.h:298
static bool LPI2C_MasterGetBusIdleState(LPI2C_Type *base)
Return whether the bus is idle.
Definition: fsl_lpi2c.h:710
static void LPI2C_MasterGetFifoCounts(LPI2C_Type *base, size_t *rxCount, size_t *txCount)
Get the current number of words in the LPI2C master FIFOs.
Definition: fsl_lpi2c.h:672
bool enableMaster
Definition: fsl_lpi2c.h:149
void LPI2C_MasterSetBaudRate(LPI2C_Type *base, uint32_t sourceClock_Hz, uint32_t baudRate_Hz)
Sets the I2C bus frequency for master transactions.
Definition: fsl_lpi2c.c:443
void * userData
Definition: fsl_lpi2c.h:253
lpi2c_data_match_config_mode_t matchMode
Definition: fsl_lpi2c.h:185
Definition: fsl_lpi2c.h:113
static uint32_t LPI2C_SlaveGetReceivedAddress(LPI2C_Type *base)
Returns the slave address sent by the I2C master.
Definition: fsl_lpi2c.h:1119
Definition: fsl_lpi2c.h:288
void LPI2C_MasterGetDefaultConfig(lpi2c_master_config_t *masterConfig)
Provides a default configuration for the LPI2C master peripheral.
Definition: fsl_lpi2c.c:332
static void LPI2C_MasterDisableInterrupts(LPI2C_Type *base, uint32_t interruptMask)
Disable LPI2C master interrupt requests.
Definition: fsl_lpi2c.h:586
Definition: fsl_lpi2c.h:289
Definition: fsl_lpi2c.h:359
bool filterDozeEnable
Definition: fsl_lpi2c.h:316
static void LPI2C_SlaveEnableInterrupts(LPI2C_Type *base, uint32_t interruptMask)
Enable LPI2C slave interrupt requests.
Definition: fsl_lpi2c.h:1025
size_t subaddressSize
Definition: fsl_lpi2c.h:236
void * userData
Definition: fsl_lpi2c.h:405
status_t LPI2C_MasterGetTransferCount(LPI2C_Type *base, lpi2c_master_handle_t *handle, size_t *count)
Returns number of bytes transferred so far.
Definition: fsl_lpi2c.c:949
void LPI2C_SlaveInit(LPI2C_Type *base, const lpi2c_slave_config_t *slaveConfig, uint32_t sourceClock_Hz)
Initializes the LPI2C slave peripheral.
Definition: fsl_lpi2c.c:1073
Structure with settings to initialize the LPI2C master module.
Definition: fsl_lpi2c.h:147
Definition: fsl_lpi2c.h:128
Definition: fsl_lpi2c.h:92
static void LPI2C_SlaveClearStatusFlags(LPI2C_Type *base, uint32_t statusMask)
Clears the LPI2C status flag state.
Definition: fsl_lpi2c.h:1005
Definition: fsl_lpi2c.h:296
static uint32_t LPI2C_MasterGetStatusFlags(LPI2C_Type *base)
Gets the LPI2C master status flags.
Definition: fsl_lpi2c.h:526
_lpi2c_master_flags
LPI2C master peripheral flags.
Definition: fsl_lpi2c.h:90
void * data
Definition: fsl_lpi2c.h:237
Definition: fsl_lpi2c.h:55
lpi2c_master_transfer_callback_t completionCallback
Definition: fsl_lpi2c.h:252
lpi2c_master_transfer_t transfer
Definition: fsl_lpi2c.h:251
static void LPI2C_MasterEnable(LPI2C_Type *base, bool enable)
Enables or disables the LPI2C module as master.
Definition: fsl_lpi2c.h:504
LPI2C master data match config struct.
Definition: fsl_lpi2c.h:183
static void LPI2C_MasterClearStatusFlags(LPI2C_Type *base, uint32_t statusMask)
Clears the LPI2C master status flag state.
Definition: fsl_lpi2c.h:551
Definition: fsl_lpi2c.h:280
_lpi2c_master_transfer_flags
Transfer option flags.
Definition: fsl_lpi2c.h:216
Definition: fsl_lpi2c.h:284
Definition: fsl_lpi2c.h:282
lpi2c_master_pin_config_t pinConfig
Definition: fsl_lpi2c.h:153
Definition: fsl_lpi2c.h:281
status_t LPI2C_MasterSend(LPI2C_Type *base, const void *txBuff, size_t txSize)
Performs a polling send transfer on the I2C bus.
Definition: fsl_lpi2c.c:621
uint32_t match0
Definition: fsl_lpi2c.h:187
Definition: fsl_lpi2c.h:287
_lpi2c_slave_flags
LPI2C slave peripheral flags.
Definition: fsl_lpi2c.h:277
Definition: fsl_lpi2c.h:358
lpi2c_slave_transfer_event_t event
Definition: fsl_lpi2c.h:369
size_t transferredCount
Definition: fsl_lpi2c.h:375
uint16_t remainingBytes
Definition: fsl_lpi2c.h:248
uint8_t state
Definition: fsl_lpi2c.h:247
uint16_t slaveAddress
Definition: fsl_lpi2c.h:233
Definition: fsl_lpi2c.h:362
uint8_t sdaGlitchFilterWidth_ns
Definition: fsl_lpi2c.h:157
uint8_t * buf
Definition: fsl_lpi2c.h:249
Definition: fsl_lpi2c.h:291
Definition: fsl_lpi2c.h:297
Definition: fsl_lpi2c.h:101
bool ignoreAck
Definition: fsl_lpi2c.h:333
bool ignoreAck
Definition: fsl_lpi2c.h:152
Definition: fsl_lpi2c.h:283
uint32_t pinLowTimeout_ns
Definition: fsl_lpi2c.h:156
uint32_t sclGlitchFilterWidth_ns
Definition: fsl_lpi2c.h:336
bool enableGeneralCall
Definition: fsl_lpi2c.h:318
Definition: fsl_lpi2c.h:53
Definition: fsl_lpi2c.h:108
void LPI2C_SlaveHandleInterrupt(LPI2C_Type *base, lpi2c_slave_handle_t *handle)
Reusable routine to handle slave interrupts.
Definition: fsl_lpi2c.c:1372
static void LPI2C_MasterSetWatermarks(LPI2C_Type *base, size_t txWords, size_t rxWords)
Set the watermarks for LPI2C master FIFOs.
Definition: fsl_lpi2c.h:658
uint32_t dataValidDelay_ns
Definition: fsl_lpi2c.h:337
uint32_t flags
Definition: fsl_lpi2c.h:231
static uint32_t LPI2C_MasterGetEnabledInterrupts(LPI2C_Type *base)
Returns the set of currently enabled LPI2C master interrupt requests.
Definition: fsl_lpi2c.h:598
Definition: fsl_lpi2c.h:169
Definition: fsl_lpi2c.h:286
bool enableSlave
Definition: fsl_lpi2c.h:312
Definition: fsl_lpi2c.h:100
Definition: fsl_lpi2c.h:172
Definition: fsl_lpi2c.h:290
status_t LPI2C_MasterReceive(LPI2C_Type *base, void *rxBuff, size_t rxSize)
Performs a polling receive transfer on the I2C bus.
Definition: fsl_lpi2c.c:572
Definition: fsl_lpi2c.h:54
Definition: fsl_lpi2c.h:63
LPI2C slave handle structure.
Definition: fsl_lpi2c.h:397
static void LPI2C_SlaveDisableInterrupts(LPI2C_Type *base, uint32_t interruptMask)
Disable LPI2C slave interrupt requests.
Definition: fsl_lpi2c.h:1040
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.
Definition: fsl_lpi2c.c:512
Definition: fsl_lpi2c.h:218
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:121
Definition: fsl_lpi2c.h:116
void LPI2C_MasterHandleInterrupt(LPI2C_Type *base, lpi2c_master_handle_t *handle)
Reusable routine to handle master interrupts.
Definition: fsl_lpi2c.c:1019
uint8_t address1
Definition: fsl_lpi2c.h:314
Definition: fsl_lpi2c.h:285
Definition: fsl_lpi2c.h:355
Definition: fsl_lpi2c.h:95
Structure with settings to initialize the LPI2C slave module.
Definition: fsl_lpi2c.h:310
Definition: fsl_lpi2c.h:135
static uint32_t LPI2C_MasterGetRxFifoAddress(LPI2C_Type *base)
Gets LPI2C master receive data register address for DMA transfer.
Definition: fsl_lpi2c.h:637
Definition: fsl_common.h:74
uint32_t eventMask
Definition: fsl_lpi2c.h:402
static void LPI2C_MasterEnableDMA(LPI2C_Type *base, bool enableTx, bool enableRx)
Enables or disables LPI2C master DMA requests.
Definition: fsl_lpi2c.h:615
uint32_t transferredCount
Definition: fsl_lpi2c.h:403
Definition: fsl_lpi2c.h:221
void LPI2C_MasterConfigureDataMatch(LPI2C_Type *base, const lpi2c_data_match_config_t *config)
Configure LPI2C master data match feature.
Definition: fsl_lpi2c.c:426
Definition: fsl_lpi2c.h:352
Definition: fsl_lpi2c.h:117
Non-blocking transfer descriptor structure.
Definition: fsl_lpi2c.h:229
Definition: fsl_lpi2c.h:93