2018-10-14 22:19:02 -04:00
|
|
|
/* i2c-tools example
|
|
|
|
|
|
|
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, this
|
|
|
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
|
|
CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2020-02-03 05:01:04 -05:00
|
|
|
#include "sdkconfig.h"
|
2018-10-14 22:19:02 -04:00
|
|
|
#include "esp_log.h"
|
|
|
|
#include "esp_console.h"
|
|
|
|
#include "esp_vfs_fat.h"
|
2020-02-03 05:01:04 -05:00
|
|
|
#include "cmd_system.h"
|
|
|
|
#include "cmd_i2ctools.h"
|
2018-10-14 22:19:02 -04:00
|
|
|
|
|
|
|
static const char *TAG = "i2c-tools";
|
|
|
|
|
2019-05-09 10:43:06 -04:00
|
|
|
#if CONFIG_EXAMPLE_STORE_HISTORY
|
2018-10-14 22:19:02 -04:00
|
|
|
|
|
|
|
#define MOUNT_PATH "/data"
|
|
|
|
#define HISTORY_PATH MOUNT_PATH "/history.txt"
|
|
|
|
|
2019-07-16 05:33:30 -04:00
|
|
|
static void initialize_filesystem(void)
|
2018-10-14 22:19:02 -04:00
|
|
|
{
|
|
|
|
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(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;
|
|
|
|
}
|
|
|
|
}
|
2019-05-09 10:43:06 -04:00
|
|
|
#endif // CONFIG_EXAMPLE_STORE_HISTORY
|
2018-10-14 22:19:02 -04:00
|
|
|
|
2019-07-16 05:33:30 -04:00
|
|
|
void app_main(void)
|
2018-10-14 22:19:02 -04:00
|
|
|
{
|
2020-02-03 05:01:04 -05:00
|
|
|
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
|
2019-05-09 10:43:06 -04:00
|
|
|
#if CONFIG_EXAMPLE_STORE_HISTORY
|
2018-10-14 22:19:02 -04:00
|
|
|
initialize_filesystem();
|
2020-02-03 05:01:04 -05:00
|
|
|
repl_config.history_save_path = HISTORY_PATH;
|
2018-10-14 22:19:02 -04:00
|
|
|
#endif
|
2020-02-03 05:01:04 -05:00
|
|
|
repl_config.prompt = "i2c-tools>";
|
|
|
|
// initialize console REPL environment
|
|
|
|
ESP_ERROR_CHECK(esp_console_repl_init(&repl_config));
|
2018-10-14 22:19:02 -04:00
|
|
|
|
|
|
|
register_i2ctools();
|
|
|
|
register_system();
|
|
|
|
|
|
|
|
printf("\n ==============================================================\n");
|
2020-02-03 05:01:04 -05:00
|
|
|
printf(" | Steps to Use i2c-tools |\n");
|
2018-10-14 22:19:02 -04:00
|
|
|
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");
|
|
|
|
|
2020-02-03 05:01:04 -05:00
|
|
|
// start console REPL
|
|
|
|
ESP_ERROR_CHECK(esp_console_repl_start());
|
2018-10-14 22:19:02 -04:00
|
|
|
}
|