File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed
libraries/Nicla_System/src Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change 22#include < I2C.h>
33#include " BQ25120A.h"
44#include " Nicla_System.h"
5+ #include " DigitalOut.h"
6+
7+ static mbed::DigitalOut cd (p25);
58
69uint8_t BQ25120A::getStatus ()
710{
@@ -11,29 +14,29 @@ uint8_t BQ25120A::getStatus()
1114
1215void BQ25120A::writeByte (uint8_t address, uint8_t subAddress, uint8_t data)
1316{
14- digitalWrite (p25, HIGH) ;
17+ cd = 1 ;
1518 nicla::i2c_mutex.lock ();
1619 Wire1.beginTransmission (address);
1720 Wire1.write (subAddress);
1821 Wire1.write (data);
1922 Wire1.endTransmission ();
2023 nicla::i2c_mutex.unlock ();
21- digitalWrite (p25, LOW) ;
24+ cd = 0 ;
2225}
2326
2427uint8_t BQ25120A::readByte (uint8_t address, uint8_t subAddress)
2528{
26- digitalWrite (p25, HIGH) ;
29+ cd = 1 ;
2730 nicla::i2c_mutex.lock ();
2831 Wire1.beginTransmission (address);
2932 Wire1.write (subAddress);
3033 Wire1.endTransmission (false );
3134 Wire1.requestFrom (address, 1 );
32- uint32_t timeout = 1000 ;
35+ uint32_t timeout = 100 ;
3336 uint32_t start_time = millis ();
3437 while (!Wire1.available () && (millis () - start_time) < timeout) {}
3538 uint8_t ret = Wire1.read ();
3639 nicla::i2c_mutex.unlock ();
37- digitalWrite (p25, LOW) ;
40+ cd = 0 ;
3841 return ret;
3942}
You can’t perform that action at this time.
0 commit comments