|
9 | 9 | extern "C" {
|
10 | 10 | #include "uiflow_utility.h"
|
11 | 11 | #include <driver/periph_ctrl.h>
|
| 12 | + #include "esp_log.h" |
12 | 13 |
|
13 |
| - void board_init() |
| 14 | + void in_i2c_init(void) |
14 | 15 | {
|
15 |
| - auto cfg = M5.config(); |
16 |
| - cfg.output_power = false; |
17 |
| - M5.begin(cfg); |
18 |
| - if (M5.getBoard() == m5::board_t::board_M5StackCoreS3 || M5.getBoard() == m5::board_t::board_M5StackCoreS3SE) { |
19 |
| - periph_module_disable(PERIPH_I2C1_MODULE); |
| 16 | + gpio_num_t in_scl = (gpio_num_t)M5.getPin(m5::pin_name_t::in_i2c_scl); |
| 17 | + gpio_num_t in_sda = (gpio_num_t)M5.getPin(m5::pin_name_t::in_i2c_sda); |
| 18 | + gpio_num_t ex_scl = (gpio_num_t)M5.getPin(m5::pin_name_t::ex_i2c_scl); |
| 19 | + gpio_num_t ex_sda = (gpio_num_t)M5.getPin(m5::pin_name_t::ex_i2c_sda); |
| 20 | + i2c_port_t ex_port = I2C_NUM_0; |
| 21 | +#if SOC_I2C_NUM == 1 |
| 22 | + i2c_port_t in_port = I2C_NUM_0; |
| 23 | +#else |
| 24 | + i2c_port_t in_port = I2C_NUM_1; |
| 25 | + if (in_scl == ex_scl && in_sda == ex_sda) { |
| 26 | + in_port = ex_port; |
| 27 | + } |
| 28 | +#endif |
| 29 | + |
| 30 | + if (in_scl != 255 || in_sda != 255) { |
| 31 | + ESP_LOGW("BOARD", "I2C1 init"); |
| 32 | + if (in_port == I2C_NUM_0) { |
| 33 | + periph_module_enable(PERIPH_I2C0_MODULE); |
| 34 | + } else { |
| 35 | + periph_module_enable(PERIPH_I2C1_MODULE); |
| 36 | + } |
20 | 37 | i2c_config_t conf;
|
21 | 38 | memset(&conf, 0, sizeof(i2c_config_t));
|
22 | 39 | conf.mode = I2C_MODE_MASTER;
|
23 |
| - conf.sda_io_num = GPIO_NUM_12; |
| 40 | + conf.sda_io_num = in_sda; |
24 | 41 | conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
|
25 |
| - conf.scl_io_num = GPIO_NUM_11; |
| 42 | + conf.scl_io_num = in_scl; |
26 | 43 | conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
|
27 | 44 | conf.master.clk_speed = 100000;
|
28 | 45 | // .clk_flags = 0, /*!< Optional, you can use I2C_SCLK_SRC_FLAG_* flags to choose i2c source clock here. */
|
29 |
| - i2c_param_config(I2C_NUM_1, &conf); |
30 |
| - i2c_driver_install(I2C_NUM_1, I2C_MODE_MASTER, 0, 0, 0); |
| 46 | + i2c_param_config(in_port, &conf); |
| 47 | + i2c_driver_install(in_port, I2C_MODE_MASTER, 0, 0, 0); |
31 | 48 | }
|
32 | 49 | }
|
33 | 50 |
|
| 51 | + void board_init() |
| 52 | + { |
| 53 | + auto cfg = M5.config(); |
| 54 | + cfg.output_power = false; |
| 55 | + M5.begin(cfg); |
| 56 | + in_i2c_init(); |
| 57 | + } |
| 58 | + |
34 | 59 | void power_init()
|
35 | 60 | {
|
36 | 61 | char power_mode[32] = {0};
|
|
0 commit comments