52 __attribute__((always_inline)) static inline
void I2cSendAck(
void *reg)
60 p->trans_extract_idx++;
62 p->trans_extract_idx = 0;
65 if (p->trans_extract_idx == p->trans_insert_idx) {
94 __attribute__((always_inline)) static inline
void I2cReceive(
void *reg,
bool ack)
105 __attribute__((always_inline)) static inline
void I2cClearIT(
void *reg)
117 switch (trans->
type) {
133 if (p->idx_buf < trans->
len_r) {
134 trans->
buf[p->idx_buf] = ((
i2cRegs_t *)(p->reg_addr))->dat;
143 if (p->idx_buf < trans->
len_r) {
144 trans->
buf[p->idx_buf] = ((
i2cRegs_t *)(p->reg_addr))->dat;
159 if (p->idx_buf < trans->
len_w) {
186 #define I2C0_SCLL 200
190 #define I2C0_SCLH 200
195 #if (PCLK == 15000000)
196 #define I2C0_SCLL_D I2C0_SCLL
197 #define I2C0_SCLH_D I2C0_SCLH
200 #if (PCLK == 30000000)
201 #define I2C0_SCLL_D (2*I2C0_SCLL)
202 #define I2C0_SCLH_D (2*I2C0_SCLH)
205 #if (PCLK == 60000000)
206 #define I2C0_SCLL_D (4*I2C0_SCLL)
207 #define I2C0_SCLH_D (4*I2C0_SCLH)
210 #error unknown PCLK frequency
215 #ifndef I2C0_VIC_SLOT
216 #define I2C0_VIC_SLOT 8
220 void i2c0_ISR(
void) __attribute__((naked));
238 void i2c0_hw_init(
void)
244 i2c0.reg_addr =
I2C0;
246 i2c0.init_struct = (
void *)(&i2c0_vic_channel);
274 #define I2C1_SCLL 200
278 #define I2C1_SCLH 200
283 #if (PCLK == 15000000)
284 #define I2C1_SCLL_D I2C1_SCLL
285 #define I2C1_SCLH_D I2C1_SCLH
288 #if (PCLK == 30000000)
289 #define I2C1_SCLL_D (2*I2C1_SCLL)
290 #define I2C1_SCLH_D (2*I2C1_SCLH)
293 #if (PCLK == 60000000)
294 #define I2C1_SCLL_D (4*I2C1_SCLL)
295 #define I2C1_SCLH_D (4*I2C1_SCLH)
298 #error unknown PCLK frequency
303 #ifndef I2C1_VIC_SLOT
304 #define I2C1_VIC_SLOT 9
308 void i2c1_ISR(
void) __attribute__((naked));
326 void i2c1_hw_init(
void)
332 i2c1.reg_addr =
I2C1;
334 i2c1.init_struct = (
void *)(&i2c1_vic_channel);
400 int period = 15000000 / 2 / bitrate;
410 #if (PCLK == 30000000)
414 #if (PCLK == 60000000)
#define I2C_TRANSACTION_QUEUE_LEN
I2C transaction queue length.
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
uint16_t len_r
Number of bytes to read/receive.
static void I2cClearIT(void *reg)
static void I2cClearStart(void *reg)
static void I2cSendAck(void *reg)
transaction successfully finished by I2C driver
transmit and receive transaction
static void i2c_lpc21_setbitrate(struct i2c_periph *p, int bitrate)
uint8_t trans_extract_idx
volatile uint16_t queue_full_cnt
static void I2cEndOfTransaction(struct i2c_periph *p)
struct i2c_errors * errors
static void I2cSendStop(struct i2c_periph *p, struct i2c_transaction *t)
static bool i2c_lpc21_idle(struct i2c_periph *p)
uint8_t len_w
Number of bytes to write/transmit.
static void I2cAutomaton(int32_t state, struct i2c_periph *p)
struct i2c_transaction * trans[I2C_TRANSACTION_QUEUE_LEN]
static void I2cFail(struct i2c_periph *p, struct i2c_transaction *t)
I2C transaction structure.
enum I2CTransactionStatus status
Transaction status.
static void I2cSendStart(struct i2c_periph *p)
uint8_t slave_addr
Slave address.
static bool i2c_lpc21_submit(struct i2c_periph *p, struct i2c_transaction *t)
unsigned disableIRQ(void)
static void I2cReceive(void *reg, bool ack)
transmit only transaction
static void I2cSendByte(void *reg, uint8_t b)
void i2c_event(void)
i2c_event() function
enum I2CTransactionType type
Transaction type.
transaction is pending in queue
Architecture independent I2C (Inter-Integrated Circuit Bus) API.