8000 Merge pull request #693 from toxuin/i2c-pullup · lowdown1983/esp32-snippets@3067f78 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3067f78

Browse files
authored
Merge pull request nkolban#693 from toxuin/i2c-pullup
I2C: Configurable pullups
2 parents 51e943f + db61e20 commit 3067f78

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

cpp_utils/I2C.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ uint8_t I2C::getAddress() const
9595
* @param [in] sclPin The pin to use for SCL clock.
9696
* @return N/A.
9797
*/
98-
void I2C::init(uint8_t address, gpio_num_t sdaPin, gpio_num_t sclPin, uint32_t clockSpeed, i2c_port_t portNum) {
98+
void I2C::init(uint8_t address, gpio_num_t sdaPin, gpio_num_t sclPin, uint32_t clockSpeed, i2c_port_t portNum, bool pullup) {
9999
ESP_LOGD(LOG_TAG, ">> I2c::init. address=%d, sda=%d, scl=%d, clockSpeed=%d, portNum=%d", address, sdaPin, sclPin, clockSpeed, portNum);
100100
assert(portNum < I2C_NUM_MAX);
101101
m_portNum = portNum;
@@ -107,8 +107,8 @@ void I2C::init(uint8_t address, gpio_num_t sdaPin, gpio_num_t sclPin, uint32_t c
107107
conf.mode = I2C_MODE_MASTER;
108108
conf.sda_io_num = sdaPin;
109109
conf.scl_io_num = sclPin;
110-
conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
111-
conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
110+
conf.sda_pullup_en = pullup ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE;
111+
conf.scl_pullup_en = pullup ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE;
112112
conf.master.clk_speed = clockSpeed;
113113
esp_err_t errRc = ::i2c_param_config(m_portNum, &conf);
114114
if (errRc != ESP_OK) {

cpp_utils/I2C.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class I2C {
4545
void beginTransaction();
4646
void endTransaction();
4747
uint8_t getAddress() const;
48-
void init(uint8_t address, gpio_num_t sdaPin = DEFAULT_SDA_PIN, gpio_num_t sclPin = DEFAULT_CLK_PIN, uint32_t clkSpeed = DEFAULT_CLK_SPEED, i2c_port_t portNum = I2C_NUM_0);
48+
void init(uint8_t address, gpio_num_t sdaPin = DEFAULT_SDA_PIN, gpio_num_t sclPin = DEFAULT_CLK_PIN, uint32_t clkSpeed = DEFAULT_CLK_SPEED, i2c_port_t portNum = I2C_NUM_0, bool pullup = true);
4949
void read(uint8_t* bytes, size_t length, bool ack=true);
5050
void read(uint8_t* byte, bool ack=true);
5151
void scan();

0 commit comments

Comments
 (0)
0