Skip to content

Commit

Permalink
Add I2C bus speed configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
kkonradpl committed Jul 7, 2024
1 parent ac30f9b commit 57bd1a6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
/* Warning: SAF775X support is currently very experimental */
#define TUNER_DRIVER TEF668X

/* I2C bus clock speed */
/* Typical values: 100 kHz (100000L) or 400 kHz (400000L)
Reduce speed to decrease interference (for bad PCB design) or when
capacitors are added to the bus lines (the speed is limited) */
#define TUNER_I2C_CLOCK 400000L

/* I2C pull-ups in Arduino AVR driver */
/* Enable only on Arduino boards modified to 3.3V operation
For 5V boards use external 10 kΩ pull-ups from SDA and SCL to 3.3V */
Expand Down
6 changes: 6 additions & 0 deletions presets/tef-headless/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
/* Warning: SAF775X support is currently very experimental */
#define TUNER_DRIVER TEF668X

/* I2C bus clock speed */
/* Typical values: 100 kHz (100000L) or 400 kHz (400000L)
Reduce speed to decrease interference (for bad PCB design) or when
capacitors are added to the bus lines (the speed is limited) */
#define TUNER_I2C_CLOCK 400000L

/* I2C pull-ups in Arduino AVR driver */
/* Enable only on Arduino boards modified to 3.3V operation
For 5V boards use external 10 kΩ pull-ups from SDA and SCL to 3.3V */
Expand Down
3 changes: 2 additions & 1 deletion src/I2c/I2cMaster/I2cMaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
#else // ARDUINO
#include <Arduino.h>
#endif // ARDUINO
#include "Config.hpp"

#ifdef ARDUINO_ARCH_AVR

/** hardware I2C clock in Hz */
uint32_t const F_TWI = 400000L;
uint32_t const F_TWI = TUNER_I2C_CLOCK;

/** Delay used for software I2C */
uint8_t const I2C_DELAY_USEC = 4;
Expand Down
2 changes: 2 additions & 0 deletions src/I2c/I2cWire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <Wire.h>
#include "I2cWire.hpp"
#include "../Utils/Utils.hpp"
#include "Config.hpp"
#ifdef ARDUINO_ARCH_ESP32
#include <driver/gpio.h>
#endif
Expand All @@ -30,6 +31,7 @@ void
I2cWire::init(void)
{
Wire.begin();
Wire.setClock(TUNER_I2C_CLOCK);
#ifdef ARDUINO_ARCH_ESP32
/* Decrease I2C bus inteference */
gpio_set_drive_capability((gpio_num_t)21, GPIO_DRIVE_CAP_0);
Expand Down

0 comments on commit 57bd1a6

Please sign in to comment.