i2c_bb: add deinit()

This commit is contained in:
Andrey Gusakov 2024-07-14 20:10:49 +03:00 committed by rusefillc
parent e85179f465
commit 8af5f51fc7
2 changed files with 13 additions and 0 deletions

View File

@ -61,6 +61,17 @@ bool BitbangI2c::init(brain_pin_e scl, brain_pin_e sda) {
return true;
}
void BitbangI2c::deinit() {
if (m_sclPort) {
gpio_pin_markUnused(m_sclPort, m_sclPin);
m_sclPort = NULL;
}
if (m_sdaPort) {
gpio_pin_markUnused(m_sdaPort, m_sdaPin);
m_sdaPort = NULL;
}
}
void BitbangI2c::start() {
// Start with both lines high (bus idle)
sda_high();

View File

@ -12,6 +12,8 @@ class BitbangI2c {
public:
// Initialize the I2C driver
bool init(brain_pin_e scl, brain_pin_e sda);
// Release resources
void deinit();
// Write a sequence of bytes to the specified device
void write(uint8_t addr, const uint8_t* data, size_t size);