hpm_i2c_drv.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. /*
  2. * Copyright (c) 2021 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_I2C_DRV_H
  8. #define HPM_I2C_DRV_H
  9. #include "hpm_common.h"
  10. #include "hpm_i2c_regs.h"
  11. #include "hpm_soc_feature.h"
  12. /**
  13. * @brief I2C driver APIs
  14. * @defgroup i2c_interface I2C driver APIs
  15. * @ingroup io_interfaces
  16. * @{
  17. */
  18. /**
  19. * @brief I2C status
  20. */
  21. enum {
  22. status_i2c_no_ack = MAKE_STATUS(status_group_i2c, 1),
  23. status_i2c_invalid_data = MAKE_STATUS(status_group_i2c, 2),
  24. status_i2c_no_addr_hit = MAKE_STATUS(status_group_i2c, 3),
  25. status_i2c_transmit_not_completed = MAKE_STATUS(status_group_i2c, 4),
  26. status_i2c_not_supported = MAKE_STATUS(status_group_i2c, 9),
  27. };
  28. /* convert data count value into register(CTRL[DATACNT] and CTRL[DATACNT_HIGH] if exist) */
  29. /* x range from 1 to I2C_SOC_TRANSFER_COUNT_MAX */
  30. /* 0 for I2C_SOC_TRANSFER_COUNT_MAX */
  31. #define I2C_DATACNT_MAP(x) (((x) == I2C_SOC_TRANSFER_COUNT_MAX) ? 0 : x)
  32. /**
  33. * @brief I2C CMD
  34. */
  35. #define I2C_CMD_NO_ACTION (I2C_CMD_CMD_SET(0))
  36. #define I2C_CMD_ISSUE_DATA_TRANSMISSION (I2C_CMD_CMD_SET(1))
  37. #define I2C_CMD_ACK (I2C_CMD_CMD_SET(2))
  38. #define I2C_CMD_NACK (I2C_CMD_CMD_SET(3))
  39. #define I2C_CMD_CLEAR_FIFO (I2C_CMD_CMD_SET(4))
  40. #define I2C_CMD_RESET (I2C_CMD_CMD_SET(5))
  41. /**
  42. * @brief I2C data direction
  43. */
  44. #define I2C_DIR_MASTER_WRITE (0U)
  45. #define I2C_DIR_MASTER_READ (1U)
  46. #define I2C_DIR_SLAVE_READ (0U)
  47. #define I2C_DIR_SLAVE_WRITE (1U)
  48. /**
  49. * @brief I2C events for interrupt enable and status check
  50. */
  51. #define I2C_EVENT_TRANSACTION_COMPLETE I2C_INTEN_CMPL_MASK
  52. #define I2C_EVENT_BYTE_RECEIVED I2C_INTEN_BYTERECV_MASK
  53. #define I2C_EVENT_BYTE_TRANSMIT I2C_INTEN_BYTETRANS_MASK
  54. #define I2C_EVENT_START_CONDITION I2C_INTEN_START_MASK
  55. #define I2C_EVENT_STOP_CONDITION I2C_INTEN_STOP_MASK
  56. #define I2C_EVENT_LOSS_ARBITRATION I2C_INTEN_ARBLOSE_MASK
  57. #define I2C_EVENT_ADDRESS_HIT I2C_INTEN_ADDRHIT_MASK
  58. #define I2C_EVENT_FIFO_HALF I2C_INTEN_FIFOHALF_MASK
  59. #define I2C_EVENT_FIFO_FULL I2C_INTEN_FIFOFULL_MASK
  60. #define I2C_EVENT_FIFO_EMPTY I2C_INTEN_FIFOEMPTY_MASK
  61. #define I2C_EVENT_ALL_MASK (I2C_INTEN_CMPL_MASK \
  62. | I2C_INTEN_BYTERECV_MASK \
  63. | I2C_INTEN_BYTETRANS_MASK \
  64. | I2C_INTEN_START_MASK \
  65. | I2C_INTEN_STOP_MASK \
  66. | I2C_INTEN_ARBLOSE_MASK \
  67. | I2C_INTEN_ADDRHIT_MASK \
  68. | I2C_INTEN_FIFOHALF_MASK \
  69. | I2C_INTEN_FIFOFULL_MASK \
  70. | I2C_INTEN_FIFOEMPTY_MASK)
  71. /**
  72. * @brief I2C status for status check only
  73. */
  74. #define I2C_STATUS_LINE_SDA I2C_STATUS_LINESDA_MASK
  75. #define I2C_STATUS_LINE_SCL I2C_STATUS_LINESCL_MASK
  76. #define I2C_STATUS_GENERAL_CALL I2C_STATUS_GENCALL_MASK
  77. #define I2C_STATUS_BUS_BUSY I2C_STATUS_BUSBUSY_MASK
  78. #define I2C_STATUS_ACK I2C_STATUS_ACK_MASK
  79. #define I2C_WR 0x0000 /* not operable with read flags*/
  80. #define I2C_RD (1u << 0) /* not operable with write flags*/
  81. #define I2C_ADDR_10BIT (1u << 2) /* this is a ten bit chip address */
  82. #define I2C_NO_START (1u << 4) /* no start */
  83. #define I2C_NO_READ_ACK (1u << 6) /* when I2C reading, we do not ACK */
  84. #define I2C_NO_STOP (1u << 7) /* no stop */
  85. /**
  86. * @brief I2C config
  87. */
  88. typedef struct {
  89. bool is_10bit_addressing;
  90. uint8_t i2c_mode;
  91. } i2c_config_t;
  92. /**
  93. * @brief I2C mode
  94. */
  95. typedef enum i2c_mode {
  96. i2c_mode_normal,
  97. i2c_mode_fast,
  98. i2c_mode_fast_plus,
  99. } i2c_mode_t;
  100. /**
  101. * @brief I2c sequential transfer options
  102. * @arg: i2c_frist_frame: has start signal
  103. * @arg: i2c_next_frame: middle transfer
  104. * @arg: i2c_last_frame: has stop signal
  105. */
  106. typedef enum i2c_seq_transfer_opt {
  107. i2c_frist_frame = 0,
  108. i2c_next_frame,
  109. i2c_last_frame,
  110. } i2c_seq_transfer_opt_t;
  111. #ifdef __cplusplus
  112. extern "C" {
  113. #endif
  114. /**
  115. * @brief respond NACK
  116. *
  117. * @param [in] ptr I2C base address
  118. */
  119. static inline void i2c_respond_Nack(I2C_Type *ptr)
  120. {
  121. ptr->CMD = I2C_CMD_NACK;
  122. }
  123. /**
  124. * @brief respond ACK
  125. *
  126. * @param [in] ptr I2C base address
  127. */
  128. static inline void i2c_respond_ack(I2C_Type *ptr)
  129. {
  130. ptr->CMD = I2C_CMD_ACK;
  131. }
  132. /**
  133. * @brief clear I2C fifo
  134. *
  135. * @param [in] ptr I2C base address
  136. */
  137. static inline void i2c_clear_fifo(I2C_Type *ptr)
  138. {
  139. ptr->CMD = I2C_CMD_CLEAR_FIFO;
  140. }
  141. /**
  142. * @brief check data count
  143. *
  144. * @details It indicates number of bytes to transfer
  145. *
  146. * @param [in] ptr I2C base address
  147. * @retval data count value in byte
  148. */
  149. static inline uint16_t i2c_get_data_count(I2C_Type *ptr)
  150. {
  151. uint32_t i2c_ctrl = ptr->CTRL;
  152. #ifdef I2C_CTRL_DATACNT_HIGH_MASK
  153. return (I2C_CTRL_DATACNT_HIGH_GET(i2c_ctrl) << 8U) + I2C_CTRL_DATACNT_GET(i2c_ctrl);
  154. #else
  155. return I2C_CTRL_DATACNT_GET(i2c_ctrl);
  156. #endif
  157. }
  158. /**
  159. * @brief check if I2C FIFO is full
  160. *
  161. * @param [in] ptr I2C base address
  162. * @retval true if FIFO is full
  163. */
  164. static inline bool i2c_fifo_is_full(I2C_Type *ptr)
  165. {
  166. return ptr->STATUS & I2C_STATUS_FIFOFULL_MASK;
  167. }
  168. /**
  169. * @brief check if I2C FIFO is half
  170. *
  171. * @note When I2C is transmitting data, it indicates if fifo is half-empty;
  172. * @note When I2C is receiving data, it indicates if fifo is half full.
  173. *
  174. * @param [in] ptr I2C base address
  175. * @retval true if FIFO is half empty or full
  176. */
  177. static inline bool i2c_fifo_is_half(I2C_Type *ptr)
  178. {
  179. return ptr->STATUS & I2C_STATUS_FIFOHALF_MASK;
  180. }
  181. /**
  182. * @brief check if I2C FIFO is empty
  183. *
  184. * @param [in] ptr I2C base address
  185. * @retval true if FIFO is empty
  186. */
  187. static inline bool i2c_fifo_is_empty(I2C_Type *ptr)
  188. {
  189. return ptr->STATUS & I2C_STATUS_FIFOEMPTY_MASK;
  190. }
  191. /**
  192. * @brief check if I2C is writing
  193. *
  194. * @param [in] ptr I2C base address
  195. * @retval bool value
  196. * @arg true: receive data if master mode, send data in slave mode
  197. * @arg false: send data if master mode, reveive data in slave mode
  198. *
  199. */
  200. static inline bool i2c_is_writing(I2C_Type *ptr)
  201. {
  202. return (ptr->CTRL & I2C_CTRL_DIR_MASK);
  203. }
  204. /**
  205. * @brief check if I2C is reading
  206. *
  207. * @param [in] ptr I2C base address
  208. * @retval bool value
  209. * @arg true: send data if master mode, receive data in slave mode
  210. * @arg false: receive data if master mode, send data in slave mode
  211. *
  212. */
  213. static inline bool i2c_is_reading(I2C_Type *ptr)
  214. {
  215. return !i2c_is_writing(ptr);
  216. }
  217. /**
  218. * @brief get i2c sda line status
  219. *
  220. * @param [in] ptr I2C base address
  221. * @retval bool value
  222. * @arg true: the sda line is high
  223. * @arg false: the sda line is low
  224. *
  225. */
  226. static inline bool i2c_get_line_sda_status(I2C_Type *ptr)
  227. {
  228. return I2C_STATUS_LINESDA_GET(ptr->STATUS);
  229. }
  230. /**
  231. * @brief get i2c scl line status
  232. *
  233. * @param [in] ptr I2C base address
  234. * @retval bool value
  235. * @arg true: the scl line is high
  236. * @arg false: the scl line is low
  237. *
  238. */
  239. static inline bool i2c_get_line_scl_status(I2C_Type *ptr)
  240. {
  241. return I2C_STATUS_LINESCL_GET(ptr->STATUS);
  242. }
  243. /**
  244. * @brief clear status
  245. *
  246. * @details Clear status based on mask
  247. *
  248. * @param [in] ptr I2C base address
  249. * @param [in] mask mask to clear status
  250. */
  251. static inline void i2c_clear_status(I2C_Type *ptr, uint32_t mask)
  252. {
  253. ptr->STATUS = mask;
  254. }
  255. /**
  256. * @brief get status
  257. *
  258. * @details Get current I2C status bits
  259. *
  260. * @param [in] ptr I2C base address
  261. * @retval current I2C status
  262. */
  263. static inline uint32_t i2c_get_status(I2C_Type *ptr)
  264. {
  265. return ptr->STATUS;
  266. }
  267. /**
  268. * @brief i2c get interrupts setting
  269. *
  270. * @details Get interrupt setting register value
  271. *
  272. * @param [in] ptr I2C base address
  273. * @retval [out] uint32_t interrupt setting register value
  274. */
  275. static inline uint32_t i2c_get_irq_setting(I2C_Type *ptr)
  276. {
  277. return ptr->INTEN;
  278. }
  279. /**
  280. * @brief disable interrupts
  281. *
  282. * @details Disable interrupts based on given mask
  283. *
  284. * @param [in] ptr I2C base address
  285. * @param [in] mask interrupt mask to be disabled
  286. */
  287. static inline void i2c_disable_irq(I2C_Type *ptr, uint32_t mask)
  288. {
  289. ptr->INTEN &= ~mask;
  290. }
  291. /**
  292. * @brief enable interrupts
  293. *
  294. * @details Enable interrupts based on given mask
  295. *
  296. * @param [in] ptr I2C base address
  297. * @param [in] mask interrupt mask to be enabled
  298. */
  299. static inline void i2c_enable_irq(I2C_Type *ptr, uint32_t mask)
  300. {
  301. ptr->INTEN |= mask;
  302. }
  303. /**
  304. * @brief disable auto ack
  305. *
  306. * @details Disable I2C auto generates proper acknowledgements for each byte received
  307. *
  308. * @param [in] ptr I2C base address
  309. */
  310. static inline void i2c_disable_auto_ack(I2C_Type *ptr)
  311. {
  312. ptr->INTEN &= ~I2C_EVENT_BYTE_RECEIVED;
  313. }
  314. /**
  315. * @brief enable auto ack
  316. *
  317. * @details Enable I2C auto generates proper acknowledgements for each byte received
  318. *
  319. * @param [in] ptr I2C base address
  320. */
  321. static inline void i2c_enable_auto_ack(I2C_Type *ptr)
  322. {
  323. ptr->INTEN |= I2C_EVENT_BYTE_RECEIVED;
  324. }
  325. /**
  326. * @brief enable 10 bit address mode
  327. *
  328. * @details enable 10 bit address mode, if not, address is 7 bit mode
  329. *
  330. * @param [in] ptr I2C base address
  331. * @param [in] enable
  332. * @arg true: enable 10 bit address mode
  333. * @arg false: enable 7 bit address mode
  334. */
  335. static inline void i2c_enable_10bit_address_mode(I2C_Type *ptr, bool enable)
  336. {
  337. ptr->SETUP |= I2C_SETUP_ADDRESSING_SET(enable);
  338. }
  339. /**
  340. * @brief I2C master initialization
  341. *
  342. * @details Initialized I2C controller working at master mode
  343. *
  344. * @param [in] ptr I2C base address
  345. * @param [in] src_clk_in_hz I2C controller source clock source frequency in Hz
  346. * @param [in] config i2c_config_t
  347. * @retval hpm_stat_t: status_success if initialization is completed without any error
  348. */
  349. hpm_stat_t i2c_init_master(I2C_Type *ptr,
  350. uint32_t src_clk_in_hz,
  351. i2c_config_t *config);
  352. /**
  353. * @brief I2C master write data to specific address of certain slave device
  354. *
  355. * @details Write to certain I2C device at specific address within that device
  356. * @note the sum of addr_size_in_byte and size_in_byte should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
  357. *
  358. * @param [in] ptr I2C base address
  359. * @param [in] device_address I2C slave address
  360. * @param [in] addr address in that I2C device
  361. * @param [in] addr_size_in_byte I2C address in byte
  362. * @param [in] buf pointer of the data to be sent
  363. * @param [in] size_in_byte size of data to be sent in bytes
  364. * @retval hpm_stat_t: status_success if writing is completed without any error
  365. */
  366. hpm_stat_t i2c_master_address_write(I2C_Type *ptr,
  367. const uint16_t device_address,
  368. uint8_t *addr,
  369. uint32_t addr_size_in_byte,
  370. uint8_t *buf,
  371. const uint32_t size_in_byte);
  372. /**
  373. * @brief I2C master read data from specific address of certain slave device
  374. *
  375. * @details Read fram certain I2C device at specific address within that device
  376. * @note both addr_size_in_byte and size_in_byte should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
  377. *
  378. * @param [in] ptr I2C base address
  379. * @param [in] device_address I2C slave address
  380. * @param [in] addr address in that I2C device
  381. * @param [in] addr_size_in_byte I2C address in byte
  382. * @param [out] buf pointer of the buffer to receive data read from the device
  383. * @param [in] size_in_byte size of data to be read in bytes
  384. * @retval hpm_stat_t: status_success if reading is completed without any error
  385. */
  386. hpm_stat_t i2c_master_address_read(I2C_Type *ptr,
  387. const uint16_t device_address,
  388. uint8_t *addr,
  389. uint32_t addr_size_in_byte,
  390. uint8_t *buf,
  391. const uint32_t size_in_byte);
  392. /**
  393. * @brief I2C master write data to certain slave device
  394. *
  395. * @details Write data to I2C device
  396. * @note size should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
  397. *
  398. * @param [in] ptr I2C base address
  399. * @param [in] device_address I2C slave address
  400. * @param [in] buf pointer of the data to be sent
  401. * @param [in] size size of data to be sent in bytes
  402. * @retval hpm_stat_t: status_success if writing is completed without any error
  403. */
  404. hpm_stat_t i2c_master_write(I2C_Type *ptr,
  405. const uint16_t device_address,
  406. uint8_t *buf,
  407. const uint32_t size);
  408. /**
  409. * @brief I2C master start write data by DMA
  410. *
  411. * @details Write data to I2C device by DMA
  412. * @note size should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
  413. *
  414. * @param [in] i2c_ptr I2C base address
  415. * @param [in] device_address I2C slave address
  416. * @param [in] size size of data to be sent in bytes
  417. * @retval hpm_stat_t status_success if starting transmission without any error
  418. */
  419. hpm_stat_t i2c_master_start_dma_write(I2C_Type *i2c_ptr, const uint16_t device_address, uint32_t size);
  420. /**
  421. * @brief I2C master start read data by DMA
  422. *
  423. * @details Read data to I2C device by DMA
  424. * @note size should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
  425. *
  426. * @param [in] i2c_ptr I2C base address
  427. * @param [in] device_address I2C slave address
  428. * @param [in] size size of data to be read in bytes
  429. * @retval hpm_stat_t status_success if starting transmission without any error
  430. */
  431. hpm_stat_t i2c_master_start_dma_read(I2C_Type *i2c_ptr, const uint16_t device_address, uint32_t size);
  432. /**
  433. * @brief I2C master read data from certain slave device
  434. *
  435. * @details Read data from I2C device
  436. * @note size should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
  437. *
  438. * @param [in] ptr I2C base address
  439. * @param [in] device_address I2C slave address
  440. * @param [out] buf pointer of the buffer to store data read from device
  441. * @param [in] size size of data to be read in bytes
  442. * @retval hpm_stat_t: status_success if reading is completed without any error
  443. */
  444. hpm_stat_t i2c_master_read(I2C_Type *ptr,
  445. const uint16_t device_address,
  446. uint8_t *buf,
  447. const uint32_t size);
  448. /**
  449. * @brief I2C slave initialization
  450. *
  451. * @details Initialize I2C controller working at slave mode
  452. *
  453. * @param [in] ptr I2C base address
  454. * @param [in] src_clk_in_hz I2C controller source clock source frequency in Hz
  455. * @param [in] config I2C configuration structure
  456. * @param [in] slave_address I2C address to be used at slave mode
  457. * @retval hpm_stat_t: status_success if initialization is completed without any error
  458. */
  459. hpm_stat_t i2c_init_slave(I2C_Type *ptr, uint32_t src_clk_in_hz,
  460. i2c_config_t *config, const uint16_t slave_address);
  461. /**
  462. * @brief I2C slave read data
  463. *
  464. * @details Read data at slave mode
  465. * @note size should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
  466. *
  467. * @param [in] ptr I2C base address
  468. * @param [in] buf pointer of the buffer to store data read from device
  469. * @param [in] size size of data to be read in bytes
  470. * @retval hpm_stat_t: status_success if reading is completed without any error
  471. */
  472. hpm_stat_t i2c_slave_read(I2C_Type *ptr, uint8_t *buf, const uint32_t size);
  473. /**
  474. * @brief I2C slave write data
  475. *
  476. * @details Write data at slave mode.
  477. * @note size should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
  478. *
  479. * @param [in] ptr I2C base address
  480. * @param [in] buf pointer of the buffer to store data sent from device
  481. * @param [in] size size of data to be sent in bytes
  482. * @retval hpm_stat_t status_success if writing is completed without any error
  483. */
  484. hpm_stat_t i2c_slave_write(I2C_Type *ptr, uint8_t *buf, const uint32_t size);
  485. /**
  486. * @brief reset I2C
  487. *
  488. * @param [in] ptr I2C base address
  489. */
  490. void i2c_reset(I2C_Type *ptr);
  491. /**
  492. * @brief Enable i2c DMA
  493. *
  494. * @param [in] ptr I2C base address
  495. */
  496. static inline void i2c_dma_enable(I2C_Type *ptr)
  497. {
  498. ptr->SETUP |= I2C_SETUP_DMAEN_MASK;
  499. }
  500. /**
  501. * @brief Disable i2c DMA
  502. *
  503. * @param [in] ptr I2C base address
  504. */
  505. static inline void i2c_dma_disable(I2C_Type *ptr)
  506. {
  507. ptr->SETUP &= ~I2C_SETUP_DMAEN_MASK;
  508. }
  509. /**
  510. * @brief I2C slave dma transfer data
  511. *
  512. * @note The direction of data transmission depends on Master setting
  513. *
  514. * @param [in] ptr I2C base address
  515. * @param [in] size size of data in bytes
  516. * @retval hpm_stat_t status_success if configuring transmission without any error
  517. */
  518. hpm_stat_t i2c_slave_dma_transfer(I2C_Type *ptr, const uint32_t size);
  519. /**
  520. * @brief I2C write byte into FIFO
  521. *
  522. * @param ptr [in] ptr I2C base address
  523. * @param data [in] byte to ne sent
  524. */
  525. static inline void i2c_write_byte(I2C_Type *ptr, uint8_t data)
  526. {
  527. ptr->DATA = I2C_DATA_DATA_SET(data);
  528. }
  529. /**
  530. * @brief I2C read byte into FIFO
  531. *
  532. * @param ptr [in] ptr I2C base address
  533. * @return uint8_t read byte
  534. */
  535. static inline uint8_t i2c_read_byte(I2C_Type *ptr)
  536. {
  537. return (uint8_t)I2C_DATA_DATA_GET(ptr->DATA);
  538. }
  539. /**
  540. * @brief I2C get direction
  541. *
  542. * @note The same value has different meanings in master and slave modes
  543. *
  544. * @param ptr [in] ptr I2C base address
  545. * @return uint8_t direction value
  546. */
  547. static inline uint8_t i2c_get_direction(I2C_Type *ptr)
  548. {
  549. return (uint8_t)I2C_CTRL_DIR_GET(ptr->CTRL);
  550. }
  551. /**
  552. * @brief I2C master configure transfer setting
  553. *
  554. * @param i2c_ptr [in] ptr I2C base address
  555. * @param device_address [in] I2C slave address
  556. * @param size [in] size of data to be transferred in bytes
  557. * @param read [in] true for receive, false for transmit
  558. * @retval hpm_stat_t status_success if configuring transmission without any error
  559. */
  560. hpm_stat_t i2c_master_configure_transfer(I2C_Type *i2c_ptr, const uint16_t device_address, uint32_t size, bool read);
  561. /**
  562. * @brief sequential transmit in master I2C mode an amount of data in blocking
  563. *
  564. * @param [in] ptr ptr I2C base address
  565. * @param [in] device_address I2C slave address
  566. * @param [in] buf pointer of the buffer to store data sent from device
  567. * @param [in] size size of data to be sent in bytes
  568. * @param [in] opt I2c sequential transfer options
  569. * @retval hpm_stat_t status_success if transmit is completed without any error
  570. */
  571. hpm_stat_t i2c_master_seq_transmit(I2C_Type *ptr, const uint16_t device_address,
  572. uint8_t *buf, const uint32_t size, i2c_seq_transfer_opt_t opt);
  573. /**
  574. * @brief sequential receive in master I2C mode an amount of data in blocking
  575. *
  576. * @param [in] ptr ptr I2C base address
  577. * @param [in] device_address I2C slave address
  578. * @param [in] buf pointer of the buffer to store data sent from device
  579. * @param [in] size size of data to be sent in bytes
  580. * @param [in] opt I2c sequential transfer options
  581. * @retval hpm_stat_t status_success if receive is completed without any error
  582. */
  583. hpm_stat_t i2c_master_seq_receive(I2C_Type *ptr, const uint16_t device_address,
  584. uint8_t *buf, const uint32_t size, i2c_seq_transfer_opt_t opt);
  585. #if defined(HPM_IP_FEATURE_I2C_SUPPORT_RESET) && (HPM_IP_FEATURE_I2C_SUPPORT_RESET == 1)
  586. /**
  587. * @brief generate SCL clock as reset signal
  588. *
  589. * @param ptr [in] ptr I2C base address
  590. * @param [in] clk_len SCL clock length
  591. */
  592. static inline void i2s_gen_reset_signal(I2C_Type *ptr, uint8_t clk_len)
  593. {
  594. ptr->CTRL = (ptr->CTRL & ~I2C_CTRL_RESET_LEN_MASK) | I2C_CTRL_RESET_LEN_SET(clk_len) \
  595. | I2C_CTRL_RESET_HOLD_SCKIN_MASK | I2C_CTRL_RESET_ON_MASK;
  596. }
  597. #endif
  598. /**
  599. * @brief data transfer on master I2C mode in blocking
  600. *
  601. * @param [in] ptr ptr I2C base address
  602. * @param [in] device_address I2C slave address
  603. * @param [in] buf pointer of the buffer to store data sent from device
  604. * @param [in] size size of data to be sent in bytes
  605. * @param [in] flags flag bit, which can be other flag bits except I2C_WR I2C_RD, and can perform "|" operation
  606. * @retval hpm_stat_t status_success if receive is completed without any error
  607. */
  608. hpm_stat_t i2c_master_transfer(I2C_Type *ptr, const uint16_t device_address,
  609. uint8_t *buf, const uint32_t size, uint16_t flags);
  610. /**
  611. * @}
  612. */
  613. #ifdef __cplusplus
  614. }
  615. #endif
  616. #endif /* HPM_I2C_DRV_H */