Skip to content
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
@@ -1,5 +1,5 @@
name=SparkFun Qwiic Power Switch Arduino Library
version=1.0.0
version=1.0.1
author=SparkFun Electronics <techsupport@sparkfun.com>
maintainer=SparkFun Electronics <sparkfun.com>
sentence=Arduino library for the Qwiic Power Switch
Expand Down
75 changes: 38 additions & 37 deletions src/SparkFun_Qwiic_Power_Switch_Arduino_Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ QWIIC_POWER::QWIIC_POWER()
_deviceAddress = PCA9536_ADDRESS_INVALID;
}

boolean QWIIC_POWER::begin(TwoWire &wirePort)
bool QWIIC_POWER::begin(TwoWire &wirePort)
{
_i2cPort = &wirePort; //Grab which port the user wants us to use
_deviceAddress = PCA9536_ADDRESS;
Expand All @@ -44,92 +44,93 @@ boolean QWIIC_POWER::begin(TwoWire &wirePort)
if (isConnected() == false)
return (false);

// Enable Qwiic Power
pinMode(0, OUTPUT); // Make GPIO0 an output
write(0, HIGH); // Set the output high

// Enable I2C
pinMode(3, OUTPUT); // Make GPIO3 an output
write(3, HIGH); // Set the output high

return (true);
return (powerOn() == PCA9536_ERROR_SUCCESS);
}

//Returns true if I2C device ack's
boolean QWIIC_POWER::isConnected()
bool QWIIC_POWER::isConnected()
{
_i2cPort->beginTransmission((uint8_t)_deviceAddress);
return ((_i2cPort->endTransmission()) == 0);
}

PCA9536_error_t QWIIC_POWER::powerOn()
{
// Enable Qwiic Power
// Enable Qwiic Power by pulling GPIO0 high
pinMode(0, OUTPUT); // Make GPIO0 an output
write(0, HIGH); // Set the output high

// Enable I2C
pinMode(3, OUTPUT); // Make GPIO3 an output
write(3, HIGH); // Set the output high
// Wait for power to stabilize
delay(10);

return PCA9536_ERROR_SUCCESS;
// Now enable I2C by pulling GPIO3 high
pinMode(3, OUTPUT); // Make GPIO3 an output
return (write(3, HIGH)); // Set the output high
}

PCA9536_error_t QWIIC_POWER::powerOff()
{
// Disable Qwiic Power
pinMode(0, OUTPUT); // Make GPIO0 an output
write(0, LOW); // Set the output low

// Disable I2C
// Disable I2C first - to avoid corruption when the power goes off
pinMode(3, OUTPUT); // Make GPIO3 an output
write(3, LOW); // Set the output low

return PCA9536_ERROR_SUCCESS;
// Wait
delay(10);

// Now disable Qwiic Power
pinMode(0, OUTPUT); // Make GPIO0 an output
return (write(0, LOW)); // Set the output low
}

PCA9536_error_t QWIIC_POWER::switchPower(uint8_t value)
{
pinMode(0, OUTPUT); // Make GPIO0 an output
write(0, value); // Set the output
if (value == LOW) // If we are turning off, isolate first
{
pinMode(3, OUTPUT); // Make GPIO3 an output
write(3, value); // Set the output

pinMode(3, OUTPUT); // Make GPIO3 an output
write(3, value); // Set the output
delay(10);

return PCA9536_ERROR_SUCCESS;
pinMode(0, OUTPUT); // Make GPIO0 an output
return (write(0, value)); // Set the output
}
else
{
pinMode(0, OUTPUT); // Make GPIO0 an output
write(0, value); // Set the output

delay(10);

pinMode(3, OUTPUT); // Make GPIO3 an output
return (write(3, value)); // Set the output
}
}

PCA9536_error_t QWIIC_POWER::isolationOn()
{
// Enable I2C isolation = I2C bus _is_ isolated
pinMode(3, OUTPUT); // Make GPIO3 an output
write(3, LOW); // Set the output low

return PCA9536_ERROR_SUCCESS;
return (write(3, LOW)); // Set the output low
}

PCA9536_error_t QWIIC_POWER::isolationOff()
{
// Disable I2C isolation = I2C bus _is not_ isolated
pinMode(3, OUTPUT); // Make GPIO3 an output
write(3, HIGH); // Set the output high

return PCA9536_ERROR_SUCCESS;
return (write(3, HIGH)); // Set the output high
}

PCA9536_error_t QWIIC_POWER::switchIsolation(uint8_t value)
{
pinMode(3, OUTPUT); // Make GPIO3 an output
if (value == 0) // If value is 0
{
write(3, HIGH); // Set the output high to disable isolation
return (write(3, HIGH)); // Set the output high to disable isolation
}
else
{
write(3, LOW); // Set the output low to enable isolation
return (write(3, LOW)); // Set the output low to enable isolation
}

return PCA9536_ERROR_SUCCESS;
}

void QWIIC_POWER::setDebugStream(Stream & debugPort)
Expand Down
4 changes: 2 additions & 2 deletions src/SparkFun_Qwiic_Power_Switch_Arduino_Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ class QWIIC_POWER {
QWIIC_POWER();

// Perform initial configuration. Has to be called once.
boolean begin(TwoWire &wirePort = Wire);
bool begin(TwoWire &wirePort = Wire);

// Check whether PCA9536 device is connected
boolean isConnected(void);
bool isConnected(void);

// enable Qwiic power
PCA9536_error_t powerOn();
Expand Down