-
Notifications
You must be signed in to change notification settings - Fork 6
/
Lorro_BQ25703A.cpp
79 lines (63 loc) · 2.03 KB
/
Lorro_BQ25703A.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**************************************************************************/
/*!
@file Arduino_BQ25703A.cpp
@author Lorro
Library for basic interfacing with BQ25703A battery management IC from TI
*/
/**************************************************************************/
#include "Arduino.h"
#include <Wire.h>
#include "Lorro_BQ25703A.h"
// Prints a binary number with leading zeros (Automatic Handling)
#define PRINTBIN(Num) for (uint32_t t = (1UL<< ((sizeof(Num)*8)-1)); t; t >>= 1) Serial.write(Num & t ? '1' : '0');
//Create instance of data structure
Lorro_BQ25703A::Regt BQ25703Areg;
Lorro_BQ25703A::Lorro_BQ25703A(){
Wire.begin();
}
//I2C functions below here
//------------------------------------------------------------------------
boolean Lorro_BQ25703A::readDataReg( const byte regAddress, byte *dataVal, const uint8_t arrLen ){
Wire.beginTransmission( BQ25703Aaddr );
Wire.write( regAddress );
byte ack = Wire.endTransmission();
if( ack == 0 ){
Wire.requestFrom( ( int )BQ25703Aaddr , ( int )( arrLen + 1 ) );
if( Wire.available() > 0 ){
for( uint8_t i = 0; i < arrLen; i++ ){
dataVal[ i ] = Wire.read();
}
}
return true;
}else{
return false; //if I2C comm fails
}
}
boolean Lorro_BQ25703A::writeDataReg( const byte regAddress, byte dataVal0, byte dataVal1 ){
Wire.beginTransmission( BQ25703Aaddr );
Wire.write( regAddress );
Wire.write( dataVal0 );
Wire.write( dataVal1 );
byte ack = Wire.endTransmission();
if( ack == 0 ){
return true;
}else{
return false; //if I2C comm fails
}
}
// boolean Lorro_BQ25703A::read2ByteReg( byte regAddress, byte *val0, byte *val1 ){
//
// Wire.beginTransmission( BQ25703Aaddr );
// Wire.write( regAddress );
// byte ack = Wire.endTransmission();
// if( ack == 0 ){
// Wire.requestFrom( ( int )BQ25703Aaddr , 2 );
// if( Wire.available() > 0 ){
// val0 = Wire.receive();
// val0 = Wire.receive();
// }
// return true;
// }else{
// return false; //if I2C comm fails
// }
// }