@@ -345,6 +345,44 @@ mp_obj_t m5_add_display(mp_obj_t i2c_bus_in, mp_obj_t addr_in, mp_obj_t dict) {
345
345
return m5_getDisplay (mp_obj_new_int (M5.getDisplayCount () - 1 ));
346
346
}
347
347
348
+
349
+ static void in_i2c_init (void ) {
350
+ gpio_num_t in_scl = (gpio_num_t )M5.getPin (m5::pin_name_t ::in_i2c_scl);
351
+ gpio_num_t in_sda = (gpio_num_t )M5.getPin (m5::pin_name_t ::in_i2c_sda);
352
+ gpio_num_t ex_scl = (gpio_num_t )M5.getPin (m5::pin_name_t ::ex_i2c_scl);
353
+ gpio_num_t ex_sda = (gpio_num_t )M5.getPin (m5::pin_name_t ::ex_i2c_sda);
354
+ i2c_port_t ex_port = I2C_NUM_0;
355
+ #if SOC_I2C_NUM == 1
356
+ i2c_port_t in_port = I2C_NUM_0;
357
+ #else
358
+ i2c_port_t in_port = I2C_NUM_1;
359
+ if (in_scl == ex_scl && in_sda == ex_sda) {
360
+ in_port = ex_port;
361
+ }
362
+ #endif
363
+
364
+ if (in_scl != 255 || in_sda != 255 ) {
365
+ ESP_LOGI (" BOARD" , " Internal I2C(%d) init" , in_port);
366
+ // if (in_port == I2C_NUM_0) {
367
+ // periph_module_enable(PERIPH_I2C0_MODULE);
368
+ // } else {
369
+ // periph_module_enable(PERIPH_I2C1_MODULE);
370
+ // }
371
+ i2c_config_t conf;
372
+ memset (&conf, 0 , sizeof (i2c_config_t ));
373
+ conf.mode = I2C_MODE_MASTER;
374
+ conf.sda_io_num = in_sda;
375
+ conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
376
+ conf.scl_io_num = in_scl;
377
+ conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
378
+ conf.master .clk_speed = 100000 ;
379
+ // .clk_flags = 0, /*!< Optional, you can use I2C_SCLK_SRC_FLAG_* flags to choose i2c source clock here. */
380
+ i2c_param_config (in_port, &conf);
381
+ i2c_driver_install (in_port, I2C_MODE_MASTER, 0 , 0 , 0 );
382
+ }
383
+ }
384
+
385
+
348
386
// TODO: pass configuration parameters
349
387
mp_obj_t m5_begin (size_t n_args, const mp_obj_t *args) {
350
388
mp_obj_t config_obj = mp_const_none;
@@ -362,6 +400,7 @@ mp_obj_t m5_begin(size_t n_args, const mp_obj_t *args) {
362
400
363
401
// initial
364
402
M5.begin (cfg);
403
+ in_i2c_init ();
365
404
// if (M5.getBoard() != m5::board_t::board_M5StackCoreS3
366
405
// && M5.getBoard() != m5::board_t::board_M5StackCoreS3SE
367
406
// && M5.getBoard() != m5::board_t::board_M5StackCore2
0 commit comments