Compare commits
33 Commits
dev-gobot-
...
motor-ctrl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51ce3af221 | ||
|
|
e091d4df18 | ||
|
|
f002a01308 | ||
|
|
6ba0535af9 | ||
|
|
46f3514c6a | ||
|
|
a755a954f6 | ||
|
|
c7c5cea341 | ||
|
|
f0ae696c4d | ||
|
|
51587757b1 | ||
|
|
f4b591a5e6 | ||
|
|
a2032d72fd | ||
|
|
57e73127cc | ||
|
|
53a5c10cee | ||
|
|
f5281e37c8 | ||
|
|
783799832c | ||
|
|
61abb16b83 | ||
|
|
0dc0f82938 | ||
|
|
1786fa0b41 | ||
|
|
f3490212bf | ||
|
|
84e351d154 | ||
|
|
986927d740 | ||
|
|
6be2dd0b7d | ||
|
|
b2ffcb5d72 | ||
|
|
1ad6c75788 | ||
|
|
e97472c2a3 | ||
|
|
bba35c9622 | ||
|
|
9640a5b747 | ||
|
|
49d52ca0ed | ||
|
|
08598ca7a3 | ||
|
|
36f6f1863b | ||
|
|
0c1b8f4e86 | ||
|
|
29af5335f5 | ||
|
|
8b97a1853d |
BIN
.gitignore
(Stored with Git LFS)
vendored
BIN
.gitignore
(Stored with Git LFS)
vendored
Binary file not shown.
BIN
.gitmodules
(Stored with Git LFS)
vendored
BIN
.gitmodules
(Stored with Git LFS)
vendored
Binary file not shown.
BIN
3D-Print-Files/RPi_Mount/RPi Mount Raw - MountPart.stl
Normal file
BIN
3D-Print-Files/RPi_Mount/RPi Mount Raw - MountPart.stl
Normal file
Binary file not shown.
BIN
3D-Print-Files/RPi_Mount/RPi Mount Raw - TopPart.stl
Normal file
BIN
3D-Print-Files/RPi_Mount/RPi Mount Raw - TopPart.stl
Normal file
Binary file not shown.
BIN
3D-Print-Files/RPi_Mount/RPi_Mount.3mf
Normal file
BIN
3D-Print-Files/RPi_Mount/RPi_Mount.3mf
Normal file
Binary file not shown.
BIN
3d-print/RPi_Mount.3mf
Normal file
BIN
3d-print/RPi_Mount.3mf
Normal file
Binary file not shown.
BIN
3d-print/models/BoardPositionMarker/Vison Marker Clip - Marker.stl
(Stored with Git LFS)
Normal file
BIN
3d-print/models/BoardPositionMarker/Vison Marker Clip - Marker.stl
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
3d-print/models/BoardPositionMarker/Vison Marker Clip - WhiteRing1.stl
(Stored with Git LFS)
Normal file
BIN
3d-print/models/BoardPositionMarker/Vison Marker Clip - WhiteRing1.stl
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
3d-print/models/BoardPositionMarker/Vison Marker Clip - WhiteRing2.stl
(Stored with Git LFS)
Normal file
BIN
3d-print/models/BoardPositionMarker/Vison Marker Clip - WhiteRing2.stl
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
3d-print/models/HeadPipeMount/HeadPipeMount - DownPart.stl
Normal file
BIN
3d-print/models/HeadPipeMount/HeadPipeMount - DownPart.stl
Normal file
Binary file not shown.
BIN
3d-print/models/HeadPipeMount/HeadPipeMount - HoseAdapter.stl
Normal file
BIN
3d-print/models/HeadPipeMount/HeadPipeMount - HoseAdapter.stl
Normal file
Binary file not shown.
BIN
3d-print/models/HeadPipeMount/HeadPipeMount - RightPart.stl
Normal file
BIN
3d-print/models/HeadPipeMount/HeadPipeMount - RightPart.stl
Normal file
Binary file not shown.
BIN
3d-print/models/PerfBoardHolder/PerfBoardHolder - BoarMount.stl
Normal file
BIN
3d-print/models/PerfBoardHolder/PerfBoardHolder - BoarMount.stl
Normal file
Binary file not shown.
BIN
3d-print/models/PerfBoardHolder/PerfBoardHolder - Mount0.stl
Normal file
BIN
3d-print/models/PerfBoardHolder/PerfBoardHolder - Mount0.stl
Normal file
Binary file not shown.
BIN
3d-print/models/PerfBoardHolder/PerfBoardHolder - Mount1.stl
Normal file
BIN
3d-print/models/PerfBoardHolder/PerfBoardHolder - Mount1.stl
Normal file
Binary file not shown.
BIN
3d-print/models/PerfBoardHolder/PerfBoardHolder.3mf
Normal file
BIN
3d-print/models/PerfBoardHolder/PerfBoardHolder.3mf
Normal file
Binary file not shown.
BIN
3d-print/models/YGantryMount/GantryMount - GantryPlate (1).stl
Normal file
BIN
3d-print/models/YGantryMount/GantryMount - GantryPlate (1).stl
Normal file
Binary file not shown.
BIN
3d-print/models/YGantryMount/GantryMount - GantryPlate.stl
Normal file
BIN
3d-print/models/YGantryMount/GantryMount - GantryPlate.stl
Normal file
Binary file not shown.
BIN
3d-print/models/YGantryMount/GantryMount - Mount (1).stl
Normal file
BIN
3d-print/models/YGantryMount/GantryMount - Mount (1).stl
Normal file
Binary file not shown.
BIN
3d-print/models/YGantryMount/GantryMount - Mount.stl
Normal file
BIN
3d-print/models/YGantryMount/GantryMount - Mount.stl
Normal file
Binary file not shown.
BIN
3d-print/slicers/BoardPositionMarker.3mf
(Stored with Git LFS)
Normal file
BIN
3d-print/slicers/BoardPositionMarker.3mf
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
3d-print/slicers/HeadPipeMount.3mf
Normal file
BIN
3d-print/slicers/HeadPipeMount.3mf
Normal file
Binary file not shown.
BIN
3d-print/slicers/YGantryMount.3mf
Normal file
BIN
3d-print/slicers/YGantryMount.3mf
Normal file
Binary file not shown.
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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
29
can-interface/.vscode/settings.json
vendored
Normal file
29
can-interface/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"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",
|
||||||
|
"files.associations": {
|
||||||
|
"*.tcc": "cpp",
|
||||||
|
"cstdint": "cpp",
|
||||||
|
"random": "cpp",
|
||||||
|
"future": "cpp",
|
||||||
|
"bitset": "cpp",
|
||||||
|
"string_view": "cpp",
|
||||||
|
"regex": "cpp",
|
||||||
|
"array": "cpp",
|
||||||
|
"string": "cpp",
|
||||||
|
"span": "cpp"
|
||||||
|
}
|
||||||
|
}
|
||||||
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)
|
||||||
1
can-interface/ESP-IDF.code-profile
Normal file
1
can-interface/ESP-IDF.code-profile
Normal file
File diff suppressed because one or more lines are too long
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.
1
can-interface/components/mcp2521
Symbolic link
1
can-interface/components/mcp2521
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
/home/alexander/Projects/gobot/common-libaries/mcp2521
|
||||||
1
can-interface/components/mcp2521_hardware_interface
Symbolic link
1
can-interface/components/mcp2521_hardware_interface
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
/home/alexander/Projects/gobot/common-libaries/mcp2521_hardware_interface
|
||||||
6
can-interface/main/CMakeLists.txt
Executable file
6
can-interface/main/CMakeLists.txt
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
idf_component_register(SRCS "hello_world_main.cpp"
|
||||||
|
REQUIRES driver
|
||||||
|
REQUIRES mcp2521
|
||||||
|
REQUIRES mcp2521_hardware_interface
|
||||||
|
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": ".."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
105
can-interface/main/hello_world_main.cpp
Executable file
105
can-interface/main/hello_world_main.cpp
Executable file
@@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.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 "mcp2521.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 CAN_INT_PIN GPIO_NUM_21
|
||||||
|
|
||||||
|
#define EXTERNAL_TRIGGER GPIO_NUM_26
|
||||||
|
|
||||||
|
void onRX(void *arg) {
|
||||||
|
MCP2521 *mcp2521 = (MCP2521 *)arg;
|
||||||
|
|
||||||
|
rx_info info = mcp2521->get_rx_id(MCP2521_RX_BUFFER::RXB0);
|
||||||
|
uint8_t data[8];
|
||||||
|
|
||||||
|
mcp2521->read_rx_buf(MCP2521_RX_BUFFER::RXB0, MCP2521_BUFFER_TYPE::DATA, data, info.length);
|
||||||
|
|
||||||
|
printf("RX: (%x) ", info.id);
|
||||||
|
for (int i = 0; i < info.length; i++) {
|
||||||
|
printf("%x ", data[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" 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);
|
||||||
|
|
||||||
|
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
|
|
||||||
|
spi_bus_config_t spi_bus;
|
||||||
|
|
||||||
|
MCP2521_Hardware_Handle_ESP hardware_mcp2521(
|
||||||
|
VSPI_HOST,
|
||||||
|
&spi_bus,
|
||||||
|
SPI_PIN_MOSI,
|
||||||
|
SPI_PIN_MISO,
|
||||||
|
SPI_PIN_SCLK,
|
||||||
|
SPI_PIN_CS0,
|
||||||
|
CAN_INT_PIN
|
||||||
|
);
|
||||||
|
|
||||||
|
MCP2521 mcp2521(&hardware_mcp2521);
|
||||||
|
|
||||||
|
uint8_t data[4] = {0xf0, 0x42, 0x13, 0x37};
|
||||||
|
|
||||||
|
gpio_set_level(EXTERNAL_TRIGGER, false);
|
||||||
|
mcp2521.reset();
|
||||||
|
mcp2521.enable_interrupts(true, true, true, true, true, true, true, true);
|
||||||
|
|
||||||
|
mcp2521.register_rx0_handler(onRX, &mcp2521);
|
||||||
|
mcp2521.register_rx1_handler(onRX, &mcp2521);
|
||||||
|
mcp2521.set_mode_of_operation(MCP2521_OPERATION_MODE::LOOPBACK, true);
|
||||||
|
|
||||||
|
vTaskDelay(3 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
|
mcp2521.prepare_tx(
|
||||||
|
MCP2521_TX_BUFFER::TXB0, 0x042, data, 4, false, false);
|
||||||
|
|
||||||
|
mcp2521.request_to_send(MCP2521_TX_BUFFER::TXB0);
|
||||||
|
|
||||||
|
mcp2521.set_tx_id(MCP2521_TX_BUFFER::TXB0, 0x041, false);
|
||||||
|
mcp2521.request_to_send(MCP2521_TX_BUFFER::TXB0);
|
||||||
|
|
||||||
|
|
||||||
|
vTaskDelay(20 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
|
bool flag = true;
|
||||||
|
while (true) {
|
||||||
|
gpio_set_level(LED_PIN, flag);
|
||||||
|
flag = !flag;
|
||||||
|
|
||||||
|
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
can-interface/pulseView-debug-session
Normal file
BIN
can-interface/pulseView-debug-session
Normal file
Binary file not shown.
BIN
can-interface/pulseview-session
Normal file
BIN
can-interface/pulseview-session
Normal file
Binary file not shown.
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
8
common-libaries/mcp2521/CMakeLists.txt
Normal file
8
common-libaries/mcp2521/CMakeLists.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
idf_component_register(SRCS
|
||||||
|
"interface_commands.cpp"
|
||||||
|
"interface_interrupts.cpp"
|
||||||
|
"toplevel_commands.cpp"
|
||||||
|
INCLUDE_DIRS "include"
|
||||||
|
REQUIRES driver
|
||||||
|
REQUIRES mcp2521_hardware_interface
|
||||||
|
)
|
||||||
0
common-libaries/mcp2521/cmake/pico.cmake
Normal file
0
common-libaries/mcp2521/cmake/pico.cmake
Normal file
177
common-libaries/mcp2521/include/bitfields.hpp
Normal file
177
common-libaries/mcp2521/include/bitfields.hpp
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief RXnBF PIN CONTROL AND STATUS REGISTER (ADDRESS: 0Ch)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
struct BFPCTRL {
|
||||||
|
uint8_t B0BFM : 1;
|
||||||
|
uint8_t B1BFM : 1;
|
||||||
|
uint8_t B0BFE : 1;
|
||||||
|
uint8_t B1BFE : 1;
|
||||||
|
uint8_t B0BFS : 1;
|
||||||
|
uint8_t B1BFS : 1;
|
||||||
|
uint8_t : 2;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TXnRTS PIN CONTROL AND STATUS REGISTER
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
struct TXRTSCTRL {
|
||||||
|
uint8_t B0RTSM : 1;
|
||||||
|
uint8_t B1RTSM : 1;
|
||||||
|
uint8_t B2RTSM : 1;
|
||||||
|
uint8_t B0RTS : 1;
|
||||||
|
uint8_t B1RTS : 1;
|
||||||
|
uint8_t B2RTS : 1;
|
||||||
|
uint8_t : 2;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CANSTAT {
|
||||||
|
uint8_t ICOD0 : ;
|
||||||
|
uint8_t : 1;
|
||||||
|
uint8_t OPMOD0 : 1;
|
||||||
|
uint8_t OPMOD1 : 1;
|
||||||
|
uint8_t OPMOD2 : 1;
|
||||||
|
uint8_t : 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CANCTRL {
|
||||||
|
uint8_t CLKPRE0 : 1;
|
||||||
|
uint8_t CLKPRE1 : 1;
|
||||||
|
uint8_t CLKEN : 1;
|
||||||
|
uint8_t OSM : 1;
|
||||||
|
uint8_t ABAT : 1;
|
||||||
|
uint8_t REQOP0 : 1;
|
||||||
|
uint8_t REQOP1 : 1;
|
||||||
|
uint8_t REQOP2 : 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TEC {
|
||||||
|
uint8_t TEC;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct REC {
|
||||||
|
uint8_t REC;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CNF3 {
|
||||||
|
uint8_t PHSEG20 : 1;
|
||||||
|
uint8_t PHSEG21 : 1;
|
||||||
|
uint8_t PHSEG22 : 1;
|
||||||
|
uint8_t : 3;
|
||||||
|
uint8_t WAKFIL : 1;
|
||||||
|
uint8_t SOF : 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CNF2 {
|
||||||
|
uint8_t PRSEG0 : 1;
|
||||||
|
uint8_t PRSEG1 : 1;
|
||||||
|
uint8_t PRSEG2 : 1;
|
||||||
|
uint8_t PHSEG10 : 1;
|
||||||
|
uint8_t PHSEG11 : 1;
|
||||||
|
uint8_t PHSEG12 : 1;
|
||||||
|
uint8_t SAM : 1;
|
||||||
|
uint8_t BTLMODE : 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CNF1 {
|
||||||
|
uint8_t BRP0 : 1;
|
||||||
|
uint8_t BRP1 : 1;
|
||||||
|
uint8_t BRP2 : 1;
|
||||||
|
uint8_t BRP3 : 1;
|
||||||
|
uint8_t BRP4 : 1;
|
||||||
|
uint8_t BRP5 : 1;
|
||||||
|
uint8_t SJW0 : 1;
|
||||||
|
uint8_t SJW1 : 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CANINTE {
|
||||||
|
uint8_t RX0IE : 1;
|
||||||
|
uint8_t RX1IE : 1;
|
||||||
|
uint8_t TX0IE : 1;
|
||||||
|
uint8_t TX1IE : 1;
|
||||||
|
uint8_t TX2IE : 1;
|
||||||
|
uint8_t ERRIE : 1;
|
||||||
|
uint8_t WAKIE : 1;
|
||||||
|
uint8_t MERRE : 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CANINTF {
|
||||||
|
uint8_t RX0IF : 1;
|
||||||
|
uint8_t RX1IF : 1;
|
||||||
|
uint8_t TX0IF : 1;
|
||||||
|
uint8_t TX1IF : 1;
|
||||||
|
uint8_t TX2IF : 1;
|
||||||
|
uint8_t ERRIF : 1;
|
||||||
|
uint8_t WAKIF : 1;
|
||||||
|
uint8_t MERRF : 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct EFLG {
|
||||||
|
uint8_t EWARN : 1;
|
||||||
|
uint8_t RXWAR : 1;
|
||||||
|
uint8_t TXWAR : 1;
|
||||||
|
uint8_t RXEP : 1;
|
||||||
|
uint8_t TXEP : 1;
|
||||||
|
uint8_t TXBO : 1;
|
||||||
|
uint8_t RX0OVR : 1;
|
||||||
|
uint8_t RX1OVR : 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TXB0CTRL {
|
||||||
|
uint8_t TXP0 : 1;
|
||||||
|
uint8_t TXP1 : 1;
|
||||||
|
uint8_t : 1;
|
||||||
|
uint8_t TXREQ : 1;
|
||||||
|
uint8_t TXERR : 1;
|
||||||
|
uint8_t MLOA : 1;
|
||||||
|
uint8_t ABTF : 1;
|
||||||
|
uint8_t : 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TXB1CTRL {
|
||||||
|
uint8_t TXP0 : 1;
|
||||||
|
uint8_t TXP1 : 1;
|
||||||
|
uint8_t : 1;
|
||||||
|
uint8_t TXREQ : 1;
|
||||||
|
uint8_t TXERR : 1;
|
||||||
|
uint8_t MLOA : 1;
|
||||||
|
uint8_t ABTF : 1;
|
||||||
|
uint8_t : 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TXB2CTRL {
|
||||||
|
uint8_t TXP0 : 1;
|
||||||
|
uint8_t TXP1 : 1;
|
||||||
|
uint8_t : 1;
|
||||||
|
uint8_t TXREQ : 1;
|
||||||
|
uint8_t TXERR : 1;
|
||||||
|
uint8_t MLOA : 1;
|
||||||
|
uint8_t ABTF : 1;
|
||||||
|
uint8_t : 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RXB0CTRL {
|
||||||
|
uint8_t FILHIT0 : 1;
|
||||||
|
uint8_t BUKT1 : 1;
|
||||||
|
uint8_t BUKT : 1;
|
||||||
|
uint8_t RXRTR : 1;
|
||||||
|
uint8_t : 1;
|
||||||
|
uint8_t RXM0 : 1;
|
||||||
|
uint8_t RXM1 : 1;
|
||||||
|
uint8_t : 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RXB1CTRL {
|
||||||
|
uint8_t FILHIT0 : 1;
|
||||||
|
uint8_t FILHIT1 : 1;
|
||||||
|
uint8_t FILHIT2 : 1;
|
||||||
|
uint8_t RXRTR : 1;
|
||||||
|
uint8_t : 1;
|
||||||
|
uint8_t RXM0 : 1;
|
||||||
|
uint8_t RXM1 : 1;
|
||||||
|
uint8_t : 1;
|
||||||
|
};
|
||||||
6
common-libaries/mcp2521/include/mcp2521.hpp
Normal file
6
common-libaries/mcp2521/include/mcp2521.hpp
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "mcp2521_toplevel.hpp"
|
||||||
|
#include "mcp2521_command.hpp"
|
||||||
|
#include "mcp2521_hardware_esp.hpp"
|
||||||
|
#include "mcp2521_addresses.hpp"
|
||||||
192
common-libaries/mcp2521/include/mcp2521_addresses.hpp
Normal file
192
common-libaries/mcp2521/include/mcp2521_addresses.hpp
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define MCP2521_BFPCTRL 0x0C
|
||||||
|
#define MCP2521_BFPCTRL_B1BFS (1 << 5)
|
||||||
|
#define MCP2521_BFPCTRL_B0BFS (1 << 4)
|
||||||
|
#define MCP2521_BFPCTRL_B1BFE (1 << 3)
|
||||||
|
#define MCP2521_BFPCTRL_B0BFE (1 << 2)
|
||||||
|
#define MCP2521_BFPCTRL_B1BFM (1 << 1)
|
||||||
|
#define MCP2521_BFPCTRL_B0BFM (1 << 0)
|
||||||
|
|
||||||
|
#define MCP2521_TXRTSCTRL 0x0D
|
||||||
|
#define MCP2521_TXRTSCTRL_B2RTS (1 << 5)
|
||||||
|
#define MCP2521_TXRTSCTRL_B1RTS (1 << 4)
|
||||||
|
#define MCP2521_TXRTSCTRL_B0RTS (1 << 3)
|
||||||
|
#define MCP2521_TXRTSCTRL_B2RTSM (1 << 2)
|
||||||
|
#define MCP2521_TXRTSCTRL_B1RTSM (1 << 1)
|
||||||
|
#define MCP2521_TXRTSCTRL_B0RTSM (1 << 0)
|
||||||
|
|
||||||
|
#define MCP2521_CANSTAT 0x0E
|
||||||
|
#define MCP2521_CANSTAT_OPMOD2 (1 << 7)
|
||||||
|
#define MCP2521_CANSTAT_OPMOD1 (1 << 6)
|
||||||
|
#define MCP2521_CANSTAT_OPMOD0 (1 << 5)
|
||||||
|
#define MCP2521_CANSTAT_ICOD2 (1 << 2)
|
||||||
|
#define MCP2521_CANSTAT_ICOD1 (1 << 1)
|
||||||
|
#define MCP2521_CANSTAT_ICOD0 (1 << 0)
|
||||||
|
|
||||||
|
struct CANSTAT_Register {
|
||||||
|
uint8_t ICOD : 3;
|
||||||
|
uint8_t : 1; // Unused bit
|
||||||
|
uint8_t OPMOD : 3;
|
||||||
|
uint8_t : 1; // Unused bit
|
||||||
|
};
|
||||||
|
|
||||||
|
#define MCP2521_CANCTRL 0x0F
|
||||||
|
#define MCP2521_CANCTRL_REQOP2 (1 << 7)
|
||||||
|
#define MCP2521_CANCTRL_REQOP1 (1 << 6)
|
||||||
|
#define MCP2521_CANCTRL_REQOP0 (1 << 5)
|
||||||
|
#define MCP2521_CANCTRL_ABAT (1 << 4)
|
||||||
|
#define MCP2521_CANCTRL_OSM (1 << 3)
|
||||||
|
#define MCP2521_CANCTRL_CLKEN (1 << 2)
|
||||||
|
#define MCP2521_CANCTRL_CLKPRE1 (1 << 1)
|
||||||
|
#define MCP2521_CANCTRL_CLKPRE0 (1 << 0)
|
||||||
|
|
||||||
|
#define MCP2521_TEC 0x1C
|
||||||
|
|
||||||
|
#define MCP2521_REC 0x1D
|
||||||
|
|
||||||
|
#define MCP2521_CNF3 0x28
|
||||||
|
#define MCP2521_CNF3_SOF (1 << 7)
|
||||||
|
#define MCP2521_CNF3_WAKFIL (1 << 6)
|
||||||
|
#define MCP2521_CNF3_PHSEG22 (1 << 2)
|
||||||
|
#define MCP2521_CNF3_PHSEG21 (1 << 1)
|
||||||
|
#define MCP2521_CNF3_PHSEG20 (1 << 0)
|
||||||
|
|
||||||
|
#define MCP2521_CNF2 0x29
|
||||||
|
#define MCP2521_CNF2_BTLMODE (1 << 7)
|
||||||
|
#define MCP2521_CNF2_SAM (1 << 6)
|
||||||
|
#define MCP2521_CNF2_PHSEG12 (1 << 5)
|
||||||
|
#define MCP2521_CNF2_PHSEG11 (1 << 4)
|
||||||
|
#define MCP2521_CNF2_PHSEG10 (1 << 3)
|
||||||
|
#define MCP2521_CNF2_PRSEG2 (1 << 2)
|
||||||
|
#define MCP2521_CNF2_PRSEG1 (1 << 1)
|
||||||
|
#define MCP2521_CNF2_PRSEG0 (1 << 0)
|
||||||
|
|
||||||
|
#define MCP2521_CNF1 0x2A
|
||||||
|
#define MCP2521_CNF1_SJW1 (1 << 7)
|
||||||
|
#define MCP2521_CNF1_SJW0 (1 << 6)
|
||||||
|
#define MCP2521_CNF1_BRP5 (1 << 5)
|
||||||
|
#define MCP2521_CNF1_BRP4 (1 << 4)
|
||||||
|
#define MCP2521_CNF1_BRP3 (1 << 3)
|
||||||
|
#define MCP2521_CNF1_BRP2 (1 << 2)
|
||||||
|
#define MCP2521_CNF1_BRP1 (1 << 1)
|
||||||
|
#define MCP2521_CNF1_BRP0 (1 << 0)
|
||||||
|
|
||||||
|
#define MCP2521_CANINTE 0x2B
|
||||||
|
#define MCP2521_CANINTE_MERRE (1 << 7)
|
||||||
|
#define MCP2521_CANINTE_WAKIE (1 << 6)
|
||||||
|
#define MCP2521_CANINTE_ERRIE (1 << 5)
|
||||||
|
#define MCP2521_CANINTE_TX2IE (1 << 4)
|
||||||
|
#define MCP2521_CANINTE_TX1IE (1 << 3)
|
||||||
|
#define MCP2521_CANINTE_TX0IE (1 << 2)
|
||||||
|
#define MCP2521_CANINTE_RX1IE (1 << 1)
|
||||||
|
#define MCP2521_CANINTE_RX0IE (1 << 0)
|
||||||
|
|
||||||
|
#define MCP2521_CANINTF 0x2C
|
||||||
|
#define MCP2521_CANINTF_MERRF (1 << 7)
|
||||||
|
#define MCP2521_CANINTF_WAKIF (1 << 6)
|
||||||
|
#define MCP2521_CANINTF_ERRIF (1 << 5)
|
||||||
|
#define MCP2521_CANINTF_TX2IF (1 << 4)
|
||||||
|
#define MCP2521_CANINTF_TX1IF (1 << 3)
|
||||||
|
#define MCP2521_CANINTF_TX0IF (1 << 2)
|
||||||
|
#define MCP2521_CANINTF_RX1IF (1 << 1)
|
||||||
|
#define MCP2521_CANINTF_RX0IF (1 << 0)
|
||||||
|
|
||||||
|
#define MCP2521_EFLG 0x2D
|
||||||
|
#define MCP2521_EFLG_RX1OVR (1 << 7)
|
||||||
|
#define MCP2521_EFLG_RX0OVR (1 << 6)
|
||||||
|
#define MCP2521_EFLG_TXBO (1 << 5)
|
||||||
|
#define MCP2521_EFLG_TXEP (1 << 4)
|
||||||
|
#define MCP2521_EFLG_RXEP (1 << 3)
|
||||||
|
#define MCP2521_EFLG_TXWAR (1 << 2)
|
||||||
|
#define MCP2521_EFLG_RXWAR (1 << 1)
|
||||||
|
#define MCP2521_EFLG_EWARN (1 << 0)
|
||||||
|
|
||||||
|
#define MCP2521_TXB0CTRL 0x30
|
||||||
|
#define MCP2521_TXB0CTRL_ABTF (1 << 6)
|
||||||
|
#define MCP2521_TXB0CTRL_MLOA (1 << 5)
|
||||||
|
#define MCP2521_TXB0CTRL_TXERR (1 << 4)
|
||||||
|
#define MCP2521_TXB0CTRL_TXREQ (1 << 3)
|
||||||
|
#define MCP2521_TXB0CTRL_TXP1 (1 << 1)
|
||||||
|
#define MCP2521_TXB0CTRL_TXP0 (1 << 0)
|
||||||
|
|
||||||
|
#define MCP2521_TXB0DLC 0x35
|
||||||
|
#define MCP2521_TXB1DLC 0x45
|
||||||
|
#define MCP2521_TXB2DLC 0x55
|
||||||
|
|
||||||
|
#define MCP2521_TXB1CTRL 0x40
|
||||||
|
#define MCP2521_TXB1CTRL_ABTF (1 << 6)
|
||||||
|
#define MCP2521_TXB1CTRL_MLOA (1 << 5)
|
||||||
|
#define MCP2521_TXB1CTRL_TXERR (1 << 4)
|
||||||
|
#define MCP2521_TXB1CTRL_TXREQ (1 << 3)
|
||||||
|
#define MCP2521_TXB1CTRL_TXP1 (1 << 1)
|
||||||
|
#define MCP2521_TXB1CTRL_TXP0 (1 << 0)
|
||||||
|
|
||||||
|
#define MCP2521_TXB2CTRL 0x50
|
||||||
|
#define MCP2521_TXB2CTRL_ABTF (1 << 6)
|
||||||
|
#define MCP2521_TXB2CTRL_MLOA (1 << 5)
|
||||||
|
#define MCP2521_TXB2CTRL_TXERR (1 << 4)
|
||||||
|
#define MCP2521_TXB2CTRL_TXREQ (1 << 3)
|
||||||
|
#define MCP2521_TXB2CTRL_TXP1 (1 << 1)
|
||||||
|
#define MCP2521_TXB2CTRL_TXP0 (1 << 0)
|
||||||
|
|
||||||
|
struct TXBnCTRL_Register {
|
||||||
|
uint8_t TXP : 2;
|
||||||
|
uint8_t : 1; // Unused bit
|
||||||
|
uint8_t TXREQ : 1;
|
||||||
|
uint8_t TXERR : 1;
|
||||||
|
uint8_t MLOA : 1;
|
||||||
|
uint8_t ABTF : 1;
|
||||||
|
uint8_t : 1; // Unused bit
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#define MCP2521_RXB0CTRL 0x60
|
||||||
|
#define MCP2521_RXB0CTRL_RXM1 (1 << 6)
|
||||||
|
#define MCP2521_RXB0CTRL_RXM0 (1 << 5)
|
||||||
|
#define MCP2521_RXB0CTRL_RXRTR (1 << 3)
|
||||||
|
#define MCP2521_RXB0CTRL_BUKT (1 << 2)
|
||||||
|
#define MCP2521_RXB0CTRL_BUKT1 (1 << 1)
|
||||||
|
#define MCP2521_RXB0CTRL_FILHIT0 (1 << 0)
|
||||||
|
|
||||||
|
#define MCP2521_RXB1CTRL 0x70
|
||||||
|
#define MCP2521_RXB1CTRL_RXM1 (1 << 6)
|
||||||
|
#define MCP2521_RXB1CTRL_RXM0 (1 << 5)
|
||||||
|
#define MCP2521_RXB1CTRL_RXRTR (1 << 3)
|
||||||
|
#define MCP2521_RXB1CTRL_FILHIT2 (1 << 2)
|
||||||
|
#define MCP2521_RXB1CTRL_FILHIT1 (1 << 1)
|
||||||
|
#define MCP2521_RXB1CTRL_FILHIT0 (1 << 0)
|
||||||
|
|
||||||
|
#define MCP2521_OP_RESET 0b11000000
|
||||||
|
#define MCP2521_OP_READ 0b00000011
|
||||||
|
#define MCP2521_OP_READ_RX_BUFFER 0b10010000
|
||||||
|
#define MCP2521_OP_WRITE 0b00000010
|
||||||
|
#define MCP2521_OP_LOAD_TX_BUFFER 0b01000000
|
||||||
|
#define MCP2521_OP_RTS 0b10000000
|
||||||
|
#define MCP2521_OP_READ_STATUS 0b10100000
|
||||||
|
#define MCP2521_OP_RX_STATUS 0b10110000
|
||||||
|
#define MCP2521_OP_BIT_MODIFY 0b00000101
|
||||||
|
|
||||||
|
#define MCP2521_TXB0SIDH 0x31
|
||||||
|
#define MCP2521_TXB1SIDH 0x41
|
||||||
|
#define MCP2521_TXB2SIDH 0x51
|
||||||
|
|
||||||
|
#define MCP2521_TXB0SIDL 0x32
|
||||||
|
#define MCP2521_TXB1SIDL 0x42
|
||||||
|
#define MCP2521_TXB2SIDL 0x52
|
||||||
|
|
||||||
|
#define MCP2521_RXB0SIDH 0x61
|
||||||
|
#define MCP2521_RXB1SIDH 0x71
|
||||||
|
|
||||||
|
#define MCP2521_RXB0SIDL 0x62
|
||||||
|
#define MCP2521_RXB1SIDL 0x72
|
||||||
|
|
||||||
|
#define MCP2521_RXB0EID8 0x63
|
||||||
|
#define MCP2521_RXB1EID8 0x73
|
||||||
|
|
||||||
|
#define MCP2521_RXB0EID0 0x64
|
||||||
|
#define MCP2521_RXB1EID0 0x74
|
||||||
|
|
||||||
|
#define MCP2521_RXB0DLC 0x65
|
||||||
|
#define MCP2521_RXB1DLC 0x75
|
||||||
102
common-libaries/mcp2521/include/mcp2521_command.hpp
Normal file
102
common-libaries/mcp2521/include/mcp2521_command.hpp
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "mcp2521_addresses.hpp"
|
||||||
|
#include "mcp2521_hardware_handle.hpp"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
enum MCP2521_RX_BUFFER {
|
||||||
|
RXB0 = 0,
|
||||||
|
RXB1 = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
enum MCP2521_TX_BUFFER {
|
||||||
|
TXB0 = 0,
|
||||||
|
TXB1 = 1,
|
||||||
|
TXB2 = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
enum MCP2521_BUFFER_TYPE {
|
||||||
|
ID = 0,
|
||||||
|
DATA = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
enum MCP2521_OPERATION_MODE {
|
||||||
|
NORMAL = 0b000,
|
||||||
|
SLEEP = 0b001,
|
||||||
|
LOOPBACK = 0b010,
|
||||||
|
LISTEN_ONLY = 0b011,
|
||||||
|
CONFIG = 0b100
|
||||||
|
};
|
||||||
|
|
||||||
|
struct rx_info {
|
||||||
|
bool extended;
|
||||||
|
|
||||||
|
uint16_t id;
|
||||||
|
uint32_t extended_id;
|
||||||
|
|
||||||
|
bool rtr;
|
||||||
|
bool extended_rtr;
|
||||||
|
|
||||||
|
uint8_t length;
|
||||||
|
};
|
||||||
|
|
||||||
|
class MCP2521_Command_Interface {
|
||||||
|
private:
|
||||||
|
MCP2521_Hardware_Handle * hardware_handle;
|
||||||
|
|
||||||
|
intHandlerFunction_t rx0_handler;
|
||||||
|
intHandlerFunction_t rx1_handler;
|
||||||
|
intHandlerFunction_t tx0_handler;
|
||||||
|
intHandlerFunction_t tx1_handler;
|
||||||
|
intHandlerFunction_t tx2_handler;
|
||||||
|
intHandlerFunction_t error_handler;
|
||||||
|
intHandlerFunction_t wakeup_handler;
|
||||||
|
intHandlerFunction_t message_error_handler;
|
||||||
|
|
||||||
|
void * rx0_handler_arg;
|
||||||
|
void * rx1_handler_arg;
|
||||||
|
void * tx0_handler_arg;
|
||||||
|
void * tx1_handler_arg;
|
||||||
|
void * tx2_handler_arg;
|
||||||
|
void * error_handler_arg;
|
||||||
|
void * wakeup_handler_arg;
|
||||||
|
void * message_error_handler_arg;
|
||||||
|
public:
|
||||||
|
|
||||||
|
MCP2521_Command_Interface(
|
||||||
|
MCP2521_Hardware_Handle * hardware_handle
|
||||||
|
);
|
||||||
|
|
||||||
|
void handleInterrupt();
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
void read_reg(uint8_t address, uint8_t *data, size_t length);
|
||||||
|
uint8_t read_reg(uint8_t address);
|
||||||
|
|
||||||
|
void read_rx_buf(MCP2521_RX_BUFFER buffer, MCP2521_BUFFER_TYPE type, uint8_t *data, size_t length);
|
||||||
|
|
||||||
|
void write_reg(uint8_t address, uint8_t *data, size_t length);
|
||||||
|
void write_reg(uint8_t address, uint8_t data);
|
||||||
|
|
||||||
|
void write_tx_buf(MCP2521_TX_BUFFER buffer, MCP2521_BUFFER_TYPE type, uint8_t *data, size_t length);
|
||||||
|
|
||||||
|
void request_to_send(bool txb2, bool txb1, bool txb0);
|
||||||
|
void request_to_send(MCP2521_TX_BUFFER buffer);
|
||||||
|
|
||||||
|
uint8_t read_status();
|
||||||
|
uint8_t read_rx_status();
|
||||||
|
|
||||||
|
void bit_modify(uint8_t address, uint8_t mask, uint8_t data);
|
||||||
|
|
||||||
|
// Registering Handlers for Interrupts
|
||||||
|
void register_rx0_handler(intHandlerFunction_t handler, void * arg);
|
||||||
|
void register_rx1_handler(intHandlerFunction_t handler, void * arg);
|
||||||
|
void register_tx0_handler(intHandlerFunction_t handler, void * arg);
|
||||||
|
void register_tx1_handler(intHandlerFunction_t handler, void * arg);
|
||||||
|
void register_tx2_handler(intHandlerFunction_t handler, void * arg);
|
||||||
|
void register_error_handler(intHandlerFunction_t handler, void * arg);
|
||||||
|
void register_wakeup_handler(intHandlerFunction_t handler, void * arg);
|
||||||
|
void register_message_error_handler(intHandlerFunction_t handler, void * arg);
|
||||||
|
};
|
||||||
|
|
||||||
38
common-libaries/mcp2521/include/mcp2521_toplevel.hpp
Normal file
38
common-libaries/mcp2521/include/mcp2521_toplevel.hpp
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "mcp2521.hpp"
|
||||||
|
#include "mcp2521_command.hpp"
|
||||||
|
#include "mcp2521_addresses.hpp"
|
||||||
|
|
||||||
|
class MCP2521 : public MCP2521_Command_Interface {
|
||||||
|
private:
|
||||||
|
public:
|
||||||
|
void set_tx_id(MCP2521_TX_BUFFER buffer, uint16_t id, bool extended);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Loads the Data Length Code register for the specified buffer
|
||||||
|
*
|
||||||
|
* @param buffer What Buffer to load the DLC register for
|
||||||
|
* @param length How many bytes are in the message (0-8)
|
||||||
|
* @param rtr: Remote Transmission Request
|
||||||
|
*/
|
||||||
|
void set_DLC_reg(MCP2521_TX_BUFFER buffer, uint8_t length, bool rtr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Loads the data and id into the specified buffer
|
||||||
|
*
|
||||||
|
* @param buffer
|
||||||
|
* @param id
|
||||||
|
* @param data
|
||||||
|
* @param length
|
||||||
|
*/
|
||||||
|
void prepare_tx(MCP2521_TX_BUFFER buffer, uint32_t id, uint8_t *data, size_t length, bool rtr, bool extended);
|
||||||
|
|
||||||
|
void set_mode_of_operation(MCP2521_OPERATION_MODE mode, bool singleshot);
|
||||||
|
void set_singleshot_mode(bool enable);
|
||||||
|
|
||||||
|
void enable_interrupts(bool MessageError, bool ErrorInterrupt, bool WakeUp, bool TXB0, bool TXB1, bool TXB2, bool RXB0, bool RXB1);
|
||||||
|
rx_info get_rx_id(MCP2521_RX_BUFFER buffer);
|
||||||
|
|
||||||
|
};
|
||||||
100
common-libaries/mcp2521/interface_commands.cpp
Normal file
100
common-libaries/mcp2521/interface_commands.cpp
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "mcp2521.hpp"
|
||||||
|
#include "mcp2521_addresses.hpp"
|
||||||
|
|
||||||
|
void runIntHandler(void *arg) {
|
||||||
|
MCP2521_Command_Interface *command_interface = (MCP2521_Command_Interface *)arg;
|
||||||
|
command_interface->handleInterrupt();
|
||||||
|
}
|
||||||
|
|
||||||
|
MCP2521_Command_Interface::MCP2521_Command_Interface(
|
||||||
|
MCP2521_Hardware_Handle * hardware_handle
|
||||||
|
) {
|
||||||
|
this->hardware_handle = hardware_handle;
|
||||||
|
this->hardware_handle->registerIntHandler(runIntHandler, (void *)this);
|
||||||
|
|
||||||
|
rx0_handler = NULL;
|
||||||
|
rx1_handler = NULL;
|
||||||
|
tx0_handler = NULL;
|
||||||
|
tx1_handler = NULL;
|
||||||
|
tx2_handler = NULL;
|
||||||
|
error_handler = NULL;
|
||||||
|
wakeup_handler = NULL;
|
||||||
|
message_error_handler = NULL;
|
||||||
|
|
||||||
|
rx0_handler_arg = NULL;
|
||||||
|
rx1_handler_arg = NULL;
|
||||||
|
tx0_handler_arg = NULL;
|
||||||
|
tx1_handler_arg = NULL;
|
||||||
|
tx2_handler_arg = NULL;
|
||||||
|
error_handler_arg = NULL;
|
||||||
|
wakeup_handler_arg = NULL;
|
||||||
|
message_error_handler_arg = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Command_Interface::reset() {
|
||||||
|
hardware_handle->execute(MCP2521_OP_RESET);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Command_Interface::read_reg(uint8_t address, uint8_t *data, size_t length) {
|
||||||
|
hardware_handle->read(MCP2521_OP_READ, data, length, address);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t MCP2521_Command_Interface::read_reg(uint8_t address) {
|
||||||
|
return hardware_handle->read(MCP2521_OP_READ, address);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Command_Interface::read_rx_buf(MCP2521_RX_BUFFER buffer, MCP2521_BUFFER_TYPE type, uint8_t *data, size_t length) {
|
||||||
|
uint8_t address = (buffer << 1) | (type << 2);
|
||||||
|
hardware_handle->read(MCP2521_OP_READ_RX_BUFFER | address, data, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Command_Interface::write_reg(uint8_t address, uint8_t *data, size_t length) {
|
||||||
|
hardware_handle->write(MCP2521_OP_WRITE, data, length, address);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Command_Interface::write_reg(uint8_t address, uint8_t data) {
|
||||||
|
hardware_handle->write(MCP2521_OP_WRITE, data, address);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Command_Interface::write_tx_buf(MCP2521_TX_BUFFER buffer, MCP2521_BUFFER_TYPE type, uint8_t *data, size_t length) {
|
||||||
|
uint8_t address = (buffer << 1) | (type);
|
||||||
|
hardware_handle->write(MCP2521_OP_LOAD_TX_BUFFER | address, data, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Command_Interface::request_to_send(bool txb2, bool txb1, bool txb0) {
|
||||||
|
uint8_t data = (txb2 << 2) | (txb1 << 1) | txb0;
|
||||||
|
hardware_handle->execute(MCP2521_OP_RTS | data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Command_Interface::request_to_send(MCP2521_TX_BUFFER buffer) {
|
||||||
|
uint8_t mask = 0;
|
||||||
|
|
||||||
|
switch (buffer) {
|
||||||
|
case MCP2521_TX_BUFFER::TXB0:
|
||||||
|
mask = 0b001;
|
||||||
|
break;
|
||||||
|
case MCP2521_TX_BUFFER::TXB1:
|
||||||
|
mask = 0b010;
|
||||||
|
break;
|
||||||
|
case MCP2521_TX_BUFFER::TXB2:
|
||||||
|
mask = 0b100;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
hardware_handle->execute(MCP2521_OP_RTS | mask);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t MCP2521_Command_Interface::read_status() {
|
||||||
|
return hardware_handle->read(MCP2521_OP_READ_STATUS);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t MCP2521_Command_Interface::read_rx_status() {
|
||||||
|
return hardware_handle->read(MCP2521_OP_RX_STATUS);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Command_Interface::bit_modify(uint8_t address, uint8_t mask, uint8_t data) {
|
||||||
|
uint8_t data_array[3] = {address, mask, data};
|
||||||
|
hardware_handle->write(MCP2521_OP_BIT_MODIFY, data_array, 3);
|
||||||
|
}
|
||||||
113
common-libaries/mcp2521/interface_interrupts.cpp
Normal file
113
common-libaries/mcp2521/interface_interrupts.cpp
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
#include "mcp2521.hpp"
|
||||||
|
#include "mcp2521_addresses.hpp"
|
||||||
|
|
||||||
|
void MCP2521_Command_Interface::register_rx0_handler(intHandlerFunction_t handler, void* args) {
|
||||||
|
rx0_handler = handler;
|
||||||
|
rx0_handler_arg = args;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Command_Interface::register_rx1_handler(intHandlerFunction_t handler, void* args) {
|
||||||
|
rx1_handler = handler;
|
||||||
|
rx1_handler_arg = args;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Command_Interface::register_tx0_handler(intHandlerFunction_t handler, void* args) {
|
||||||
|
tx0_handler = handler;
|
||||||
|
tx0_handler_arg = args;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Command_Interface::register_tx1_handler(intHandlerFunction_t handler, void* args) {
|
||||||
|
tx1_handler = handler;
|
||||||
|
tx1_handler_arg = args;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Command_Interface::register_tx2_handler(intHandlerFunction_t handler, void* args) {
|
||||||
|
tx2_handler = handler;
|
||||||
|
tx2_handler_arg = args;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Command_Interface::register_error_handler(intHandlerFunction_t handler, void* args) {
|
||||||
|
error_handler = handler;
|
||||||
|
error_handler_arg = args;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Command_Interface::register_wakeup_handler(intHandlerFunction_t handler, void* args) {
|
||||||
|
wakeup_handler = handler;
|
||||||
|
wakeup_handler_arg = args;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Command_Interface::register_message_error_handler(intHandlerFunction_t handler, void* args) {
|
||||||
|
message_error_handler = handler;
|
||||||
|
message_error_handler_arg = args;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Command_Interface::handleInterrupt() {
|
||||||
|
uint8_t flags = read_reg(MCP2521_CANINTF);
|
||||||
|
uint8_t clearBits = 0;
|
||||||
|
|
||||||
|
if (flags & MCP2521_CANINTF_RX0IF) {
|
||||||
|
if (rx0_handler) {
|
||||||
|
rx0_handler(rx0_handler_arg);
|
||||||
|
}
|
||||||
|
flags &= ~MCP2521_CANINTF_RX0IF;
|
||||||
|
clearBits |= MCP2521_CANINTF_RX0IF;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & MCP2521_CANINTF_RX1IF) {
|
||||||
|
if (rx1_handler) {
|
||||||
|
rx1_handler(rx1_handler_arg);
|
||||||
|
}
|
||||||
|
flags &= ~MCP2521_CANINTF_RX1IF;
|
||||||
|
clearBits |= MCP2521_CANINTF_RX1IF;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & MCP2521_CANINTF_TX0IF) {
|
||||||
|
if (tx0_handler) {
|
||||||
|
tx0_handler(tx0_handler_arg);
|
||||||
|
}
|
||||||
|
flags &= ~MCP2521_CANINTF_TX0IF;
|
||||||
|
clearBits |= MCP2521_CANINTF_TX0IF;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & MCP2521_CANINTF_TX1IF) {
|
||||||
|
if (tx1_handler) {
|
||||||
|
tx1_handler(tx1_handler_arg);
|
||||||
|
}
|
||||||
|
flags &= ~MCP2521_CANINTF_TX1IF;
|
||||||
|
clearBits |= MCP2521_CANINTF_TX1IF;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & MCP2521_CANINTF_TX2IF) {
|
||||||
|
if (tx2_handler) {
|
||||||
|
tx2_handler(tx2_handler_arg);
|
||||||
|
}
|
||||||
|
flags &= ~MCP2521_CANINTF_TX2IF;
|
||||||
|
clearBits |= MCP2521_CANINTF_TX2IF;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & MCP2521_CANINTF_ERRIF) {
|
||||||
|
if (error_handler) {
|
||||||
|
error_handler(error_handler_arg);
|
||||||
|
}
|
||||||
|
flags &= ~MCP2521_CANINTF_ERRIF;
|
||||||
|
clearBits |= MCP2521_CANINTF_ERRIF;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & MCP2521_CANINTF_WAKIF) {
|
||||||
|
if (wakeup_handler) {
|
||||||
|
wakeup_handler(wakeup_handler_arg);
|
||||||
|
}
|
||||||
|
flags &= ~MCP2521_CANINTF_WAKIF;
|
||||||
|
clearBits |= MCP2521_CANINTF_WAKIF;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & MCP2521_CANINTF_MERRF) {
|
||||||
|
if (message_error_handler) {
|
||||||
|
message_error_handler(message_error_handler_arg);
|
||||||
|
}
|
||||||
|
flags &= ~MCP2521_CANINTF_MERRF;
|
||||||
|
clearBits |= MCP2521_CANINTF_MERRF;
|
||||||
|
}
|
||||||
|
|
||||||
|
bit_modify(MCP2521_CANINTF, clearBits, 0);
|
||||||
|
}
|
||||||
119
common-libaries/mcp2521/toplevel_commands.cpp
Normal file
119
common-libaries/mcp2521/toplevel_commands.cpp
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "mcp2521.hpp"
|
||||||
|
#include "mcp2521_addresses.hpp"
|
||||||
|
|
||||||
|
void MCP2521::set_tx_id(MCP2521_TX_BUFFER buffer, uint16_t id, bool extended) {
|
||||||
|
uint8_t addr_offset = 0;
|
||||||
|
switch (buffer)
|
||||||
|
{
|
||||||
|
case MCP2521_TX_BUFFER::TXB0:
|
||||||
|
addr_offset = 0x00;
|
||||||
|
break;
|
||||||
|
case MCP2521_TX_BUFFER::TXB1:
|
||||||
|
addr_offset = 0x10;
|
||||||
|
break;
|
||||||
|
case MCP2521_TX_BUFFER::TXB2:
|
||||||
|
addr_offset = 0x20;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t upper_id = (id >> 3) & 0xFF;
|
||||||
|
uint8_t lower_id = ((id & 0b111) << 5);
|
||||||
|
|
||||||
|
if(extended) {
|
||||||
|
lower_id |= 0b1000;
|
||||||
|
lower_id |= (id >> 8) & 0b11;
|
||||||
|
}
|
||||||
|
|
||||||
|
write_reg(MCP2521_TXB0SIDH | addr_offset, upper_id);
|
||||||
|
write_reg(MCP2521_TXB0SIDL | addr_offset, lower_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521::set_DLC_reg(MCP2521_TX_BUFFER buffer, uint8_t length, bool rtr) {
|
||||||
|
uint8_t data = length;
|
||||||
|
|
||||||
|
if (rtr)
|
||||||
|
data |= 0b01000000;
|
||||||
|
|
||||||
|
uint8_t reg_address = 0;
|
||||||
|
|
||||||
|
switch (buffer) {
|
||||||
|
case MCP2521_TX_BUFFER::TXB0:
|
||||||
|
reg_address = MCP2521_TXB0DLC;
|
||||||
|
break;
|
||||||
|
case MCP2521_TX_BUFFER::TXB1:
|
||||||
|
reg_address = MCP2521_TXB1DLC;
|
||||||
|
break;
|
||||||
|
case MCP2521_TX_BUFFER::TXB2:
|
||||||
|
reg_address = MCP2521_TXB2DLC;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
write_reg(reg_address, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521::set_mode_of_operation(MCP2521_OPERATION_MODE mode, bool singleshot) {
|
||||||
|
|
||||||
|
uint8_t single = singleshot ? 0b00001000 : 0x0;
|
||||||
|
|
||||||
|
bit_modify(MCP2521_CANCTRL, 0b11101000 , (mode << 5) | single);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521::set_singleshot_mode(bool enable) {
|
||||||
|
uint8_t data = enable ? 0x08 : 0x00;
|
||||||
|
bit_modify(MCP2521_CANCTRL, 0x08, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521::enable_interrupts(bool MessageError, bool ErrorInterrupt, bool WakeUp, bool TXB0, bool TXB1, bool TXB2, bool RXB0, bool RXB1) {
|
||||||
|
uint8_t interrupt_flags = 0;
|
||||||
|
|
||||||
|
if (MessageError) interrupt_flags |= 0b10000000;
|
||||||
|
if (WakeUp) interrupt_flags |= 0b01000000;
|
||||||
|
if (ErrorInterrupt) interrupt_flags |= 0b00100000;
|
||||||
|
if (TXB2) interrupt_flags |= 0b00010000;
|
||||||
|
if (TXB1) interrupt_flags |= 0b00001000;
|
||||||
|
if (TXB0) interrupt_flags |= 0b00000100;
|
||||||
|
if (RXB1) interrupt_flags |= 0b00000010;
|
||||||
|
if (RXB0) interrupt_flags |= 0b00000001;
|
||||||
|
|
||||||
|
write_reg(MCP2521_CANINTE, interrupt_flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
rx_info MCP2521::get_rx_id(MCP2521_RX_BUFFER buffer) {
|
||||||
|
uint8_t data[5];
|
||||||
|
uint8_t addr_offset = MCP2521_RXB0SIDH;
|
||||||
|
|
||||||
|
switch (buffer) {
|
||||||
|
case MCP2521_RX_BUFFER::RXB0:
|
||||||
|
addr_offset |= 0x00;
|
||||||
|
break;
|
||||||
|
case MCP2521_RX_BUFFER::RXB1:
|
||||||
|
addr_offset |= 0x10;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
read_reg(addr_offset, data, 5);
|
||||||
|
|
||||||
|
rx_info res;
|
||||||
|
res.extended = data[1] & 0b1000;
|
||||||
|
res.id = (data[0] << 3) | (data[1] >> 5);
|
||||||
|
res.extended_id = ((data[1] & 0b11) << 16) | (data[2] << 8) | data[3];
|
||||||
|
res.rtr = data[1] & 0b10000;
|
||||||
|
res.extended_rtr = (data[4] & 0b1000000);
|
||||||
|
res.length = (data[4] & 0b1111);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521::prepare_tx(
|
||||||
|
MCP2521_TX_BUFFER buffer,
|
||||||
|
uint32_t id,
|
||||||
|
uint8_t *data,
|
||||||
|
size_t length,
|
||||||
|
bool rtr, bool extended) {
|
||||||
|
|
||||||
|
set_tx_id(buffer, id, extended);
|
||||||
|
set_DLC_reg(buffer, length, rtr);
|
||||||
|
write_tx_buf(buffer, MCP2521_BUFFER_TYPE::DATA, data, length);
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
idf_component_register(SRCS "esp_implementation_init.cpp"
|
||||||
|
"esp_implementation_cmd.cpp"
|
||||||
|
"esp_implementation_int.cpp"
|
||||||
|
INCLUDE_DIRS "include"
|
||||||
|
REQUIRES driver)
|
||||||
@@ -0,0 +1,209 @@
|
|||||||
|
#include "mcp2521_hardware_handle.hpp"
|
||||||
|
|
||||||
|
#ifdef ESP_PLATFORM
|
||||||
|
#include "mcp2521_hardware_esp.hpp"
|
||||||
|
|
||||||
|
const uint8_t null_buffer[32] = {0};
|
||||||
|
|
||||||
|
void MCP2521_Hardware_Handle_ESP::spi_transmit(spi_transaction_t *t) {
|
||||||
|
xSemaphoreTake(spiMutex, portMAX_DELAY);
|
||||||
|
spi_device_transmit(this->spi_device_handle, t);
|
||||||
|
xSemaphoreGive(spiMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Hardware_Handle_ESP::execute(uint8_t cmd) {
|
||||||
|
spi_transaction_ext_t t = {
|
||||||
|
.base = {
|
||||||
|
.flags = SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR,
|
||||||
|
.cmd = cmd,
|
||||||
|
.addr = 0,
|
||||||
|
.length = 0,
|
||||||
|
.rxlength = 0,
|
||||||
|
.tx_buffer = NULL,
|
||||||
|
.rx_buffer = NULL
|
||||||
|
},
|
||||||
|
.command_bits = 8,
|
||||||
|
.address_bits = 0,
|
||||||
|
.dummy_bits = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
spi_transmit((spi_transaction_t*)(&t));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Hardware_Handle_ESP::execute(uint8_t cmd, uint8_t address) {
|
||||||
|
spi_transaction_ext_t t = {
|
||||||
|
.base = {
|
||||||
|
.flags = SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR,
|
||||||
|
.cmd = cmd,
|
||||||
|
.addr = address,
|
||||||
|
.length = 0,
|
||||||
|
.rxlength = 0,
|
||||||
|
.tx_buffer = NULL,
|
||||||
|
.rx_buffer = NULL
|
||||||
|
},
|
||||||
|
.command_bits = 8,
|
||||||
|
.address_bits = 8,
|
||||||
|
.dummy_bits = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
spi_transmit((spi_transaction_t*)(&t));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t *data, size_t length, uint8_t address) {
|
||||||
|
spi_transaction_ext_t t = {
|
||||||
|
.base = {
|
||||||
|
.flags = SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR,
|
||||||
|
.cmd = cmd,
|
||||||
|
.addr = address,
|
||||||
|
.length = 8*length,
|
||||||
|
.rxlength = 8*length,
|
||||||
|
.tx_buffer = null_buffer,
|
||||||
|
.rx_buffer = data
|
||||||
|
},
|
||||||
|
.command_bits = 8,
|
||||||
|
.address_bits = 8,
|
||||||
|
.dummy_bits = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
spi_transmit((spi_transaction_t*)(&t));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t *data, size_t length) {
|
||||||
|
spi_transaction_ext_t t = {
|
||||||
|
.base = {
|
||||||
|
.flags = SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR,
|
||||||
|
.cmd = cmd,
|
||||||
|
.addr = 0,
|
||||||
|
.length = 8*length,
|
||||||
|
.rxlength = 8*length,
|
||||||
|
.tx_buffer = NULL,
|
||||||
|
.rx_buffer = data
|
||||||
|
},
|
||||||
|
.command_bits = 8,
|
||||||
|
.address_bits = 0,
|
||||||
|
.dummy_bits = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
spi_transmit((spi_transaction_t*)(&t));
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t address) {
|
||||||
|
uint8_t result = 0;
|
||||||
|
spi_transaction_ext_t t = {
|
||||||
|
.base = {
|
||||||
|
.flags = SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR,
|
||||||
|
.cmd = cmd,
|
||||||
|
.addr = address,
|
||||||
|
.length = 8,
|
||||||
|
.rxlength = 8,
|
||||||
|
.tx_buffer = null_buffer,
|
||||||
|
.rx_buffer = &result
|
||||||
|
},
|
||||||
|
.command_bits = 8,
|
||||||
|
.address_bits = 8,
|
||||||
|
.dummy_bits = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
spi_transmit((spi_transaction_t*)(&t));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t MCP2521_Hardware_Handle_ESP::read(uint8_t cmd) {
|
||||||
|
uint8_t result;
|
||||||
|
spi_transaction_ext_t t = {
|
||||||
|
.base = {
|
||||||
|
.flags = SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR,
|
||||||
|
.cmd = cmd,
|
||||||
|
.addr = 0,
|
||||||
|
.length = 8,
|
||||||
|
.rxlength = 8,
|
||||||
|
.tx_buffer = null_buffer,
|
||||||
|
.rx_buffer = &result
|
||||||
|
},
|
||||||
|
.command_bits = 8,
|
||||||
|
.address_bits = 0,
|
||||||
|
.dummy_bits = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
spi_transmit((spi_transaction_t*)(&t));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t *data, size_t length, uint8_t address) {
|
||||||
|
uint8_t result;
|
||||||
|
spi_transaction_ext_t t = {
|
||||||
|
.base = {
|
||||||
|
.flags = SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR,
|
||||||
|
.cmd = cmd,
|
||||||
|
.addr = address,
|
||||||
|
.length = 8*length,
|
||||||
|
.rxlength = 0,
|
||||||
|
.tx_buffer = data,
|
||||||
|
.rx_buffer = NULL
|
||||||
|
},
|
||||||
|
.command_bits = 8,
|
||||||
|
.address_bits = 8,
|
||||||
|
.dummy_bits = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
spi_transmit((spi_transaction_t*)(&t));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t *data, size_t length) {
|
||||||
|
spi_transaction_ext_t t = {
|
||||||
|
.base = {
|
||||||
|
.flags = SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR,
|
||||||
|
.cmd = cmd,
|
||||||
|
.addr = 0,
|
||||||
|
.length = 8*length,
|
||||||
|
.rxlength = 0,
|
||||||
|
.tx_buffer = data,
|
||||||
|
.rx_buffer = NULL
|
||||||
|
},
|
||||||
|
.command_bits = 8,
|
||||||
|
.address_bits = 0,
|
||||||
|
.dummy_bits = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
spi_transmit((spi_transaction_t*)(&t));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t data, uint8_t address) {
|
||||||
|
spi_transaction_ext_t t = {
|
||||||
|
.base = {
|
||||||
|
.flags = SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR,
|
||||||
|
.cmd = cmd,
|
||||||
|
.addr = address,
|
||||||
|
.length = 8,
|
||||||
|
.rxlength = 0,
|
||||||
|
.tx_buffer = &data,
|
||||||
|
.rx_buffer = NULL
|
||||||
|
},
|
||||||
|
.command_bits = 8,
|
||||||
|
.address_bits = 8,
|
||||||
|
.dummy_bits = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
spi_transmit((spi_transaction_t*)(&t));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t data) {
|
||||||
|
spi_transaction_ext_t t = {
|
||||||
|
.base = {
|
||||||
|
.flags = SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR,
|
||||||
|
.cmd = cmd,
|
||||||
|
.addr = 0,
|
||||||
|
.length = 8,
|
||||||
|
.rxlength = 0,
|
||||||
|
.tx_buffer = &data,
|
||||||
|
.rx_buffer = NULL
|
||||||
|
},
|
||||||
|
.command_bits = 8,
|
||||||
|
.address_bits = 0,
|
||||||
|
.dummy_bits = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
spi_transmit((spi_transaction_t*)(&t));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
#include "mcp2521_hardware_handle.hpp"
|
||||||
|
|
||||||
|
#ifdef ESP_PLATFORM
|
||||||
|
#include "mcp2521_hardware_esp.hpp"
|
||||||
|
#include "driver/gpio.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
|
||||||
|
MCP2521_Hardware_Handle_ESP::MCP2521_Hardware_Handle_ESP(
|
||||||
|
spi_host_device_t spi_host,
|
||||||
|
spi_bus_config_t *bus_config,
|
||||||
|
gpio_num_t mosi,
|
||||||
|
gpio_num_t miso,
|
||||||
|
gpio_num_t sclk,
|
||||||
|
gpio_num_t cs,
|
||||||
|
gpio_num_t int_pin
|
||||||
|
) {
|
||||||
|
initPins(int_pin);
|
||||||
|
initSPIBus(spi_host, mosi, miso, sclk, bus_config);
|
||||||
|
this->spi_bus_config = bus_config;
|
||||||
|
initSPIDevice(spi_host, cs);
|
||||||
|
}
|
||||||
|
|
||||||
|
MCP2521_Hardware_Handle_ESP::MCP2521_Hardware_Handle_ESP(
|
||||||
|
spi_host_device_t spi_host,
|
||||||
|
spi_bus_config_t *bus_config,
|
||||||
|
gpio_num_t cs,
|
||||||
|
gpio_num_t int_pin
|
||||||
|
) {
|
||||||
|
initPins(int_pin);
|
||||||
|
this->spi_bus_config = bus_config;
|
||||||
|
initSPIDevice(spi_host, cs);
|
||||||
|
}
|
||||||
|
|
||||||
|
MCP2521_Hardware_Handle_ESP::~MCP2521_Hardware_Handle_ESP() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Hardware_Handle_ESP::initSPIBus(
|
||||||
|
spi_host_device_t spi_host,
|
||||||
|
gpio_num_t mosi,
|
||||||
|
gpio_num_t miso,
|
||||||
|
gpio_num_t sclk,
|
||||||
|
spi_bus_config_t *bus_config
|
||||||
|
) {
|
||||||
|
memset(bus_config, 0, sizeof(spi_bus_config_t));
|
||||||
|
bus_config->mosi_io_num = mosi;
|
||||||
|
bus_config->miso_io_num = miso;
|
||||||
|
bus_config->sclk_io_num = sclk;
|
||||||
|
|
||||||
|
bus_config->quadwp_io_num = -1;
|
||||||
|
bus_config->quadhd_io_num = -1;
|
||||||
|
|
||||||
|
bus_config->flags = SPICOMMON_BUSFLAG_MASTER;
|
||||||
|
spi_bus_initialize(spi_host, bus_config, SPI_DMA_CH_AUTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Hardware_Handle_ESP::initSPIDevice(
|
||||||
|
spi_host_device_t spi_host,
|
||||||
|
gpio_num_t cs
|
||||||
|
) {
|
||||||
|
memset(&this->spi_device_config, 0, sizeof(spi_device_interface_config_t));
|
||||||
|
this->spi_device_config = {
|
||||||
|
.command_bits = 8,
|
||||||
|
.address_bits = 0,
|
||||||
|
.dummy_bits = 0,
|
||||||
|
|
||||||
|
.mode = 0,
|
||||||
|
.duty_cycle_pos = 128,
|
||||||
|
// cs_ena_pretrans = 0 and cs_ena_posttrans = 0 need to be set to zero, if not its not compatible with full-duplex mode
|
||||||
|
// Learned this the hard way
|
||||||
|
.cs_ena_pretrans = 0,
|
||||||
|
.cs_ena_posttrans = 0,
|
||||||
|
.clock_speed_hz = 10000,
|
||||||
|
|
||||||
|
.spics_io_num = cs,
|
||||||
|
.flags = SPI_DEVICE_NO_DUMMY,
|
||||||
|
.queue_size = 5,
|
||||||
|
};
|
||||||
|
|
||||||
|
spi_bus_add_device(spi_host, &this->spi_device_config, &this->spi_device_handle);
|
||||||
|
|
||||||
|
spiMutex = xSemaphoreCreateMutex();
|
||||||
|
}
|
||||||
|
|
||||||
|
spi_bus_config_t * MCP2521_Hardware_Handle_ESP::getSPI_bus_config() {
|
||||||
|
return this->spi_bus_config;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
#include "mcp2521_hardware_handle.hpp"
|
||||||
|
|
||||||
|
#ifdef ESP_PLATFORM
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "mcp2521_hardware_esp.hpp"
|
||||||
|
|
||||||
|
static void IRAM_ATTR gpio_isr_can_handler(void* arg) {
|
||||||
|
MCP2521_Hardware_Handle_ESP * handle = (MCP2521_Hardware_Handle_ESP *)arg;
|
||||||
|
handle->isr_can_interrupt();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handleInteruptTaskCallerFn(void *arg) {
|
||||||
|
MCP2521_Hardware_Handle_ESP * handle = (MCP2521_Hardware_Handle_ESP *)arg;
|
||||||
|
handle->handleIntteruptTaskFn();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Hardware_Handle_ESP::initPins(
|
||||||
|
gpio_num_t int_pin
|
||||||
|
) {
|
||||||
|
canInterruptSemaphore = xSemaphoreCreateBinary();
|
||||||
|
|
||||||
|
gpio_config_t io_conf;
|
||||||
|
io_conf.intr_type = GPIO_INTR_NEGEDGE;
|
||||||
|
io_conf.mode = GPIO_MODE_INPUT;
|
||||||
|
io_conf.pin_bit_mask = 1 << int_pin;
|
||||||
|
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||||
|
io_conf.pull_up_en = GPIO_PULLUP_ENABLE;
|
||||||
|
gpio_config(&io_conf);
|
||||||
|
|
||||||
|
gpio_install_isr_service(0);
|
||||||
|
gpio_isr_handler_add(int_pin, gpio_isr_can_handler, this);
|
||||||
|
|
||||||
|
xTaskCreate(
|
||||||
|
(TaskFunction_t)&handleInteruptTaskCallerFn,
|
||||||
|
"canInterruptTask",
|
||||||
|
2048,
|
||||||
|
this,
|
||||||
|
5,
|
||||||
|
&canInterruptTaskHandle
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Hardware_Handle_ESP::handleIntteruptTaskFn() {
|
||||||
|
while(true) {
|
||||||
|
xSemaphoreTake(canInterruptSemaphore, portMAX_DELAY);
|
||||||
|
intHandler(intHandlerArg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Hardware_Handle_ESP::isr_can_interrupt() {
|
||||||
|
BaseType_t wokenTask = pdFALSE;
|
||||||
|
xSemaphoreGiveFromISR(canInterruptSemaphore, &wokenTask);
|
||||||
|
|
||||||
|
if(wokenTask) {
|
||||||
|
portYIELD_FROM_ISR();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCP2521_Hardware_Handle_ESP::registerIntHandler(intHandlerFunction_t handler, void * arg) {
|
||||||
|
intHandlerArg = arg;
|
||||||
|
intHandler = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "mcp2521_hardware_handle.hpp"
|
||||||
|
|
||||||
|
#ifdef ESP_PLATFORM
|
||||||
|
|
||||||
|
#include "driver/gpio.h"
|
||||||
|
#include "driver/spi_master.h"
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
|
||||||
|
class MCP2521_Hardware_Handle_ESP : public MCP2521_Hardware_Handle {
|
||||||
|
char spi_tmp_buffer;
|
||||||
|
|
||||||
|
spi_bus_config_t * spi_bus_config;
|
||||||
|
spi_device_interface_config_t spi_device_config;
|
||||||
|
spi_device_handle_t spi_device_handle;
|
||||||
|
|
||||||
|
SemaphoreHandle_t canInterruptSemaphore = NULL;
|
||||||
|
SemaphoreHandle_t spiMutex = NULL;
|
||||||
|
TaskHandle_t canInterruptTaskHandle = NULL;
|
||||||
|
|
||||||
|
void spi_transmit(spi_transaction_t *t);
|
||||||
|
|
||||||
|
void * intHandlerArg = NULL;
|
||||||
|
intHandlerFunction_t intHandler = NULL;
|
||||||
|
|
||||||
|
public:
|
||||||
|
MCP2521_Hardware_Handle_ESP(
|
||||||
|
spi_host_device_t spi_host,
|
||||||
|
spi_bus_config_t *bus_config,
|
||||||
|
gpio_num_t mosi,
|
||||||
|
gpio_num_t miso,
|
||||||
|
gpio_num_t sclk,
|
||||||
|
gpio_num_t cs,
|
||||||
|
gpio_num_t int_pin
|
||||||
|
);
|
||||||
|
|
||||||
|
MCP2521_Hardware_Handle_ESP(
|
||||||
|
spi_host_device_t spi_host,
|
||||||
|
spi_bus_config_t *bus_config,
|
||||||
|
gpio_num_t cs,
|
||||||
|
gpio_num_t int_pin
|
||||||
|
);
|
||||||
|
|
||||||
|
static void initSPIBus(
|
||||||
|
spi_host_device_t spi_host,
|
||||||
|
gpio_num_t mosi,
|
||||||
|
gpio_num_t miso,
|
||||||
|
gpio_num_t sclk,
|
||||||
|
spi_bus_config_t *bus_config
|
||||||
|
);
|
||||||
|
|
||||||
|
void initSPIDevice(
|
||||||
|
spi_host_device_t spi_host,
|
||||||
|
gpio_num_t cs
|
||||||
|
);
|
||||||
|
|
||||||
|
void initPins(
|
||||||
|
gpio_num_t int_pin
|
||||||
|
);
|
||||||
|
|
||||||
|
~MCP2521_Hardware_Handle_ESP();
|
||||||
|
|
||||||
|
spi_bus_config_t * getSPI_bus_config();
|
||||||
|
|
||||||
|
// ISR Stuff
|
||||||
|
void isr_can_interrupt();
|
||||||
|
void handleIntteruptTaskFn();
|
||||||
|
|
||||||
|
// Inherited from MCP2521_Hardware_Handle
|
||||||
|
void execute(uint8_t cmd);
|
||||||
|
void execute(uint8_t cmd, uint8_t address);
|
||||||
|
|
||||||
|
void read(uint8_t cmd, uint8_t *data, size_t length, uint8_t address);
|
||||||
|
void read(uint8_t cmd, uint8_t *data, size_t length);
|
||||||
|
uint8_t read(uint8_t cmd, uint8_t address);
|
||||||
|
uint8_t read(uint8_t cmd);
|
||||||
|
|
||||||
|
void write(uint8_t cmd, uint8_t *data, size_t length, uint8_t address);
|
||||||
|
void write(uint8_t cmd, uint8_t *data, size_t length);
|
||||||
|
void write(uint8_t cmd, uint8_t data, uint8_t address);
|
||||||
|
void write(uint8_t cmd, uint8_t data);
|
||||||
|
|
||||||
|
void registerIntHandler(intHandlerFunction_t handler, void * arg);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <cstdint>
|
||||||
|
#include <strings.h>
|
||||||
|
|
||||||
|
typedef void (*intHandlerFunction_t)(void *);
|
||||||
|
|
||||||
|
class MCP2521_Hardware_Handle {
|
||||||
|
public:
|
||||||
|
virtual void registerIntHandler(intHandlerFunction_t handler, void * arg) = 0;
|
||||||
|
|
||||||
|
virtual void execute(uint8_t cmd) = 0;
|
||||||
|
virtual void execute(uint8_t cmd, uint8_t address) = 0;
|
||||||
|
|
||||||
|
virtual void read(uint8_t cmd, uint8_t *data, size_t length, uint8_t address) = 0;
|
||||||
|
virtual void read(uint8_t cmd, uint8_t *data, size_t length) = 0;
|
||||||
|
virtual uint8_t read(uint8_t cmd, uint8_t address) = 0;
|
||||||
|
virtual uint8_t read(uint8_t cmd) = 0;
|
||||||
|
|
||||||
|
virtual void write(uint8_t cmd, uint8_t *data, size_t length, uint8_t address) = 0;
|
||||||
|
virtual void write(uint8_t cmd, uint8_t *data, size_t length) = 0;
|
||||||
|
virtual void write(uint8_t cmd, uint8_t data, uint8_t address) = 0;
|
||||||
|
virtual void write(uint8_t cmd, uint8_t data) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
BIN
motor-control/.gitignore
(Stored with Git LFS)
vendored
Normal file
BIN
motor-control/.gitignore
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
motor-control/firmware/.gitignore
(Stored with Git LFS)
vendored
Normal file
BIN
motor-control/firmware/.gitignore
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
18
motor-control/firmware/.vscode/c_cpp_properties.json
vendored
Normal file
18
motor-control/firmware/.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Linux",
|
||||||
|
"includePath": [
|
||||||
|
"${workspaceFolder}/include/**",
|
||||||
|
"${workspaceFolder}/lib/pico-sdk/lib/tinyusb/src"
|
||||||
|
],
|
||||||
|
"defines": [],
|
||||||
|
"compilerPath": "/usr/bin/gcc",
|
||||||
|
"cStandard": "c17",
|
||||||
|
"cppStandard": "c++14",
|
||||||
|
"intelliSenseMode": "linux-gcc-arm",
|
||||||
|
"configurationProvider": "ms-vscode.cmake-tools"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
||||||
31
motor-control/firmware/.vscode/launch.json
vendored
Executable file
31
motor-control/firmware/.vscode/launch.json
vendored
Executable file
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Pico: Debug External OpenOCD",
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"executable": "${command:cmake.launchTargetPath}",
|
||||||
|
"request": "launch",
|
||||||
|
"preLaunchTask": "Pico: flash main",
|
||||||
|
"type": "cortex-debug",
|
||||||
|
"servertype": "external",
|
||||||
|
"gdbPath" : "gdb-multiarch",
|
||||||
|
"gdbTarget": "gobot-rpi:3333",
|
||||||
|
"device": "RP2040",
|
||||||
|
"configFiles": [
|
||||||
|
"interface/cmsis-dap.cfg",
|
||||||
|
"target/rp2040.cfg"
|
||||||
|
],
|
||||||
|
|
||||||
|
"svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd",
|
||||||
|
"runToEntryPoint": "main",
|
||||||
|
|
||||||
|
"postRestartCommands": [
|
||||||
|
"continue"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
79
motor-control/firmware/.vscode/settings.json
vendored
Normal file
79
motor-control/firmware/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
{
|
||||||
|
"cSpell.words": [
|
||||||
|
"apcsw",
|
||||||
|
"apreg",
|
||||||
|
"apsel",
|
||||||
|
"arrayname",
|
||||||
|
"baseaddr",
|
||||||
|
"Bhaskra",
|
||||||
|
"bitwidth",
|
||||||
|
"BOOTSEL",
|
||||||
|
"cget",
|
||||||
|
"channellist",
|
||||||
|
"charmsg",
|
||||||
|
"clkdiv",
|
||||||
|
"cpnum",
|
||||||
|
"deassert",
|
||||||
|
"deasserted",
|
||||||
|
"deasserting",
|
||||||
|
"doxygen",
|
||||||
|
"dpreg",
|
||||||
|
"drawio",
|
||||||
|
"dreq",
|
||||||
|
"eabi",
|
||||||
|
"eventlist",
|
||||||
|
"gpio",
|
||||||
|
"helptext",
|
||||||
|
"jtag",
|
||||||
|
"lindex",
|
||||||
|
"memaccess",
|
||||||
|
"microcontroller",
|
||||||
|
"multiarch",
|
||||||
|
"multicore",
|
||||||
|
"Pico",
|
||||||
|
"picoprobe",
|
||||||
|
"pindirs",
|
||||||
|
"pinout",
|
||||||
|
"pregen",
|
||||||
|
"resexit",
|
||||||
|
"semihosting",
|
||||||
|
"srst",
|
||||||
|
"struct",
|
||||||
|
"targetname",
|
||||||
|
"TPIU",
|
||||||
|
"trst",
|
||||||
|
"UART",
|
||||||
|
"virt",
|
||||||
|
"waitstate",
|
||||||
|
"watchpoint",
|
||||||
|
"watchpoints",
|
||||||
|
"wready"
|
||||||
|
],
|
||||||
|
"cmake.sourceDirectory": "/home/alexander/Projects/gobot/motor-control/firmware",
|
||||||
|
"cmake.buildDirectory": "${workspaceFolder}/build",
|
||||||
|
"cmake.configureOnOpen": true,
|
||||||
|
"files.associations": {
|
||||||
|
"timer.h": "c",
|
||||||
|
"stdlib.h": "c",
|
||||||
|
"stdio.h": "c",
|
||||||
|
"string.h": "c",
|
||||||
|
"assert.h": "c",
|
||||||
|
"gen.h": "c",
|
||||||
|
"multicore.h": "c",
|
||||||
|
"pio.h": "c",
|
||||||
|
"freertos.h": "c",
|
||||||
|
"random": "c",
|
||||||
|
"queue.h": "c",
|
||||||
|
"string_view": "c",
|
||||||
|
"instructionformat.h": "c",
|
||||||
|
"includeglobals.h": "c",
|
||||||
|
"dacconfig.h": "c",
|
||||||
|
"freertosconfig.h": "c",
|
||||||
|
"*.tcc": "cpp"
|
||||||
|
},
|
||||||
|
"cortex-debug.variableUseNaturalFormat": false,
|
||||||
|
"todo-tree.filtering.ignoreGitSubmodules": true,
|
||||||
|
"todo-tree.tree.showBadges": true,
|
||||||
|
"terminal.integrated.scrollback": 10000,
|
||||||
|
"C_Cpp.refactoring.includeHeader": "always",
|
||||||
|
}
|
||||||
165
motor-control/firmware/.vscode/tasks.json
vendored
Normal file
165
motor-control/firmware/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"type": "cmake",
|
||||||
|
"label": "CMake: build main",
|
||||||
|
"command": "build",
|
||||||
|
"targets": [
|
||||||
|
"main"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceRoot}"
|
||||||
|
},
|
||||||
|
"group": "build",
|
||||||
|
"presentation": {
|
||||||
|
"echo": true,
|
||||||
|
"reveal": "always",
|
||||||
|
"focus": true,
|
||||||
|
"panel": "dedicated",
|
||||||
|
"showReuseMessage": true,
|
||||||
|
"clear": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "shell",
|
||||||
|
"label": "Pico: flash main",
|
||||||
|
"command": [
|
||||||
|
"scripts/flash.exp",
|
||||||
|
"${workspaceRoot}/build/bin/main.elf"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceRoot}"
|
||||||
|
},
|
||||||
|
"group": "test",
|
||||||
|
"dependsOn": [
|
||||||
|
"CMake: build main"
|
||||||
|
],
|
||||||
|
"presentation": {
|
||||||
|
"echo": true,
|
||||||
|
"reveal": "always",
|
||||||
|
"focus": true,
|
||||||
|
"panel": "dedicated",
|
||||||
|
"showReuseMessage": true,
|
||||||
|
"clear": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "shell",
|
||||||
|
"label": "Pico: launch openocd",
|
||||||
|
"command": [
|
||||||
|
"scripts/launch_openocd.sh"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceRoot}"
|
||||||
|
},
|
||||||
|
"isBackground": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "shell",
|
||||||
|
"label": "Pico: Reset Device",
|
||||||
|
"command": [
|
||||||
|
"scripts/reset.exp"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceRoot}"
|
||||||
|
},
|
||||||
|
"isBackground": true,
|
||||||
|
"problemMatcher": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "cmake",
|
||||||
|
"label": "CMake: Clean",
|
||||||
|
"command": "clean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "cmake",
|
||||||
|
"label": "CMake: Clean Rebuild",
|
||||||
|
"command": "cleanRebuild"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "cmake",
|
||||||
|
"label": "CMake: Configure",
|
||||||
|
"command": "configure"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "shell",
|
||||||
|
"label": "Doxygen: Generate Docs",
|
||||||
|
"command": [
|
||||||
|
"doxygen ./docs/Doxyfile"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceRoot}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "shell",
|
||||||
|
"label": "Nuke Build Directory",
|
||||||
|
"command": [
|
||||||
|
"rm -rf build"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceRoot}"
|
||||||
|
},
|
||||||
|
"problemMatcher": []
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "shell",
|
||||||
|
"label": "Pico Remote: Launch OpenOCD",
|
||||||
|
"command": [
|
||||||
|
"scripts/remote/run_openocd.exp",
|
||||||
|
"gobot-rpi",
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceRoot}"
|
||||||
|
},
|
||||||
|
"presentation": {
|
||||||
|
"echo": true,
|
||||||
|
"reveal": "always",
|
||||||
|
"focus": true,
|
||||||
|
"panel": "dedicated",
|
||||||
|
"showReuseMessage": true,
|
||||||
|
"clear": true
|
||||||
|
},
|
||||||
|
"isBackground": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "shell",
|
||||||
|
"label": "Pico Remote: flash main",
|
||||||
|
"command": [
|
||||||
|
"scripts/remote/flash.sh",
|
||||||
|
"${workspaceRoot}/build/bin/main.elf",
|
||||||
|
"gobot-rpi",
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceRoot}"
|
||||||
|
},
|
||||||
|
"group": "test",
|
||||||
|
"dependsOn": [
|
||||||
|
"CMake: build main"
|
||||||
|
],
|
||||||
|
"presentation": {
|
||||||
|
"echo": true,
|
||||||
|
"reveal": "always",
|
||||||
|
"focus": true,
|
||||||
|
"panel": "dedicated",
|
||||||
|
"showReuseMessage": true,
|
||||||
|
"clear": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "shell",
|
||||||
|
"label": "Pico Remote: Reset Device",
|
||||||
|
"command": [
|
||||||
|
"scripts/remote/reset.exp",
|
||||||
|
"gobot-rpi"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceRoot}"
|
||||||
|
},
|
||||||
|
"isBackground": true,
|
||||||
|
"problemMatcher": []
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
77
motor-control/firmware/CMakeLists.txt
Executable file
77
motor-control/firmware/CMakeLists.txt
Executable file
@@ -0,0 +1,77 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.12)
|
||||||
|
|
||||||
|
# Including the SDK (must be before project)
|
||||||
|
|
||||||
|
if (NOT "$ENV{PICO_SDK_PATH_OVERRIDE}" STREQUAL "")
|
||||||
|
SET(PICO_SDK_PATH "$ENV{PICO_SDK_PATH_OVERRIDE}")
|
||||||
|
else()
|
||||||
|
SET(PICO_SDK_PATH "${CMAKE_SOURCE_DIR}/lib/pico-sdk")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
#SET(PICO_TOOLCHAIN_PATH "${PICO_SDK_PATH}/cmake/preload/toolchains/")
|
||||||
|
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
||||||
|
|
||||||
|
include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
|
||||||
|
include(cmake/freeRTOS.cmake)
|
||||||
|
|
||||||
|
#include(pico_extras_import_optional.cmake)
|
||||||
|
|
||||||
|
project(pico_examples C CXX ASM)
|
||||||
|
set(CMAKE_C_STANDARD 23)
|
||||||
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
|
|
||||||
|
if (PICO_SDK_VERSION_STRING VERSION_LESS "1.3.0")
|
||||||
|
message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.3.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(PICO_EXAMPLES_PATH ${PROJECT_SOURCE_DIR})
|
||||||
|
|
||||||
|
# Initialize the SDK
|
||||||
|
pico_sdk_init()
|
||||||
|
|
||||||
|
include(example_auto_set_url.cmake)
|
||||||
|
|
||||||
|
add_compile_options(-Wall
|
||||||
|
-Wno-format # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int
|
||||||
|
-Wno-unused-function # we have some for the docs that aren't called
|
||||||
|
)
|
||||||
|
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
||||||
|
add_compile_options(-Wno-maybe-uninitialized)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# adding sources files & includes
|
||||||
|
add_executable(main
|
||||||
|
src/main.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(main PUBLIC
|
||||||
|
include/
|
||||||
|
include/freeRTOS
|
||||||
|
build/
|
||||||
|
)
|
||||||
|
|
||||||
|
include(${PROJECT_SOURCE_DIR}/cmake/tmc2209.cmake)
|
||||||
|
|
||||||
|
# Adding PIO
|
||||||
|
pico_generate_pio_header(main ${CMAKE_CURRENT_LIST_DIR}/src/tmc2209/pulser.pio)
|
||||||
|
|
||||||
|
# pull in common dependencies
|
||||||
|
target_link_libraries(main
|
||||||
|
pico_stdlib
|
||||||
|
pico_time
|
||||||
|
pico_multicore
|
||||||
|
pico_stdio_usb
|
||||||
|
hardware_pio
|
||||||
|
|
||||||
|
tmc2209_driver
|
||||||
|
FreeRTOS
|
||||||
|
)
|
||||||
|
|
||||||
|
pico_enable_stdio_usb(main 1)
|
||||||
|
pico_enable_stdio_uart(main 0)
|
||||||
|
|
||||||
|
# create map/bin/hex file etc.
|
||||||
|
pico_add_extra_outputs(main)
|
||||||
|
|
||||||
|
# add url via pico_set_program_url
|
||||||
|
example_auto_set_url(main)
|
||||||
106
motor-control/firmware/Jenkinsfile
vendored
Normal file
106
motor-control/firmware/Jenkinsfile
vendored
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
pipeline {
|
||||||
|
agent none
|
||||||
|
|
||||||
|
stages {
|
||||||
|
stage('git checkout') {
|
||||||
|
agent {
|
||||||
|
label 'docker'
|
||||||
|
}
|
||||||
|
|
||||||
|
steps {
|
||||||
|
git branch: 'firmware-dev',
|
||||||
|
credentialsId: 'osci-rendering_github',
|
||||||
|
url: 'git@github.com:AlexanderHD27/oscilloscope-drawing.git'
|
||||||
|
|
||||||
|
sh 'git submodule update --init --recursive'
|
||||||
|
sh "ls -laF"
|
||||||
|
stash includes: "firmware/lib/doxygen-awesome-css/**", name: 'libs-doxygen'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('build build-container') {
|
||||||
|
agent {
|
||||||
|
label 'docker'
|
||||||
|
}
|
||||||
|
|
||||||
|
steps {
|
||||||
|
sh 'docker build -t rpi_pico_build_container firmware/docker/'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('build') {
|
||||||
|
parallel {
|
||||||
|
stage('build firmware') {
|
||||||
|
agent {
|
||||||
|
docker {
|
||||||
|
image 'rpi_pico_build_container'
|
||||||
|
label 'docker'
|
||||||
|
reuseNode true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
env.PICO_SDK_PATH_OVERRIDE = sh(script: 'echo $PWD/firmware/lib/pico-sdk', returnStdout: true).trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
dir('firmware/build') {
|
||||||
|
sh 'echo building in $PWD'
|
||||||
|
sh 'rm -rf *'
|
||||||
|
sh 'echo PicoSDK path: $PICO_SDK_PATH_OVERRIDE'
|
||||||
|
sh 'cmake ..'
|
||||||
|
sh 'cmake --build . --config Debug'
|
||||||
|
sh 'make -j4 all'
|
||||||
|
}
|
||||||
|
|
||||||
|
stash includes: "firmware/build/bin/*", name: 'binary'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('build docs') {
|
||||||
|
agent {
|
||||||
|
docker {
|
||||||
|
image 'rpi_pico_build_container'
|
||||||
|
label 'docker'
|
||||||
|
reuseNode true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
steps {
|
||||||
|
unstash 'libs-doxygen'
|
||||||
|
sh "doxygen firmware/docs/Doxyfile"
|
||||||
|
stash includes: "firmware/docs/html/*", name: 'html-docs'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('publish') {
|
||||||
|
parallel {
|
||||||
|
stage('publish docs') {
|
||||||
|
agent {
|
||||||
|
label 'cdc-deploy'
|
||||||
|
}
|
||||||
|
|
||||||
|
steps {
|
||||||
|
sh 'rm -rf /www/projects/osci-rendering/docs/*'
|
||||||
|
unstash 'html-docs'
|
||||||
|
sh 'cp -r firmware/docs/html/* /www/projects/osci-rendering/docs'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('publish binary') {
|
||||||
|
agent {
|
||||||
|
label 'cdc-deploy'
|
||||||
|
}
|
||||||
|
|
||||||
|
steps {
|
||||||
|
sh 'rm -rf /www/projects/osci-rendering/bin/*'
|
||||||
|
unstash 'binary'
|
||||||
|
sh 'cp -r bin/* /www/projects/osci-rendering/bin'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
motor-control/firmware/README.md
(Stored with Git LFS)
Normal file
BIN
motor-control/firmware/README.md
(Stored with Git LFS)
Normal file
Binary file not shown.
0
motor-control/firmware/TODOs.md
Normal file
0
motor-control/firmware/TODOs.md
Normal file
14
motor-control/firmware/cmake/freeRTOS.cmake
Normal file
14
motor-control/firmware/cmake/freeRTOS.cmake
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
SET(FreeRTOS_DIR ${CMAKE_CURRENT_LIST_DIR}/../lib/FreeRTOS-Kernel)
|
||||||
|
FILE(GLOB FreeRTOS_src ${FreeRTOS_DIR}/*.c)
|
||||||
|
|
||||||
|
add_library(FreeRTOS STATIC
|
||||||
|
${FreeRTOS_src}
|
||||||
|
${FreeRTOS_DIR}/portable/GCC/ARM_CM0/port.c
|
||||||
|
${FreeRTOS_DIR}/portable/MemMang/heap_4.c
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(FreeRTOS PUBLIC
|
||||||
|
${FreeRTOS_DIR}/portable/GCC/ARM_CM0/
|
||||||
|
${FreeRTOS_DIR}/include/
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/../include/freeRTOS
|
||||||
|
)
|
||||||
16
motor-control/firmware/cmake/tmc2209.cmake
Normal file
16
motor-control/firmware/cmake/tmc2209.cmake
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
add_library(tmc2209_driver STATIC
|
||||||
|
src/tmc2209/uart_interface.cpp
|
||||||
|
src/tmc2209/uart_registers.cpp
|
||||||
|
src/tmc2209/step.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(tmc2209_driver PRIVATE
|
||||||
|
include/tmc2209/
|
||||||
|
build/
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(tmc2209_driver
|
||||||
|
pico_stdlib
|
||||||
|
hardware_uart
|
||||||
|
hardware_pio
|
||||||
|
)
|
||||||
8
motor-control/firmware/docker/Dockerfile
Normal file
8
motor-control/firmware/docker/Dockerfile
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
FROM ubuntu:22.04
|
||||||
|
|
||||||
|
RUN apt -y update
|
||||||
|
RUN apt -y install build-essential gcc-arm-none-eabi doxygen cmake python3
|
||||||
|
RUN mkdir /data
|
||||||
|
|
||||||
|
WORKDIR /data
|
||||||
|
|
||||||
3
motor-control/firmware/docker/build_docs.sh
Executable file
3
motor-control/firmware/docker/build_docs.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
doxygen ./firmware/docs/Doxyfile
|
||||||
11
motor-control/firmware/docker/build_firmware.sh
Executable file
11
motor-control/firmware/docker/build_firmware.sh
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
cd ./firmware/build
|
||||||
|
rm -rf *
|
||||||
|
|
||||||
|
export PICO_SDK_PATH_OVERRIDE="/data/firmware/lib/pico-sdk"
|
||||||
|
echo $PICO_SDK_PATH_OVERRIDE
|
||||||
|
|
||||||
|
cmake ..
|
||||||
|
cmake --build . --config Debug
|
||||||
|
make -j4 all
|
||||||
2658
motor-control/firmware/docs/Doxyfile
Normal file
2658
motor-control/firmware/docs/Doxyfile
Normal file
File diff suppressed because it is too large
Load Diff
BIN
motor-control/firmware/docs/tmc2209_datasheet_rev1.09.pdf
(Stored with Git LFS)
Normal file
BIN
motor-control/firmware/docs/tmc2209_datasheet_rev1.09.pdf
(Stored with Git LFS)
Normal file
Binary file not shown.
5
motor-control/firmware/example_auto_set_url.cmake
Executable file
5
motor-control/firmware/example_auto_set_url.cmake
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
set(PICO_EXAMPLE_URL_BASE "https://github.com/raspberrypi/pico-examples/tree/HEAD")
|
||||||
|
macro(example_auto_set_url TARGET)
|
||||||
|
file(RELATIVE_PATH URL_REL_PATH "${PICO_EXAMPLES_PATH}" "${CMAKE_CURRENT_LIST_DIR}")
|
||||||
|
pico_set_program_url(${TARGET} "${PICO_EXAMPLE_URL_BASE}/${URL_REL_PATH}")
|
||||||
|
endmacro()
|
||||||
101
motor-control/firmware/include/freeRTOS/FreeRTOSConfig.h
Normal file
101
motor-control/firmware/include/freeRTOS/FreeRTOSConfig.h
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
#ifndef FREERTOS_CONFIG_H
|
||||||
|
#define FREERTOS_CONFIG_H
|
||||||
|
|
||||||
|
#define configENABLE_MPU 1
|
||||||
|
|
||||||
|
#define configUSE_PREEMPTION 1
|
||||||
|
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
|
||||||
|
#define configUSE_TICKLESS_IDLE 0
|
||||||
|
#define configCPU_CLOCK_HZ 133000000
|
||||||
|
#define configSYSTICK_CLOCK_HZ 1000000
|
||||||
|
#define configTICK_RATE_HZ 1000
|
||||||
|
#define configMAX_PRIORITIES 4
|
||||||
|
#define configMINIMAL_STACK_SIZE 256
|
||||||
|
#define configMAX_TASK_NAME_LEN 16
|
||||||
|
#define configUSE_16_BIT_TICKS 0
|
||||||
|
#define configIDLE_SHOULD_YIELD 1
|
||||||
|
#define configUSE_TASK_NOTIFICATIONS 1
|
||||||
|
#define configTASK_NOTIFICATION_ARRAY_ENTRIES 3
|
||||||
|
#define configUSE_MUTEXES 0
|
||||||
|
#define configUSE_RECURSIVE_MUTEXES 0
|
||||||
|
#define configUSE_COUNTING_SEMAPHORES 1
|
||||||
|
#define configUSE_ALTERNATIVE_API 0 /* Deprecated! */
|
||||||
|
#define configQUEUE_REGISTRY_SIZE 10
|
||||||
|
#define configUSE_QUEUE_SETS 0
|
||||||
|
#define configUSE_TIME_SLICING 1
|
||||||
|
#define configUSE_NEWLIB_REENTRANT 0
|
||||||
|
#define configENABLE_BACKWARD_COMPATIBILITY 0
|
||||||
|
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5
|
||||||
|
#define configSTACK_DEPTH_TYPE uint16_t
|
||||||
|
#define configMESSAGE_BUFFER_LENGTH_TYPE size_t
|
||||||
|
|
||||||
|
/* Memory allocation related definitions. */
|
||||||
|
#define configSUPPORT_STATIC_ALLOCATION 0
|
||||||
|
#define configSUPPORT_DYNAMIC_ALLOCATION 1
|
||||||
|
#define configTOTAL_HEAP_SIZE 50000
|
||||||
|
#define configAPPLICATION_ALLOCATED_HEAP 0
|
||||||
|
|
||||||
|
/* Hook function related definitions. */
|
||||||
|
#define configUSE_IDLE_HOOK 0
|
||||||
|
#define configUSE_TICK_HOOK 0
|
||||||
|
#define configCHECK_FOR_STACK_OVERFLOW 0
|
||||||
|
#define configUSE_MALLOC_FAILED_HOOK 0
|
||||||
|
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0
|
||||||
|
|
||||||
|
/* Run time and task stats gathering related definitions. */
|
||||||
|
#define configGENERATE_RUN_TIME_STATS 0
|
||||||
|
#define configUSE_TRACE_FACILITY 0
|
||||||
|
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
|
||||||
|
|
||||||
|
/* Co-routine related definitions. */
|
||||||
|
#define configUSE_CO_ROUTINES 0
|
||||||
|
#define configMAX_CO_ROUTINE_PRIORITIES 1
|
||||||
|
|
||||||
|
/* Software timer related definitions. */
|
||||||
|
#define configUSE_TIMERS 1
|
||||||
|
#define configTIMER_TASK_PRIORITY 3
|
||||||
|
#define configTIMER_QUEUE_LENGTH 10
|
||||||
|
#define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE
|
||||||
|
|
||||||
|
/* Interrupt nesting behaviour configuration. */
|
||||||
|
#define configKERNEL_INTERRUPT_PRIORITY [dependent of processor]
|
||||||
|
#define configMAX_SYSCALL_INTERRUPT_PRIORITY [dependent on processor and application]
|
||||||
|
#define configMAX_API_CALL_INTERRUPT_PRIORITY [dependent on processor and application]
|
||||||
|
|
||||||
|
/* Define to trap errors during development. */
|
||||||
|
//#define configASSERT( ( x ) ) assert()
|
||||||
|
|
||||||
|
/* FreeRTOS MPU specific definitions. */
|
||||||
|
#define configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS 0
|
||||||
|
#define configTOTAL_MPU_REGIONS 8 /* Default value. */
|
||||||
|
#define configTEX_S_C_B_FLASH 0x07UL /* Default value. */
|
||||||
|
#define configTEX_S_C_B_SRAM 0x07UL /* Default value. */
|
||||||
|
#define configENFORCE_SYSTEM_CALLS_FROM_KERNEL_ONLY 1
|
||||||
|
|
||||||
|
/* Optional functions - most linkers will remove unused functions anyway. */
|
||||||
|
#define INCLUDE_vTaskPrioritySet 1
|
||||||
|
#define INCLUDE_uxTaskPriorityGet 1
|
||||||
|
#define INCLUDE_vTaskDelete 1
|
||||||
|
#define INCLUDE_vTaskSuspend 1
|
||||||
|
#define INCLUDE_xResumeFromISR 1
|
||||||
|
#define INCLUDE_vTaskDelayUntil 1
|
||||||
|
#define INCLUDE_vTaskDelay 1
|
||||||
|
#define INCLUDE_xTaskGetSchedulerState 1
|
||||||
|
#define INCLUDE_xTaskGetCurrentTaskHandle 1
|
||||||
|
#define INCLUDE_uxTaskGetStackHighWaterMark 0
|
||||||
|
#define INCLUDE_xTaskGetIdleTaskHandle 0
|
||||||
|
#define INCLUDE_eTaskGetState 0
|
||||||
|
#define INCLUDE_xEventGroupSetBitFromISR 1
|
||||||
|
#define INCLUDE_xTimerPendFunctionCall 0
|
||||||
|
#define INCLUDE_xTaskAbortDelay 0
|
||||||
|
#define INCLUDE_xTaskGetHandle 0
|
||||||
|
#define INCLUDE_xTaskResumeFromISR 1
|
||||||
|
|
||||||
|
#define vPortSVCHandler isr_svcall
|
||||||
|
#define xPortPendSVHandler isr_pendsv
|
||||||
|
#define xPortSysTickHandler isr_systick
|
||||||
|
|
||||||
|
|
||||||
|
/* A header file that defines trace macro can be included here. */
|
||||||
|
|
||||||
|
#endif /* FREERTOS_CONFIG_H */
|
||||||
517
motor-control/firmware/include/tmc2209/registers_map.hpp
Normal file
517
motor-control/firmware/include/tmc2209/registers_map.hpp
Normal file
@@ -0,0 +1,517 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// =================================================================================================
|
||||||
|
// General Registers (p.23)
|
||||||
|
// =================================================================================================
|
||||||
|
#define REG_ADDR_GENERAL_GCONF 0x00
|
||||||
|
#define REG_ADDR_GENERAL_GSTAT 0x01
|
||||||
|
#define REG_ADDR_GENERAL_IFCNT 0x02
|
||||||
|
#define REG_ADDR_GENERAL_NODECONF 0x03
|
||||||
|
#define REG_ADDR_GENERAL_OTP_PROG 0x04
|
||||||
|
#define REG_ADDR_GENERAL_OTP_READ 0x05
|
||||||
|
#define REG_ADDR_GENERAL_IOIN 0x06
|
||||||
|
#define REG_ADDR_GENERAL_FACTORY_CONF 0x07
|
||||||
|
|
||||||
|
/// @brief Global configuration flags
|
||||||
|
struct REG_GCONF {
|
||||||
|
/**
|
||||||
|
* (Reset default=1)
|
||||||
|
* 0: Use internal reference derived from 5VOUT
|
||||||
|
* 1: Use voltage supplied to VREF as current reference
|
||||||
|
*/
|
||||||
|
unsigned int I_scale_analog: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (Reset default: OTP)
|
||||||
|
* 0: Operation with external sense resistors
|
||||||
|
* 1: Internal sense resistors. Use current supplied into VREF as reference for internal sense resistor. VREF pin internally is driven to GND in this mode.
|
||||||
|
*/
|
||||||
|
unsigned int internal_Rsense: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (Reset default: OTP)
|
||||||
|
* 0: StealthChop PWM mode enabled (depending on velocity thresholds). Initially switch from off to on state while in stand still, only.
|
||||||
|
* 1: SpreadCycle mode enabled A high level on the pin SPREAD inverts this flag to switch between both chopper modes.
|
||||||
|
*/
|
||||||
|
unsigned int en_SpreadCycle: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1: Inverse motor direction
|
||||||
|
*/
|
||||||
|
unsigned int shaft: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0: INDEX shows the first microstep position of sequencer
|
||||||
|
* 1: INDEX pin outputs overtemperature prewarning flag (otpw) instead
|
||||||
|
*/
|
||||||
|
unsigned int index_otpw: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0: INDEX output as selected by index_otpw
|
||||||
|
* 1: INDEX output shows step pulses from internal pulse generator (toggle upon each step)
|
||||||
|
*/
|
||||||
|
unsigned int index_step: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0: PDN_UART controls standstill current reduction
|
||||||
|
* 1: PDN_UART input function disabled. Set this bit, when using the UART interface!
|
||||||
|
*/
|
||||||
|
unsigned int pdn_disable: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0: Microstep resolution selected by pins MS1, MS2
|
||||||
|
* 1: Microstep resolution selected by MRES register
|
||||||
|
*/
|
||||||
|
unsigned int mstep_reg_select: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0: No filtering of STEP pulses
|
||||||
|
* 1: Software pulse generator optimization enabled when fullstep frequency > 750Hz (roughly). TSTEP shows filtered step time values when active
|
||||||
|
*/
|
||||||
|
unsigned int multistep_filt: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0: Normal operation
|
||||||
|
* 1: Enable analog test output on pin ENN (pull down resistor off), ENN treated as enabled. IHOLD[1..0] selects the function of DCO: 0…2: T120, DAC, VDDH
|
||||||
|
*/
|
||||||
|
unsigned int test_mode: 1;
|
||||||
|
|
||||||
|
unsigned int :22;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief Global status flags
|
||||||
|
struct REG_GSTAT {
|
||||||
|
/**
|
||||||
|
* 1: Indicates that the IC has been reset since the last read access to GSTAT. All registers have been cleared to reset values.
|
||||||
|
*/
|
||||||
|
unsigned int reset: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1: Indicates, that the driver has been shut down due to overtemperature or short circuit detection since the last read access. Read DRV_STATUS for details. The flag can only be cleared when all error conditions are cleared
|
||||||
|
*/
|
||||||
|
unsigned int drv_err: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates an undervoltage on the charge pump. The driver is disabled in this case. This flag is not latched and thus does not need to be cleared
|
||||||
|
*/
|
||||||
|
unsigned int uv_cp: 1;
|
||||||
|
|
||||||
|
unsigned int :29;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief Interface transmission counter
|
||||||
|
struct REG_IFCNT {
|
||||||
|
/**
|
||||||
|
* Interface transmission counter. This register becomes incremented with each successful UART interface write access. Read out to check the serial transmission for lost data. Read accesses do not change the content. The counter wraps around from 255 to 0.
|
||||||
|
*/
|
||||||
|
unsigned int mstep: 8;
|
||||||
|
|
||||||
|
unsigned int :24;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief Node configuration
|
||||||
|
struct REG_NODECONF {
|
||||||
|
unsigned int :8;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SENDDELAY for read access (time until reply is sent):
|
||||||
|
* 0, 1: 8 bit times (Attention: Don’t use in multi-node)
|
||||||
|
* 2, 3: 3*8 bit times
|
||||||
|
* 4, 5: 5*8 bit times
|
||||||
|
* 6, 7: 7*8 bit times
|
||||||
|
* 8, 9: 9*8 bit times
|
||||||
|
* 10, 11: 11*8 bit times
|
||||||
|
* 12, 13: 13*8 bit times
|
||||||
|
* 14, 15: 15*8 bit times
|
||||||
|
*/
|
||||||
|
unsigned int senddelay: 4;
|
||||||
|
|
||||||
|
unsigned int :16;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief OTP programming
|
||||||
|
struct REG_OPT_PROG {
|
||||||
|
/**
|
||||||
|
* Selection of OTP bit to be programmed to the selected byte location (n=0..7: programs bit n to a logic 1)
|
||||||
|
*/
|
||||||
|
unsigned int otpbit: 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selection of OTP programming location (0, 1 or 2)
|
||||||
|
*/
|
||||||
|
unsigned int optbyte: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to 0xbd to enable programming. A programming time of minimum 10ms per bit is recommended (check by reading OTP_READ).
|
||||||
|
*/
|
||||||
|
unsigned int optmagic: 8;
|
||||||
|
|
||||||
|
unsigned int :16;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief OTP read (Access to OTP memory result and update)
|
||||||
|
struct OTP_READ {
|
||||||
|
/// @brief OTP0 byte 0 read data
|
||||||
|
unsigned int opt0: 8;
|
||||||
|
|
||||||
|
/// @brief OTP1 byte 1 read data
|
||||||
|
unsigned int opt1: 8;
|
||||||
|
|
||||||
|
/// @brief OTP2 byte 2 read data
|
||||||
|
unsigned int opt2: 8;
|
||||||
|
|
||||||
|
unsigned int :8;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// @brief Inputs (Reads the state of all input pins available)
|
||||||
|
struct REG_IOIN {
|
||||||
|
unsigned int enn: 1;
|
||||||
|
unsigned int :1;
|
||||||
|
unsigned int ms1: 1;
|
||||||
|
unsigned int ms2: 1;
|
||||||
|
unsigned int diag: 1;
|
||||||
|
unsigned int :1;
|
||||||
|
unsigned int pdn_uart: 1;
|
||||||
|
unsigned int step: 1;
|
||||||
|
unsigned int spread_en: 1;
|
||||||
|
unsigned int dir: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief VERSION: 0x21=first version of the IC Identical numbers mean full digital compatibility.
|
||||||
|
*/
|
||||||
|
unsigned int version: 8;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct REG_FACTORY_CONF {
|
||||||
|
/**
|
||||||
|
* Lowest to highest clock frequency. Check at charge pump output. The frequency span is not guaranteed, but it is tested, that tuning to 12MHz internal clock is possible. The devices come preset to 12MHz clock frequency by OTP programming.
|
||||||
|
*/
|
||||||
|
unsigned int fclktrim: 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* %00: OT=143°C, OTPW=120°C
|
||||||
|
* %01: OT=150°C, OTPW=120°C
|
||||||
|
* %10: OT=150°C, OTPW=143°C
|
||||||
|
* %11: OT=157°C, OTPW=143°C
|
||||||
|
*/
|
||||||
|
unsigned int ottrim: 2;
|
||||||
|
|
||||||
|
unsigned int :25;
|
||||||
|
};
|
||||||
|
|
||||||
|
// =================================================================================================
|
||||||
|
// Velocity Dependent Control (p.28)
|
||||||
|
// =================================================================================================
|
||||||
|
#define REG_ADDR_VELOCITY_IHOLD_IRUN 0x10
|
||||||
|
#define REG_ADDR_VELOCITY_TPOWERDOWN 0x11
|
||||||
|
#define REG_ADDR_VELOCITY_TSTEP 0x12
|
||||||
|
#define REG_ADDR_VELOCITY_TPWMTHRS 0x13
|
||||||
|
#define REG_ADDR_VELOCITY_VACTUAL 0x22
|
||||||
|
|
||||||
|
/// @brief Driver current control
|
||||||
|
struct REG_IHOLD_IRUN {
|
||||||
|
/**
|
||||||
|
* (Reset default: OTP)
|
||||||
|
* IHOLD (Reset default: OTP)
|
||||||
|
* Standstill current (0=1/32 … 31=32/32)
|
||||||
|
* In combination with StealthChop mode, setting
|
||||||
|
* IHOLD=0 allows to choose freewheeling or coil short circuit (passive braking) for motor stand still.
|
||||||
|
*/
|
||||||
|
unsigned int ihold: 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (Reset default=31)
|
||||||
|
* Motor run current (0=1/32 … 31=32/32)
|
||||||
|
*
|
||||||
|
* Tint: Choose sense resistors in a way, that normal IRUN is 16 to 31 for best microstep performance.
|
||||||
|
*/
|
||||||
|
unsigned int irun: 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (Reset default: OTP)
|
||||||
|
* Controls the number of clock cycles for motor power down after standstill is detected (stst=1) and TPOWERDOWN has expired. The smooth transition avoids a motor jerk upon power down.
|
||||||
|
* 0: instant power down
|
||||||
|
* 1..15: Delay per current reduction step in multiple of 2^18 clocks
|
||||||
|
*/
|
||||||
|
unsigned int iholddelay: 4;
|
||||||
|
unsigned int :18;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct REG_TPOWERDOWN {
|
||||||
|
/**
|
||||||
|
* (Reset default=20)
|
||||||
|
* Sets the delay time from stand still (stst) detection to motor current power down. Time range is about 0 to 5.6 seconds.
|
||||||
|
* 0…((2^8)-1) * 2^18 tCLK
|
||||||
|
* Attention: A minimum setting of 2 is required to allow automatic tuning of StealthChop PWM_OFFS_AUTO.
|
||||||
|
*/
|
||||||
|
unsigned int tpow: 8;
|
||||||
|
|
||||||
|
unsigned int :24;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief Time between two 1/256 microsteps
|
||||||
|
struct REG_TSTEP {
|
||||||
|
/**
|
||||||
|
* Actual measured time between two 1/256 microsteps derived from the step input frequency in units of 1/fCLK. Measured value is (2^20)-1 in case of overflow or stand still. TSTEP always relates to 1/256 step, independent of the actual MRES. The TSTEP related threshold uses a hysteresis of 1/16 of the compare value to compensate for jitter in the clock or the step frequency: (Txxx*15/16)-1 is the lower compare value for each TSTEP based comparison.
|
||||||
|
* This means, that the lower switching velocity equals the calculated setting, but the upper switching velocity is higher as defined by the hysteresis setting.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
unsigned int tstep: 20;
|
||||||
|
|
||||||
|
unsigned int :12;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief Upper velocity for StealthChop voltage PWM mode
|
||||||
|
struct REG_TPWMTHRS {
|
||||||
|
/**
|
||||||
|
* Sets the upper velocity for StealthChop voltage PWM mode.
|
||||||
|
* TSTEP ≥ TPWMTHRS
|
||||||
|
* - StealthChop PWM mode is enabled, if configured
|
||||||
|
* When the velocity exceeds the limit set by TPWMTHRS, the driver switches to SpreadCycle.
|
||||||
|
* 0: Disabled
|
||||||
|
*/
|
||||||
|
unsigned int tpwmthrs: 20;
|
||||||
|
|
||||||
|
unsigned int :12;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct REG_VACTUAL {
|
||||||
|
/**
|
||||||
|
* ACTUAL allows moving the motor by UART control.
|
||||||
|
* It gives the motor velocity in +-(2^23)-1 [μsteps / t]
|
||||||
|
* 0: Normal operation. Driver reacts to STEP input.
|
||||||
|
* !=0: Motor moves with the velocity given by VACTUAL. Step pulses can be monitored via INDEX output. The motor direction is controlled by the sign of VACTUAL.
|
||||||
|
*/
|
||||||
|
int vactual: 24;
|
||||||
|
|
||||||
|
unsigned int :8;
|
||||||
|
};
|
||||||
|
|
||||||
|
// =================================================================================================
|
||||||
|
// StallGuard (p.29)
|
||||||
|
// =================================================================================================
|
||||||
|
|
||||||
|
#define REG_ADDR_STALLGUARD_TCOOLTHRS 0x14
|
||||||
|
#define REG_ADDR_STALLGUARD_SGTHRS 0x40
|
||||||
|
#define REG_ADDR_STALLGUARD_SG_RESULT 0x41
|
||||||
|
#define REG_ADDR_STALLGUARD_COOLCONF 0x42
|
||||||
|
|
||||||
|
struct REG_TCOOLTHRS {
|
||||||
|
/**
|
||||||
|
* This is the lower threshold velocity for switching on smart energy CoolStep and StallGuard to DIAG output. (unsigned) Set this parameter to disable CoolStep at low speeds, where it cannot work reliably. The stall output signal become enabled when exceeding this velocity. It becomes disabled again once the velocity falls below this threshold.
|
||||||
|
* TCOOLTHRS ≥ TSTEP > TPWMTHRS
|
||||||
|
* - CoolStep is enabled, if configured (only with StealthChop)
|
||||||
|
* - Stall output signal on pin DIAG is enabled
|
||||||
|
*/
|
||||||
|
unsigned int tcoolthrs: 20;
|
||||||
|
|
||||||
|
unsigned int :12;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct REG_SGTHRS {
|
||||||
|
/**
|
||||||
|
* Detection threshold for stall. The StallGuard value SG_RESULT becomes compared to the double of this threshold. A stall is signaled with
|
||||||
|
* SG_RESULT ≤ SGTHRS*2
|
||||||
|
*/
|
||||||
|
unsigned int sgthrs: 8;
|
||||||
|
|
||||||
|
unsigned int :24;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct REG_SG_RESULT {
|
||||||
|
/**
|
||||||
|
* StallGuard result. SG_RESULT becomes updated with each fullstep, independent of TCOOLTHRS and SGTHRS. A higher value signals a lower motor load and more torque headroom. Intended for StealthChop mode, only. Bits 9 and 0 will always show 0. Scaling to 10 bit is for compatibility to StallGuard2
|
||||||
|
*/
|
||||||
|
unsigned int sg_result: 10;
|
||||||
|
|
||||||
|
unsigned int :22;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct REG_COOLCONF {
|
||||||
|
/**
|
||||||
|
* @brief CoolStep configuration
|
||||||
|
*/
|
||||||
|
unsigned int coolconf: 16;
|
||||||
|
|
||||||
|
unsigned int :16;
|
||||||
|
};
|
||||||
|
|
||||||
|
// =================================================================================================
|
||||||
|
// Sequencer Registers (p.30)
|
||||||
|
// =================================================================================================q
|
||||||
|
|
||||||
|
#define REG_ADDR_SEQUENCER_MSCNT 0x6A
|
||||||
|
#define REG_ADDR_SEQUENCER_MSCURACT 0x6B
|
||||||
|
|
||||||
|
/// @brief Microstep counter
|
||||||
|
struct REG_MSCNT {
|
||||||
|
/**
|
||||||
|
* Microstep counter. Indicates actual position in the microstep table for CUR_A. CUR_B uses an offset of 256 into the table. Reading out MSCNT allows determination of the motor position within the electrical wave.
|
||||||
|
*/
|
||||||
|
unsigned int mscnt: 10;
|
||||||
|
|
||||||
|
unsigned int :22;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief Microstep current (actual)
|
||||||
|
struct REG_MSCURACT {
|
||||||
|
/**
|
||||||
|
* Actual microstep current for motor phase B (sine wave) as read from the internal sine wave table (not scaled by current setting)
|
||||||
|
*/
|
||||||
|
int cur_a: 9;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Actual microstep current for motor phase A (co-sine wave) as read from the internal sine wave table (not scaled by current setting)
|
||||||
|
*/
|
||||||
|
int cur_b: 9;
|
||||||
|
|
||||||
|
unsigned int :14;
|
||||||
|
};
|
||||||
|
|
||||||
|
// =================================================================================================
|
||||||
|
// Chopper Registers (p.32)
|
||||||
|
// =================================================================================================
|
||||||
|
|
||||||
|
#define REG_ADDR_CHOPPER_CHOPCONF 0x6C
|
||||||
|
#define REG_ADDR_CHOPPER_DRV_STATUS 0x6F
|
||||||
|
#define REG_ADDR_CHOPPER_PWMCONF 0x70
|
||||||
|
#define REG_ADDR_CHOPPER_PWM_SCALE 0x71
|
||||||
|
#define REG_ADDR_CHOPPER_PWM_AUTO 0x72
|
||||||
|
|
||||||
|
struct REG_CHOPCONF {
|
||||||
|
/**
|
||||||
|
* @brief off time and driver enable
|
||||||
|
* Off time setting controls duration of slow decay phase
|
||||||
|
* NCLK= 24 + 32*TOFF
|
||||||
|
* %0000: Driver disable, all bridges off
|
||||||
|
* %0001: 1 – use only with TBL ≥ 2
|
||||||
|
* %0010 ... %1111: 2 ... 15
|
||||||
|
* (Default: OTP, resp. 3 in StealthChop mode)
|
||||||
|
*/
|
||||||
|
unsigned int toff: 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief hysteresis start value added to HEND
|
||||||
|
* %000 ... %111:
|
||||||
|
* Add 1, 2, ..., 8 to hysteresis low value HEND
|
||||||
|
* (1/512 of this setting adds to current setting)
|
||||||
|
* Attention: Effective HEND+HSTRT ≤ 16.
|
||||||
|
* Hint: Hysteresis decrement is done each 16 clocks
|
||||||
|
*/
|
||||||
|
unsigned int hstrt: 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief HEND hysteresis low value OFFSET sine wave offset
|
||||||
|
* %0000 ... %1111:
|
||||||
|
* Hysteresis is -3, -2, -1, 0, 1, ..., 12
|
||||||
|
* (1/512 of this setting adds to current setting)
|
||||||
|
* This is the hysteresis value which becomes used for the hysteresis chopper.
|
||||||
|
* (Default: OTP, resp. 0 in StealthChop mode)
|
||||||
|
*/
|
||||||
|
unsigned int hend: 4;
|
||||||
|
|
||||||
|
unsigned int :1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TBL blank time select
|
||||||
|
* %00 ... %11:
|
||||||
|
* Set comparator blank time to 16, 24, 32 or 40 clocks
|
||||||
|
* Hint: %00 or %01 is recommended for most applications
|
||||||
|
* (Default: OTP)
|
||||||
|
*/
|
||||||
|
unsigned int tbl: 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sense resistor voltage based current scaling
|
||||||
|
* 0: Low sensitivity, high sense resistor voltage
|
||||||
|
* 1: High sensitivity, low sense resistor voltage
|
||||||
|
*/
|
||||||
|
unsigned int vsense: 1;
|
||||||
|
|
||||||
|
unsigned int :6;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief micro step resolution
|
||||||
|
* %0000: Native 256 microstep setting.
|
||||||
|
* %0001 ... %1000:
|
||||||
|
* 128, 64, 32, 16, 8, 4, 2, FULLSTEP
|
||||||
|
* Reduced microstep resolution.
|
||||||
|
* The resolution gives the number of microstep entries per sine quarter wave.
|
||||||
|
* When choosing a lower microstep resolution, the driver automatically uses microstep positions which result in a symmetrical wave.
|
||||||
|
* Number of microsteps per step pulse = 2^MRES (Selection by pins unless disabled by GCONF. mstep_reg_select)
|
||||||
|
*/
|
||||||
|
unsigned int mres: 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief interpolation to 256 microsteps
|
||||||
|
* 1: The actual microstep resolution (MRES) becomes extrapolated to 256 microsteps for smoothest motor operation. (Default: 1)
|
||||||
|
*/
|
||||||
|
unsigned int intpol: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief enable double edge step pulses
|
||||||
|
* 1: Enable step impulse at each step edge to reduce step frequency requirement. This mode is not compatible with the step filtering function (multistep_filt)
|
||||||
|
*/
|
||||||
|
unsigned int dedge: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief short to GND protection disable
|
||||||
|
* 0: Short to GND protection is on
|
||||||
|
* 1: Short to GND protection is disabled
|
||||||
|
*/
|
||||||
|
unsigned int diss2g: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Low side short protection disable
|
||||||
|
* 0: Short protection low side is on
|
||||||
|
* 1: Short protection low side is disabled
|
||||||
|
*/
|
||||||
|
unsigned int diss2vs: 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DRV_STATUS {
|
||||||
|
unsigned int drv_status: 32;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PWMCONF {
|
||||||
|
unsigned int pwmconf: 22;
|
||||||
|
unsigned int :10;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Results of StealthChop amplitude regulator. These values can be used to monitor automatic PWM amplitude scaling (255=max. voltage).
|
||||||
|
*/
|
||||||
|
struct PWM_SCALE {
|
||||||
|
/**
|
||||||
|
* Actual PWM duty cycle. This value is used for scaling the values CUR_A and CUR_B read from the sine wave table.
|
||||||
|
*/
|
||||||
|
unsigned int pwm_scale_sum: 8;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 9 Bit signed offset added to the calculated PWM duty cycle. This is the result of the automatic amplitude regulation based on current measurement.
|
||||||
|
*/
|
||||||
|
unsigned int pwm_scale_auto: 9;
|
||||||
|
|
||||||
|
unsigned int :15;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* These automatically generated values can be read out in order to determine a default / power up setting for PWM_GRAD and PWM_OFS.
|
||||||
|
*/
|
||||||
|
struct PWM_AUTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Automatically determined offset value
|
||||||
|
*/
|
||||||
|
unsigned int pwm_ofs_auto: 8;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Automatically determined gradient value
|
||||||
|
*/
|
||||||
|
unsigned int pwm_grad_auto: 8;
|
||||||
|
|
||||||
|
unsigned int :16;
|
||||||
|
};
|
||||||
78
motor-control/firmware/include/tmc2209/step.hpp
Normal file
78
motor-control/firmware/include/tmc2209/step.hpp
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "hardware/pio.h"
|
||||||
|
#include "pulser.pio.h"
|
||||||
|
|
||||||
|
class TMC2209_step_dual {
|
||||||
|
private:
|
||||||
|
uint step0_pin;
|
||||||
|
uint step1_pin;
|
||||||
|
uint dir0_pin;
|
||||||
|
uint dir1_pin;
|
||||||
|
uint enable0_pin;
|
||||||
|
uint enable1_pin;
|
||||||
|
|
||||||
|
const int sm_num_divider0 = 0;
|
||||||
|
const int sm_num_divider1 = 1;
|
||||||
|
const int sm_num_counter0 = 2;
|
||||||
|
const int sm_num_counter1 = 3;
|
||||||
|
|
||||||
|
PIO pio_core;
|
||||||
|
|
||||||
|
pio_sm_config sm_config_divider0;
|
||||||
|
pio_sm_config sm_config_counter0;
|
||||||
|
pio_sm_config sm_config_divider1;
|
||||||
|
pio_sm_config sm_config_counter1;
|
||||||
|
|
||||||
|
uint pulser_program_offset;
|
||||||
|
const uint subprogram_offset_divider = 0;
|
||||||
|
const uint subprogram_offset_counter = 6;
|
||||||
|
|
||||||
|
const float base_clock_freq_khz = 500.0;
|
||||||
|
|
||||||
|
const uint32_t sleep_time_us = 500;
|
||||||
|
bool done_flag0;
|
||||||
|
bool done_flag1;
|
||||||
|
bool done_flag0_arm;
|
||||||
|
bool done_flag1_arm;
|
||||||
|
|
||||||
|
uint remaining_step_count0;
|
||||||
|
uint remaining_step_count1;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void init_pio();
|
||||||
|
void init_gpio();
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
void irq_handler0();
|
||||||
|
void irq_handler1();
|
||||||
|
|
||||||
|
TMC2209_step_dual(
|
||||||
|
uint step0_pin,
|
||||||
|
uint step1_pin,
|
||||||
|
uint dir0_pin,
|
||||||
|
uint dir1_pin,
|
||||||
|
uint enable0_pin,
|
||||||
|
uint enable1_pin,
|
||||||
|
PIO pio_core
|
||||||
|
);
|
||||||
|
|
||||||
|
void set_conf0(uint frequency, bool dir);
|
||||||
|
void set_conf1(uint frequency, bool dir);
|
||||||
|
|
||||||
|
void pulse0(uint n);
|
||||||
|
void pulse1(uint n);
|
||||||
|
|
||||||
|
void pulse0_int(int n);
|
||||||
|
void pulse1_int(int n);
|
||||||
|
|
||||||
|
bool wait0(int timeout_ms);
|
||||||
|
bool wait1(int timeout_ms);
|
||||||
|
|
||||||
|
uint get_remaining_steps0();
|
||||||
|
uint get_remaining_steps1();
|
||||||
|
};
|
||||||
|
|
||||||
|
extern TMC2209_step_dual * g_step_driver_instance;
|
||||||
|
void step_irq0_handler();
|
||||||
|
void step_irq1_handler();
|
||||||
125
motor-control/firmware/include/tmc2209/tmc2209.hpp
Normal file
125
motor-control/firmware/include/tmc2209/tmc2209.hpp
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "pico/stdlib.h"
|
||||||
|
#include "hardware/uart.h"
|
||||||
|
|
||||||
|
#include "registers_map.hpp"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Interface to communicate with TMC2209 driver via UART
|
||||||
|
* This implements basic read and write operations to the TMC2209 driver
|
||||||
|
* It does not implement any register specific operations
|
||||||
|
*/
|
||||||
|
class TMC2209_UART {
|
||||||
|
private:
|
||||||
|
uint8_t node_address;
|
||||||
|
uart_inst_t *uart_inst;
|
||||||
|
uint baudrate;
|
||||||
|
uint tx_pin;
|
||||||
|
uint rx_pin;
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a new tmc2209 uart object
|
||||||
|
* This does not initialize the UART peripheral, it just sets the parameters
|
||||||
|
*
|
||||||
|
* @param uart_id which UART to use (uart0 or uart1)
|
||||||
|
* @param node_address this is the address of the TMC2209 driver set by ms1, ms2 pins (0-3)
|
||||||
|
* @param baudrate UART baudrate to use (250k > baudrate > 2000, good value 115200, the tmc2209 has automatic baudrate detection)
|
||||||
|
* @param tx_pin TX pin of RP2040. Depending on the UART peripheral, diffrent pins are valid
|
||||||
|
* @param rx_pin RX pin of RP2040. Depending on the UART peripheral, diffrent pins are valid
|
||||||
|
*/
|
||||||
|
TMC2209_UART(uart_inst_t *uart_inst, uint8_t node_address, uint baudrate, uint tx_pin, uint rx_pin);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialize UART peripheral and pins
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void init();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Calculate CRC8-ATM checksum for the given data
|
||||||
|
* the specific implementation is taken from TMC2209 datasheet
|
||||||
|
*
|
||||||
|
* @param data Data to calculate CRC for
|
||||||
|
* @param size Size of the data (without CRC byte)
|
||||||
|
* @return uint8_t Calculated CRC8 checksum
|
||||||
|
*/
|
||||||
|
uint8_t calc_crc8_atm(uint8_t *data, uint8_t size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Perform a read operation to the TMC2209 driver
|
||||||
|
* This does not check if register is write only.
|
||||||
|
* It will wait for the response from the driver
|
||||||
|
*
|
||||||
|
* @param address
|
||||||
|
* @return uint32_t Data read from the register
|
||||||
|
*/
|
||||||
|
uint32_t read(uint8_t address);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Perform a write operation to the TMC2209 driver
|
||||||
|
* This does not check if register is read only.
|
||||||
|
* It will wait for the response from the driver
|
||||||
|
*
|
||||||
|
* @param address Where to write the data (register Address)
|
||||||
|
* @param value Data to write to the register
|
||||||
|
*/
|
||||||
|
void write(uint8_t address, uint32_t value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This if any CRC error occured during the last read/write operation. Should be checked after each operation
|
||||||
|
*/
|
||||||
|
bool crc_error_flag = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Higher level interface to TMC2209 driver
|
||||||
|
* This class simplifies dealing with the registers of the TMC2209 driver
|
||||||
|
* so you can just set the values
|
||||||
|
*/
|
||||||
|
class TMC2209_Registers {
|
||||||
|
|
||||||
|
private:
|
||||||
|
TMC2209_UART uart_driver;
|
||||||
|
|
||||||
|
REG_CHOPCONF chopconfBuffer;
|
||||||
|
|
||||||
|
public:
|
||||||
|
TMC2209_Registers(TMC2209_UART uart_driver);
|
||||||
|
|
||||||
|
void set_reg_gconf(
|
||||||
|
bool i_scale_analog,
|
||||||
|
bool internal_rsense,
|
||||||
|
bool en_SpreadCycle,
|
||||||
|
bool shaft,
|
||||||
|
bool index_otpw,
|
||||||
|
bool index_step,
|
||||||
|
bool pdn_disable,
|
||||||
|
bool mstep_reg_select,
|
||||||
|
bool multistep_filt
|
||||||
|
);
|
||||||
|
|
||||||
|
void set_holdCurrent(
|
||||||
|
uint8_t currentHold,
|
||||||
|
uint8_t currentRun,
|
||||||
|
uint8_t holdDelay
|
||||||
|
);
|
||||||
|
|
||||||
|
void set_thresholdPowerdown(uint8_t threshold);
|
||||||
|
void set_thresholdStealthChop(uint32_t threshold);
|
||||||
|
void set_thresholdCoolStep(uint32_t threshold);
|
||||||
|
void set_thresholdStall(uint8_t threshold);
|
||||||
|
|
||||||
|
void set_chopConfig(
|
||||||
|
bool lowsideShortProtection,
|
||||||
|
bool GNDShortProtection,
|
||||||
|
bool doubleEdge,
|
||||||
|
bool interpolation,
|
||||||
|
uint8_t microstepResolution,
|
||||||
|
bool voltageSensatifity,
|
||||||
|
uint8_t hysteresisOffset,
|
||||||
|
uint8_t hysteresisStart
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
1
motor-control/firmware/lib/FreeRTOS-Kernel
Submodule
1
motor-control/firmware/lib/FreeRTOS-Kernel
Submodule
Submodule motor-control/firmware/lib/FreeRTOS-Kernel added at 0240cd55f2
1
motor-control/firmware/lib/doxygen-awesome-css
Submodule
1
motor-control/firmware/lib/doxygen-awesome-css
Submodule
Submodule motor-control/firmware/lib/doxygen-awesome-css added at cc1bee0804
1
motor-control/firmware/lib/pico-sdk
Submodule
1
motor-control/firmware/lib/pico-sdk
Submodule
Submodule motor-control/firmware/lib/pico-sdk added at beb6f990a6
1
motor-control/firmware/lib/tinyusb
Submodule
1
motor-control/firmware/lib/tinyusb
Submodule
Submodule motor-control/firmware/lib/tinyusb added at 3eea46056e
1
motor-control/firmware/rpiPico.code-profile
Normal file
1
motor-control/firmware/rpiPico.code-profile
Normal file
File diff suppressed because one or more lines are too long
2
motor-control/firmware/scripts/build.sh
Executable file
2
motor-control/firmware/scripts/build.sh
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
cd build
|
||||||
|
make -j10
|
||||||
8
motor-control/firmware/scripts/build_and_flash.sh
Executable file
8
motor-control/firmware/scripts/build_and_flash.sh
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
if ! scripts/build.sh; then
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
scripts/flash.exp main.elf
|
||||||
|
fi
|
||||||
|
|
||||||
21
motor-control/firmware/scripts/flash.exp
Executable file
21
motor-control/firmware/scripts/flash.exp
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/expect
|
||||||
|
|
||||||
|
set timeout 30
|
||||||
|
|
||||||
|
set input_file [lindex $argv 0]
|
||||||
|
|
||||||
|
spawn telnet localhost 4444
|
||||||
|
expect "> "
|
||||||
|
send "program $input_file verify\n"
|
||||||
|
expect "** Programming Finished **"
|
||||||
|
|
||||||
|
send "reset halt\n"
|
||||||
|
expect "> "
|
||||||
|
|
||||||
|
send "rp2040.core1 arp_reset assert 0\n"
|
||||||
|
expect "> "
|
||||||
|
send "rp2040.core0 arp_reset assert 0\n"
|
||||||
|
expect "> "
|
||||||
|
|
||||||
|
send "exit\n"
|
||||||
|
exit
|
||||||
3
motor-control/firmware/scripts/flash_direct.sh
Executable file
3
motor-control/firmware/scripts/flash_direct.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
openocd -f interface/cmsis-dap.cfg -c "adapter speed 5000" -f target/rp2040.cfg -c "program $1 verify reset exit"
|
||||||
4
motor-control/firmware/scripts/launch_openocd.sh
Executable file
4
motor-control/firmware/scripts/launch_openocd.sh
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
sudo openocd -f interface/cmsis-dap.cfg -c "adapter speed 5000" -f target/rp2040.cfg
|
||||||
|
|
||||||
2
motor-control/firmware/scripts/launch_serial_monitor.sh
Executable file
2
motor-control/firmware/scripts/launch_serial_monitor.sh
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
minicom -D $1
|
||||||
20
motor-control/firmware/scripts/remote/flash.exp
Executable file
20
motor-control/firmware/scripts/remote/flash.exp
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/expect
|
||||||
|
|
||||||
|
set timeout 30
|
||||||
|
|
||||||
|
set input_file [lindex $argv 0]
|
||||||
|
set host [lindex $argv 1]
|
||||||
|
|
||||||
|
spawn telnet $host 4444
|
||||||
|
expect "> "
|
||||||
|
send "program $input_file verify\n"
|
||||||
|
expect "** Programming Finished **"
|
||||||
|
|
||||||
|
send "reset halt\n"
|
||||||
|
expect "> "
|
||||||
|
|
||||||
|
send "rp2040.core1 arp_reset assert 0\n"
|
||||||
|
expect "> "
|
||||||
|
send "rp2040.core0 arp_reset assert 0\n"
|
||||||
|
expect "> "
|
||||||
|
exit
|
||||||
12
motor-control/firmware/scripts/remote/flash.sh
Executable file
12
motor-control/firmware/scripts/remote/flash.sh
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
in_file=$(basename "$1")
|
||||||
|
|
||||||
|
echo "Input file: $1"
|
||||||
|
echo "Input file (base): $in_file"
|
||||||
|
echo "Host: $2"
|
||||||
|
|
||||||
|
scp $1 $2:/tmp
|
||||||
|
|
||||||
|
./scripts/remote/flash.exp "/tmp/$in_file" "$2"
|
||||||
13
motor-control/firmware/scripts/remote/reset.exp
Executable file
13
motor-control/firmware/scripts/remote/reset.exp
Executable file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/usr/bin/expect
|
||||||
|
|
||||||
|
set timeout 30
|
||||||
|
|
||||||
|
set host [lindex $argv 0]
|
||||||
|
|
||||||
|
spawn telnet $host 4444
|
||||||
|
|
||||||
|
expect "> "
|
||||||
|
send "reset\n"
|
||||||
|
expect "> "
|
||||||
|
send "exit\n"
|
||||||
|
exit
|
||||||
21
motor-control/firmware/scripts/remote/run_openocd.exp
Executable file
21
motor-control/firmware/scripts/remote/run_openocd.exp
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/expect
|
||||||
|
|
||||||
|
set timeout 30
|
||||||
|
|
||||||
|
spawn ssh [lindex $argv 0]
|
||||||
|
|
||||||
|
expect "$ "
|
||||||
|
send "cd ~/gobot/\n"
|
||||||
|
expect "$ "
|
||||||
|
|
||||||
|
send "git fetch\n"
|
||||||
|
expect "$ "
|
||||||
|
|
||||||
|
send "git checkout motor-ctrl-firmware\n"
|
||||||
|
expect "$ "
|
||||||
|
|
||||||
|
send "cd motor-control/firmware/scripts/remote\n"
|
||||||
|
expect "$ "
|
||||||
|
|
||||||
|
send "./run_openocd.sh\n"
|
||||||
|
expect "Kill Me Please, this is should not be triggered!"
|
||||||
3
motor-control/firmware/scripts/remote/run_openocd.sh
Executable file
3
motor-control/firmware/scripts/remote/run_openocd.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
openocd -f interface/cmsis-dap.cfg -c "bindto 0.0.0.0" -c "adapter speed 100" -f target/rp2040.cfg -s tclErt645$
|
||||||
13
motor-control/firmware/scripts/reset.exp
Executable file
13
motor-control/firmware/scripts/reset.exp
Executable file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/usr/bin/expect
|
||||||
|
|
||||||
|
set timeout 30
|
||||||
|
|
||||||
|
set input_file [lindex $argv 0]
|
||||||
|
|
||||||
|
spawn telnet localhost 4444
|
||||||
|
|
||||||
|
expect "> "
|
||||||
|
send "reset\n"
|
||||||
|
expect "> "
|
||||||
|
send "exit\n"
|
||||||
|
exit
|
||||||
307
motor-control/firmware/src/main.cpp
Executable file
307
motor-control/firmware/src/main.cpp
Executable file
@@ -0,0 +1,307 @@
|
|||||||
|
/**
|
||||||
|
* @file main.c
|
||||||
|
* @author AlexanderHD27
|
||||||
|
* @brief Main file of the RPi Pico Firmware for the Oscilloscope-Renderer
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2024-02-15
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "pico/stdio.h"
|
||||||
|
#include "pico/stdlib.h"
|
||||||
|
#include "pico/time.h"
|
||||||
|
#include "hardware/uart.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "pulser.pio.h"
|
||||||
|
#include "tmc2209/tmc2209.hpp"
|
||||||
|
#include "tmc2209/step.hpp"
|
||||||
|
|
||||||
|
#include "FreeRTOSConfig.h"
|
||||||
|
#include "FreeRTOS.h"
|
||||||
|
#include "task.h"
|
||||||
|
|
||||||
|
#define LED_PIN 25
|
||||||
|
|
||||||
|
#define RGB1_B_PIN 21
|
||||||
|
#define RGB1_G_PIN 22
|
||||||
|
|
||||||
|
#define RGB2_R_PIN 26
|
||||||
|
#define RGB2_G_PIN 27
|
||||||
|
#define RGB2_B_PIN 28
|
||||||
|
|
||||||
|
#define BOARD_LED1_PIN 14
|
||||||
|
#define BOARD_LED2_PIN 15
|
||||||
|
|
||||||
|
#define ENABLE0_PIN 2
|
||||||
|
#define ENABLE1_PIN 3
|
||||||
|
|
||||||
|
#define LIMIT0_PIN 10
|
||||||
|
#define LIMIT1_PIN 11
|
||||||
|
#define LIMIT2_PIN 12
|
||||||
|
#define LIMIT3_PIN 13
|
||||||
|
|
||||||
|
#define STEP0_PIN 6
|
||||||
|
#define STEP1_PIN 7
|
||||||
|
#define DIR0_PIN 8
|
||||||
|
#define DIR1_PIN 9
|
||||||
|
|
||||||
|
enum SYSTEM_STATE {
|
||||||
|
STARTUP,
|
||||||
|
HOMEING_FIRST_RUN,
|
||||||
|
HOMEING_BACKOFF,
|
||||||
|
HOMEING_SECOND_RUN,
|
||||||
|
IDLE
|
||||||
|
};
|
||||||
|
|
||||||
|
SYSTEM_STATE system_state = STARTUP;
|
||||||
|
|
||||||
|
|
||||||
|
absolute_time_t debounce_cooldown_ticks= 5000;
|
||||||
|
absolute_time_t limit_debounce_tick = 0;
|
||||||
|
|
||||||
|
|
||||||
|
void isr_LimitSwitch(uint gpio, uint32_t event_mask) {
|
||||||
|
absolute_time_t current_tick = get_absolute_time();
|
||||||
|
if((current_tick - limit_debounce_tick) < debounce_cooldown_ticks) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
limit_debounce_tick = current_tick;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (gpio) {
|
||||||
|
case LIMIT0_PIN:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void homeMotors0(TMC2209_step_dual * driver) {
|
||||||
|
|
||||||
|
driver->set_conf0(10000, 1);
|
||||||
|
driver->pulse0(10000);
|
||||||
|
driver->wait0(0);
|
||||||
|
|
||||||
|
driver->set_conf0(10000, 0);
|
||||||
|
driver->pulse0(100000);
|
||||||
|
while(!gpio_get(LIMIT2_PIN)) {
|
||||||
|
sleep_ms(1);
|
||||||
|
}
|
||||||
|
driver->pulse0(0);
|
||||||
|
sleep_ms(500);
|
||||||
|
|
||||||
|
// Second Run
|
||||||
|
driver->set_conf0(5000, 1);
|
||||||
|
driver->pulse0(200);
|
||||||
|
driver->wait0(0);
|
||||||
|
|
||||||
|
driver->set_conf0(500, 0);
|
||||||
|
driver->pulse0(5000);
|
||||||
|
while(!gpio_get(LIMIT2_PIN)) {
|
||||||
|
sleep_ms(1);
|
||||||
|
}
|
||||||
|
driver->pulse0(0);
|
||||||
|
sleep_ms(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void homeMotors1(TMC2209_step_dual * driver) {
|
||||||
|
|
||||||
|
driver->set_conf1(10000, 1);
|
||||||
|
driver->pulse1(5000);
|
||||||
|
driver->wait1(0);
|
||||||
|
|
||||||
|
driver->set_conf1(10000, 0);
|
||||||
|
driver->pulse1(100000);
|
||||||
|
while(!gpio_get(LIMIT3_PIN)) {
|
||||||
|
sleep_ms(1);
|
||||||
|
}
|
||||||
|
driver->pulse1(0);
|
||||||
|
sleep_ms(500);
|
||||||
|
|
||||||
|
// Second Run
|
||||||
|
driver->set_conf1(5000, 1);
|
||||||
|
driver->pulse1(200);
|
||||||
|
driver->wait1(0);
|
||||||
|
|
||||||
|
driver->set_conf1(500, 0);
|
||||||
|
driver->pulse1(5000);
|
||||||
|
while(!gpio_get(LIMIT3_PIN)) {
|
||||||
|
sleep_ms(1);
|
||||||
|
}
|
||||||
|
driver->pulse1(0);
|
||||||
|
sleep_ms(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void task_home0(void *pvParameters) {
|
||||||
|
TMC2209_step_dual * driver = (TMC2209_step_dual *)pvParameters;
|
||||||
|
vTaskDelay(500);
|
||||||
|
homeMotors0(driver);
|
||||||
|
}
|
||||||
|
|
||||||
|
void task_home1(void *pvParameters) {
|
||||||
|
TMC2209_step_dual * driver = (TMC2209_step_dual *)pvParameters;
|
||||||
|
homeMotors1(driver);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
sleep_ms(100);
|
||||||
|
stdio_usb_init();
|
||||||
|
|
||||||
|
gpio_init(DIR0_PIN);
|
||||||
|
gpio_set_dir(DIR0_PIN, GPIO_OUT);
|
||||||
|
gpio_put(DIR0_PIN, 0);
|
||||||
|
|
||||||
|
gpio_init(DIR1_PIN);
|
||||||
|
gpio_set_dir(DIR1_PIN, GPIO_OUT);
|
||||||
|
gpio_put(DIR1_PIN, 0);
|
||||||
|
|
||||||
|
for(int i=0; i<100; i++) {
|
||||||
|
gpio_put(DIR0_PIN, 1);
|
||||||
|
gpio_put(DIR1_PIN, 1);
|
||||||
|
sleep_ms(2);
|
||||||
|
gpio_put(DIR0_PIN, 0);
|
||||||
|
gpio_put(DIR1_PIN, 0);
|
||||||
|
sleep_ms(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TMC2209_step_dual step_driver = TMC2209_step_dual(
|
||||||
|
STEP0_PIN, STEP1_PIN,
|
||||||
|
DIR0_PIN, DIR1_PIN,
|
||||||
|
ENABLE0_PIN, ENABLE1_PIN,
|
||||||
|
pio0
|
||||||
|
);
|
||||||
|
TMC2209_UART uart_driver0 = TMC2209_UART(uart0, 0, 19200, 0, 1);
|
||||||
|
TMC2209_UART uart_driver1 = TMC2209_UART(uart1, 0, 19200, 4, 5);
|
||||||
|
uart_driver0.init();
|
||||||
|
uart_driver1.init();
|
||||||
|
|
||||||
|
sleep_ms(5);
|
||||||
|
|
||||||
|
//step_driver.set_conf1(10000, 0);
|
||||||
|
//step_driver.set_conf0(10000, 0);
|
||||||
|
//step_driver.pulse1(1000);
|
||||||
|
//step_driver.pulse0(1000);
|
||||||
|
//step_driver.wait1(0);
|
||||||
|
//step_driver.wait0(0);
|
||||||
|
|
||||||
|
gpio_init(LIMIT0_PIN);
|
||||||
|
gpio_set_dir(LIMIT0_PIN, GPIO_IN);
|
||||||
|
gpio_pull_up(LIMIT0_PIN);
|
||||||
|
gpio_set_input_hysteresis_enabled(LIMIT0_PIN, true);
|
||||||
|
|
||||||
|
gpio_init(LIMIT1_PIN);
|
||||||
|
gpio_set_dir(LIMIT1_PIN, GPIO_IN);
|
||||||
|
gpio_pull_up(LIMIT1_PIN);
|
||||||
|
gpio_set_input_hysteresis_enabled(LIMIT1_PIN, true);
|
||||||
|
|
||||||
|
gpio_init(LIMIT2_PIN);
|
||||||
|
gpio_set_dir(LIMIT2_PIN, GPIO_IN);
|
||||||
|
gpio_pull_up(LIMIT2_PIN);
|
||||||
|
gpio_set_input_hysteresis_enabled(LIMIT2_PIN, true);
|
||||||
|
|
||||||
|
gpio_init(LIMIT3_PIN);
|
||||||
|
gpio_set_dir(LIMIT3_PIN, GPIO_IN);
|
||||||
|
gpio_pull_up(LIMIT3_PIN);
|
||||||
|
gpio_set_input_hysteresis_enabled(LIMIT3_PIN, true);
|
||||||
|
|
||||||
|
/*
|
||||||
|
gpio_set_irq_enabled_with_callback(
|
||||||
|
LIMIT0_PIN,
|
||||||
|
GPIO_IRQ_EDGE_RISE,
|
||||||
|
true,
|
||||||
|
isr_LimitSwitch
|
||||||
|
);
|
||||||
|
gpio_set_irq_enabled_with_callback(
|
||||||
|
LIMIT1_PIN,
|
||||||
|
GPIO_IRQ_EDGE_RISE,
|
||||||
|
true,
|
||||||
|
isr_LimitSwitch
|
||||||
|
);
|
||||||
|
gpio_set_irq_enabled_with_callback(
|
||||||
|
LIMIT2_PIN,
|
||||||
|
GPIO_IRQ_EDGE_RISE,
|
||||||
|
true,
|
||||||
|
isr_LimitSwitch
|
||||||
|
);
|
||||||
|
gpio_set_irq_enabled_with_callback(
|
||||||
|
LIMIT3_PIN,
|
||||||
|
GPIO_IRQ_EDGE_RISE,
|
||||||
|
true,
|
||||||
|
isr_LimitSwitch
|
||||||
|
);*/
|
||||||
|
|
||||||
|
gpio_init(RGB2_B_PIN);
|
||||||
|
gpio_init(RGB2_G_PIN);
|
||||||
|
gpio_init(RGB2_R_PIN);
|
||||||
|
gpio_set_dir(RGB2_B_PIN, GPIO_OUT);
|
||||||
|
gpio_set_dir(RGB2_G_PIN, GPIO_OUT);
|
||||||
|
gpio_set_dir(RGB2_R_PIN, GPIO_OUT);
|
||||||
|
|
||||||
|
gpio_init(RGB1_B_PIN);
|
||||||
|
gpio_init(RGB1_G_PIN);
|
||||||
|
gpio_set_dir(RGB1_B_PIN, GPIO_OUT);
|
||||||
|
gpio_set_dir(RGB1_G_PIN, GPIO_OUT);
|
||||||
|
|
||||||
|
gpio_put(RGB1_B_PIN, 1);
|
||||||
|
gpio_put(RGB1_G_PIN, 1);
|
||||||
|
gpio_put(RGB2_B_PIN, 1);
|
||||||
|
gpio_put(RGB2_G_PIN, 1);
|
||||||
|
gpio_put(RGB2_R_PIN, 1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
gpio_init(LED_PIN);
|
||||||
|
gpio_set_dir(LED_PIN, GPIO_OUT);
|
||||||
|
|
||||||
|
//step_driver.set_conf0(10000, 0);
|
||||||
|
//step_driver.pulse0(1000000);
|
||||||
|
*/
|
||||||
|
homeMotors0(&step_driver);
|
||||||
|
printf("Home0 done\n");
|
||||||
|
homeMotors1(&step_driver);
|
||||||
|
printf("Home1 done\n");
|
||||||
|
|
||||||
|
//xTaskCreate(task_home0, "Home0", 1024, &step_driver, 5, NULL);
|
||||||
|
//xTaskCreate(task_home1, "Home1", 1024, &step_driver, 5, NULL);
|
||||||
|
vTaskStartScheduler();
|
||||||
|
|
||||||
|
/*
|
||||||
|
while (true) {
|
||||||
|
sleep_ms(50);
|
||||||
|
gpio_put(LED_PIN, 0);
|
||||||
|
sleep_ms(50);
|
||||||
|
gpio_put(LED_PIN, 1);
|
||||||
|
|
||||||
|
if(gpio_get(LIMIT1_PIN)) {
|
||||||
|
gpio_put(RGB1_B_PIN, 0);
|
||||||
|
} else {
|
||||||
|
gpio_put(RGB1_B_PIN, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(gpio_get(LIMIT3_PIN)) {
|
||||||
|
gpio_put(RGB1_G_PIN, 0);
|
||||||
|
} else {
|
||||||
|
gpio_put(RGB1_G_PIN, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(gpio_get(LIMIT0_PIN)) {
|
||||||
|
gpio_put(RGB2_B_PIN, 0);
|
||||||
|
} else {
|
||||||
|
gpio_put(RGB2_B_PIN, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(gpio_get(LIMIT2_PIN)) {
|
||||||
|
gpio_put(RGB2_G_PIN, 0);
|
||||||
|
} else {
|
||||||
|
gpio_put(RGB2_G_PIN, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user