| 86 | }; |
| 87 | |
| 88 | int rt_hw_i2c_init(void) |
| 89 | { |
| 90 | int result = RT_EOK; |
| 91 | |
| 92 | for (rt_size_t i = 0; i < sizeof(pico_i2c_obj) / sizeof(struct pico_i2c_bus); i++) |
| 93 | { |
| 94 | i2c_init(pico_i2c_obj[i].handle, pico_i2c_obj[i].baud); |
| 95 | gpio_set_function(pico_i2c_obj[i].i2c_sda_pin, GPIO_FUNC_I2C); |
| 96 | gpio_set_function(pico_i2c_obj[i].i2c_scl_pin, GPIO_FUNC_I2C); |
| 97 | gpio_pull_up(pico_i2c_obj[i].i2c_sda_pin); |
| 98 | gpio_pull_up(pico_i2c_obj[i].i2c_scl_pin); |
| 99 | // Make the I2C pins available to picotool |
| 100 | bi_decl(bi_2pins_with_func(pico_i2c_obj[i].i2c_sda_pin, pico_i2c_obj[i].i2c_scl_pin, GPIO_FUNC_I2C)); |
| 101 | pico_i2c_obj[i].parent.ops = &i2c_ops; |
| 102 | |
| 103 | /* register i2c device */ |
| 104 | if (rt_i2c_bus_device_register(&pico_i2c_obj[i].parent, pico_i2c_obj[i].device_name) == RT_EOK) |
| 105 | { |
| 106 | LOG_D("%s init success", pico_i2c_obj[i].device_name); |
| 107 | } |
| 108 | else |
| 109 | { |
| 110 | LOG_E("%s register failed", pico_i2c_obj[i].device_name); |
| 111 | result = -RT_ERROR; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | return result; |
| 116 | } |
| 117 | INIT_BOARD_EXPORT(rt_hw_i2c_init); |
| 118 | |
| 119 | #endif /* BSP_USING_I2C */ |
nothing calls this directly
no test coverage detected