Skip to content

Commit 4f3b57a

Browse files
author
gojimmypi
committed
flexibility for I2C_MASTER_NUM, add settings comments
1 parent fb19d7a commit 4f3b57a

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

IDE/Espressif/components/wolfssl/include/user_settings.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,11 +656,24 @@ Turn on timer debugging (used when CPU cycles not available)
656656
#define TPM_TIMEOUT_TRIES 10000
657657

658658
/* If not defined here, TPM_I2C_TRIES is set to a default value of 10 */
659-
/* TPM_I2C_TRIES 10 */
659+
/* #define TPM_I2C_TRIES 10 */
660+
661+
/* If not defined here, I2C_MASTER_FREQ_HZ is 100000
662+
* Do not exceed a value of 400000 */
663+
/* #define I2C_MASTER_FREQ_HZ 100000 */
660664

661665
/* Examples may have a main() function, we'll have oour own: */
662666
#define NO_MAIN_DRIVER
663667

668+
/* I2C GPIO settings are defined in idf.py menuconfig
669+
*
670+
* CONFIG_I2C_MASTER_SCL (default SCL GPIO pin is 19)
671+
* CONFIG_I2C_MASTER_SDA (default SDA GPIO pin is 18)
672+
*/
673+
674+
/* The default I2C_MASTER_NUM is 0 but can be overridden: */
675+
/* #define I2C_MASTER_NUM 0 */
676+
664677
/* I2C_MASTER_FREQ_HZ notes:
665678
*
666679
* Although the Infineon supports higher speeds, the ESP32 does not.

hal/tpm_io.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
#include "hal/tpm_io_infineon.c"
7070
#elif defined(WOLFTPM_MICROCHIP_HARMONY)
7171
#include "hal/tpm_io_microchip.c"
72+
#elif defined(WOLFSSL_ESPIDF)
73+
#include "hal/tpm_io_espressif.c"
7274
#endif
7375

7476
#if !defined(WOLFTPM_I2C) && !defined(WOLFTPM_MMIO)

hal/tpm_io_espressif.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,14 @@
7474
#include <driver/i2c_master.h>
7575
#endif
7676

77+
#ifndef CONFIG_SOC_I2C_SUPPORTED
78+
#error "It appears I2C is not supported. Please check sdkconfig."
79+
#endif
80+
7781
/* GPIO number used for I2C master clock */
7882
#ifdef CONFIG_I2C_MASTER_SCL
7983
/* Yellow wire Clock */
80-
#define I2C_MASTER_SCL_IO CONFIG_I2C_MASTER_SCL
84+
#define I2C_MASTER_SCL_IO CONFIG_I2C_MASTER_SCL
8185
#else
8286
/* There should have been a Kconfig.projbuild file in the ./main
8387
* directory to set I2C parameters in the sdkconfig project file. */
@@ -87,7 +91,7 @@
8791
/* GPIO number used for I2C master data */
8892
#ifdef CONFIG_I2C_MASTER_SDA
8993
/* Orange wire */
90-
#define I2C_MASTER_SDA_IO CONFIG_I2C_MASTER_SDA
94+
#define I2C_MASTER_SDA_IO CONFIG_I2C_MASTER_SDA
9195
#else
9296
/* There should have been a Kconfig.projbuild file in the ./main
9397
* directory to set I2C parameters in the sdkconfig project file. */
@@ -96,7 +100,9 @@
96100

97101
/* I2C master i2c port number,
98102
* the number of i2c peripheral interfaces available will depend on the chip */
99-
#define I2C_MASTER_NUM 0
103+
#ifndef I2C_MASTER_NUM
104+
#define I2C_MASTER_NUM 0
105+
#endif
100106

101107
/* I2C master clock frequency
102108
* Typically, an I2C slave device has a 7-bit address or 10-bit address.
@@ -184,11 +190,19 @@ static esp_err_t esp_i2c_master_init(void)
184190
int i2c_master_port = I2C_MASTER_NUM;
185191
esp_err_t ret = ESP_OK;
186192

193+
/* I2C port number, can be I2C_NUM_0 ~ (I2C_NUM_MAX-1). */
194+
if (I2C_MASTER_NUM >= I2C_NUM_MAX) {
195+
ESP_LOGW(TAG, "Warning: I2C_MASTER_NUM value %d exceeds (I2C_NUM_MAX-1)"
196+
" %d ", I2C_MASTER_NUM, I2C_NUM_MAX);
197+
}
187198
ESP_LOGI(TAG, "esp_i2c_master_init");
188199
ESP_LOGI(TAG, "I2C_MASTER_FREQ_HZ = %d", (int)I2C_MASTER_FREQ_HZ);
189200
ESP_LOGI(TAG, "I2C_READ_WAIT_TICKS = %d", (int)I2C_READ_WAIT_TICKS);
190201
ESP_LOGI(TAG, "I2C_WRITE_WAIT_TICKS = %d", (int)I2C_WRITE_WAIT_TICKS);
191202
ESP_LOGI(TAG, "I2C_MASTER_TIMEOUT_MS = %d", (int)I2C_MASTER_TIMEOUT_MS);
203+
ESP_LOGI(TAG, "I2C_MASTER_NUM = %d", (int)I2C_MASTER_NUM);
204+
ESP_LOGI(TAG, "I2C_MASTER_SCL_IO = %d", (int)I2C_MASTER_SCL_IO);
205+
ESP_LOGI(TAG, "I2C_MASTER_SDA_IO = %d", (int)I2C_MASTER_SDA_IO);
192206

193207
conf.mode = I2C_MODE_MASTER;
194208
conf.sda_io_num = I2C_MASTER_SDA_IO;

0 commit comments

Comments
 (0)