rom_i2c_8xx.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * @brief LPC8xx I2C ROM API declarations and functions
  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. #ifndef __ROM_I2C_8XX_H_
  32. #define __ROM_I2C_8XX_H_
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /** @defgroup CHIP_I2CROM_8XX CHIP: LPC8xx I2C ROM API declarations and functions
  37. * @ingroup CHIP_8XX_Drivers
  38. * @{
  39. */
  40. /**
  41. * @brief LPC8xx I2C ROM driver handle structure
  42. */
  43. typedef void *I2C_HANDLE_T;
  44. /**
  45. * @brief LPC8xx I2C ROM driver callback function
  46. */
  47. typedef void (*I2C_CALLBK_T)(uint32_t err_code, uint32_t n);
  48. /**
  49. * LPC8xx I2C ROM driver parameter structure
  50. */
  51. typedef struct I2C_PARAM {
  52. uint32_t num_bytes_send; /*!< No. of bytes to send */
  53. uint32_t num_bytes_rec; /*!< No. of bytes to receive */
  54. uint8_t *buffer_ptr_send; /*!< Pointer to send buffer */
  55. uint8_t *buffer_ptr_rec; /*!< Pointer to receive buffer */
  56. I2C_CALLBK_T func_pt; /*!< Callback function */
  57. uint8_t stop_flag; /*!< Stop flag */
  58. uint8_t dummy[3];
  59. } I2C_PARAM_T;
  60. /**
  61. * LPC8xx I2C ROM driver result structure
  62. */
  63. typedef struct I2C_RESULT {
  64. uint32_t n_bytes_sent; /*!< No. of bytes sent */
  65. uint32_t n_bytes_recd; /*!< No. of bytes received */
  66. } I2C_RESULT_T;
  67. /**
  68. * LPC8xx I2C ROM driver modes enum
  69. */
  70. typedef enum CHIP_I2C_MODE {
  71. IDLE, /*!< IDLE state */
  72. MASTER_SEND, /*!< Master send state */
  73. MASTER_RECEIVE, /*!< Master Receive state */
  74. SLAVE_SEND, /*!< Slave send state */
  75. SLAVE_RECEIVE /*!< Slave receive state */
  76. } CHIP_I2C_MODE_T;
  77. /**
  78. * LPC8xx I2C ROM driver APIs structure
  79. */
  80. typedef struct I2CD_API {
  81. /*!< Interrupt Support Routine */
  82. void (*i2c_isr_handler)(I2C_HANDLE_T *handle);
  83. /*!< MASTER functions */
  84. ErrorCode_t (*i2c_master_transmit_poll)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
  85. ErrorCode_t (*i2c_master_receive_poll)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
  86. ErrorCode_t (*i2c_master_tx_rx_poll)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
  87. ErrorCode_t (*i2c_master_transmit_intr)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
  88. ErrorCode_t (*i2c_master_receive_intr)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
  89. ErrorCode_t (*i2c_master_tx_rx_intr)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
  90. /*!< SLAVE functions */
  91. ErrorCode_t (*i2c_slave_receive_poll)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
  92. ErrorCode_t (*i2c_slave_transmit_poll)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
  93. ErrorCode_t (*i2c_slave_receive_intr)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
  94. ErrorCode_t (*i2c_slave_transmit_intr)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
  95. ErrorCode_t (*i2c_set_slave_addr)(I2C_HANDLE_T *handle, uint32_t slave_addr_0_3, uint32_t slave_mask_0_3);
  96. /*!< OTHER support functions */
  97. uint32_t (*i2c_get_mem_size)(void);
  98. I2C_HANDLE_T * (*i2c_setup)( uint32_t i2c_base_addr, uint32_t * start_of_ram);
  99. ErrorCode_t (*i2c_set_bitrate)(I2C_HANDLE_T *handle, uint32_t p_clk_in_hz, uint32_t bitrate_in_bps);
  100. uint32_t (*i2c_get_firmware_version)(void);
  101. CHIP_I2C_MODE_T (*i2c_get_status)(I2C_HANDLE_T *handle);
  102. ErrorCode_t (*i2c_set_timeout)(I2C_HANDLE_T *handle, uint32_t timeout);
  103. } I2CD_API_T;
  104. /**
  105. * @}
  106. */
  107. #ifdef __cplusplus
  108. }
  109. #endif
  110. #endif /* __ROM_I2C_8XX_H_ */