Select one of the symbols to view example projects that use it.
 
Outline
#include <stdio.h>
#include <string.h>
#include "sdkconfig.h"
#include "esp_log.h"
#include "esp_console.h"
#include "esp_vfs_fat.h"
#include "cmd_system.h"
#include "cmd_i2ctools.h"
#include "driver/i2c_master.h"
TAG
i2c_gpio_sda
i2c_gpio_scl
i2c_port
#define MOUNT_PATH
#define HISTORY_PATH
initialize_filesystem()
app_main()
Files
loading...
SourceVuESP-IDF Framework and Examplesi2c_tools samplemain/i2ctools_example_main.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */ #include <stdio.h> #include <string.h> #include "sdkconfig.h" #include "esp_log.h" #include "esp_console.h" #include "esp_vfs_fat.h" #include "cmd_system.h" #include "cmd_i2ctools.h" #include "driver/i2c_master.h"9 includes static const char *TAG = "i2c-tools"; static gpio_num_t i2c_gpio_sda = CONFIG_EXAMPLE_I2C_MASTER_SDA; static gpio_num_t i2c_gpio_scl = CONFIG_EXAMPLE_I2C_MASTER_SCL; static i2c_port_t i2c_port = I2C_NUM_0; #if CONFIG_EXAMPLE_STORE_HISTORY #define MOUNT_PATH "/data" #define HISTORY_PATH MOUNT_PATH "/history.txt" static void initialize_filesystem(void) { static wl_handle_t wl_handle; const esp_vfs_fat_mount_config_t mount_config = { .max_files = 4, .format_if_mount_failed = true }{...}; esp_err_t err = esp_vfs_fat_spiflash_mount_rw_wl(MOUNT_PATH, "storage", &mount_config, &wl_handle); if (err != ESP_OK) { ESP_LOGE(TAG, "Failed to mount FATFS (%s)", esp_err_to_name(err)); return; }{...} }{ ... } #endif/* ... */ // CONFIG_EXAMPLE_STORE_HISTORY void app_main(void) { esp_console_repl_t *repl = NULL; esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT(); #if CONFIG_EXAMPLE_STORE_HISTORY initialize_filesystem(); repl_config.history_save_path = HISTORY_PATH;/* ... */ #endif repl_config.prompt = "i2c-tools>"; // install console REPL environment #if CONFIG_ESP_CONSOLE_UART esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl));/* ... */ #elif CONFIG_ESP_CONSOLE_USB_CDC esp_console_dev_usb_cdc_config_t cdc_config = ESP_CONSOLE_DEV_CDC_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_console_new_repl_usb_cdc(&cdc_config, &repl_config, &repl));/* ... */ #elif CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG esp_console_dev_usb_serial_jtag_config_t usbjtag_config = ESP_CONSOLE_DEV_USB_SERIAL_JTAG_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_console_new_repl_usb_serial_jtag(&usbjtag_config, &repl_config, &repl));/* ... */ #endif i2c_master_bus_config_t i2c_bus_config = { .clk_source = I2C_CLK_SRC_DEFAULT, .i2c_port = i2c_port, .scl_io_num = i2c_gpio_scl, .sda_io_num = i2c_gpio_sda, .glitch_ignore_cnt = 7, .flags.enable_internal_pullup = true, }{...}; ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_config, &tool_bus_handle)); register_i2ctools(); printf("\n ==============================================================\n"); printf(" | Steps to Use i2c-tools |\n"); printf(" | |\n"); printf(" | 1. Try 'help', check all supported commands |\n"); printf(" | 2. Try 'i2cconfig' to configure your I2C bus |\n"); printf(" | 3. Try 'i2cdetect' to scan devices on the bus |\n"); printf(" | 4. Try 'i2cget' to get the content of specific register |\n"); printf(" | 5. Try 'i2cset' to set the value of specific register |\n"); printf(" | 6. Try 'i2cdump' to dump all the register (Experiment) |\n"); printf(" | |\n"); printf(" ==============================================================\n\n"); // start console REPL ESP_ERROR_CHECK(esp_console_start_repl(repl)); }{ ... }
Details