i2c_11xx.h
Go to the documentation of this file.
1 /*
2  * @brief LPC11xx I2C driver
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2012
6  * All rights reserved.
7  *
8  * @par
9  * Software that is described herein is for illustrative purposes only
10  * which provides customers with programming information regarding the
11  * LPC products. This software is supplied "AS IS" without any warranties of
12  * any kind, and NXP Semiconductors and its licensor disclaim any and
13  * all warranties, express or implied, including all implied warranties of
14  * merchantability, fitness for a particular purpose and non-infringement of
15  * intellectual property rights. NXP Semiconductors assumes no responsibility
16  * or liability for the use of the software, conveys no license or rights under any
17  * patent, copyright, mask work right, or any other intellectual property rights in
18  * or to any products. NXP Semiconductors reserves the right to make changes
19  * in the software without notification. NXP Semiconductors also makes no
20  * representation or warranty that such application will be suitable for the
21  * specified use without further testing or modification.
22  *
23  * @par
24  * Permission to use, copy, modify, and distribute this software and its
25  * documentation is hereby granted, under NXP Semiconductors' and its
26  * licensor's relevant copyrights in the software, without fee, provided that it
27  * is used in conjunction with NXP Semiconductors microcontrollers. This
28  * copyright, permission, and disclaimer notice must appear in all copies of
29  * this code.
30  */
31 
32 #ifndef __I2C_11XX_H_
33 #define __I2C_11XX_H_
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
44 #if !defined(CHIP_LPC110X)
45 
49 typedef struct { /* I2C0 Structure */
62  __IO uint32_t MASK[4];
63 } LPC_I2C_T;
64 
70 #define RET_SLAVE_TX 6
71 #define RET_SLAVE_RX 5
72 #define RET_SLAVE_IDLE 2
73 #define RET_SLAVE_BUSY 0
78 #define I2C_STA_STO_RECV 0x20
79 
80 /*
81  * @brief I2C Control Set register description
82  */
83 #define I2C_I2CONSET_AA ((0x04))
84 #define I2C_I2CONSET_SI ((0x08))
85 #define I2C_I2CONSET_STO ((0x10))
86 #define I2C_I2CONSET_STA ((0x20))
87 #define I2C_I2CONSET_I2EN ((0x40))
89 /*
90  * @brief I2C Control Clear register description
91  */
92 #define I2C_I2CONCLR_AAC ((1 << 2))
93 #define I2C_I2CONCLR_SIC ((1 << 3))
94 #define I2C_I2CONCLR_STOC ((1 << 4))
95 #define I2C_I2CONCLR_STAC ((1 << 5))
96 #define I2C_I2CONCLR_I2ENC ((1 << 6))
98 /*
99  * @brief I2C Common Control register description
100  */
101 #define I2C_CON_AA (1UL << 2)
102 #define I2C_CON_SI (1UL << 3)
103 #define I2C_CON_STO (1UL << 4)
104 #define I2C_CON_STA (1UL << 5)
105 #define I2C_CON_I2EN (1UL << 6)
107 /*
108  * @brief I2C Status Code definition (I2C Status register)
109  */
110 #define I2C_STAT_CODE_BITMASK ((0xF8))
111 #define I2C_STAT_CODE_ERROR ((0xFF))
113 /*
114  * @brief I2C return status code definitions
115  */
116 #define I2C_I2STAT_NO_INF ((0xF8))
117 #define I2C_I2STAT_BUS_ERROR ((0x00))
119 /*
120  * @brief I2C Master transmit mode
121  */
122 #define I2C_I2STAT_M_TX_START ((0x08))
123 #define I2C_I2STAT_M_TX_RESTART ((0x10))
124 #define I2C_I2STAT_M_TX_SLAW_ACK ((0x18))
125 #define I2C_I2STAT_M_TX_SLAW_NACK ((0x20))
126 #define I2C_I2STAT_M_TX_DAT_ACK ((0x28))
127 #define I2C_I2STAT_M_TX_DAT_NACK ((0x30))
128 #define I2C_I2STAT_M_TX_ARB_LOST ((0x38))
130 /*
131  * @brief I2C Master receive mode
132  */
133 #define I2C_I2STAT_M_RX_START ((0x08))
134 #define I2C_I2STAT_M_RX_RESTART ((0x10))
135 #define I2C_I2STAT_M_RX_ARB_LOST ((0x38))
136 #define I2C_I2STAT_M_RX_SLAR_ACK ((0x40))
137 #define I2C_I2STAT_M_RX_SLAR_NACK ((0x48))
138 #define I2C_I2STAT_M_RX_DAT_ACK ((0x50))
139 #define I2C_I2STAT_M_RX_DAT_NACK ((0x58))
141 /*
142  * @brief I2C Slave receive mode
143  */
144 #define I2C_I2STAT_S_RX_SLAW_ACK ((0x60))
145 #define I2C_I2STAT_S_RX_ARB_LOST_M_SLA ((0x68))
146 // #define I2C_I2STAT_S_RX_SLAW_ACK ((0x68))
147 #define I2C_I2STAT_S_RX_GENCALL_ACK ((0x70))
148 #define I2C_I2STAT_S_RX_ARB_LOST_M_GENCALL ((0x78))
149 // #define I2C_I2STAT_S_RX_GENCALL_ACK ((0x78))
150 #define I2C_I2STAT_S_RX_PRE_SLA_DAT_ACK ((0x80))
151 #define I2C_I2STAT_S_RX_PRE_SLA_DAT_NACK ((0x88))
152 #define I2C_I2STAT_S_RX_PRE_GENCALL_DAT_ACK ((0x90))
153 #define I2C_I2STAT_S_RX_PRE_GENCALL_DAT_NACK ((0x98))
154 #define I2C_I2STAT_S_RX_STA_STO_SLVREC_SLVTRX ((0xA0))
157 /*
158  * @brief I2C Slave transmit mode
159  */
160 #define I2C_I2STAT_S_TX_SLAR_ACK ((0xA8))
161 #define I2C_I2STAT_S_TX_ARB_LOST_M_SLA ((0xB0))
162 // #define I2C_I2STAT_S_TX_SLAR_ACK ((0xB0))
163 #define I2C_I2STAT_S_TX_DAT_ACK ((0xB8))
164 #define I2C_I2STAT_S_TX_DAT_NACK ((0xC0))
165 #define I2C_I2STAT_S_TX_LAST_DAT_ACK ((0xC8))
166 #define I2C_SLAVE_TIME_OUT 0x10000000UL
168 /*
169  * @brief I2C Data register definition
170  */
171 #define I2C_I2DAT_BITMASK ((0xFF))
172 #define I2C_I2DAT_IDLE_CHAR (0xFF)
175 /*
176  * @brief I2C Monitor mode control register description
177  */
178 #define I2C_I2MMCTRL_MM_ENA ((1 << 0))
179 #define I2C_I2MMCTRL_ENA_SCL ((1 << 1))
180 #define I2C_I2MMCTRL_MATCH_ALL ((1 << 2))
181 #define I2C_I2MMCTRL_BITMASK ((0x07))
183 /*
184  * @brief I2C Data buffer register description
185  */
186 #define I2DATA_BUFFER_BITMASK ((0xFF))
188 /*
189  * @brief I2C Slave Address registers definition
190  */
191 #define I2C_I2ADR_GC ((1 << 0))
192 #define I2C_I2ADR_BITMASK ((0xFF))
194 /*
195  * @brief I2C Mask Register definition
196  */
197 #define I2C_I2MASK_MASK(n) ((n & 0xFE))
199 /*
200  * @brief I2C SCL HIGH duty cycle Register definition
201  */
202 #define I2C_I2SCLH_BITMASK ((0xFFFF))
204 /*
205  * @brief I2C SCL LOW duty cycle Register definition
206  */
207 #define I2C_I2SCLL_BITMASK ((0xFFFF))
209 /*
210  * @brief I2C status values
211  */
212 #define I2C_SETUP_STATUS_ARBF (1 << 8)
213 #define I2C_SETUP_STATUS_NOACKF (1 << 9)
214 #define I2C_SETUP_STATUS_DONE (1 << 10)
216 /*
217  * @brief I2C state handle return values
218  */
219 #define I2C_OK 0x00
220 #define I2C_BYTE_SENT 0x01
221 #define I2C_BYTE_RECV 0x02
222 #define I2C_LAST_BYTE_RECV 0x04
223 #define I2C_SEND_END 0x08
224 #define I2C_RECV_END 0x10
225 #define I2C_STA_STO_RECV 0x20
226 
227 #define I2C_ERR (0x10000000)
228 #define I2C_NAK_RECV (0x10000000 | 0x01)
229 
230 #define I2C_CheckError(ErrorCode) (ErrorCode & 0x10000000)
231 
232 /*
233  * @brief I2C monitor control configuration defines
234  */
235 #define I2C_MONITOR_CFG_SCL_OUTPUT I2C_I2MMCTRL_ENA_SCL
236 #define I2C_MONITOR_CFG_MATCHALL I2C_I2MMCTRL_MATCH_ALL
241 typedef enum {
248 } I2C_SLAVE_ID;
249 
253 typedef enum {
259 } I2C_STATUS_T;
260 
264 typedef struct {
266  const uint8_t *txBuff;
267  int txSz;
270  int rxSz;
273 } I2C_XFER_T;
274 
283 typedef enum I2C_ID {
286 } I2C_ID_T;
287 
291 typedef enum {
298 } I2C_EVENT_T;
299 
304 
310 void Chip_I2C_Init(I2C_ID_T id);
311 
317 void Chip_I2C_DeInit(I2C_ID_T id);
318 
330 void Chip_I2C_SetClockRate(I2C_ID_T id, uint32_t clockrate);
331 
338 
359 
368 int Chip_I2C_MasterSend(I2C_ID_T id, uint8_t slaveAddr, const uint8_t *buff, uint8_t len);
369 
379 int Chip_I2C_MasterCmdRead(I2C_ID_T id, uint8_t slaveAddr, uint8_t cmd, uint8_t *buff, int len);
380 
387 
395 
404 int Chip_I2C_MasterRead(I2C_ID_T id, uint8_t slaveAddr, uint8_t *buff, int len);
405 
413 
421 
429 
435 void Chip_I2C_Disable(I2C_ID_T id);
436 
447 
510  I2C_SLAVE_ID sid,
511  I2C_XFER_T *xfer,
512  I2C_EVENTHANDLER_T event,
513  uint8_t addrMask);
514 
521 
532 
533 #endif /* !defined(CHIP_LPC110X) */
534 
539  #ifdef __cplusplus
540 }
541 #endif
542 
543 #endif /* __I2C_11XX_H_ */
I2C_SLAVE_NUM_INTERFACE
@ I2C_SLAVE_NUM_INTERFACE
Definition: i2c_11xx.h:247
LPC_I2C_T::CONSET
__IO uint32_t CONSET
Definition: i2c_11xx.h:50
Chip_I2C_Init
void Chip_I2C_Init(I2C_ID_T id)
Initializes the LPC_I2C peripheral with specified parameter.
Chip_I2C_EventHandlerPolling
void Chip_I2C_EventHandlerPolling(I2C_ID_T id, I2C_EVENT_T event)
Default event handler for polling operation.
I2C_EVENTHANDLER_T
void(* I2C_EVENTHANDLER_T)(I2C_ID_T, I2C_EVENT_T)
Event handler function type.
Definition: i2c_11xx.h:303
LPC_I2C_T::ADR3
__IO uint32_t ADR3
Definition: i2c_11xx.h:60
I2C_STATUS_BUSY
@ I2C_STATUS_BUSY
Definition: i2c_11xx.h:258
Chip_I2C_MasterTransfer
int Chip_I2C_MasterTransfer(I2C_ID_T id, I2C_XFER_T *xfer)
Transmit and Receive data in master mode.
I2C_SLAVE_ID
I2C_SLAVE_ID
I2C Slave Identifiers.
Definition: i2c_11xx.h:241
Chip_I2C_IsMasterActive
int Chip_I2C_IsMasterActive(I2C_ID_T id)
Checks if master xfer in progress.
uavcan::uint32_t
std::uint32_t uint32_t
Definition: std.hpp:26
__IO
#define __IO
Definition: core_cm0.h:154
LPC_I2C_T::SCLH
__IO uint32_t SCLH
Definition: i2c_11xx.h:54
I2C_STATUS_BUSERR
@ I2C_STATUS_BUSERR
Definition: i2c_11xx.h:257
I2C_STATUS_DONE
@ I2C_STATUS_DONE
Definition: i2c_11xx.h:254
Chip_I2C_GetMasterEventHandler
I2C_EVENTHANDLER_T Chip_I2C_GetMasterEventHandler(I2C_ID_T id)
Get pointer to current function handling the events.
LPC_I2C_T::SCLL
__IO uint32_t SCLL
Definition: i2c_11xx.h:55
Chip_I2C_SetMasterEventHandler
int Chip_I2C_SetMasterEventHandler(I2C_ID_T id, I2C_EVENTHANDLER_T event)
Set function that must handle I2C events.
I2C_EVENT_SLAVE_RX
@ I2C_EVENT_SLAVE_RX
Definition: i2c_11xx.h:296
I2C_STATUS_ARBLOST
@ I2C_STATUS_ARBLOST
Definition: i2c_11xx.h:256
I2C_SLAVE_3
@ I2C_SLAVE_3
Definition: i2c_11xx.h:246
I2C_XFER_T::rxSz
int rxSz
Definition: i2c_11xx.h:270
__I
#define __I
Definition: core_cm0.h:151
Chip_I2C_SetClockRate
void Chip_I2C_SetClockRate(I2C_ID_T id, uint32_t clockrate)
Set up clock rate for LPC_I2C peripheral.
Chip_I2C_MasterCmdRead
int Chip_I2C_MasterCmdRead(I2C_ID_T id, uint8_t slaveAddr, uint8_t cmd, uint8_t *buff, int len)
Transfer a command to slave and receive data from slave after a repeated start.
I2C_XFER_T::status
I2C_STATUS_T status
Definition: i2c_11xx.h:272
I2C_EVENT_T
I2C_EVENT_T
I2C master events.
Definition: i2c_11xx.h:291
Chip_I2C_Disable
void Chip_I2C_Disable(I2C_ID_T id)
Disable I2C peripheral's operation.
I2C_SLAVE_GENERAL
@ I2C_SLAVE_GENERAL
Definition: i2c_11xx.h:242
I2C_ID_T
enum I2C_ID I2C_ID_T
I2C interface IDs.
LPC_I2C_T::ADR0
__IO uint32_t ADR0
Definition: i2c_11xx.h:53
Chip_I2C_EventHandler
void Chip_I2C_EventHandler(I2C_ID_T id, I2C_EVENT_T event)
Default event handler for interrupt base operation.
I2C_XFER_T::txBuff
const uint8_t * txBuff
Definition: i2c_11xx.h:266
uavcan::uint8_t
std::uint8_t uint8_t
Definition: std.hpp:24
I2C_XFER_T::txSz
int txSz
Definition: i2c_11xx.h:267
Chip_I2C_DeInit
void Chip_I2C_DeInit(I2C_ID_T id)
De-initializes the I2C peripheral registers to their default reset values.
LPC_I2C_T::DAT
__IO uint32_t DAT
Definition: i2c_11xx.h:52
LPC_I2C_T::ADR2
__IO uint32_t ADR2
Definition: i2c_11xx.h:59
I2C_XFER_T::rxBuff
uint8_t * rxBuff
Definition: i2c_11xx.h:269
I2C_STATUS_T
I2C_STATUS_T
I2C transfer status.
Definition: i2c_11xx.h:253
I2C_NUM_INTERFACE
@ I2C_NUM_INTERFACE
Definition: i2c_11xx.h:285
Chip_I2C_MasterStateHandler
void Chip_I2C_MasterStateHandler(I2C_ID_T id)
I2C Master transfer state change handler.
__O
#define __O
Definition: core_cm0.h:153
I2C_SLAVE_0
@ I2C_SLAVE_0
Definition: i2c_11xx.h:243
Chip_I2C_MasterSend
int Chip_I2C_MasterSend(I2C_ID_T id, uint8_t slaveAddr, const uint8_t *buff, uint8_t len)
Transmit data to I2C slave using I2C Master mode.
LPC_I2C_T::STAT
__I uint32_t STAT
Definition: i2c_11xx.h:51
Chip_I2C_MasterRead
int Chip_I2C_MasterRead(I2C_ID_T id, uint8_t slaveAddr, uint8_t *buff, int len)
Set function that must handle I2C events.
I2C_ID
I2C_ID
I2C interface IDs.
Definition: i2c_11xx.h:283
I2C0
@ I2C0
Definition: i2c_11xx.h:284
LPC_I2C_T::MMCTRL
__IO uint32_t MMCTRL
Definition: i2c_11xx.h:57
LPC_I2C_T::DATA_BUFFER
__I uint32_t DATA_BUFFER
Definition: i2c_11xx.h:61
I2C_SLAVE_1
@ I2C_SLAVE_1
Definition: i2c_11xx.h:244
I2C_EVENT_LOCK
@ I2C_EVENT_LOCK
Definition: i2c_11xx.h:294
I2C_EVENT_DONE
@ I2C_EVENT_DONE
Definition: i2c_11xx.h:293
I2C_EVENT_UNLOCK
@ I2C_EVENT_UNLOCK
Definition: i2c_11xx.h:295
Chip_I2C_SlaveSetup
void Chip_I2C_SlaveSetup(I2C_ID_T id, I2C_SLAVE_ID sid, I2C_XFER_T *xfer, I2C_EVENTHANDLER_T event, uint8_t addrMask)
Setup a slave I2C device.
I2C_EVENT_WAIT
@ I2C_EVENT_WAIT
Definition: i2c_11xx.h:292
LPC_I2C_T::CONCLR
__O uint32_t CONCLR
Definition: i2c_11xx.h:56
I2C_EVENT_SLAVE_TX
@ I2C_EVENT_SLAVE_TX
Definition: i2c_11xx.h:297
Chip_I2C_IsStateChanged
int Chip_I2C_IsStateChanged(I2C_ID_T id)
I2C peripheral state change checking.
LPC_I2C_T::ADR1
__IO uint32_t ADR1
Definition: i2c_11xx.h:58
Chip_I2C_GetClockRate
uint32_t Chip_I2C_GetClockRate(I2C_ID_T id)
Get current clock rate for LPC_I2C peripheral.
I2C_XFER_T
Master transfer data structure definitions.
Definition: i2c_11xx.h:264
I2C_SLAVE_2
@ I2C_SLAVE_2
Definition: i2c_11xx.h:245
Chip_I2C_SlaveStateHandler
void Chip_I2C_SlaveStateHandler(I2C_ID_T id)
I2C Slave event handler.
I2C_STATUS_NAK
@ I2C_STATUS_NAK
Definition: i2c_11xx.h:255
LPC_I2C_T
I2C register block structure.
Definition: i2c_11xx.h:49
I2C_XFER_T::slaveAddr
uint8_t slaveAddr
Definition: i2c_11xx.h:265


uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:02