Skip to content

Commit bc5d30b

Browse files
committed
board.cpp: Fix I2C1 initialization exception of CoreS3.
Signed-off-by: lbuque <[email protected]>
1 parent d32a1d9 commit bc5d30b

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

m5stack/board.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,27 @@
88

99
extern "C" {
1010
#include "uiflow_utility.h"
11+
#include <driver/periph_ctrl.h>
1112

1213
void board_init()
1314
{
1415
auto cfg = M5.config();
1516
cfg.output_power = false;
1617
M5.begin(cfg);
18+
if (M5.getBoard() == m5::board_t::board_M5StackCoreS3) {
19+
periph_module_disable(PERIPH_I2C1_MODULE);
20+
i2c_config_t conf;
21+
memset(&conf, 0, sizeof(i2c_config_t));
22+
conf.mode = I2C_MODE_MASTER;
23+
conf.sda_io_num = GPIO_NUM_12;
24+
conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
25+
conf.scl_io_num = GPIO_NUM_11;
26+
conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
27+
conf.master.clk_speed = 100000;
28+
// .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);
31+
}
1732
}
1833

1934
void power_init()

m5stack/components/M5Unified/mpy_m5unified.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ extern "C"
3535
{
3636
#include "mpy_m5unified.h"
3737
#include "mphalport.h"
38+
#include <driver/i2c.h>
39+
#include <driver/periph_ctrl.h>
3840

3941
typedef struct _machine_hw_i2c_obj_t {
4042
mp_obj_base_t base;
@@ -360,7 +362,23 @@ mp_obj_t m5_begin(size_t n_args, const mp_obj_t *args) {
360362

361363
// initial
362364
M5.begin(cfg);
363-
M5.In_I2C.release();
365+
// if (M5.getBoard() == m5::board_t::board_M5StackCoreS3) {
366+
// periph_module_disable(PERIPH_I2C1_MODULE);
367+
// i2c_config_t conf;
368+
// memset(&conf, 0, sizeof(i2c_config_t));
369+
// conf.mode = I2C_MODE_MASTER;
370+
// conf.sda_io_num = GPIO_NUM_12;
371+
// conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
372+
// conf.scl_io_num = GPIO_NUM_11;
373+
// conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
374+
// conf.master.clk_speed = 100000;
375+
// // .clk_flags = 0, /*!< Optional, you can use I2C_SCLK_SRC_FLAG_* flags to choose i2c source clock here. */
376+
// esp_err_t ret = i2c_param_config(I2C_NUM_1, &conf);
377+
// ESP_LOGE("*", "i2c_param_config: %d", ret);
378+
// ret = i2c_driver_install(I2C_NUM_1, I2C_MODE_MASTER, 0, 0, 0);
379+
// ESP_LOGE("*", "i2c_driver_install: %d", ret);
380+
// }
381+
// M5.In_I2C.release();
364382

365383
M5.Display.clear();
366384
// default display

0 commit comments

Comments
 (0)