8000 I2C: Configurable pullups · perody/esp32-snippets@18e77c7 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 18e77c7

Browse files
committed
I2C: Configurable pullups
1 parent 8f106d7 commit 18e77c7

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