loragw_i2c.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. / _____) _ | |
  3. ( (____ _____ ____ _| |_ _____ ____| |__
  4. \____ \| ___ | (_ _) ___ |/ ___) _ \
  5. _____) ) ____| | | || |_| ____( (___| | | |
  6. (______/|_____)_|_|_| \__)_____)\____)_| |_|
  7. (C)2019 Semtech
  8. Description:
  9. Host specific functions to address the LoRa concentrator I2C peripherals.
  10. License: Revised BSD License, see LICENSE.TXT file include in the project
  11. */
  12. #ifndef _LORAGW_I2C_H
  13. #define _LORAGW_I2C_H
  14. /* -------------------------------------------------------------------------- */
  15. /* --- DEPENDANCIES --------------------------------------------------------- */
  16. #include <stdint.h> /* C99 types*/
  17. #include "config.h" /* library configuration options (dynamically generated) */
  18. /* -------------------------------------------------------------------------- */
  19. /* --- PUBLIC CONSTANTS ----------------------------------------------------- */
  20. #define LGW_I2C_SUCCESS 0
  21. #define LGW_I2C_ERROR -1
  22. #define I2C_DEVICE "/dev/i2c-1"
  23. /* -------------------------------------------------------------------------- */
  24. /* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
  25. /**
  26. @brief Open I2C port
  27. @param path Path to the I2C device driver (absolute or relative)
  28. @param device_addr Address of the device
  29. @param i2c_fd Pointer to receive I2C port file descriptor index
  30. @return 0 if I2C port was open successfully, -1 else
  31. */
  32. int i2c_linuxdev_open(const char *path, uint8_t device_addr, int *i2c_fd);
  33. /**
  34. @brief Close I2C port
  35. @param i2c_fd I2C port file descriptor index
  36. @return 0 if I2C port was closed successfully, -1 else
  37. */
  38. int i2c_linuxdev_close(int i2c_fd);
  39. /**
  40. @brief Read data from an I2C port
  41. @param i2c_fd I2C port file descriptor index
  42. @param device_addr I2C device address
  43. @param reg_addr Address of the register to be read
  44. @param data Pointer to a buffer to store read data
  45. @return 0 if I2C data read is successful, -1 else
  46. */
  47. int i2c_linuxdev_read(int i2c_fd, uint8_t device_addr, uint8_t reg_addr, uint8_t *data);
  48. /**
  49. @brief Write data to an I2C port
  50. @param i2c_fd I2C port file descriptor index
  51. @param device_addr I2C device address
  52. @param reg_addr Address of the register to write to
  53. @param data byte to write in the register
  54. @return 0 if I2C data write is successful, -1 else
  55. */
  56. int i2c_linuxdev_write(int i2c_fd, uint8_t device_addr, uint8_t reg_addr, uint8_t data);
  57. /**
  58. @brief Write a raw buffer to an I2C port
  59. @param i2c_fd I2C port file descriptor index
  60. @param device_addr I2C device address
  61. @param buffer Buffer to be written to the device
  62. @param size Size of the buffer to be written
  63. @return 0 if I2C data write is successful, -1 else
  64. */
  65. int i2c_linuxdev_write_buffer(int i2c_fd, uint8_t device_addr, uint8_t *buffer, uint8_t size);
  66. #endif
  67. /* --- EOF ------------------------------------------------------------------ */