bq27220.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #define BQ27220_ERROR 0x0
  5. #define BQ27220_SUCCESS 0x1
  6. typedef struct {
  7. // Low byte, Low bit first
  8. bool DSG : 1; // The device is in DISCHARGE
  9. bool SYSDWN : 1; // System down bit indicating the system should shut down
  10. bool TDA : 1; // Terminate Discharge Alarm
  11. bool BATTPRES : 1; // Battery Present detected
  12. bool AUTH_GD : 1; // Detect inserted battery
  13. bool OCVGD : 1; // Good OCV measurement taken
  14. bool TCA : 1; // Terminate Charge Alarm
  15. bool RSVD : 1; // Reserved
  16. // High byte, Low bit first
  17. bool CHGINH : 1; // Charge inhibit
  18. bool FC : 1; // Full-charged is detected
  19. bool OTD : 1; // Overtemperature in discharge condition is detected
  20. bool OTC : 1; // Overtemperature in charge condition is detected
  21. bool SLEEP : 1; // Device is operating in SLEEP mode when set
  22. bool OCVFAIL : 1; // Status bit indicating that the OCV reading failed due to current
  23. bool OCVCOMP : 1; // An OCV measurement update is complete
  24. bool FD : 1; // Full-discharge is detected
  25. } BatteryStatus;
  26. typedef struct {
  27. // Low byte, Low bit first
  28. bool CALMD : 1;
  29. bool SEC0 : 1;
  30. bool SEC1 : 1;
  31. bool EDV2 : 1;
  32. bool VDQ : 1;
  33. bool INITCOMP : 1;
  34. bool SMTH : 1;
  35. bool BTPINT : 1;
  36. // High byte, Low bit first
  37. uint8_t RSVD1 : 2;
  38. bool CFGUPDATE : 1;
  39. uint8_t RSVD0 : 5;
  40. } OperationStatus;
  41. /** Initialize Driver */
  42. void bq27220_init();
  43. /** Get battery voltage in mV or error */
  44. uint16_t bq27220_get_voltage();
  45. /** Get current in mA or error*/
  46. int16_t bq27220_get_current();
  47. /** Get battery status */
  48. uint8_t bq27220_get_battery_status(BatteryStatus* battery_status);
  49. /** Get operation status */
  50. uint8_t bq27220_get_operation_status(OperationStatus* operation_status);
  51. /** Get temperature in units of 0.1°K */
  52. uint16_t bq27220_get_temperature();
  53. /** Get compensated full charge capacity in in mAh */
  54. uint16_t bq27220_get_full_charge_capacity();
  55. /** Get remaining capacity in in mAh */
  56. uint16_t bq27220_get_remaining_capacity();
  57. /** Get predicted remaining battery capacity in percents */
  58. uint16_t bq27220_get_state_of_charge();
  59. /** Get ratio of full charge capacity over design capacity in percents */
  60. uint16_t bq27220_get_state_of_health();