Created ESP-IDF for can-interface
This commit is contained in:
47
can-interface/.devcontainer/Dockerfile
Normal file
47
can-interface/.devcontainer/Dockerfile
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
FROM espressif/idf
|
||||||
|
|
||||||
|
ARG DEBIAN_FRONTEND=nointeractive
|
||||||
|
ARG CONTAINER_USER=esp
|
||||||
|
ARG USER_UID=1050
|
||||||
|
ARG USER_GID=$USER_UID
|
||||||
|
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt install -y -q \
|
||||||
|
cmake \
|
||||||
|
git \
|
||||||
|
libglib2.0-0 \
|
||||||
|
libnuma1 \
|
||||||
|
libpixman-1-0 \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# QEMU
|
||||||
|
ENV QEMU_REL=esp_develop_8.2.0_20240122
|
||||||
|
ENV QEMU_SHA256=e7c72ef5705ad1444d391711088c8717fc89f42e9bf6d1487f9c2a326b8cfa83
|
||||||
|
ENV QEMU_DIST=qemu-xtensa-softmmu-${QEMU_REL}-x86_64-linux-gnu.tar.xz
|
||||||
|
ENV QEMU_URL=https://github.com/espressif/qemu/releases/download/esp-develop-8.2.0-20240122/${QEMU_DIST}
|
||||||
|
|
||||||
|
ENV LC_ALL=C.UTF-8
|
||||||
|
ENV LANG=C.UTF-8
|
||||||
|
|
||||||
|
RUN wget --no-verbose ${QEMU_URL} \
|
||||||
|
&& echo "${QEMU_SHA256} *${QEMU_DIST}" | sha256sum --check --strict - \
|
||||||
|
&& tar -xf $QEMU_DIST -C /opt \
|
||||||
|
&& rm ${QEMU_DIST}
|
||||||
|
|
||||||
|
ENV PATH=/opt/qemu/bin:${PATH}
|
||||||
|
|
||||||
|
RUN groupadd --gid $USER_GID $CONTAINER_USER \
|
||||||
|
&& adduser --uid $USER_UID --gid $USER_GID --disabled-password --gecos "" ${CONTAINER_USER} \
|
||||||
|
&& usermod -a -G root $CONTAINER_USER && usermod -a -G dialout $CONTAINER_USER
|
||||||
|
|
||||||
|
RUN chmod -R 775 /opt/esp/python_env/
|
||||||
|
|
||||||
|
USER ${CONTAINER_USER}
|
||||||
|
ENV USER=${CONTAINER_USER}
|
||||||
|
WORKDIR /home/${CONTAINER_USER}
|
||||||
|
|
||||||
|
RUN echo "source /opt/esp/idf/export.sh > /dev/null 2>&1" >> ~/.bashrc
|
||||||
|
|
||||||
|
ENTRYPOINT [ "/opt/esp/entrypoint.sh" ]
|
||||||
|
|
||||||
|
CMD ["/bin/bash", "-c"]
|
||||||
36
can-interface/.devcontainer/devcontainer.json
Normal file
36
can-interface/.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
{
|
||||||
|
"name": "ESP-IDF QEMU",
|
||||||
|
"build": {
|
||||||
|
"dockerfile": "Dockerfile"
|
||||||
|
},
|
||||||
|
"customizations": {
|
||||||
|
"vscode": {
|
||||||
|
"settings": {
|
||||||
|
"terminal.integrated.defaultProfile.linux": "bash",
|
||||||
|
"idf.espIdfPath": "/opt/esp/idf",
|
||||||
|
"idf.customExtraPaths": "",
|
||||||
|
"idf.pythonBinPath": "/opt/esp/python_env/idf5.4_py3.12_env/bin/python",
|
||||||
|
"idf.toolsPath": "/opt/esp",
|
||||||
|
"idf.gitPath": "/usr/bin/git"
|
||||||
|
},
|
||||||
|
"extensions": [
|
||||||
|
"espressif.esp-idf-extension"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"codespaces": {
|
||||||
|
"settings": {
|
||||||
|
"terminal.integrated.defaultProfile.linux": "bash",
|
||||||
|
"idf.espIdfPath": "/opt/esp/idf",
|
||||||
|
"idf.customExtraPaths": "",
|
||||||
|
"idf.pythonBinPath": "/opt/esp/python_env/idf5.4_py3.12_env/bin/python",
|
||||||
|
"idf.toolsPath": "/opt/esp",
|
||||||
|
"idf.gitPath": "/usr/bin/git"
|
||||||
|
},
|
||||||
|
"extensions": [
|
||||||
|
"espressif.esp-idf-extension",
|
||||||
|
"espressif.esp-idf-web"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"runArgs": ["--privileged"]
|
||||||
|
}
|
||||||
BIN
can-interface/.gitignore
(Stored with Git LFS)
vendored
Normal file
BIN
can-interface/.gitignore
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
23
can-interface/.vscode/c_cpp_properties.json
vendored
Normal file
23
can-interface/.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "ESP-IDF",
|
||||||
|
"compilerPath": "${config:idf.toolsPath}/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin/xtensa-esp32-elf-gcc",
|
||||||
|
"compileCommands": "${config:idf.buildPath}/compile_commands.json",
|
||||||
|
"includePath": [
|
||||||
|
"${config:idf.espIdfPath}/components/**",
|
||||||
|
"${config:idf.espIdfPathWin}/components/**",
|
||||||
|
"${workspaceFolder}/**"
|
||||||
|
],
|
||||||
|
"browse": {
|
||||||
|
"path": [
|
||||||
|
"${config:idf.espIdfPath}/components",
|
||||||
|
"${config:idf.espIdfPathWin}/components",
|
||||||
|
"${workspaceFolder}"
|
||||||
|
],
|
||||||
|
"limitSymbolsToIncludedHeaders": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
||||||
15
can-interface/.vscode/launch.json
vendored
Normal file
15
can-interface/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "gdbtarget",
|
||||||
|
"request": "attach",
|
||||||
|
"name": "Eclipse CDT GDB Adapter"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "espidf",
|
||||||
|
"name": "Launch",
|
||||||
|
"request": "launch"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
17
can-interface/.vscode/settings.json
vendored
Normal file
17
can-interface/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"C_Cpp.intelliSenseEngine": "default",
|
||||||
|
"idf.adapterTargetName": "esp32",
|
||||||
|
"idf.customExtraPaths": "/home/alexander/.espressif/tools/xtensa-esp-elf-gdb/14.2_20240403/xtensa-esp-elf-gdb/bin:/home/alexander/.espressif/tools/riscv32-esp-elf-gdb/14.2_20240403/riscv32-esp-elf-gdb/bin:/home/alexander/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin:/home/alexander/.espressif/tools/riscv32-esp-elf/esp-13.2.0_20240530/riscv32-esp-elf/bin:/home/alexander/.espressif/tools/esp32ulp-elf/2.38_20240113/esp32ulp-elf/bin:/home/alexander/.espressif/tools/openocd-esp32/v0.12.0-esp32-20240318/openocd-esp32/bin:/home/alexander/.espressif/tools/ninja/1.11.1:/home/alexander/.espressif/tools/esp-rom-elfs/20240305",
|
||||||
|
"idf.customExtraVars": {
|
||||||
|
"OPENOCD_SCRIPTS": "/home/alexander/.espressif/tools/openocd-esp32/v0.12.0-esp32-20240318/openocd-esp32/share/openocd/scripts",
|
||||||
|
"ESP_ROM_ELF_DIR": "/home/alexander/.espressif/tools/esp-rom-elfs/20240305/"
|
||||||
|
},
|
||||||
|
"idf.espIdfPath": "/opt/esp/v5.3.1/esp-idf",
|
||||||
|
"idf.openOcdConfigs": [
|
||||||
|
"board/esp32-wrover-kit-3.3v.cfg"
|
||||||
|
],
|
||||||
|
"idf.port": "/dev/ttyUSB0",
|
||||||
|
"idf.pythonBinPath": "/home/alexander/.espressif/python_env/idf5.3_py3.12_env/bin/python",
|
||||||
|
"idf.toolsPath": "/home/alexander/.espressif",
|
||||||
|
"idf.flashType": "UART"
|
||||||
|
}
|
||||||
259
can-interface/.vscode/tasks.json
vendored
Normal file
259
can-interface/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,259 @@
|
|||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "Build - Build project",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "${config:idf.pythonBinPath} ${config:idf.espIdfPath}/tools/idf.py build",
|
||||||
|
"windows": {
|
||||||
|
"command": "${config:idf.pythonBinPathWin} ${config:idf.espIdfPathWin}\\tools\\idf.py build",
|
||||||
|
"options": {
|
||||||
|
"env": {
|
||||||
|
"PATH": "${env:PATH};${config:idf.customExtraPaths}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"options": {
|
||||||
|
"env": {
|
||||||
|
"PATH": "${env:PATH}:${config:idf.customExtraPaths}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"problemMatcher": [
|
||||||
|
{
|
||||||
|
"owner": "cpp",
|
||||||
|
"fileLocation": [
|
||||||
|
"autoDetect",
|
||||||
|
"${workspaceFolder}"
|
||||||
|
],
|
||||||
|
"pattern": {
|
||||||
|
"regexp": "^(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
|
||||||
|
"file": 1,
|
||||||
|
"line": 2,
|
||||||
|
"column": 3,
|
||||||
|
"severity": 4,
|
||||||
|
"message": 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"group": {
|
||||||
|
"kind": "build",
|
||||||
|
"isDefault": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Set ESP-IDF Target",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "${command:espIdf.setTarget}",
|
||||||
|
"problemMatcher": {
|
||||||
|
"owner": "cpp",
|
||||||
|
"fileLocation": [
|
||||||
|
"autoDetect",
|
||||||
|
"${workspaceFolder}"
|
||||||
|
],
|
||||||
|
"pattern": {
|
||||||
|
"regexp": "^(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
|
||||||
|
"file": 1,
|
||||||
|
"line": 2,
|
||||||
|
"column": 3,
|
||||||
|
"severity": 4,
|
||||||
|
"message": 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Clean - Clean the project",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "${config:idf.pythonBinPath} ${config:idf.espIdfPath}/tools/idf.py fullclean",
|
||||||
|
"windows": {
|
||||||
|
"command": "${config:idf.pythonBinPathWin} ${config:idf.espIdfPathWin}\\tools\\idf.py fullclean",
|
||||||
|
"options": {
|
||||||
|
"env": {
|
||||||
|
"PATH": "${env:PATH};${config:idf.customExtraPaths}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"options": {
|
||||||
|
"env": {
|
||||||
|
"PATH": "${env:PATH}:${config:idf.customExtraPaths}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"problemMatcher": [
|
||||||
|
{
|
||||||
|
"owner": "cpp",
|
||||||
|
"fileLocation": [
|
||||||
|
"autoDetect",
|
||||||
|
"${workspaceFolder}"
|
||||||
|
],
|
||||||
|
"pattern": {
|
||||||
|
"regexp": "^(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
|
||||||
|
"file": 1,
|
||||||
|
"line": 2,
|
||||||
|
"column": 3,
|
||||||
|
"severity": 4,
|
||||||
|
"message": 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Flash - Flash the device",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "${config:idf.pythonBinPath} ${config:idf.espIdfPath}/tools/idf.py -p ${config:idf.port} -b ${config:idf.flashBaudRate} flash",
|
||||||
|
"windows": {
|
||||||
|
"command": "${config:idf.pythonBinPathWin} ${config:idf.espIdfPathWin}\\tools\\idf.py flash -p ${config:idf.portWin} -b ${config:idf.flashBaudRate}",
|
||||||
|
"options": {
|
||||||
|
"env": {
|
||||||
|
"PATH": "${env:PATH};${config:idf.customExtraPaths}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"options": {
|
||||||
|
"env": {
|
||||||
|
"PATH": "${env:PATH}:${config:idf.customExtraPaths}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"problemMatcher": [
|
||||||
|
{
|
||||||
|
"owner": "cpp",
|
||||||
|
"fileLocation": [
|
||||||
|
"autoDetect",
|
||||||
|
"${workspaceFolder}"
|
||||||
|
],
|
||||||
|
"pattern": {
|
||||||
|
"regexp": "^(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
|
||||||
|
"file": 1,
|
||||||
|
"line": 2,
|
||||||
|
"column": 3,
|
||||||
|
"severity": 4,
|
||||||
|
"message": 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Monitor: Start the monitor",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "${config:idf.pythonBinPath} ${config:idf.espIdfPath}/tools/idf.py -p ${config:idf.port} monitor",
|
||||||
|
"windows": {
|
||||||
|
"command": "${config:idf.pythonBinPathWin} ${config:idf.espIdfPathWin}\\tools\\idf.py -p ${config:idf.portWin} monitor",
|
||||||
|
"options": {
|
||||||
|
"env": {
|
||||||
|
"PATH": "${env:PATH};${config:idf.customExtraPaths}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"options": {
|
||||||
|
"env": {
|
||||||
|
"PATH": "${env:PATH}:${config:idf.customExtraPaths}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"problemMatcher": [
|
||||||
|
{
|
||||||
|
"owner": "cpp",
|
||||||
|
"fileLocation": [
|
||||||
|
"autoDetect",
|
||||||
|
"${workspaceFolder}"
|
||||||
|
],
|
||||||
|
"pattern": {
|
||||||
|
"regexp": "^(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
|
||||||
|
"file": 1,
|
||||||
|
"line": 2,
|
||||||
|
"column": 3,
|
||||||
|
"severity": 4,
|
||||||
|
"message": 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"dependsOn": "Flash - Flash the device"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OpenOCD: Start openOCD",
|
||||||
|
"type": "shell",
|
||||||
|
"presentation": {
|
||||||
|
"echo": true,
|
||||||
|
"reveal": "never",
|
||||||
|
"focus": false,
|
||||||
|
"panel": "new"
|
||||||
|
},
|
||||||
|
"command": "openocd -s ${command:espIdf.getOpenOcdScriptValue} ${command:espIdf.getOpenOcdConfigs}",
|
||||||
|
"windows": {
|
||||||
|
"command": "openocd.exe -s ${command:espIdf.getOpenOcdScriptValue} ${command:espIdf.getOpenOcdConfigs}",
|
||||||
|
"options": {
|
||||||
|
"env": {
|
||||||
|
"PATH": "${env:PATH};${config:idf.customExtraPaths}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"options": {
|
||||||
|
"env": {
|
||||||
|
"PATH": "${env:PATH}:${config:idf.customExtraPaths}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"problemMatcher": {
|
||||||
|
"owner": "cpp",
|
||||||
|
"fileLocation": [
|
||||||
|
"autoDetect",
|
||||||
|
"${workspaceFolder}"
|
||||||
|
],
|
||||||
|
"pattern": {
|
||||||
|
"regexp": "^(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
|
||||||
|
"file": 1,
|
||||||
|
"line": 2,
|
||||||
|
"column": 3,
|
||||||
|
"severity": 4,
|
||||||
|
"message": 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "adapter",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "${config:idf.pythonBinPath}",
|
||||||
|
"isBackground": true,
|
||||||
|
"options": {
|
||||||
|
"env": {
|
||||||
|
"PATH": "${env:PATH}:${config:idf.customExtraPaths}",
|
||||||
|
"PYTHONPATH": "${command:espIdf.getExtensionPath}/esp_debug_adapter/debug_adapter"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"problemMatcher": {
|
||||||
|
"background": {
|
||||||
|
"beginsPattern": "\bDEBUG_ADAPTER_STARTED\b",
|
||||||
|
"endsPattern": "DEBUG_ADAPTER_READY2CONNECT",
|
||||||
|
"activeOnStart": true
|
||||||
|
},
|
||||||
|
"pattern": {
|
||||||
|
"regexp": "(\\d+)-(\\d+)-(\\d+)\\s(\\d+):(\\d+):(\\d+),(\\d+)\\s-(.+)\\s(ERROR)",
|
||||||
|
"file": 8,
|
||||||
|
"line": 2,
|
||||||
|
"column": 3,
|
||||||
|
"severity": 4,
|
||||||
|
"message": 9
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"args": [
|
||||||
|
"${command:espIdf.getExtensionPath}/esp_debug_adapter/debug_adapter_main.py",
|
||||||
|
"-e",
|
||||||
|
"${workspaceFolder}/build/${command:espIdf.getProjectName}.elf",
|
||||||
|
"-s",
|
||||||
|
"$OPENOCD_SCRIPTS",
|
||||||
|
"-dn",
|
||||||
|
"esp32",
|
||||||
|
"-om",
|
||||||
|
"connect_to_instance",
|
||||||
|
"-t",
|
||||||
|
"xtensa-esp32-elf-"
|
||||||
|
|
||||||
|
],
|
||||||
|
"windows": {
|
||||||
|
"command": "${config:idf.pythonBinPathWin}",
|
||||||
|
"options": {
|
||||||
|
"env": {
|
||||||
|
"PATH": "${env:PATH};${config:idf.customExtraPaths}",
|
||||||
|
"PYTHONPATH": "${command:espIdf.getExtensionPath}/esp_debug_adapter/debug_adapter"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
6
can-interface/CMakeLists.txt
Executable file
6
can-interface/CMakeLists.txt
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
# The following 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(can-interface)
|
||||||
BIN
can-interface/README.md
(Stored with Git LFS)
Executable file
BIN
can-interface/README.md
(Stored with Git LFS)
Executable file
Binary file not shown.
3
can-interface/components/mcp2125/CMakeLists.txt
Normal file
3
can-interface/components/mcp2125/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
idf_component_register(SRCS "operations.cpp"
|
||||||
|
INCLUDE_DIRS "include"
|
||||||
|
REQUIRES driver)
|
||||||
2
can-interface/components/mcp2125/include/mcp2125.hpp
Normal file
2
can-interface/components/mcp2125/include/mcp2125.hpp
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
bool dummy_function(bool flag);
|
||||||
4
can-interface/components/mcp2125/operations.cpp
Normal file
4
can-interface/components/mcp2125/operations.cpp
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
bool dummy_function(bool flag) {
|
||||||
|
return !flag;
|
||||||
|
}
|
||||||
5
can-interface/main/CMakeLists.txt
Executable file
5
can-interface/main/CMakeLists.txt
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
idf_component_register(SRCS "hello_world_main.cpp"
|
||||||
|
REQUIRES driver
|
||||||
|
REQUIRES mcp2125
|
||||||
|
REQUIRES spi_flash
|
||||||
|
INCLUDE_DIRS "")
|
||||||
7
can-interface/main/can-interface.code-workspace
Normal file
7
can-interface/main/can-interface.code-workspace
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"path": ".."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
113
can-interface/main/hello_world_main.cpp
Executable file
113
can-interface/main/hello_world_main.cpp
Executable file
@@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "freertos/semphr.h"
|
||||||
|
#include "freertos/queue.h"
|
||||||
|
|
||||||
|
#include "esp_chip_info.h"
|
||||||
|
#include "esp_flash.h"
|
||||||
|
#include "esp_system.h"
|
||||||
|
|
||||||
|
#include "driver/gpio.h"
|
||||||
|
#include "driver/spi_master.h"
|
||||||
|
|
||||||
|
#include "mcp2125.hpp"
|
||||||
|
|
||||||
|
#define SPI_PIN_CS0 GPIO_NUM_5
|
||||||
|
#define SPI_PIN_SCLK GPIO_NUM_18
|
||||||
|
#define SPI_PIN_MISO GPIO_NUM_19
|
||||||
|
#define SPI_PIN_MOSI GPIO_NUM_23
|
||||||
|
|
||||||
|
#define EXTERNAL_TRIGGER GPIO_NUM_26
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void app_main() {
|
||||||
|
printf("Hello world!\n");
|
||||||
|
|
||||||
|
const gpio_num_t LED_PIN = GPIO_NUM_2;
|
||||||
|
gpio_set_direction(LED_PIN, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
|
gpio_set_direction(EXTERNAL_TRIGGER, GPIO_MODE_OUTPUT);
|
||||||
|
gpio_set_level(EXTERNAL_TRIGGER, true);
|
||||||
|
|
||||||
|
spi_bus_config_t spi_config = {
|
||||||
|
.mosi_io_num = SPI_PIN_MOSI,
|
||||||
|
.miso_io_num = SPI_PIN_MISO,
|
||||||
|
.sclk_io_num = SPI_PIN_SCLK,
|
||||||
|
|
||||||
|
.quadwp_io_num = -1,
|
||||||
|
.quadhd_io_num = -1,
|
||||||
|
|
||||||
|
.flags = SPICOMMON_BUSFLAG_MASTER
|
||||||
|
};
|
||||||
|
|
||||||
|
spi_device_interface_config_t mp2125_devcfg = {
|
||||||
|
.command_bits = 8,
|
||||||
|
.address_bits = 0,
|
||||||
|
.dummy_bits = 0,
|
||||||
|
|
||||||
|
.mode = 0,
|
||||||
|
.duty_cycle_pos = 128,
|
||||||
|
.cs_ena_pretrans = 1,
|
||||||
|
.cs_ena_posttrans = 1,
|
||||||
|
.clock_speed_hz = 10000,
|
||||||
|
|
||||||
|
.spics_io_num = SPI_PIN_CS0,
|
||||||
|
.flags = SPI_DEVICE_HALFDUPLEX,
|
||||||
|
.queue_size = 5,
|
||||||
|
};
|
||||||
|
|
||||||
|
spi_device_handle_t mp2125_handle;
|
||||||
|
|
||||||
|
spi_bus_initialize(VSPI_HOST, &spi_config, SPI_DMA_CH_AUTO);
|
||||||
|
spi_bus_add_device(VSPI_HOST, &mp2125_devcfg, &mp2125_handle);
|
||||||
|
|
||||||
|
char rxBuffer[32] = {0};
|
||||||
|
|
||||||
|
spi_transaction_t transaction0 = { // RESET
|
||||||
|
.cmd = 0b11000000,
|
||||||
|
.length = 0,
|
||||||
|
.rxlength = 2 * 8,
|
||||||
|
.tx_buffer = NULL,
|
||||||
|
.rx_buffer = rxBuffer
|
||||||
|
};
|
||||||
|
|
||||||
|
spi_transaction_t transaction1 = { // READ STAT/S
|
||||||
|
.cmd = 0b10110000,
|
||||||
|
.length = 0,
|
||||||
|
.rxlength = 2 * 8,
|
||||||
|
.tx_buffer = NULL,
|
||||||
|
.rx_buffer = rxBuffer
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||||
|
gpio_set_level(EXTERNAL_TRIGGER, false);
|
||||||
|
spi_device_transmit(mp2125_handle, &transaction0);
|
||||||
|
spi_device_transmit(mp2125_handle, &transaction1);
|
||||||
|
gpio_set_level(EXTERNAL_TRIGGER, true);
|
||||||
|
|
||||||
|
bool flag = true;
|
||||||
|
while (true) {
|
||||||
|
gpio_set_level(LED_PIN, flag);
|
||||||
|
flag = dummy_function(flag);
|
||||||
|
|
||||||
|
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
BIN
can-interface/pytest_hello_world.py
(Stored with Git LFS)
Executable file
BIN
can-interface/pytest_hello_world.py
(Stored with Git LFS)
Executable file
Binary file not shown.
2008
can-interface/sdkconfig
Normal file
2008
can-interface/sdkconfig
Normal file
File diff suppressed because it is too large
Load Diff
0
can-interface/sdkconfig.ci
Executable file
0
can-interface/sdkconfig.ci
Executable file
Reference in New Issue
Block a user