update
This commit is contained in:
13
Slave/.devcontainer/Dockerfile
Normal file
13
Slave/.devcontainer/Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
||||
ARG DOCKER_TAG=latest
|
||||
FROM espressif/idf:${DOCKER_TAG}
|
||||
|
||||
ENV LC_ALL=C.UTF-8
|
||||
ENV LANG=C.UTF-8
|
||||
|
||||
RUN apt-get update -y && apt-get install udev -y
|
||||
|
||||
RUN echo "source /opt/esp/idf/export.sh > /dev/null 2>&1" >> ~/.bashrc
|
||||
|
||||
ENTRYPOINT [ "/opt/esp/entrypoint.sh" ]
|
||||
|
||||
CMD ["/bin/bash", "-c"]
|
||||
19
Slave/.devcontainer/devcontainer.json
Normal file
19
Slave/.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "ESP-IDF QEMU",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile"
|
||||
},
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"settings": {
|
||||
"terminal.integrated.defaultProfile.linux": "bash",
|
||||
"idf.gitPath": "/usr/bin/git"
|
||||
},
|
||||
"extensions": [
|
||||
"espressif.esp-idf-extension",
|
||||
"espressif.esp-idf-web"
|
||||
]
|
||||
}
|
||||
},
|
||||
"runArgs": ["--privileged"]
|
||||
}
|
||||
78
Slave/.gitignore
vendored
Normal file
78
Slave/.gitignore
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
# macOS
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Directory metadata
|
||||
.directory
|
||||
|
||||
# Temporary files
|
||||
*~
|
||||
*.swp
|
||||
*.swo
|
||||
*.bak
|
||||
*.tmp
|
||||
|
||||
# Log files
|
||||
*.log
|
||||
|
||||
# Build artifacts and directories
|
||||
**/build/
|
||||
build/
|
||||
*.o
|
||||
*.a
|
||||
*.out
|
||||
*.exe # For any host-side utilities compiled on Windows
|
||||
|
||||
# ESP-IDF specific build outputs
|
||||
*.bin
|
||||
*.elf
|
||||
*.map
|
||||
flasher_args.json # Generated in build directory
|
||||
sdkconfig.old
|
||||
sdkconfig
|
||||
|
||||
# ESP-IDF dependencies
|
||||
# For older versions or manual component management
|
||||
/components/.idf/
|
||||
**/components/.idf/
|
||||
# For modern ESP-IDF component manager
|
||||
managed_components/
|
||||
# If ESP-IDF tools are installed/referenced locally to the project
|
||||
.espressif/
|
||||
|
||||
# CMake generated files
|
||||
CMakeCache.txt
|
||||
CMakeFiles/
|
||||
cmake_install.cmake
|
||||
install_manifest.txt
|
||||
CTestTestfile.cmake
|
||||
|
||||
# Python environment files
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.pyd
|
||||
__pycache__/
|
||||
*.egg-info/
|
||||
dist/
|
||||
|
||||
# Virtual environment folders
|
||||
venv/
|
||||
.venv/
|
||||
env/
|
||||
|
||||
# Language Servers
|
||||
.clangd/
|
||||
.ccls-cache/
|
||||
compile_commands.json
|
||||
|
||||
# Windows specific
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
Desktop.ini
|
||||
|
||||
# User-specific configuration files
|
||||
*.user
|
||||
*.workspace # General workspace files, can be from various tools
|
||||
*.suo # Visual Studio Solution User Options
|
||||
*.sln.docstates # Visual Studio
|
||||
19
Slave/.vscode/c_cpp_properties.json
vendored
Normal file
19
Slave/.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "ESP-IDF",
|
||||
"compilerPath": "c:\\Espressif\\tools\\tools\\xtensa-esp-elf\\esp-14.2.0_20241119\\xtensa-esp-elf\\bin\\xtensa-esp32-elf-gcc.exe",
|
||||
"compileCommands": "${config:idf.buildPath}/compile_commands.json",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"browse": {
|
||||
"path": [
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
"limitSymbolsToIncludedHeaders": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
10
Slave/.vscode/launch.json
vendored
Normal file
10
Slave/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "gdbtarget",
|
||||
"request": "attach",
|
||||
"name": "Eclipse CDT GDB Adapter"
|
||||
}
|
||||
]
|
||||
}
|
||||
11
Slave/.vscode/settings.json
vendored
Normal file
11
Slave/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"C_Cpp.intelliSenseEngine": "default",
|
||||
"idf.openOcdConfigs": [
|
||||
"board/esp32-wrover-kit-3.3v.cfg"
|
||||
],
|
||||
"idf.portWin": "detect",
|
||||
"idf.currentSetup": "C:\\Users\\mahmo\\esp\\v5.4\\esp-idf",
|
||||
"idf.customExtraVars": {
|
||||
"IDF_TARGET": "esp32"
|
||||
}
|
||||
}
|
||||
6
Slave/CMakeLists.txt
Normal file
6
Slave/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
# The following five lines of boilerplate have to be in your project's
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(Slave)
|
||||
2
Slave/main/CMakeLists.txt
Normal file
2
Slave/main/CMakeLists.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "main.c"
|
||||
INCLUDE_DIRS ".")
|
||||
76
Slave/main/main.c
Normal file
76
Slave/main/main.c
Normal file
@@ -0,0 +1,76 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "esp_log.h"
|
||||
#include "driver/i2c.h"
|
||||
#include "driver/gpio.h"
|
||||
|
||||
static const char *TAG = "i2c-slave";
|
||||
|
||||
#define LED_PIN 2
|
||||
|
||||
#define I2C_SLAVE_SCL_IO 22 /*!< gpio number for I2C master clock */
|
||||
#define I2C_SLAVE_SDA_IO 21 /*!< gpio number for I2C master data */
|
||||
#define I2C_SLAVE_FREQ_HZ 100000 /*!< I2C master clock frequency */
|
||||
#define I2C_SLAVE_TX_BUF_LEN 255 /*!< I2C master doesn't need buffer */
|
||||
#define I2C_SLAVE_RX_BUF_LEN 255 /*!< I2C master doesn't need buffer */
|
||||
#define ESP_SLAVE_ADDR 0x0A
|
||||
|
||||
#define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
|
||||
#define READ_BIT I2C_MASTER_READ /*!< I2C master read */
|
||||
#define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
|
||||
#define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
|
||||
#define ACK_VAL 0x0 /*!< I2C ack value */
|
||||
#define NACK_VAL 0x1 /*!< I2C nack value */
|
||||
|
||||
int i2c_slave_port = 0;
|
||||
static esp_err_t i2c_slave_init(void)
|
||||
{
|
||||
|
||||
i2c_config_t conf_slave = {
|
||||
.sda_io_num = I2C_SLAVE_SDA_IO, // select GPIO specific to your project
|
||||
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.scl_io_num = I2C_SLAVE_SCL_IO, // select GPIO specific to your project
|
||||
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.mode = I2C_MODE_SLAVE,
|
||||
.slave.addr_10bit_en = 0,
|
||||
.slave.slave_addr = ESP_SLAVE_ADDR, // address of your project
|
||||
.clk_flags = 0,
|
||||
};
|
||||
esp_err_t err = i2c_param_config(i2c_slave_port, &conf_slave);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
return i2c_driver_install(i2c_slave_port, conf_slave.mode, I2C_SLAVE_RX_BUF_LEN, I2C_SLAVE_TX_BUF_LEN, 0);
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
uint8_t received_data[I2C_SLAVE_RX_BUF_LEN] = {0};
|
||||
uint8_t on_command[] = "LED_ON";
|
||||
|
||||
esp_rom_gpio_pad_select_gpio(LED_PIN);
|
||||
gpio_set_direction(LED_PIN, GPIO_MODE_OUTPUT);
|
||||
|
||||
ESP_ERROR_CHECK(i2c_slave_init());
|
||||
ESP_LOGI(TAG, "I2C Slave initialized successfully");
|
||||
|
||||
while(1)
|
||||
{
|
||||
i2c_slave_read_buffer(i2c_slave_port, received_data, I2C_SLAVE_RX_BUF_LEN, 100 / portTICK_PERIOD_MS);
|
||||
i2c_reset_rx_fifo(i2c_slave_port);
|
||||
|
||||
if(strncmp((const char*)received_data, "LED_ON", 6) == 0)
|
||||
{
|
||||
ESP_LOGI(TAG, "Data Recived = %s", received_data);
|
||||
gpio_set_level(LED_PIN, 1);
|
||||
}
|
||||
else if(strncmp((const char*)received_data, "LED_OFF", 7) == 0)
|
||||
{
|
||||
ESP_LOGI(TAG, "Data Recived = %s", received_data);
|
||||
gpio_set_level(LED_PIN, 0);
|
||||
}
|
||||
|
||||
memset(received_data, 0, I2C_SLAVE_RX_BUF_LEN);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user