driver_axp209.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <unistd.h>
  7. #include <fcntl.h>
  8. #include <errno.h>
  9. #include <sys/select.h>
  10. #include <linux/input.h>
  11. #include "read_conf_file.h"
  12. #include <assert.h>
  13. #include <linux/i2c.h>
  14. #include <linux/i2c-dev.h>
  15. #include "smbus.h"
  16. #include "driver_axp209.h"
  17. /****************************************************************
  18. * Defines
  19. ****************************************************************/
  20. #define DEBUG_AXP209_PRINTF (1)
  21. #if (DEBUG_AXP209_PRINTF)
  22. #define DEBUG_PRINTF(...) printf(__VA_ARGS__);
  23. #else
  24. #define DEBUG_PRINTF(...)
  25. #endif
  26. /****************************************************************
  27. * Static variables
  28. ****************************************************************/
  29. static int fd_axp209;
  30. static char i2c0_sysfs_filename[] = "/dev/i2c-0";
  31. /****************************************************************
  32. * Static functions
  33. ****************************************************************/
  34. /****************************************************************
  35. * Public functions
  36. ****************************************************************/
  37. bool axp209_init(void) {
  38. if ((fd_axp209 = open(i2c0_sysfs_filename,O_RDWR)) < 0) {
  39. printf("In axp209_init - Failed to open the I2C bus %s", i2c0_sysfs_filename);
  40. // ERROR HANDLING; you can check errno to see what went wrong
  41. return false;
  42. }
  43. if (ioctl(fd_axp209, I2C_SLAVE, AXP209_I2C_ADDR) < 0) {
  44. printf("In axp209_init - Failed to acquire bus access and/or talk to slave.\n");
  45. // ERROR HANDLING; you can check errno to see what went wrong
  46. return false;
  47. }
  48. return true;
  49. }
  50. bool axp209_deinit(void) {
  51. // Close I2C open interface
  52. close(fd_axp209);
  53. return true;
  54. }
  55. int axp209_read_interrupt_bank_3(void){
  56. int val = i2c_smbus_read_byte_data ( fd_axp209 , AXP209_INTERRUPT_BANK_3_STATUS );
  57. if(val < 0){
  58. return val;
  59. }
  60. DEBUG_PRINTF("READ AXP209_INTERRUPT_BANK_3_STATUS: 0x%02X\n",val);
  61. return 0xFF & val;
  62. }