nu_i2c.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**************************************************************************//**
  2. * @file i2c.h
  3. * @brief N9H30 I2C driver header file
  4. *
  5. * @note
  6. * SPDX-License-Identifier: Apache-2.0
  7. * Copyright (C) 2018 Nuvoton Technology Corp. All rights reserved.
  8. *****************************************************************************/
  9. #ifndef __NU_I2C_H__
  10. #define __NU_I2C_H__
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif
  15. /** @addtogroup N9H30_Device_Driver N9H30 Device Driver
  16. @{
  17. */
  18. /** @addtogroup N9H30_I2C_Driver I2C Driver
  19. @{
  20. */
  21. /** @addtogroup N9H30_I2C_EXPORTED_CONSTANTS I2C Exported Constants
  22. @{
  23. */
  24. /// @cond HIDDEN_SYMBOLS
  25. /*-----------------------------------------*/
  26. /* marco, type and constant definitions */
  27. /*-----------------------------------------*/
  28. #define I2C_MAX_BUF_LEN 450
  29. /*-----------------------------------------*/
  30. /* global interface variables declarations */
  31. /*-----------------------------------------*/
  32. /*
  33. bit map in CMDR
  34. */
  35. #define I2C_CMD_START 0x10
  36. #define I2C_CMD_STOP 0x08
  37. #define I2C_CMD_READ 0x04
  38. #define I2C_CMD_WRITE 0x02
  39. #define I2C_CMD_NACK 0x01
  40. /*
  41. for transfer use
  42. */
  43. #define I2C_WRITE 0x00
  44. #define I2C_READ 0x01
  45. #define I2C_STATE_NOP 0x00
  46. #define I2C_STATE_READ 0x01
  47. #define I2C_STATE_WRITE 0x02
  48. #define I2C_STATE_PROBE 0x03
  49. /*
  50. i2c register offset
  51. */
  52. #define I2C_CSR (0x00) /*!< Control and Status Register */
  53. #define I2C_DIVIDER (0x04) /*!< Clock Prescale Register */
  54. #define I2C_CMDR (0x08) /*!< Command Register */
  55. #define I2C_SWR (0x0C) /*!< Software Mode Control Register */
  56. #define I2C_RxR (0x10) /*!< Data Receive Register */
  57. #define I2C_TxR (0x14) /*!< Data Transmit Register */
  58. /// @endcond HIDDEN_SYMBOLS
  59. /*
  60. ioctl commands
  61. */
  62. #define I2C_IOC_SET_DEV_ADDRESS 0 /*!< Set device slave address */
  63. #define I2C_IOC_SET_SUB_ADDRESS 1 /*!< Set sub address */
  64. #define I2C_IOC_SET_SPEED 2 /*!< Set I2C interface speed */
  65. /*
  66. error code
  67. */
  68. #define I2C_ERR_ID 0xFFFF1100 /*!< I2C library ID */
  69. #define I2C_ERR_NOERROR (0x00) /*!< No error */
  70. #define I2C_ERR_LOSTARBITRATION (0x01 | I2C_ERR_ID) /*!< Arbitration lost error */
  71. #define I2C_ERR_BUSBUSY (0x02 | I2C_ERR_ID) /*!< Bus busy error */
  72. #define I2C_ERR_NACK (0x03 | I2C_ERR_ID) /*!< data transfer error */
  73. #define I2C_ERR_SLAVENACK (0x04 | I2C_ERR_ID) /*!< slave not respond after address */
  74. #define I2C_ERR_NODEV (0x05 | I2C_ERR_ID) /*!< Wrong device */
  75. #define I2C_ERR_BUSY (0x06 | I2C_ERR_ID) /*!< Device busy */
  76. #define I2C_ERR_IO (0x07 | I2C_ERR_ID) /*!< Interface not open */
  77. #define I2C_ERR_NOTTY (0x08 | I2C_ERR_ID) /*!< Command not support */
  78. /*@}*/ /* end of group N9H30_I2C_EXPORTED_CONSTANTS */
  79. /*@}*/ /* end of group N9H30_I2C_Driver */
  80. /*@}*/ /* end of group N9H30_Device_Driver */
  81. #ifdef __cplusplus
  82. }
  83. #endif
  84. #endif //__NU_I2C_H__
  85. /*** (C) COPYRIGHT 2018 Nuvoton Technology Corp. ***/