save some implementation

This commit is contained in:
2025-04-22 14:27:07 +02:00
parent 35a11734e2
commit 9104869ecf
27 changed files with 1789 additions and 1734 deletions

View File

@@ -3,50 +3,84 @@
i2c_master_bus_config_t i2c0_bus_cfg = {
.clk_source = I2C_CLK_SRC_DEFAULT,
.i2c_port = I2C_NUM_0,
.scl_io_num = GPIO_NUM_9,
.sda_io_num = GPIO_NUM_8,
.scl_io_num = HWI2C_SCL,
.sda_io_num = HWI2C_SDA,
.glitch_ignore_cnt = 7,
.flags.enable_internal_pullup = true,
};
i2c_master_bus_handle_t i2c0_bus_hdl;
esp_err_t i2c_master_bus_detect_devices(i2c_master_bus_handle_t handle)
{
const uint16_t probe_timeout_ms = 50; // timeout in milliseconds
uint8_t address;
// esp_err_t i2c_master_bus_detect_devices(i2c_master_bus_handle_t handle)
// {
// const uint16_t probe_timeout_ms = 20; // timeout in milliseconds
// uint8_t address;
printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\r\n");
// printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\r\n");
for (int i = 0; i < 128; i += 16)
{
printf("%02x: ", i);
// for (int i = 0; i < 128; i += 16)
// {
// printf("%02x: ", i);
for (int j = 0; j < 16; j++)
{
fflush(stdout);
// for (int j = 0; j < 16; j++)
// {
// fflush(stdout);
address = i + j;
// address = i + j;
esp_err_t ret = i2c_master_probe(handle, address, probe_timeout_ms);
// esp_err_t ret = i2c_master_probe(handle, address, probe_timeout_ms);
if (ret == ESP_OK)
{
printf("%02x ", address);
}
else if (ret == ESP_ERR_TIMEOUT)
{
printf("UU ");
}
else
{
printf("-- ");
}
}
printf("\r\n");
}
// if (ret == ESP_OK)
// {
// printf("%02x ", address);
// }
// else if (ret == ESP_ERR_TIMEOUT)
// {
// printf("UU ");
// }
// else
// {
// printf("-- ");
// }
// }
// printf("\r\n");
// }
return ESP_OK;
}
// return ESP_OK;
// }
/**
* i2c master initialization
*/
esp_err_t i2c_master_bus_detect_devices(i2c_master_bus_handle_t handle)
{
uint8_t address;
bool found_any = false;
printf("Scanning I2C bus...\n");
for (int i = 0; i < 128; i++)
{
fflush(stdout);
address = i;
esp_err_t ret = i2c_master_probe(handle, address, 20);
if (ret == ESP_OK)
{
printf("Found device at 0x%02X\n", address);
found_any = true;
}
}
if (!found_any)
{
printf("No I2C devices found.\n");
}
return ESP_OK;
}
/**
* @brief Writes data to a specific register of an I2C device.