Skip to content

Add begin() guard #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ sentence=Arduino library for the PF1550 Power Management IC
paragraph=This library allows the control and configuration of the PF1550 used on various Arduino boards.
category=Device Control
url=https://github.com/arduino-libraries/Arduino_PF1550
architectures=mbed,mbed_nicla,mbed_portenta,renesas
architectures=mbed,mbed_nicla,mbed_portenta,renesas,renesas_portenta
16 changes: 13 additions & 3 deletions src/PF1550.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
******************************************************************************/

PF1550::PF1550(PF1550_IO & io)
: _control(io),
_debug(NULL)
: _control(io)
, _initialized(false)
, _debug(NULL)
{

}
Expand All @@ -45,10 +46,19 @@ PF1550::PF1550(PF1550_IO & io)

int PF1550::begin()
{
if(_initialized) {
return 0;
}

if (_debug) {
_debug->println("PF1550 begin");
}
return _control.begin();
int returnCode = _control.begin();

if (returnCode == 0) {
_initialized = true;
}
return returnCode;
}

void PF1550::debug(Stream& stream)
Expand Down
1 change: 1 addition & 0 deletions src/PF1550.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class PF1550

private:
PF1550_Control _control;
bool _initialized;
Stream* _debug;
};

Expand Down
17 changes: 16 additions & 1 deletion src/PF1550/PF1550_IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ void PF1550_IO::readRegister(Register const reg_addr, uint8_t * data)
{
_wire->beginTransmission(_i2c_addr);
_wire->write(static_cast<uint8_t>(reg_addr));
_wire->endTransmission(false); /* No Stop. */

/* No Stop. */
if(_wire->endTransmission(false) != 0) {
if (_debug) {
_debug->println("PF1550_IO::readRegister: endTransmission failed");
}
return;
}

_wire->requestFrom(_i2c_addr, 1, true);
while (_wire->available() < 1) { }
Expand All @@ -77,6 +84,14 @@ void PF1550_IO::setBit(Register const reg, uint8_t const bit_pos)
writeRegister(reg, reg_val);
}

uint8_t PF1550_IO::getBit(Register const reg, uint8_t const bit_pos)
{
assert(bit_pos < 8);
uint8_t reg_val;
readRegister(reg, &reg_val);
return (reg_val >> bit_pos) & 1;
}

void PF1550_IO::clrBit(Register const reg, uint8_t const bit_pos)
{
assert(bit_pos < 8);
Expand Down
1 change: 1 addition & 0 deletions src/PF1550/PF1550_IO.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class PF1550_IO
void writeRegister(Register const reg_addr, uint8_t const data);

void setBit(Register const reg, uint8_t const bit_pos);
uint8_t getBit(Register const reg, uint8_t const bit_pos);
void clrBit(Register const reg, uint8_t const bit_pos);


Expand Down
9 changes: 9 additions & 0 deletions src/PF1550/PF1550_IO_C33.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ class PF1550_IO_C33 : public PF1550_IO
setBit(Register::CHARGER_LED_PWM, REG_LED_PWM_LED_EN_bp);
/* Allow LED control by software. */
setBit(Register::CHARGER_LED_CNFG, REG_LED_CNFG_LEDOVRD_bp);

if(getBit(Register::CHARGER_LED_PWM, REG_LED_PWM_LED_EN_bp) == 0){
return -1;
}

if(getBit(Register::CHARGER_LED_CNFG, REG_LED_CNFG_LEDOVRD_bp) == 0){
return -1;
}
return 0;
}

};
Expand Down
2 changes: 1 addition & 1 deletion src/PF1550/PF1550_IO_Nicla_Vision.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PF1550_IO_Nicla_Vision : public PF1550_IO


protected:
virtual int derived_begin() override { }
virtual int derived_begin() override { return 0; }
};

#endif /* PF1550_IO_NICLA_VISION_H_ */
2 changes: 1 addition & 1 deletion src/PF1550/PF1550_IO_Portenta_H7.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PF1550_IO_Portenta_H7 : public PF1550_IO


protected:
virtual int derived_begin() override { }
virtual int derived_begin() override { return 0;}
};

#endif /* PF1550_IO_ENVIEH747_H_ */
Loading