1 /* 2 * Copyright (c) 2021-2022 HPMicro 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 9 #ifndef HPM_I2C_H 10 #define HPM_I2C_H 11 12 typedef struct { 13 __R uint8_t RESERVED0[16]; /* 0x0 - 0xF: Reserved */ 14 __RW uint32_t CFG; /* 0x10: Configuration Register */ 15 __RW uint32_t INTEN; /* 0x14: Interrupt Enable Register */ 16 __RW uint32_t STATUS; /* 0x18: Status Register */ 17 __RW uint32_t ADDR; /* 0x1C: Address Register */ 18 __RW uint32_t DATA; /* 0x20: Data Register */ 19 __RW uint32_t CTRL; /* 0x24: Control Register */ 20 __RW uint32_t CMD; /* 0x28: Command Register */ 21 __RW uint32_t SETUP; /* 0x2C: Setup Register */ 22 __RW uint32_t TPM; /* 0x30: I2C Timing Paramater Multiplier */ 23 } I2C_Type; 24 25 26 /* Bitfield definition for register: CFG */ 27 /* 28 * FIFOSIZE (RO) 29 * 30 * FIFO Size: 31 * 0: 2 bytes 32 * 1: 4 bytes 33 * 2: 8 bytes 34 * 3: 16 bytes 35 */ 36 #define I2C_CFG_FIFOSIZE_MASK (0x3U) 37 #define I2C_CFG_FIFOSIZE_SHIFT (0U) 38 #define I2C_CFG_FIFOSIZE_GET(x) (((uint32_t)(x) & I2C_CFG_FIFOSIZE_MASK) >> I2C_CFG_FIFOSIZE_SHIFT) 39 40 /* Bitfield definition for register: INTEN */ 41 /* 42 * CMPL (RW) 43 * 44 * Set to enable the Completion Interrupt. 45 * Master: interrupts when a transaction is issued from this master and completed without losing the bus arbitration. 46 * Slave: interrupts when a transaction addressing the controller is completed. 47 */ 48 #define I2C_INTEN_CMPL_MASK (0x200U) 49 #define I2C_INTEN_CMPL_SHIFT (9U) 50 #define I2C_INTEN_CMPL_SET(x) (((uint32_t)(x) << I2C_INTEN_CMPL_SHIFT) & I2C_INTEN_CMPL_MASK) 51 #define I2C_INTEN_CMPL_GET(x) (((uint32_t)(x) & I2C_INTEN_CMPL_MASK) >> I2C_INTEN_CMPL_SHIFT) 52 53 /* 54 * BYTERECV (RW) 55 * 56 * Set to enable the Byte Receive Interrupt. 57 * Interrupts when a byte of data is received 58 * Auto-ACK will be disabled if this interrupt is enabled, that is, the software needs to ACK/NACK the received byte manually. 59 */ 60 #define I2C_INTEN_BYTERECV_MASK (0x100U) 61 #define I2C_INTEN_BYTERECV_SHIFT (8U) 62 #define I2C_INTEN_BYTERECV_SET(x) (((uint32_t)(x) << I2C_INTEN_BYTERECV_SHIFT) & I2C_INTEN_BYTERECV_MASK) 63 #define I2C_INTEN_BYTERECV_GET(x) (((uint32_t)(x) & I2C_INTEN_BYTERECV_MASK) >> I2C_INTEN_BYTERECV_SHIFT) 64 65 /* 66 * BYTETRANS (RW) 67 * 68 * Set to enable the Byte Transmit Interrupt. 69 * Interrupts when a byte of data is transmitted. 70 */ 71 #define I2C_INTEN_BYTETRANS_MASK (0x80U) 72 #define I2C_INTEN_BYTETRANS_SHIFT (7U) 73 #define I2C_INTEN_BYTETRANS_SET(x) (((uint32_t)(x) << I2C_INTEN_BYTETRANS_SHIFT) & I2C_INTEN_BYTETRANS_MASK) 74 #define I2C_INTEN_BYTETRANS_GET(x) (((uint32_t)(x) & I2C_INTEN_BYTETRANS_MASK) >> I2C_INTEN_BYTETRANS_SHIFT) 75 76 /* 77 * START (RW) 78 * 79 * Set to enable the START Condition Interrupt. 80 * Interrupts when a START condition/repeated START condition is detected. 81 */ 82 #define I2C_INTEN_START_MASK (0x40U) 83 #define I2C_INTEN_START_SHIFT (6U) 84 #define I2C_INTEN_START_SET(x) (((uint32_t)(x) << I2C_INTEN_START_SHIFT) & I2C_INTEN_START_MASK) 85 #define I2C_INTEN_START_GET(x) (((uint32_t)(x) & I2C_INTEN_START_MASK) >> I2C_INTEN_START_SHIFT) 86 87 /* 88 * STOP (RW) 89 * 90 * Set to enable the STOP Condition Interrupt 91 * Interrupts when a STOP condition is detected. 92 */ 93 #define I2C_INTEN_STOP_MASK (0x20U) 94 #define I2C_INTEN_STOP_SHIFT (5U) 95 #define I2C_INTEN_STOP_SET(x) (((uint32_t)(x) << I2C_INTEN_STOP_SHIFT) & I2C_INTEN_STOP_MASK) 96 #define I2C_INTEN_STOP_GET(x) (((uint32_t)(x) & I2C_INTEN_STOP_MASK) >> I2C_INTEN_STOP_SHIFT) 97 98 /* 99 * ARBLOSE (RW) 100 * 101 * Set to enable the Arbitration Lose Interrupt. 102 * Master: interrupts when the controller loses the bus arbitration 103 * Slave: not available in this mode. 104 */ 105 #define I2C_INTEN_ARBLOSE_MASK (0x10U) 106 #define I2C_INTEN_ARBLOSE_SHIFT (4U) 107 #define I2C_INTEN_ARBLOSE_SET(x) (((uint32_t)(x) << I2C_INTEN_ARBLOSE_SHIFT) & I2C_INTEN_ARBLOSE_MASK) 108 #define I2C_INTEN_ARBLOSE_GET(x) (((uint32_t)(x) & I2C_INTEN_ARBLOSE_MASK) >> I2C_INTEN_ARBLOSE_SHIFT) 109 110 /* 111 * ADDRHIT (RW) 112 * 113 * Set to enable the Address Hit Interrupt. 114 * Master: interrupts when the addressed slave returned an ACK. 115 * Slave: interrupts when the controller is addressed. 116 */ 117 #define I2C_INTEN_ADDRHIT_MASK (0x8U) 118 #define I2C_INTEN_ADDRHIT_SHIFT (3U) 119 #define I2C_INTEN_ADDRHIT_SET(x) (((uint32_t)(x) << I2C_INTEN_ADDRHIT_SHIFT) & I2C_INTEN_ADDRHIT_MASK) 120 #define I2C_INTEN_ADDRHIT_GET(x) (((uint32_t)(x) & I2C_INTEN_ADDRHIT_MASK) >> I2C_INTEN_ADDRHIT_SHIFT) 121 122 /* 123 * FIFOHALF (RW) 124 * 125 * Set to enable the FIFO Half Interrupt. 126 * Receiver: Interrupts when the FIFO is half-empty, i.e, there is >= 1/2 entries in the FIFO. 127 * Transmitter: Interrupts when the FIFO is half-empty, i.e. there is <= 1/2 entries in the FIFO. 128 * This interrupt depends on the transaction direction; don’t enable this interrupt unless the transfer direction is determined, otherwise unintended interrupts may be triggered. 129 */ 130 #define I2C_INTEN_FIFOHALF_MASK (0x4U) 131 #define I2C_INTEN_FIFOHALF_SHIFT (2U) 132 #define I2C_INTEN_FIFOHALF_SET(x) (((uint32_t)(x) << I2C_INTEN_FIFOHALF_SHIFT) & I2C_INTEN_FIFOHALF_MASK) 133 #define I2C_INTEN_FIFOHALF_GET(x) (((uint32_t)(x) & I2C_INTEN_FIFOHALF_MASK) >> I2C_INTEN_FIFOHALF_SHIFT) 134 135 /* 136 * FIFOFULL (RW) 137 * 138 * Set to enable the FIFO Full Interrupt. 139 * Interrupts when the FIFO is full. 140 */ 141 #define I2C_INTEN_FIFOFULL_MASK (0x2U) 142 #define I2C_INTEN_FIFOFULL_SHIFT (1U) 143 #define I2C_INTEN_FIFOFULL_SET(x) (((uint32_t)(x) << I2C_INTEN_FIFOFULL_SHIFT) & I2C_INTEN_FIFOFULL_MASK) 144 #define I2C_INTEN_FIFOFULL_GET(x) (((uint32_t)(x) & I2C_INTEN_FIFOFULL_MASK) >> I2C_INTEN_FIFOFULL_SHIFT) 145 146 /* 147 * FIFOEMPTY (RW) 148 * 149 * Set to enabled the FIFO Empty Interrupt 150 * Interrupts when the FIFO is empty. 151 */ 152 #define I2C_INTEN_FIFOEMPTY_MASK (0x1U) 153 #define I2C_INTEN_FIFOEMPTY_SHIFT (0U) 154 #define I2C_INTEN_FIFOEMPTY_SET(x) (((uint32_t)(x) << I2C_INTEN_FIFOEMPTY_SHIFT) & I2C_INTEN_FIFOEMPTY_MASK) 155 #define I2C_INTEN_FIFOEMPTY_GET(x) (((uint32_t)(x) & I2C_INTEN_FIFOEMPTY_MASK) >> I2C_INTEN_FIFOEMPTY_SHIFT) 156 157 /* Bitfield definition for register: STATUS */ 158 /* 159 * LINESDA (RO) 160 * 161 * Indicates the current status of the SDA line on the bus 162 * 1: high 163 * 0: low 164 */ 165 #define I2C_STATUS_LINESDA_MASK (0x4000U) 166 #define I2C_STATUS_LINESDA_SHIFT (14U) 167 #define I2C_STATUS_LINESDA_GET(x) (((uint32_t)(x) & I2C_STATUS_LINESDA_MASK) >> I2C_STATUS_LINESDA_SHIFT) 168 169 /* 170 * LINESCL (RO) 171 * 172 * Indicates the current status of the SCL line on the bus 173 * 1: high 174 * 0: low 175 */ 176 #define I2C_STATUS_LINESCL_MASK (0x2000U) 177 #define I2C_STATUS_LINESCL_SHIFT (13U) 178 #define I2C_STATUS_LINESCL_GET(x) (((uint32_t)(x) & I2C_STATUS_LINESCL_MASK) >> I2C_STATUS_LINESCL_SHIFT) 179 180 /* 181 * GENCALL (RO) 182 * 183 * Indicates that the address of the current transaction is a general call address: 184 * 1: General call 185 * 0: Not general call 186 */ 187 #define I2C_STATUS_GENCALL_MASK (0x1000U) 188 #define I2C_STATUS_GENCALL_SHIFT (12U) 189 #define I2C_STATUS_GENCALL_GET(x) (((uint32_t)(x) & I2C_STATUS_GENCALL_MASK) >> I2C_STATUS_GENCALL_SHIFT) 190 191 /* 192 * BUSBUSY (RO) 193 * 194 * Indicates that the bus is busy 195 * The bus is busy when a START condition is on bus and it ends when a STOP condition is seen on bus 196 * 1: Busy 197 * 0: Not busy 198 */ 199 #define I2C_STATUS_BUSBUSY_MASK (0x800U) 200 #define I2C_STATUS_BUSBUSY_SHIFT (11U) 201 #define I2C_STATUS_BUSBUSY_GET(x) (((uint32_t)(x) & I2C_STATUS_BUSBUSY_MASK) >> I2C_STATUS_BUSBUSY_SHIFT) 202 203 /* 204 * ACK (RO) 205 * 206 * Indicates the type of the last received/transmitted acknowledgement bit: 207 * 1: ACK 208 * 0: NACK 209 */ 210 #define I2C_STATUS_ACK_MASK (0x400U) 211 #define I2C_STATUS_ACK_SHIFT (10U) 212 #define I2C_STATUS_ACK_GET(x) (((uint32_t)(x) & I2C_STATUS_ACK_MASK) >> I2C_STATUS_ACK_SHIFT) 213 214 /* 215 * CMPL (W1C) 216 * 217 * Transaction Completion 218 * Master: Indicates that a transaction has been issued from this master and completed without losing the bus arbitration 219 * Slave: Indicates that a transaction addressing the controller has been completed. This status bit must be cleared to receive the next transaction; otherwise, the next incoming transaction will be blocked. 220 */ 221 #define I2C_STATUS_CMPL_MASK (0x200U) 222 #define I2C_STATUS_CMPL_SHIFT (9U) 223 #define I2C_STATUS_CMPL_SET(x) (((uint32_t)(x) << I2C_STATUS_CMPL_SHIFT) & I2C_STATUS_CMPL_MASK) 224 #define I2C_STATUS_CMPL_GET(x) (((uint32_t)(x) & I2C_STATUS_CMPL_MASK) >> I2C_STATUS_CMPL_SHIFT) 225 226 /* 227 * BYTERECV (W1C) 228 * 229 * Indicates that a byte of data has been received. 230 */ 231 #define I2C_STATUS_BYTERECV_MASK (0x100U) 232 #define I2C_STATUS_BYTERECV_SHIFT (8U) 233 #define I2C_STATUS_BYTERECV_SET(x) (((uint32_t)(x) << I2C_STATUS_BYTERECV_SHIFT) & I2C_STATUS_BYTERECV_MASK) 234 #define I2C_STATUS_BYTERECV_GET(x) (((uint32_t)(x) & I2C_STATUS_BYTERECV_MASK) >> I2C_STATUS_BYTERECV_SHIFT) 235 236 /* 237 * BYTETRANS (W1C) 238 * 239 * Indicates that a byte of data has been transmitted. 240 */ 241 #define I2C_STATUS_BYTETRANS_MASK (0x80U) 242 #define I2C_STATUS_BYTETRANS_SHIFT (7U) 243 #define I2C_STATUS_BYTETRANS_SET(x) (((uint32_t)(x) << I2C_STATUS_BYTETRANS_SHIFT) & I2C_STATUS_BYTETRANS_MASK) 244 #define I2C_STATUS_BYTETRANS_GET(x) (((uint32_t)(x) & I2C_STATUS_BYTETRANS_MASK) >> I2C_STATUS_BYTETRANS_SHIFT) 245 246 /* 247 * START (W1C) 248 * 249 * Indicates that a START Condition or a repeated START condition has been transmitted/received. 250 */ 251 #define I2C_STATUS_START_MASK (0x40U) 252 #define I2C_STATUS_START_SHIFT (6U) 253 #define I2C_STATUS_START_SET(x) (((uint32_t)(x) << I2C_STATUS_START_SHIFT) & I2C_STATUS_START_MASK) 254 #define I2C_STATUS_START_GET(x) (((uint32_t)(x) & I2C_STATUS_START_MASK) >> I2C_STATUS_START_SHIFT) 255 256 /* 257 * STOP (W1C) 258 * 259 * Indicates that a STOP Condition has been transmitted/received. 260 */ 261 #define I2C_STATUS_STOP_MASK (0x20U) 262 #define I2C_STATUS_STOP_SHIFT (5U) 263 #define I2C_STATUS_STOP_SET(x) (((uint32_t)(x) << I2C_STATUS_STOP_SHIFT) & I2C_STATUS_STOP_MASK) 264 #define I2C_STATUS_STOP_GET(x) (((uint32_t)(x) & I2C_STATUS_STOP_MASK) >> I2C_STATUS_STOP_SHIFT) 265 266 /* 267 * ARBLOSE (W1C) 268 * 269 * Indicates that the controller has lost the bus arbitration. 270 */ 271 #define I2C_STATUS_ARBLOSE_MASK (0x10U) 272 #define I2C_STATUS_ARBLOSE_SHIFT (4U) 273 #define I2C_STATUS_ARBLOSE_SET(x) (((uint32_t)(x) << I2C_STATUS_ARBLOSE_SHIFT) & I2C_STATUS_ARBLOSE_MASK) 274 #define I2C_STATUS_ARBLOSE_GET(x) (((uint32_t)(x) & I2C_STATUS_ARBLOSE_MASK) >> I2C_STATUS_ARBLOSE_SHIFT) 275 276 /* 277 * ADDRHIT (W1C) 278 * 279 * Master: indicates that a slave has responded to the transaction. 280 * Slave: indicates that a transaction is targeting the controller (including the General Call). 281 */ 282 #define I2C_STATUS_ADDRHIT_MASK (0x8U) 283 #define I2C_STATUS_ADDRHIT_SHIFT (3U) 284 #define I2C_STATUS_ADDRHIT_SET(x) (((uint32_t)(x) << I2C_STATUS_ADDRHIT_SHIFT) & I2C_STATUS_ADDRHIT_MASK) 285 #define I2C_STATUS_ADDRHIT_GET(x) (((uint32_t)(x) & I2C_STATUS_ADDRHIT_MASK) >> I2C_STATUS_ADDRHIT_SHIFT) 286 287 /* 288 * FIFOHALF (RO) 289 * 290 * Transmitter: Indicates that the FIFO is half-empty. 291 */ 292 #define I2C_STATUS_FIFOHALF_MASK (0x4U) 293 #define I2C_STATUS_FIFOHALF_SHIFT (2U) 294 #define I2C_STATUS_FIFOHALF_GET(x) (((uint32_t)(x) & I2C_STATUS_FIFOHALF_MASK) >> I2C_STATUS_FIFOHALF_SHIFT) 295 296 /* 297 * FIFOFULL (RO) 298 * 299 * Indicates that the FIFO is full. 300 */ 301 #define I2C_STATUS_FIFOFULL_MASK (0x2U) 302 #define I2C_STATUS_FIFOFULL_SHIFT (1U) 303 #define I2C_STATUS_FIFOFULL_GET(x) (((uint32_t)(x) & I2C_STATUS_FIFOFULL_MASK) >> I2C_STATUS_FIFOFULL_SHIFT) 304 305 /* 306 * FIFOEMPTY (RO) 307 * 308 * Indicates that the FIFO is empty. 309 */ 310 #define I2C_STATUS_FIFOEMPTY_MASK (0x1U) 311 #define I2C_STATUS_FIFOEMPTY_SHIFT (0U) 312 #define I2C_STATUS_FIFOEMPTY_GET(x) (((uint32_t)(x) & I2C_STATUS_FIFOEMPTY_MASK) >> I2C_STATUS_FIFOEMPTY_SHIFT) 313 314 /* Bitfield definition for register: ADDR */ 315 /* 316 * ADDR (RW) 317 * 318 * The slave address. 319 * For 7-bit addressing mode, the most significant 3 bits are ignored and only the least-significant 7 bits of Addr are valid 320 */ 321 #define I2C_ADDR_ADDR_MASK (0x3FFU) 322 #define I2C_ADDR_ADDR_SHIFT (0U) 323 #define I2C_ADDR_ADDR_SET(x) (((uint32_t)(x) << I2C_ADDR_ADDR_SHIFT) & I2C_ADDR_ADDR_MASK) 324 #define I2C_ADDR_ADDR_GET(x) (((uint32_t)(x) & I2C_ADDR_ADDR_MASK) >> I2C_ADDR_ADDR_SHIFT) 325 326 /* Bitfield definition for register: DATA */ 327 /* 328 * DATA (RW) 329 * 330 * Write this register to put one byte of data to the FIFO. 331 * Read this register to get one byte of data from the FIFO. 332 */ 333 #define I2C_DATA_DATA_MASK (0xFFU) 334 #define I2C_DATA_DATA_SHIFT (0U) 335 #define I2C_DATA_DATA_SET(x) (((uint32_t)(x) << I2C_DATA_DATA_SHIFT) & I2C_DATA_DATA_MASK) 336 #define I2C_DATA_DATA_GET(x) (((uint32_t)(x) & I2C_DATA_DATA_MASK) >> I2C_DATA_DATA_SHIFT) 337 338 /* Bitfield definition for register: CTRL */ 339 /* 340 * PHASE_START (RW) 341 * 342 * Enable this bit to send a START condition at the beginning of transaction. 343 * Master mode only. 344 */ 345 #define I2C_CTRL_PHASE_START_MASK (0x1000U) 346 #define I2C_CTRL_PHASE_START_SHIFT (12U) 347 #define I2C_CTRL_PHASE_START_SET(x) (((uint32_t)(x) << I2C_CTRL_PHASE_START_SHIFT) & I2C_CTRL_PHASE_START_MASK) 348 #define I2C_CTRL_PHASE_START_GET(x) (((uint32_t)(x) & I2C_CTRL_PHASE_START_MASK) >> I2C_CTRL_PHASE_START_SHIFT) 349 350 /* 351 * PHASE_ADDR (RW) 352 * 353 * Enable this bit to send the address after START condition. 354 * Master mode only. 355 */ 356 #define I2C_CTRL_PHASE_ADDR_MASK (0x800U) 357 #define I2C_CTRL_PHASE_ADDR_SHIFT (11U) 358 #define I2C_CTRL_PHASE_ADDR_SET(x) (((uint32_t)(x) << I2C_CTRL_PHASE_ADDR_SHIFT) & I2C_CTRL_PHASE_ADDR_MASK) 359 #define I2C_CTRL_PHASE_ADDR_GET(x) (((uint32_t)(x) & I2C_CTRL_PHASE_ADDR_MASK) >> I2C_CTRL_PHASE_ADDR_SHIFT) 360 361 /* 362 * PHASE_DATA (RW) 363 * 364 * Enable this bit to send the data after Address phase. 365 * Master mode only. 366 */ 367 #define I2C_CTRL_PHASE_DATA_MASK (0x400U) 368 #define I2C_CTRL_PHASE_DATA_SHIFT (10U) 369 #define I2C_CTRL_PHASE_DATA_SET(x) (((uint32_t)(x) << I2C_CTRL_PHASE_DATA_SHIFT) & I2C_CTRL_PHASE_DATA_MASK) 370 #define I2C_CTRL_PHASE_DATA_GET(x) (((uint32_t)(x) & I2C_CTRL_PHASE_DATA_MASK) >> I2C_CTRL_PHASE_DATA_SHIFT) 371 372 /* 373 * PHASE_STOP (RW) 374 * 375 * Enable this bit to send a STOP condition at the end of a transaction. 376 * Master mode only. 377 */ 378 #define I2C_CTRL_PHASE_STOP_MASK (0x200U) 379 #define I2C_CTRL_PHASE_STOP_SHIFT (9U) 380 #define I2C_CTRL_PHASE_STOP_SET(x) (((uint32_t)(x) << I2C_CTRL_PHASE_STOP_SHIFT) & I2C_CTRL_PHASE_STOP_MASK) 381 #define I2C_CTRL_PHASE_STOP_GET(x) (((uint32_t)(x) & I2C_CTRL_PHASE_STOP_MASK) >> I2C_CTRL_PHASE_STOP_SHIFT) 382 383 /* 384 * DIR (RW) 385 * 386 * Transaction direction 387 * Master: Set this bit to determine the direction for the next transaction. 388 * 0: Transmitter 389 * 1: Receiver 390 * Slave: The direction of the last received transaction. 391 * 0: Receiver 392 * 1: Transmitter 393 */ 394 #define I2C_CTRL_DIR_MASK (0x100U) 395 #define I2C_CTRL_DIR_SHIFT (8U) 396 #define I2C_CTRL_DIR_SET(x) (((uint32_t)(x) << I2C_CTRL_DIR_SHIFT) & I2C_CTRL_DIR_MASK) 397 #define I2C_CTRL_DIR_GET(x) (((uint32_t)(x) & I2C_CTRL_DIR_MASK) >> I2C_CTRL_DIR_SHIFT) 398 399 /* 400 * DATACNT (RW) 401 * 402 * Data counts in bytes. 403 * Master: The number of bytes to transmit/receive. 0 means 256 bytes. DataCnt will be decreased by one for each byte transmitted/received. 404 * Slave: the meaning of DataCnt depends on the DMA mode: 405 * If DMA is not enabled, DataCnt is the number of bytes transmitted/received from the bus master. It is reset to 0 when the controller is addressed and then increased by one for each byte of data transmitted/received. 406 * If DMA is enabled, DataCnt is the number of bytes to transmit/receive. It will not be reset to 0 when the slave is addressed and it will be decreased by one for each byte of data transmitted/received. 407 */ 408 #define I2C_CTRL_DATACNT_MASK (0xFFU) 409 #define I2C_CTRL_DATACNT_SHIFT (0U) 410 #define I2C_CTRL_DATACNT_SET(x) (((uint32_t)(x) << I2C_CTRL_DATACNT_SHIFT) & I2C_CTRL_DATACNT_MASK) 411 #define I2C_CTRL_DATACNT_GET(x) (((uint32_t)(x) & I2C_CTRL_DATACNT_MASK) >> I2C_CTRL_DATACNT_SHIFT) 412 413 /* Bitfield definition for register: CMD */ 414 /* 415 * CMD (RW) 416 * 417 * Write this register with the following values to perform the corresponding actions: 418 * 0x0: no action 419 * 0x1: issue a data transaction (Master only) 420 * 0x2: respond with an ACK to the received byte 421 * 0x3: respond with a NACK to the received byte 422 * 0x4: clear the FIFO 423 * 0x5: reset the I2C controller (abort current transaction, set the SDA and SCL line to the open-drain mode, reset the Status Register and the Interrupt Enable Register, and empty the FIFO) 424 * When issuing a data transaction by writing 0x1 to this register, the CMD field stays at 0x1 for the duration of the entire transaction, and it is only cleared to 0x0 after when the transaction has completed or when the controller loses the arbitration. 425 * Note: No transaction will be issued by the controller when all phases (Start, Address, Data and Stop) are disabled. 426 */ 427 #define I2C_CMD_CMD_MASK (0x7U) 428 #define I2C_CMD_CMD_SHIFT (0U) 429 #define I2C_CMD_CMD_SET(x) (((uint32_t)(x) << I2C_CMD_CMD_SHIFT) & I2C_CMD_CMD_MASK) 430 #define I2C_CMD_CMD_GET(x) (((uint32_t)(x) & I2C_CMD_CMD_MASK) >> I2C_CMD_CMD_SHIFT) 431 432 /* Bitfield definition for register: SETUP */ 433 /* 434 * T_SUDAT (RW) 435 * 436 * T_SUDAT defines the data setup time before releasing the SCL. 437 * Setup time = (2 * tpclk) + (2 + T_SP + T_SUDAT) * tpclk* (TPM+1) 438 * tpclk = PCLK period 439 * TPM = The multiplier value in Timing Parameter Multiplier Register 440 */ 441 #define I2C_SETUP_T_SUDAT_MASK (0x1F000000UL) 442 #define I2C_SETUP_T_SUDAT_SHIFT (24U) 443 #define I2C_SETUP_T_SUDAT_SET(x) (((uint32_t)(x) << I2C_SETUP_T_SUDAT_SHIFT) & I2C_SETUP_T_SUDAT_MASK) 444 #define I2C_SETUP_T_SUDAT_GET(x) (((uint32_t)(x) & I2C_SETUP_T_SUDAT_MASK) >> I2C_SETUP_T_SUDAT_SHIFT) 445 446 /* 447 * T_SP (RW) 448 * 449 * T_SP defines the pulse width of spikes that must be suppressed by the input filter. 450 * Pulse width = T_SP * tpclk* (TPM+1) 451 */ 452 #define I2C_SETUP_T_SP_MASK (0xE00000UL) 453 #define I2C_SETUP_T_SP_SHIFT (21U) 454 #define I2C_SETUP_T_SP_SET(x) (((uint32_t)(x) << I2C_SETUP_T_SP_SHIFT) & I2C_SETUP_T_SP_MASK) 455 #define I2C_SETUP_T_SP_GET(x) (((uint32_t)(x) & I2C_SETUP_T_SP_MASK) >> I2C_SETUP_T_SP_SHIFT) 456 457 /* 458 * T_HDDAT (RW) 459 * 460 * T_HDDAT defines the data hold time after SCL goes LOW 461 * Hold time = (2 * tpclk) + (2 + T_SP + T_HDDAT) * tpclk* (TPM+1) 462 */ 463 #define I2C_SETUP_T_HDDAT_MASK (0x1F0000UL) 464 #define I2C_SETUP_T_HDDAT_SHIFT (16U) 465 #define I2C_SETUP_T_HDDAT_SET(x) (((uint32_t)(x) << I2C_SETUP_T_HDDAT_SHIFT) & I2C_SETUP_T_HDDAT_MASK) 466 #define I2C_SETUP_T_HDDAT_GET(x) (((uint32_t)(x) & I2C_SETUP_T_HDDAT_MASK) >> I2C_SETUP_T_HDDAT_SHIFT) 467 468 /* 469 * T_SCLRADIO (RW) 470 * 471 * The LOW period of the generated SCL clock is defined by the combination of T_SCLRatio and T_SCLHi values. When T_SCLRatio = 0, the LOW period is equal to HIGH period. When T_SCLRatio = 1, the LOW period is roughly two times of HIGH period. 472 * SCL LOW period = (2 * tpclk) + (2 + T_SP + T_SCLHi * ratio) * tpclk * (TPM+1) 473 * 1: ratio = 2 474 * 0: ratio = 1 475 * This field is only valid when the controller is in the master mode. 476 */ 477 #define I2C_SETUP_T_SCLRADIO_MASK (0x2000U) 478 #define I2C_SETUP_T_SCLRADIO_SHIFT (13U) 479 #define I2C_SETUP_T_SCLRADIO_SET(x) (((uint32_t)(x) << I2C_SETUP_T_SCLRADIO_SHIFT) & I2C_SETUP_T_SCLRADIO_MASK) 480 #define I2C_SETUP_T_SCLRADIO_GET(x) (((uint32_t)(x) & I2C_SETUP_T_SCLRADIO_MASK) >> I2C_SETUP_T_SCLRADIO_SHIFT) 481 482 /* 483 * T_SCLHI (RW) 484 * 485 * The HIGH period of generated SCL clock is defined by T_SCLHi. 486 * SCL HIGH period = (2 * tpclk) + (2 + T_SP + T_SCLHi) * tpclk* (TPM+1) 487 * The T_SCLHi value must be greater than T_SP and T_HDDAT values. 488 * This field is only valid when the controller is in the master mode. 489 */ 490 #define I2C_SETUP_T_SCLHI_MASK (0x1FF0U) 491 #define I2C_SETUP_T_SCLHI_SHIFT (4U) 492 #define I2C_SETUP_T_SCLHI_SET(x) (((uint32_t)(x) << I2C_SETUP_T_SCLHI_SHIFT) & I2C_SETUP_T_SCLHI_MASK) 493 #define I2C_SETUP_T_SCLHI_GET(x) (((uint32_t)(x) & I2C_SETUP_T_SCLHI_MASK) >> I2C_SETUP_T_SCLHI_SHIFT) 494 495 /* 496 * DMAEN (RW) 497 * 498 * Enable the direct memory access mode data transfer. 499 * 1: Enable 500 * 0: Disable 501 */ 502 #define I2C_SETUP_DMAEN_MASK (0x8U) 503 #define I2C_SETUP_DMAEN_SHIFT (3U) 504 #define I2C_SETUP_DMAEN_SET(x) (((uint32_t)(x) << I2C_SETUP_DMAEN_SHIFT) & I2C_SETUP_DMAEN_MASK) 505 #define I2C_SETUP_DMAEN_GET(x) (((uint32_t)(x) & I2C_SETUP_DMAEN_MASK) >> I2C_SETUP_DMAEN_SHIFT) 506 507 /* 508 * MASTER (RW) 509 * 510 * Configure this device as a master or a slave. 511 * 1: Master mode 512 * 0: Slave mode 513 */ 514 #define I2C_SETUP_MASTER_MASK (0x4U) 515 #define I2C_SETUP_MASTER_SHIFT (2U) 516 #define I2C_SETUP_MASTER_SET(x) (((uint32_t)(x) << I2C_SETUP_MASTER_SHIFT) & I2C_SETUP_MASTER_MASK) 517 #define I2C_SETUP_MASTER_GET(x) (((uint32_t)(x) & I2C_SETUP_MASTER_MASK) >> I2C_SETUP_MASTER_SHIFT) 518 519 /* 520 * ADDRESSING (RW) 521 * 522 * I2C addressing mode: 523 * 1: 10-bit addressing mode 524 * 0: 7-bit addressing mode 525 */ 526 #define I2C_SETUP_ADDRESSING_MASK (0x2U) 527 #define I2C_SETUP_ADDRESSING_SHIFT (1U) 528 #define I2C_SETUP_ADDRESSING_SET(x) (((uint32_t)(x) << I2C_SETUP_ADDRESSING_SHIFT) & I2C_SETUP_ADDRESSING_MASK) 529 #define I2C_SETUP_ADDRESSING_GET(x) (((uint32_t)(x) & I2C_SETUP_ADDRESSING_MASK) >> I2C_SETUP_ADDRESSING_SHIFT) 530 531 /* 532 * IICEN (RW) 533 * 534 * Enable the I2C controller. 535 * 1: Enable 536 * 0: Disable 537 */ 538 #define I2C_SETUP_IICEN_MASK (0x1U) 539 #define I2C_SETUP_IICEN_SHIFT (0U) 540 #define I2C_SETUP_IICEN_SET(x) (((uint32_t)(x) << I2C_SETUP_IICEN_SHIFT) & I2C_SETUP_IICEN_MASK) 541 #define I2C_SETUP_IICEN_GET(x) (((uint32_t)(x) & I2C_SETUP_IICEN_MASK) >> I2C_SETUP_IICEN_SHIFT) 542 543 /* Bitfield definition for register: TPM */ 544 /* 545 * TPM (RW) 546 * 547 * A multiplication value for I2C timing parameters. All the timing parameters in the Setup Register are multiplied by (TPM+1). 548 */ 549 #define I2C_TPM_TPM_MASK (0x1FU) 550 #define I2C_TPM_TPM_SHIFT (0U) 551 #define I2C_TPM_TPM_SET(x) (((uint32_t)(x) << I2C_TPM_TPM_SHIFT) & I2C_TPM_TPM_MASK) 552 #define I2C_TPM_TPM_GET(x) (((uint32_t)(x) & I2C_TPM_TPM_MASK) >> I2C_TPM_TPM_SHIFT) 553 554 555 556 557 #endif /* HPM_I2C_H */