Compare commits
17 Commits
motor-ctrl
...
stone-disp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
801e791199 | ||
|
|
bdec2db94d | ||
|
|
c1dc89eb58 | ||
|
|
f26cc07558 | ||
|
|
c6fd825e39 | ||
|
|
e7a0035041 | ||
|
|
4bfb1f533e | ||
|
|
5683168a47 | ||
|
|
9c0c676be8 | ||
|
|
b150a905a3 | ||
|
|
7eebf619ae | ||
|
|
93c40e1805 | ||
|
|
91c2125458 | ||
|
|
096a6c18d6 | ||
|
|
48fded7981 | ||
|
|
ec5e5cbf13 | ||
|
|
58d31964b2 |
BIN
.gitmodules
(Stored with Git LFS)
vendored
BIN
.gitmodules
(Stored with Git LFS)
vendored
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
can-interface/.gitignore
(Stored with Git LFS)
vendored
BIN
can-interface/.gitignore
(Stored with Git LFS)
vendored
Binary file not shown.
5
can-interface/.vscode/settings.json
vendored
5
can-interface/.vscode/settings.json
vendored
@@ -14,6 +14,8 @@
|
||||
"idf.pythonBinPath": "/home/alexander/.espressif/python_env/idf5.3_py3.12_env/bin/python",
|
||||
"idf.toolsPath": "/home/alexander/.espressif",
|
||||
"idf.flashType": "UART",
|
||||
"idf.openOcdLaunchArgs": ["-c", "adapter_khz 1000"],
|
||||
"idf.openOcdDebugLevel": 2,
|
||||
"files.associations": {
|
||||
"*.tcc": "cpp",
|
||||
"cstdint": "cpp",
|
||||
@@ -24,6 +26,7 @@
|
||||
"regex": "cpp",
|
||||
"array": "cpp",
|
||||
"string": "cpp",
|
||||
"span": "cpp"
|
||||
"span": "cpp",
|
||||
"cstring": "cpp"
|
||||
}
|
||||
}
|
||||
|
||||
BIN
can-interface/circuit/CanIntefacePerfboard.fzz
Normal file
BIN
can-interface/circuit/CanIntefacePerfboard.fzz
Normal file
Binary file not shown.
BIN
can-interface/circuit/gobot-can-interface/external/ESP32-DEVKIT-V1/ESP32-DEVKIT-V1.kicad_sym
(Stored with Git LFS)
vendored
Normal file
BIN
can-interface/circuit/gobot-can-interface/external/ESP32-DEVKIT-V1/ESP32-DEVKIT-V1.kicad_sym
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
can-interface/circuit/gobot-can-interface/external/ESP32-DEVKIT-V1/ESP32-DEVKIT-V1.step
(Stored with Git LFS)
vendored
Normal file
BIN
can-interface/circuit/gobot-can-interface/external/ESP32-DEVKIT-V1/ESP32-DEVKIT-V1.step
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
can-interface/circuit/gobot-can-interface/external/ESP32-DEVKIT-V1/MODULE_ESP32_DEVKIT_V1.kicad_mod
(Stored with Git LFS)
vendored
Normal file
BIN
can-interface/circuit/gobot-can-interface/external/ESP32-DEVKIT-V1/MODULE_ESP32_DEVKIT_V1.kicad_mod
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
1
can-interface/circuit/gobot-can-interface/external/ESP32-DEVKIT-V1/how-to-import.htm
vendored
Normal file
1
can-interface/circuit/gobot-can-interface/external/ESP32-DEVKIT-V1/how-to-import.htm
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<!DOCTYPE HTML><html lang="en-US"> <head> <meta charset="UTF-8"> <meta http-equiv="refresh" content="0; url=https://www.snapeda.com/about/import/#"> <script type="text/javascript">window.location.href="https://www.snapeda.com/about/import/#" </script> <title>Page Redirection</title> </head> <body> If you are not redirected automatically, follow this <a href="https://www.snapeda.com/about/import/#">link to the import guide</a>. </body></html>
|
||||
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-08_133537.zip
(Stored with Git LFS)
Normal file
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-08_133537.zip
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-12_000642.zip
(Stored with Git LFS)
Normal file
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-12_000642.zip
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-12_001228.zip
(Stored with Git LFS)
Normal file
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-12_001228.zip
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-12_010429.zip
(Stored with Git LFS)
Normal file
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-12_010429.zip
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-12_011347.zip
(Stored with Git LFS)
Normal file
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-12_011347.zip
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-14_202426.zip
(Stored with Git LFS)
Normal file
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-14_202426.zip
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-15_170909.zip
(Stored with Git LFS)
Normal file
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-15_170909.zip
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-15_204011.zip
(Stored with Git LFS)
Normal file
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-15_204011.zip
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-21_223757.zip
(Stored with Git LFS)
Normal file
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-21_223757.zip
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-30_000501.zip
(Stored with Git LFS)
Normal file
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-30_000501.zip
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-30_140231.zip
(Stored with Git LFS)
Normal file
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-11-30_140231.zip
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-12-22_095043.zip
(Stored with Git LFS)
Normal file
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-12-22_095043.zip
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-12-27_204815.zip
(Stored with Git LFS)
Normal file
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface-backups/gobot-can-interface-2024-12-27_204815.zip
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface.kicad_pcb
(Stored with Git LFS)
Normal file
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface.kicad_pcb
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface.kicad_prl
(Stored with Git LFS)
Normal file
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface.kicad_prl
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface.kicad_pro
(Stored with Git LFS)
Normal file
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface.kicad_pro
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface.kicad_sch
(Stored with Git LFS)
Normal file
BIN
can-interface/circuit/gobot-can-interface/gobot-can-interface.kicad_sch
(Stored with Git LFS)
Normal file
Binary file not shown.
File diff suppressed because it is too large
Load Diff
4
can-interface/circuit/gobot-can-interface/sym-lib-table
Normal file
4
can-interface/circuit/gobot-can-interface/sym-lib-table
Normal file
@@ -0,0 +1,4 @@
|
||||
(sym_lib_table
|
||||
(version 7)
|
||||
(lib (name "ESP32-DEVKIT-V1")(type "KiCad")(uri "${KIPRJMOD}/external/ESP32-DEVKIT-V1/ESP32-DEVKIT-V1.kicad_sym")(options "")(descr ""))
|
||||
)
|
||||
1
can-interface/components/gobot_rpc
Symbolic link
1
can-interface/components/gobot_rpc
Symbolic link
@@ -0,0 +1 @@
|
||||
/home/alexander/Projects/gobot/common-libaries/gobot_rpc
|
||||
File diff suppressed because it is too large
Load Diff
1
can-interface/docs/doxygen-awesome-css
Submodule
1
can-interface/docs/doxygen-awesome-css
Submodule
Submodule can-interface/docs/doxygen-awesome-css added at 568f56cde6
@@ -2,5 +2,6 @@ idf_component_register(SRCS "hello_world_main.cpp"
|
||||
REQUIRES driver
|
||||
REQUIRES mcp2521
|
||||
REQUIRES mcp2521_hardware_interface
|
||||
REQUIRES gobot_rpc
|
||||
REQUIRES spi_flash
|
||||
INCLUDE_DIRS "")
|
||||
|
||||
@@ -23,26 +23,43 @@
|
||||
|
||||
#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
|
||||
#define SPI_PIN_CS0 GPIO_NUM_25
|
||||
#define SPI_PIN_CS1 GPIO_NUM_27
|
||||
|
||||
void onRX(void *arg) {
|
||||
#define CAN_INT0_PIN GPIO_NUM_5
|
||||
#define CAN_INT1_PIN GPIO_NUM_26
|
||||
|
||||
void onRX0(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);
|
||||
//mcp2521->read_rx_buf(MCP2521_RX_BUFFER::RXB0, MCP2521_BUFFER_TYPE::DATA, data, info.length);
|
||||
|
||||
printf("RX0: (%x) ", info.id);
|
||||
//for (int i = 0; i < 8; i++) {
|
||||
// printf("%x ", data[i]);
|
||||
//}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void onRX1(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("RX1: (%x) ", info.id);
|
||||
//for (int i = 0; i < 8; i++) {
|
||||
// printf("%x ", data[i]);
|
||||
//}
|
||||
|
||||
printf("RX: (%x) ", info.id);
|
||||
for (int i = 0; i < info.length; i++) {
|
||||
printf("%x ", data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
@@ -52,46 +69,58 @@ extern "C" void app_main() {
|
||||
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);
|
||||
|
||||
MCP2521_HardwareHandleFactory_ESPBus mcp2521_hardware_factory(
|
||||
VSPI_HOST,
|
||||
SPI_PIN_MOSI,
|
||||
SPI_PIN_MISO,
|
||||
SPI_PIN_SCLK
|
||||
);
|
||||
|
||||
MCP2521_HardwareHandle_ESPBus hardware_mcp2521_0 = mcp2521_hardware_factory.create(CAN_INT0_PIN, SPI_PIN_CS0);
|
||||
MCP2521_HardwareHandle_ESPBus hardware_mcp2521_1 = mcp2521_hardware_factory.create(CAN_INT1_PIN, SPI_PIN_CS1);
|
||||
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
|
||||
MCP2521 mcp2521_0(&hardware_mcp2521_0);
|
||||
MCP2521 mcp2521_1(&hardware_mcp2521_1);
|
||||
|
||||
spi_bus_config_t spi_bus;
|
||||
uint8_t data[8] = {0x1, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
|
||||
|
||||
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_0.reset();
|
||||
mcp2521_1.reset();
|
||||
mcp2521_0.enable_interrupts(true, true, true, true, true, true, true, true);
|
||||
mcp2521_1.enable_interrupts(true, true, true, true, true, true, true, true);
|
||||
|
||||
MCP2521 mcp2521(&hardware_mcp2521);
|
||||
mcp2521_0.register_rx0_handler(onRX0, &mcp2521_0);
|
||||
mcp2521_1.register_rx0_handler(onRX1, &mcp2521_1);
|
||||
mcp2521_0.register_rx1_handler(onRX0, &mcp2521_0);
|
||||
mcp2521_1.register_rx1_handler(onRX1, &mcp2521_1);
|
||||
|
||||
uint8_t data[4] = {0xf0, 0x42, 0x13, 0x37};
|
||||
mcp2521_0.set_mode_of_operation(MCP2521_OPERATION_MODE::LOOPBACK, true);
|
||||
mcp2521_1.set_mode_of_operation(MCP2521_OPERATION_MODE::LOOPBACK, true);
|
||||
|
||||
gpio_set_level(EXTERNAL_TRIGGER, false);
|
||||
mcp2521.reset();
|
||||
mcp2521.enable_interrupts(true, true, true, true, true, true, true, true);
|
||||
//printf("CANSTAT0: %x\n", mcp2521_0.read_reg(MCP2521_CANSTAT));
|
||||
//printf("CANSTAT1: %x\n", mcp2521_1.read_reg(MCP2521_CANSTAT));
|
||||
|
||||
mcp2521.register_rx0_handler(onRX, &mcp2521);
|
||||
mcp2521.register_rx1_handler(onRX, &mcp2521);
|
||||
mcp2521.set_mode_of_operation(MCP2521_OPERATION_MODE::LOOPBACK, true);
|
||||
vTaskDelay(20 / portTICK_PERIOD_MS);
|
||||
|
||||
vTaskDelay(3 / portTICK_PERIOD_MS);
|
||||
mcp2521_1.prepare_tx(
|
||||
MCP2521_TX_BUFFER::TXB0, 0x042, data, 8, false, false);
|
||||
//mcp2521_1.prepare_tx(
|
||||
// MCP2521_TX_BUFFER::TXB0, 0x041, data, 4, false, false);
|
||||
|
||||
mcp2521.prepare_tx(
|
||||
MCP2521_TX_BUFFER::TXB0, 0x042, data, 4, false, false);
|
||||
|
||||
mcp2521.request_to_send(MCP2521_TX_BUFFER::TXB0);
|
||||
vTaskDelay(20 / portTICK_PERIOD_MS);
|
||||
mcp2521_1.request_to_send(MCP2521_TX_BUFFER::TXB0);
|
||||
//vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
//mcp2521_1.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);
|
||||
|
||||
//mcp2521_0.set_tx_id(MCP2521_TX_BUFFER::TXB0, 0x042, false);
|
||||
//mcp2521_0.request_to_send(MCP2521_TX_BUFFER::TXB0);
|
||||
|
||||
vTaskDelay(20 / portTICK_PERIOD_MS);
|
||||
|
||||
@@ -100,6 +129,6 @@ extern "C" void app_main() {
|
||||
gpio_set_level(LED_PIN, flag);
|
||||
flag = !flag;
|
||||
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
2008
can-interface/sdkconfig.old
Normal file
2008
can-interface/sdkconfig.old
Normal file
File diff suppressed because it is too large
Load Diff
152
can-interface/session-setup
Normal file
152
can-interface/session-setup
Normal file
@@ -0,0 +1,152 @@
|
||||
[General]
|
||||
decode_signals=2
|
||||
meta_objs=0
|
||||
views=1
|
||||
|
||||
[D0]
|
||||
color=4291714048
|
||||
conv_options=0
|
||||
conversion_type=0
|
||||
enabled=true
|
||||
name=INT0
|
||||
|
||||
[D1]
|
||||
color=4281623972
|
||||
conv_options=0
|
||||
conversion_type=0
|
||||
enabled=true
|
||||
name=CLK
|
||||
|
||||
[D2]
|
||||
color=4281623972
|
||||
conv_options=0
|
||||
conversion_type=0
|
||||
enabled=true
|
||||
name=MOSI
|
||||
|
||||
[D3]
|
||||
color=4281623972
|
||||
conv_options=0
|
||||
conversion_type=0
|
||||
enabled=true
|
||||
name=MISO
|
||||
|
||||
[D4]
|
||||
color=4294277376
|
||||
conv_options=0
|
||||
conversion_type=0
|
||||
enabled=true
|
||||
name=CE0
|
||||
|
||||
[D5]
|
||||
color=4279638298
|
||||
conv_options=0
|
||||
conversion_type=0
|
||||
enabled=true
|
||||
name=INT1
|
||||
|
||||
[D6]
|
||||
color=4279638298
|
||||
conv_options=0
|
||||
conversion_type=0
|
||||
enabled=true
|
||||
name=CE1
|
||||
|
||||
[D7]
|
||||
color=4285878395
|
||||
conv_options=0
|
||||
conversion_type=0
|
||||
enabled=true
|
||||
name=D7
|
||||
|
||||
[decode_signal0]
|
||||
channel0\assigned_signal_name=CLK
|
||||
channel0\initial_pin_state=2
|
||||
channel0\name=CLK
|
||||
channel1\assigned_signal_name=MISO
|
||||
channel1\initial_pin_state=2
|
||||
channel1\name=MISO
|
||||
channel2\assigned_signal_name=MOSI
|
||||
channel2\initial_pin_state=2
|
||||
channel2\name=MOSI
|
||||
channel3\assigned_signal_name=CE0
|
||||
channel3\initial_pin_state=2
|
||||
channel3\name=CS#
|
||||
channels=4
|
||||
color=4294277376
|
||||
conv_options=0
|
||||
conversion_type=0
|
||||
decoder0\ann_class0\visible=true
|
||||
decoder0\ann_class1\visible=true
|
||||
decoder0\ann_class2\visible=true
|
||||
decoder0\ann_class3\visible=true
|
||||
decoder0\ann_class4\visible=true
|
||||
decoder0\ann_class5\visible=true
|
||||
decoder0\ann_class6\visible=true
|
||||
decoder0\id=spi
|
||||
decoder0\options=0
|
||||
decoder0\row0\visible=true
|
||||
decoder0\row1\visible=true
|
||||
decoder0\row2\visible=true
|
||||
decoder0\row3\visible=true
|
||||
decoder0\row4\visible=true
|
||||
decoder0\row5\visible=true
|
||||
decoder0\row6\visible=true
|
||||
decoder0\visible=true
|
||||
decoders=1
|
||||
enabled=true
|
||||
name=SPI0
|
||||
|
||||
[decode_signal1]
|
||||
channel0\assigned_signal_name=CLK
|
||||
channel0\initial_pin_state=2
|
||||
channel0\name=CLK
|
||||
channel1\assigned_signal_name=MISO
|
||||
channel1\initial_pin_state=2
|
||||
channel1\name=MISO
|
||||
channel2\assigned_signal_name=MOSI
|
||||
channel2\initial_pin_state=2
|
||||
channel2\name=MOSI
|
||||
channel3\assigned_signal_name=CE1
|
||||
channel3\initial_pin_state=2
|
||||
channel3\name=CS#
|
||||
channels=4
|
||||
color=4279638298
|
||||
conv_options=0
|
||||
conversion_type=0
|
||||
decoder0\ann_class0\visible=true
|
||||
decoder0\ann_class1\visible=true
|
||||
decoder0\ann_class2\visible=true
|
||||
decoder0\ann_class3\visible=true
|
||||
decoder0\ann_class4\visible=true
|
||||
decoder0\ann_class5\visible=true
|
||||
decoder0\ann_class6\visible=true
|
||||
decoder0\id=spi
|
||||
decoder0\options=0
|
||||
decoder0\row0\visible=true
|
||||
decoder0\row1\visible=true
|
||||
decoder0\row2\visible=true
|
||||
decoder0\row3\visible=true
|
||||
decoder0\row4\visible=true
|
||||
decoder0\row5\visible=true
|
||||
decoder0\row6\visible=true
|
||||
decoder0\visible=true
|
||||
decoders=1
|
||||
enabled=true
|
||||
name=SPI1
|
||||
|
||||
[view0]
|
||||
D0\trace_height=38
|
||||
D1\trace_height=38
|
||||
D2\trace_height=38
|
||||
D3\trace_height=38
|
||||
D4\trace_height=38
|
||||
D5\trace_height=38
|
||||
D6\trace_height=38
|
||||
D7\trace_height=38
|
||||
offset=22 serialization::archive 19 0 0 0 0 52315583 48568089 25582163 47181659 91047901 0 -8 1 0 6
|
||||
scale=0.0021854614351496547
|
||||
segment_display_mode=1
|
||||
splitter_state=@ByteArray(\0\0\0\xff\0\0\0\x1\0\0\0\x2\0\0\0Z\0\0\x5\xa2\x1\0\0\0\x1\x1\0\0\0\x1\0)
|
||||
v_offset=-10
|
||||
zero_offset=22 serialization::archive 19 0 0 0 0 0 0 0 0 0 0 0 0 0 6
|
||||
10
common-libaries/gobot_rpc/CMakeLists.txt
Normal file
10
common-libaries/gobot_rpc/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
idf_component_register(SRCS
|
||||
"gobot_rpc_sender.cpp"
|
||||
"gobot_rpc_receiver.cpp"
|
||||
"gobot_rpc_statemaschine.cpp"
|
||||
"gobot_rpc_numberMap.cpp"
|
||||
"gobot_rpc_transiver.cpp"
|
||||
REQUIRES mcp2521
|
||||
REQUIRES mcp2521_hardware_interface
|
||||
REQUIRES driver
|
||||
INCLUDE_DIRS "include")
|
||||
19
common-libaries/gobot_rpc/gobot_rpc_numberMap.cpp
Normal file
19
common-libaries/gobot_rpc/gobot_rpc_numberMap.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "gobot_rpc.hpp"
|
||||
#include "protocol_spec.hpp"
|
||||
#include <string.h>
|
||||
|
||||
GobotRPCNumberMap::GobotRPCNumberMap() {
|
||||
memset(rpc_number_map, 0xffffffff, 16);
|
||||
}
|
||||
|
||||
GobotRPCNumberMap::~GobotRPCNumberMap() {
|
||||
|
||||
}
|
||||
|
||||
void GobotRPCNumberMap::set(RpcNum rpc_num, uint32_t id) {
|
||||
rpc_number_map[(int)rpc_num] = id;
|
||||
}
|
||||
|
||||
uint32_t GobotRPCNumberMap::get(RpcNum rpc_num) {
|
||||
return rpc_number_map[(int)rpc_num];
|
||||
}
|
||||
43
common-libaries/gobot_rpc/gobot_rpc_receiver.cpp
Normal file
43
common-libaries/gobot_rpc/gobot_rpc_receiver.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <string.h>
|
||||
#include "gobot_rpc.hpp"
|
||||
#include "sm.hpp"
|
||||
#include "protocol_spec.hpp"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
|
||||
GobotRPCReciver::GobotRPCReciver(MCP2521 * can_interface) {
|
||||
this->can_interface = can_interface;
|
||||
this->state_mashine = GobotRPCStateMashine();
|
||||
|
||||
can_interface->register_rx0_handler(onRX0_GoboRPC, can_interface);
|
||||
}
|
||||
|
||||
|
||||
void onRX0_GoboRPC(void *arg) {
|
||||
GobotRPCReciver *rpc_socket = (GobotRPCReciver *)arg;
|
||||
rpc_socket->onRX();
|
||||
}
|
||||
|
||||
void GobotRPCReciver::onRX() {
|
||||
rx_info info = can_interface->get_rx_id(MCP2521_RX_BUFFER::RXB0);
|
||||
uint8_t data[8];
|
||||
|
||||
can_interface->read_rx_buf(MCP2521_RX_BUFFER::RXB0, MCP2521_BUFFER_TYPE::DATA, data, info.length);
|
||||
|
||||
RPCFrame frame;
|
||||
memcpy(((char *)data) + 1, (char *)frame.data, 7);
|
||||
frame.header = (RPCHeader)(data[0]);
|
||||
|
||||
SMResult smResult;
|
||||
state_mashine.submitFrame(&frame, &smResult);
|
||||
|
||||
if(smResult.done) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void GobotRPCReciver::registerOnDoneFrameHandler(GobotRPCHandler_t handler, void * arg) {
|
||||
onDoneFrameHandler = handler;
|
||||
argOnDoneFrameHandler = arg;
|
||||
}
|
||||
|
||||
74
common-libaries/gobot_rpc/gobot_rpc_statemaschine.cpp
Normal file
74
common-libaries/gobot_rpc/gobot_rpc_statemaschine.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#include "sm.hpp"
|
||||
#include "protocol_spec.hpp"
|
||||
#include <string.h>
|
||||
|
||||
GobotRPCStateMashine::GobotRPCStateMashine() {
|
||||
memset(requestDataBuffer, 0, REQUEST_DATA_BUFFER_SIZE*sizeof(uint8_t)*SLOTS);
|
||||
memset(responseDataBuffer, 0, RESPONSE_DATA_BUFFER_SIZE*sizeof(uint8_t)*SLOTS);
|
||||
memset(errorDataBuffer, 0, RESPONSE_DATA_BUFFER_SIZE*sizeof(uint8_t)*SLOTS);
|
||||
|
||||
memset(requestSegmentArrivedFlags, 0, sizeof(uint8_t)*SLOTS);
|
||||
memset(responseSegmentArrivedFlags, 0, sizeof(uint8_t)*SLOTS);
|
||||
memset(errorSegmentArrivedFlags, 0, sizeof(uint8_t)*SLOTS);
|
||||
|
||||
slotCounter = 0;
|
||||
rpc_number_map = GobotRPCNumberMap();
|
||||
}
|
||||
|
||||
void GobotRPCStateMashine::registerRPC(RpcNum rpc_num) {
|
||||
rpc_number_map.set(rpc_num, slotCounter);
|
||||
slotCounter = (slotCounter + 1) % SLOTS;
|
||||
}
|
||||
|
||||
void GobotRPCStateMashine::submitFrame(RPCFrame * frame, SMResult * result) {
|
||||
RpcNum rpcNum = (RpcNum)(frame->header.rpc_num);
|
||||
|
||||
result->done = false;
|
||||
result->rpc_num = rpcNum;
|
||||
|
||||
if(rpcNum == RpcNum::INVALID)
|
||||
return;
|
||||
|
||||
size_t slot = rpc_number_map.get(rpcNum);
|
||||
if (slot == 0xffffffff)
|
||||
return;
|
||||
|
||||
uint8_t segNum = frame->header.rpc_segement;
|
||||
|
||||
if(frame->header.error) {
|
||||
memcpy(result->data, frame->data, 7);
|
||||
errorSegmentArrivedFlags[slot] |= (1 << segNum);
|
||||
|
||||
result->done = true;
|
||||
result->type = RPCPackageType::ERROR;
|
||||
|
||||
} else if(frame->header.response) {
|
||||
memcpy(responseDataBuffer[slot] + segNum, frame->data, 7);
|
||||
responseSegmentArrivedFlags[slot] |= (1 << segNum);
|
||||
|
||||
uint8_t mask = SEGMENT_MASK_RESPONSE[(int)rpcNum];
|
||||
|
||||
if(((responseSegmentArrivedFlags[slot] & mask) ^ mask) == 0) {
|
||||
responseSegmentArrivedFlags[slot] = 0;
|
||||
|
||||
result->done = true;
|
||||
memcpy(result->data, responseDataBuffer[slot], 7*4);
|
||||
result->type = RPCPackageType::RESPONSE;
|
||||
}
|
||||
|
||||
} else {
|
||||
memcpy(requestDataBuffer[slot] + segNum, frame->data, 7);
|
||||
requestSegmentArrivedFlags[slot] |= (1 << segNum);
|
||||
|
||||
uint8_t mask = SEGMENT_MASK_RESPONSE[(int)rpcNum];
|
||||
|
||||
if(((requestSegmentArrivedFlags[slot] & mask) ^ mask) == 0) {
|
||||
requestSegmentArrivedFlags[slot] = 0;
|
||||
|
||||
result->done = true;
|
||||
memcpy(result->data, requestDataBuffer[slot], 7*4);
|
||||
result->type = RPCPackageType::REQUEST;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
56
common-libaries/gobot_rpc/include/gobot_rpc.hpp
Normal file
56
common-libaries/gobot_rpc/include/gobot_rpc.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
#include "protocol_spec.hpp"
|
||||
#include "mcp2521.hpp"
|
||||
#include "sm.hpp"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
|
||||
|
||||
|
||||
typedef void (*GobotRPCHandler_t)(void *);
|
||||
typedef void (*GobotRPCFrameHandler)(void *, RPCFrame *);
|
||||
|
||||
class GobotRPCReciver {
|
||||
protected:
|
||||
MCP2521 * can_interface;
|
||||
GobotRPCStateMashine state_mashine;
|
||||
|
||||
GobotRPCHandler_t onDoneFrameHandler;
|
||||
void * argOnDoneFrameHandler;
|
||||
|
||||
public:
|
||||
GobotRPCReciver(MCP2521 * can_interface);
|
||||
~GobotRPCReciver();
|
||||
|
||||
void onRX();
|
||||
|
||||
void registerOnDoneFrameHandler(GobotRPCHandler_t handler, void * arg);
|
||||
};
|
||||
|
||||
void onRX0_GoboRPC(void *arg);
|
||||
|
||||
class GoboRPCTransiver {
|
||||
private:
|
||||
MCP2521 * can_interface;
|
||||
GobotRPCReciver rx;
|
||||
|
||||
GobotRPCHandler_t onRequestHandler;
|
||||
GobotRPCHandler_t onResponseHandler;
|
||||
GobotRPCHandler_t onResponseErrorHandler;
|
||||
|
||||
void * argOnRequestHandler;
|
||||
void * argOnResponseHandler;
|
||||
void * argOnResponseErrorHandler;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
GoboRPCTransiver(MCP2521 * can_interface);
|
||||
~GoboRPCTransiver();
|
||||
|
||||
void send(RPCFrame * frame);
|
||||
|
||||
void registerOnRequestHandler(GobotRPCHandler_t handler, void * arg);
|
||||
void registerOnResponseHandler(GobotRPCHandler_t handler, void * arg);
|
||||
void registerOnResponseErrorHandler(GobotRPCHandler_t handler, void * arg);
|
||||
};
|
||||
123
common-libaries/gobot_rpc/include/protocol_spec.hpp
Normal file
123
common-libaries/gobot_rpc/include/protocol_spec.hpp
Normal file
@@ -0,0 +1,123 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
enum RpcNum {
|
||||
Get_Info = 0x0,
|
||||
Home = 0x1,
|
||||
Move_Step = 0x2,
|
||||
Move_XY = 0x3,
|
||||
Set_Padding = 0x4,
|
||||
Release_Motors = 0x5,
|
||||
Drop_Stones = 0x6,
|
||||
Get_Stone_Status = 0x7,
|
||||
Mov_Z_Axis = 0x8,
|
||||
Set_Vacum = 0x9,
|
||||
INVALID = 0xF,
|
||||
};
|
||||
|
||||
struct RPCHeader {
|
||||
unsigned char rpc_num : 4;
|
||||
unsigned char response : 1;
|
||||
unsigned char error : 1;
|
||||
unsigned char rpc_segement : 1;
|
||||
};
|
||||
|
||||
struct RPCFrame {
|
||||
RPCHeader header;
|
||||
uint8_t data[7];
|
||||
};
|
||||
|
||||
enum RPC_Node_Type {
|
||||
NODE_ALL = 0x0,
|
||||
NODE_CORE_XY = 0x1,
|
||||
NODE_HEAD = 0x2,
|
||||
NODE_VACUM = 0x3,
|
||||
};
|
||||
|
||||
// RPC Request and Response structures
|
||||
struct RPC_RES_Get_Info {
|
||||
uint32_t can_address;
|
||||
RPC_Node_Type node_type;
|
||||
uint32_t status;
|
||||
uint32_t error;
|
||||
};
|
||||
|
||||
enum RPC_Home_Corner {
|
||||
HOME_CORNER_0 = 0b00,
|
||||
HOME_CORNER_1 = 0b01,
|
||||
HOME_CORNER_2 = 0b10,
|
||||
HOME_CORNER_3 = 0b11,
|
||||
};
|
||||
|
||||
struct RPC_REQ_Home {
|
||||
RPC_Home_Corner corner;
|
||||
};
|
||||
|
||||
struct RPC_RES_Home {
|
||||
uint32_t x;
|
||||
uint32_t y;
|
||||
};
|
||||
|
||||
struct RPC_REQ_Move_Step {
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
};
|
||||
|
||||
struct RPC_RES_Move_Step {
|
||||
uint32_t x;
|
||||
uint32_t y;
|
||||
};
|
||||
|
||||
struct RPC_REQ_Set_Padding {
|
||||
uint32_t c_1x;
|
||||
uint32_t c_1y;
|
||||
uint32_t c_2x;
|
||||
uint32_t c_2y;
|
||||
uint8_t n_x;
|
||||
uint8_t n_y;
|
||||
};
|
||||
|
||||
struct RPC_REQ_Move_Z_Axis {
|
||||
bool up;
|
||||
};
|
||||
|
||||
struct RPC_REQ_Set_Vacum {
|
||||
bool on;
|
||||
};
|
||||
|
||||
// Segment3, Segment2, Segment1, Segment0
|
||||
const uint8_t SEGMENT_MASK_REQUEST[16] = {
|
||||
0b0001, // Get_Info
|
||||
0b0001, // Home
|
||||
0b0001, // Move_Step
|
||||
0b0001, // Move_XY
|
||||
0b0111, // Set_Padding
|
||||
0b0001, // Release_Motors
|
||||
0b0001, // Drop_Stones
|
||||
0b0001, // Get_Stone_Status
|
||||
0b0001, // Mov_Z_Axis
|
||||
0b0001, // Set_Vacum
|
||||
0b0001, //
|
||||
0b0001, //
|
||||
0b0001, //
|
||||
0b0001, //
|
||||
0b0001, //
|
||||
};
|
||||
|
||||
const uint8_t SEGMENT_MASK_RESPONSE[16] = {
|
||||
0b0001, // Get_Info
|
||||
0b0001, // Home
|
||||
0b0001, // Move_Step
|
||||
0b0001, // Move_XY
|
||||
0b0001, // Set_Padding
|
||||
0b0001, // Release_Motors
|
||||
0b0001, // Drop_Stones
|
||||
0b0001, // Get_Stone_Status
|
||||
0b0001, // Mov_Z_Axis
|
||||
0b0001, // Set_Vacum
|
||||
0b0001, //
|
||||
0b0001, //
|
||||
0b0001, //
|
||||
0b0001, //
|
||||
0b0001, //
|
||||
};
|
||||
58
common-libaries/gobot_rpc/include/sm.hpp
Normal file
58
common-libaries/gobot_rpc/include/sm.hpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include "protocol_spec.hpp"
|
||||
#include <strings.h>
|
||||
|
||||
class GobotRPCNumberMap {
|
||||
private:
|
||||
int32_t rpc_number_map[16];
|
||||
public:
|
||||
GobotRPCNumberMap();
|
||||
~GobotRPCNumberMap();
|
||||
|
||||
void set(RpcNum rpc_num, uint32_t id);
|
||||
uint32_t get(RpcNum rpc_num);
|
||||
};
|
||||
|
||||
|
||||
enum RPCPackageType {
|
||||
REQUEST,
|
||||
RESPONSE,
|
||||
ERROR
|
||||
};
|
||||
|
||||
struct SMResult {
|
||||
bool done;
|
||||
uint8_t data[7*4];
|
||||
RpcNum rpc_num;
|
||||
RPCPackageType type;
|
||||
};
|
||||
|
||||
class GobotRPCStateMashine {
|
||||
private:
|
||||
static const size_t SLOTS = 6;
|
||||
static const size_t REQUEST_DATA_BUFFER_SIZE = 7*4;
|
||||
static const size_t RESPONSE_DATA_BUFFER_SIZE = 7*4;
|
||||
|
||||
|
||||
GobotRPCNumberMap rpc_number_map;
|
||||
size_t slotCounter;
|
||||
|
||||
uint8_t requestDataBuffer[REQUEST_DATA_BUFFER_SIZE][SLOTS];
|
||||
bool requestSegmentArrivedFlags [SLOTS];
|
||||
|
||||
uint8_t responseDataBuffer[RESPONSE_DATA_BUFFER_SIZE][SLOTS];
|
||||
uint8_t responseSegmentArrivedFlags [SLOTS];
|
||||
|
||||
uint8_t errorDataBuffer[RESPONSE_DATA_BUFFER_SIZE][SLOTS];
|
||||
uint8_t errorSegmentArrivedFlags [SLOTS];
|
||||
|
||||
public:
|
||||
GobotRPCStateMashine();
|
||||
~GobotRPCStateMashine();
|
||||
|
||||
void registerRPC(RpcNum rpc_num);
|
||||
|
||||
void submitFrame(RPCFrame * frame, SMResult * result);
|
||||
|
||||
};
|
||||
@@ -0,0 +1,102 @@
|
||||
<mxfile host="Electron" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/24.7.17 Chrome/128.0.6613.36 Electron/32.0.1 Safari/537.36" version="24.7.17">
|
||||
<diagram name="Page-1" id="FmQN2vLuPXQQGOlHbBG4">
|
||||
<mxGraphModel dx="1434" dy="838" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1169" pageHeight="827" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0" />
|
||||
<mxCell id="1" parent="0" />
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-21" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.75;exitY=1;exitDx=0;exitDy=0;entryX=0.75;entryY=0;entryDx=0;entryDy=0;endArrow=diamondThin;endFill=0;" parent="1" source="xzzxaMGRirp7Gwq30BhV-1" target="xzzxaMGRirp7Gwq30BhV-18" edge="1">
|
||||
<mxGeometry relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-1" value="«interface»<br><font face="Courier New"><b>I_MCP2521_</b><b>HardwareHandle</b></font>" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
|
||||
<mxGeometry x="520" y="120" width="200" height="60" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-9" value="<b><font face="Courier New">MCP2521_HardwareHandle_ESP</font></b>" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
|
||||
<mxGeometry x="230" y="260" width="250" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-11" value="<b><font face="Courier New">MCP2521_</font></b><b><font face="Courier New">HardwareHandle_ESPBus</font></b>" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
|
||||
<mxGeometry x="230" y="200" width="250" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-12" value="" style="endArrow=none;dashed=1;html=1;rounded=0;exitX=1;exitY=1;exitDx=0;exitDy=0;strokeWidth=1;dashPattern=1 1;" parent="1" source="xzzxaMGRirp7Gwq30BhV-14" edge="1">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="1060" y="320" as="sourcePoint" />
|
||||
<mxPoint x="120" y="320" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-14" value="SPI - Hardware Level" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
|
||||
<mxGeometry x="760" y="280" width="160" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-15" value="" style="endArrow=block;html=1;rounded=0;dashed=1;endFill=0;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0.25;entryY=1;entryDx=0;entryDy=0;" parent="1" source="xzzxaMGRirp7Gwq30BhV-11" target="xzzxaMGRirp7Gwq30BhV-1" edge="1">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="590" y="290" as="sourcePoint" />
|
||||
<mxPoint x="640" y="240" as="targetPoint" />
|
||||
<Array as="points">
|
||||
<mxPoint x="570" y="220" />
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-16" value="" style="endArrow=block;html=1;rounded=0;dashed=1;endFill=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" parent="1" source="xzzxaMGRirp7Gwq30BhV-9" target="xzzxaMGRirp7Gwq30BhV-1" edge="1">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="520" y="280" as="sourcePoint" />
|
||||
<mxPoint x="580" y="250" as="targetPoint" />
|
||||
<Array as="points">
|
||||
<mxPoint x="620" y="280" />
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-17" value="MCP2521 - Device Level" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
|
||||
<mxGeometry x="760" y="388" width="160" height="32" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-18" value="<b><font face="Courier New">MCP2521_CommandInterface</font></b>" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
|
||||
<mxGeometry x="520" y="340" width="200" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-19" value="<b>MCP2521</b>" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
|
||||
<mxGeometry x="520" y="420" width="200" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-20" value="" style="endArrow=block;html=1;rounded=0;endFill=0;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" parent="1" source="xzzxaMGRirp7Gwq30BhV-19" target="xzzxaMGRirp7Gwq30BhV-18" edge="1">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="670" y="544" as="sourcePoint" />
|
||||
<mxPoint x="720" y="494" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-23" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.746;entryY=0.064;entryDx=0;entryDy=0;entryPerimeter=0;" parent="1" source="xzzxaMGRirp7Gwq30BhV-22" target="xzzxaMGRirp7Gwq30BhV-11" edge="1">
|
||||
<mxGeometry relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-24" value="creates" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" parent="xzzxaMGRirp7Gwq30BhV-23" vertex="1" connectable="0">
|
||||
<mxGeometry x="-0.3135" y="1" relative="1" as="geometry">
|
||||
<mxPoint x="16" y="1" as="offset" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-22" value="<b><font face="Courier New">MCP2521_HardwareHandleFactory_ESPBus</font></b>" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
|
||||
<mxGeometry x="180" y="120" width="300" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-25" value="" style="endArrow=none;dashed=1;html=1;rounded=0;exitX=1;exitY=1;exitDx=0;exitDy=0;strokeWidth=1;dashPattern=1 1;" parent="1" edge="1">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="920" y="480" as="sourcePoint" />
|
||||
<mxPoint x="120" y="480" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-26" value="Network Stack" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
|
||||
<mxGeometry x="760" y="480" width="160" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-27" value="<b>Socket_CANTP</b>" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
|
||||
<mxGeometry x="520" y="500" width="200" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-28" value="<b>Socket_GoBotRPC</b>" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
|
||||
<mxGeometry x="520" y="580" width="200" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-29" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.75;exitY=1;exitDx=0;exitDy=0;endArrow=diamondThin;endFill=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" target="xzzxaMGRirp7Gwq30BhV-27" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="619.76" y="460" as="sourcePoint" />
|
||||
<mxPoint x="640" y="520" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-30" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.75;exitY=1;exitDx=0;exitDy=0;endArrow=diamondThin;endFill=0;" parent="1" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="619.5799999999999" y="540" as="sourcePoint" />
|
||||
<mxPoint x="619.9699999999999" y="580" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
||||
@@ -0,0 +1,93 @@
|
||||
<mxfile host="Electron" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/24.7.17 Chrome/128.0.6613.36 Electron/32.0.1 Safari/537.36" version="24.7.17">
|
||||
<diagram name="Page-1" id="FmQN2vLuPXQQGOlHbBG4">
|
||||
<mxGraphModel dx="1195" dy="698" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1169" pageHeight="827" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0" />
|
||||
<mxCell id="1" parent="0" />
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-21" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.75;exitY=1;exitDx=0;exitDy=0;entryX=0.75;entryY=0;entryDx=0;entryDy=0;endArrow=diamondThin;endFill=0;" parent="1" source="xzzxaMGRirp7Gwq30BhV-1" target="xzzxaMGRirp7Gwq30BhV-18" edge="1">
|
||||
<mxGeometry relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-1" value="«interface»<br><font face="Courier New"><b>I_MCP2521_</b><b>HardwareHandle</b></font>" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
|
||||
<mxGeometry x="520" y="120" width="200" height="60" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-9" value="<b><font face="Courier New">MCP2521_HardwareHandle_ESP</font></b>" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
|
||||
<mxGeometry x="230" y="260" width="250" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-11" value="<b><font face="Courier New">MCP2521_</font></b><b><font face="Courier New">HardwareHandle_ESPBus</font></b>" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
|
||||
<mxGeometry x="230" y="200" width="250" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-12" value="" style="endArrow=none;dashed=1;html=1;rounded=0;exitX=1;exitY=1;exitDx=0;exitDy=0;strokeWidth=1;dashPattern=1 1;" parent="1" source="xzzxaMGRirp7Gwq30BhV-14" edge="1">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="1060" y="320" as="sourcePoint" />
|
||||
<mxPoint x="120" y="320" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-14" value="SPI - Hardware Level" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
|
||||
<mxGeometry x="760" y="280" width="160" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-15" value="" style="endArrow=block;html=1;rounded=0;dashed=1;endFill=0;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0.25;entryY=1;entryDx=0;entryDy=0;" parent="1" source="xzzxaMGRirp7Gwq30BhV-11" target="xzzxaMGRirp7Gwq30BhV-1" edge="1">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="590" y="290" as="sourcePoint" />
|
||||
<mxPoint x="640" y="240" as="targetPoint" />
|
||||
<Array as="points">
|
||||
<mxPoint x="570" y="220" />
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-16" value="" style="endArrow=block;html=1;rounded=0;dashed=1;endFill=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" parent="1" source="xzzxaMGRirp7Gwq30BhV-9" target="xzzxaMGRirp7Gwq30BhV-1" edge="1">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="520" y="280" as="sourcePoint" />
|
||||
<mxPoint x="580" y="250" as="targetPoint" />
|
||||
<Array as="points">
|
||||
<mxPoint x="620" y="280" />
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-17" value="MCP2521 - Device Level" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
|
||||
<mxGeometry x="760" y="388" width="160" height="32" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-18" value="<b><font face="Courier New">MCP2521_CommandInterface</font></b>" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
|
||||
<mxGeometry x="520" y="340" width="200" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-19" value="<b>MCP2521</b>" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
|
||||
<mxGeometry x="520" y="420" width="200" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-20" value="" style="endArrow=block;html=1;rounded=0;endFill=0;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" parent="1" source="xzzxaMGRirp7Gwq30BhV-19" target="xzzxaMGRirp7Gwq30BhV-18" edge="1">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="670" y="544" as="sourcePoint" />
|
||||
<mxPoint x="720" y="494" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-23" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.746;entryY=0.064;entryDx=0;entryDy=0;entryPerimeter=0;" parent="1" source="xzzxaMGRirp7Gwq30BhV-22" target="xzzxaMGRirp7Gwq30BhV-11" edge="1">
|
||||
<mxGeometry relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-24" value="creates" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" parent="xzzxaMGRirp7Gwq30BhV-23" vertex="1" connectable="0">
|
||||
<mxGeometry x="-0.3135" y="1" relative="1" as="geometry">
|
||||
<mxPoint x="16" y="1" as="offset" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-22" value="<b><font face="Courier New">MCP2521_HardwareHandleFactory_ESPBus</font></b>" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
|
||||
<mxGeometry x="180" y="120" width="300" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-25" value="" style="endArrow=none;dashed=1;html=1;rounded=0;exitX=1;exitY=1;exitDx=0;exitDy=0;strokeWidth=1;dashPattern=1 1;" parent="1" edge="1">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="920" y="480" as="sourcePoint" />
|
||||
<mxPoint x="120" y="480" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-26" value="Network Stack" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
|
||||
<mxGeometry x="760" y="480" width="160" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-28" value="<b>Socket_GoBotRPC</b>" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
|
||||
<mxGeometry x="520" y="500" width="200" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="xzzxaMGRirp7Gwq30BhV-29" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.75;exitY=1;exitDx=0;exitDy=0;endArrow=diamondThin;endFill=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" target="xzzxaMGRirp7Gwq30BhV-28" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="619.76" y="460" as="sourcePoint" />
|
||||
<mxPoint x="620" y="500" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
||||
@@ -3,4 +3,5 @@
|
||||
#include "mcp2521_toplevel.hpp"
|
||||
#include "mcp2521_command.hpp"
|
||||
#include "mcp2521_hardware_esp.hpp"
|
||||
#include "mcp2521_hardware_esp_bus_factory.hpp"
|
||||
#include "mcp2521_addresses.hpp"
|
||||
@@ -40,9 +40,9 @@ struct rx_info {
|
||||
uint8_t length;
|
||||
};
|
||||
|
||||
class MCP2521_Command_Interface {
|
||||
class MCP2521_CommandInterface {
|
||||
private:
|
||||
MCP2521_Hardware_Handle * hardware_handle;
|
||||
I_MCP2521_HardwareHandle * hardware_handle;
|
||||
|
||||
intHandlerFunction_t rx0_handler;
|
||||
intHandlerFunction_t rx1_handler;
|
||||
@@ -63,8 +63,8 @@ private:
|
||||
void * message_error_handler_arg;
|
||||
public:
|
||||
|
||||
MCP2521_Command_Interface(
|
||||
MCP2521_Hardware_Handle * hardware_handle
|
||||
MCP2521_CommandInterface(
|
||||
I_MCP2521_HardwareHandle * hardware_handle
|
||||
);
|
||||
|
||||
void handleInterrupt();
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "mcp2521_command.hpp"
|
||||
#include "mcp2521_addresses.hpp"
|
||||
|
||||
class MCP2521 : public MCP2521_Command_Interface {
|
||||
class MCP2521 : public MCP2521_CommandInterface {
|
||||
private:
|
||||
public:
|
||||
void set_tx_id(MCP2521_TX_BUFFER buffer, uint16_t id, bool extended);
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
#include "mcp2521_addresses.hpp"
|
||||
|
||||
void runIntHandler(void *arg) {
|
||||
MCP2521_Command_Interface *command_interface = (MCP2521_Command_Interface *)arg;
|
||||
MCP2521_CommandInterface *command_interface = (MCP2521_CommandInterface *)arg;
|
||||
command_interface->handleInterrupt();
|
||||
}
|
||||
|
||||
MCP2521_Command_Interface::MCP2521_Command_Interface(
|
||||
MCP2521_Hardware_Handle * hardware_handle
|
||||
MCP2521_CommandInterface::MCP2521_CommandInterface(
|
||||
I_MCP2521_HardwareHandle * hardware_handle
|
||||
) {
|
||||
this->hardware_handle = hardware_handle;
|
||||
this->hardware_handle->registerIntHandler(runIntHandler, (void *)this);
|
||||
@@ -33,42 +33,42 @@ MCP2521_Command_Interface::MCP2521_Command_Interface(
|
||||
message_error_handler_arg = NULL;
|
||||
}
|
||||
|
||||
void MCP2521_Command_Interface::reset() {
|
||||
void MCP2521_CommandInterface::reset() {
|
||||
hardware_handle->execute(MCP2521_OP_RESET);
|
||||
}
|
||||
|
||||
void MCP2521_Command_Interface::read_reg(uint8_t address, uint8_t *data, size_t length) {
|
||||
void MCP2521_CommandInterface::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) {
|
||||
uint8_t MCP2521_CommandInterface::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) {
|
||||
void MCP2521_CommandInterface::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) {
|
||||
void MCP2521_CommandInterface::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) {
|
||||
void MCP2521_CommandInterface::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) {
|
||||
void MCP2521_CommandInterface::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) {
|
||||
void MCP2521_CommandInterface::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) {
|
||||
void MCP2521_CommandInterface::request_to_send(MCP2521_TX_BUFFER buffer) {
|
||||
uint8_t mask = 0;
|
||||
|
||||
switch (buffer) {
|
||||
@@ -86,15 +86,15 @@ void MCP2521_Command_Interface::request_to_send(MCP2521_TX_BUFFER buffer) {
|
||||
hardware_handle->execute(MCP2521_OP_RTS | mask);
|
||||
}
|
||||
|
||||
uint8_t MCP2521_Command_Interface::read_status() {
|
||||
uint8_t MCP2521_CommandInterface::read_status() {
|
||||
return hardware_handle->read(MCP2521_OP_READ_STATUS);
|
||||
}
|
||||
|
||||
uint8_t MCP2521_Command_Interface::read_rx_status() {
|
||||
uint8_t MCP2521_CommandInterface::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) {
|
||||
void MCP2521_CommandInterface::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);
|
||||
}
|
||||
@@ -1,47 +1,47 @@
|
||||
#include "mcp2521.hpp"
|
||||
#include "mcp2521_addresses.hpp"
|
||||
|
||||
void MCP2521_Command_Interface::register_rx0_handler(intHandlerFunction_t handler, void* args) {
|
||||
void MCP2521_CommandInterface::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) {
|
||||
void MCP2521_CommandInterface::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) {
|
||||
void MCP2521_CommandInterface::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) {
|
||||
void MCP2521_CommandInterface::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) {
|
||||
void MCP2521_CommandInterface::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) {
|
||||
void MCP2521_CommandInterface::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) {
|
||||
void MCP2521_CommandInterface::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) {
|
||||
void MCP2521_CommandInterface::register_message_error_handler(intHandlerFunction_t handler, void* args) {
|
||||
message_error_handler = handler;
|
||||
message_error_handler_arg = args;
|
||||
}
|
||||
|
||||
void MCP2521_Command_Interface::handleInterrupt() {
|
||||
void MCP2521_CommandInterface::handleInterrupt() {
|
||||
uint8_t flags = read_reg(MCP2521_CANINTF);
|
||||
uint8_t clearBits = 0;
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
idf_component_register(SRCS "esp_implementation_init.cpp"
|
||||
"esp_implementation_cmd.cpp"
|
||||
"esp_implementation_int.cpp"
|
||||
"esp_implementation_bus.cpp"
|
||||
"esp_implementation_bus_factory.cpp"
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES driver)
|
||||
@@ -0,0 +1,58 @@
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "freertos/FreeRTOS.h"
|
||||
|
||||
#include "mcp2521_hardware_esp_bus.hpp"
|
||||
#include "mcp2521_hardware_esp.hpp"
|
||||
|
||||
MCP2521_HardwareHandle_ESPBus::MCP2521_HardwareHandle_ESPBus(
|
||||
QueueHandle_t send_queue,
|
||||
spi_host_device_t spi_host,
|
||||
spi_bus_config_t * bus_config,
|
||||
gpio_num_t cs,
|
||||
gpio_num_t int_pin
|
||||
) : MCP2521_HardwareHandle_ESP(spi_host, bus_config, cs, int_pin) {
|
||||
this->send_queue = send_queue;
|
||||
this->receive_queue = xQueueCreate(3, sizeof(spi_message_t));
|
||||
}
|
||||
|
||||
void MCP2521_HardwareHandle_ESPBus::spi_transmit(spi_transaction_t *t) {
|
||||
spi_message_t message = {
|
||||
.transaction = t,
|
||||
.queue = send_queue,
|
||||
.spi_device_handle = spi_device_handle
|
||||
};
|
||||
|
||||
xQueueSend(send_queue, &message, portMAX_DELAY);
|
||||
xQueueReceive(receive_queue, &message, portMAX_DELAY);
|
||||
}
|
||||
|
||||
void MCP2521_HardwareHandle_ESPBus::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_isr_handler_add(int_pin, gpio_isr_can_handler, this);
|
||||
|
||||
char taskName[32];
|
||||
sprintf(taskName, "canInterruptTask_%d", int_pin);
|
||||
|
||||
xTaskCreatePinnedToCore(
|
||||
(TaskFunction_t)&handleInteruptTaskCallerFn,
|
||||
taskName,
|
||||
2048,
|
||||
this,
|
||||
5,
|
||||
&canInterruptTaskHandle,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "freertos/FreeRTOS.h"
|
||||
|
||||
#include "mcp2521_hardware_esp_bus_factory.hpp"
|
||||
#include "mcp2521_hardware_esp_bus.hpp"
|
||||
#include "mcp2521_hardware_esp.hpp"
|
||||
|
||||
void transactionTaskWrapperFn(void *pvParameters) {
|
||||
MCP2521_HardwareHandleFactory_ESPBus *factory = (MCP2521_HardwareHandleFactory_ESPBus *)pvParameters;
|
||||
factory->transactionTaskFn();
|
||||
|
||||
}
|
||||
|
||||
MCP2521_HardwareHandleFactory_ESPBus::MCP2521_HardwareHandleFactory_ESPBus(
|
||||
spi_host_device_t spi_host,
|
||||
gpio_num_t mosi,
|
||||
gpio_num_t miso,
|
||||
gpio_num_t sclk
|
||||
) {
|
||||
this->spi_host = spi_host;
|
||||
this->mosi = mosi;
|
||||
this->miso = miso;
|
||||
this->sclk = sclk;
|
||||
|
||||
|
||||
gpio_install_isr_service(0);
|
||||
|
||||
MCP2521_HardwareHandle_ESP::initSPIBus(spi_host, mosi, miso, sclk, &bus_config);
|
||||
|
||||
spi_queue = xQueueCreate(12, sizeof(spi_message_t));
|
||||
xTaskCreatePinnedToCore(
|
||||
(TaskFunction_t)&transactionTaskWrapperFn,
|
||||
"transactionTask",
|
||||
2048,
|
||||
this,
|
||||
3,
|
||||
&transactionTaskHandle,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
void MCP2521_HardwareHandleFactory_ESPBus::transactionTaskFn() {
|
||||
spi_message_t message;
|
||||
|
||||
while(true) {
|
||||
xQueueReceive(spi_queue, &message, portMAX_DELAY);
|
||||
spi_device_transmit(message.spi_device_handle, message.transaction);
|
||||
}
|
||||
}
|
||||
|
||||
MCP2521_HardwareHandle_ESPBus MCP2521_HardwareHandleFactory_ESPBus::create(
|
||||
gpio_num_t int_pin,
|
||||
gpio_num_t cs
|
||||
) {
|
||||
return MCP2521_HardwareHandle_ESPBus(
|
||||
spi_queue,
|
||||
spi_host,
|
||||
&bus_config,
|
||||
cs,
|
||||
int_pin
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -5,13 +5,13 @@
|
||||
|
||||
const uint8_t null_buffer[32] = {0};
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::spi_transmit(spi_transaction_t *t) {
|
||||
void MCP2521_HardwareHandle_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) {
|
||||
void MCP2521_HardwareHandle_ESP::execute(uint8_t cmd) {
|
||||
spi_transaction_ext_t t = {
|
||||
.base = {
|
||||
.flags = SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR,
|
||||
@@ -30,7 +30,7 @@ void MCP2521_Hardware_Handle_ESP::execute(uint8_t cmd) {
|
||||
spi_transmit((spi_transaction_t*)(&t));
|
||||
}
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::execute(uint8_t cmd, uint8_t address) {
|
||||
void MCP2521_HardwareHandle_ESP::execute(uint8_t cmd, uint8_t address) {
|
||||
spi_transaction_ext_t t = {
|
||||
.base = {
|
||||
.flags = SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR,
|
||||
@@ -49,7 +49,7 @@ void MCP2521_Hardware_Handle_ESP::execute(uint8_t cmd, uint8_t address) {
|
||||
spi_transmit((spi_transaction_t*)(&t));
|
||||
}
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t *data, size_t length, uint8_t address) {
|
||||
void MCP2521_HardwareHandle_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,
|
||||
@@ -68,7 +68,7 @@ void MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t *data, size_t length
|
||||
spi_transmit((spi_transaction_t*)(&t));
|
||||
}
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t *data, size_t length) {
|
||||
void MCP2521_HardwareHandle_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,
|
||||
@@ -76,7 +76,7 @@ void MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t *data, size_t length
|
||||
.addr = 0,
|
||||
.length = 8*length,
|
||||
.rxlength = 8*length,
|
||||
.tx_buffer = NULL,
|
||||
.tx_buffer = null_buffer,
|
||||
.rx_buffer = data
|
||||
},
|
||||
.command_bits = 8,
|
||||
@@ -87,7 +87,7 @@ void MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t *data, size_t length
|
||||
spi_transmit((spi_transaction_t*)(&t));
|
||||
}
|
||||
|
||||
uint8_t MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t address) {
|
||||
uint8_t MCP2521_HardwareHandle_ESP::read(uint8_t cmd, uint8_t address) {
|
||||
uint8_t result = 0;
|
||||
spi_transaction_ext_t t = {
|
||||
.base = {
|
||||
@@ -108,7 +108,7 @@ uint8_t MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t address) {
|
||||
return result;
|
||||
}
|
||||
|
||||
uint8_t MCP2521_Hardware_Handle_ESP::read(uint8_t cmd) {
|
||||
uint8_t MCP2521_HardwareHandle_ESP::read(uint8_t cmd) {
|
||||
uint8_t result;
|
||||
spi_transaction_ext_t t = {
|
||||
.base = {
|
||||
@@ -129,7 +129,7 @@ uint8_t MCP2521_Hardware_Handle_ESP::read(uint8_t cmd) {
|
||||
return result;
|
||||
}
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t *data, size_t length, uint8_t address) {
|
||||
void MCP2521_HardwareHandle_ESP::write(uint8_t cmd, uint8_t *data, size_t length, uint8_t address) {
|
||||
uint8_t result;
|
||||
spi_transaction_ext_t t = {
|
||||
.base = {
|
||||
@@ -149,7 +149,7 @@ void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t *data, size_t lengt
|
||||
spi_transmit((spi_transaction_t*)(&t));
|
||||
}
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t *data, size_t length) {
|
||||
void MCP2521_HardwareHandle_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,
|
||||
@@ -168,7 +168,7 @@ void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t *data, size_t lengt
|
||||
spi_transmit((spi_transaction_t*)(&t));
|
||||
}
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t data, uint8_t address) {
|
||||
void MCP2521_HardwareHandle_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,
|
||||
@@ -187,7 +187,7 @@ void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t data, uint8_t addre
|
||||
spi_transmit((spi_transaction_t*)(&t));
|
||||
}
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t data) {
|
||||
void MCP2521_HardwareHandle_ESP::write(uint8_t cmd, uint8_t data) {
|
||||
spi_transaction_ext_t t = {
|
||||
.base = {
|
||||
.flags = SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR,
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
MCP2521_Hardware_Handle_ESP::MCP2521_Hardware_Handle_ESP(
|
||||
MCP2521_HardwareHandle_ESP::MCP2521_HardwareHandle_ESP(
|
||||
spi_host_device_t spi_host,
|
||||
spi_bus_config_t *bus_config,
|
||||
gpio_num_t mosi,
|
||||
@@ -23,7 +23,7 @@ MCP2521_Hardware_Handle_ESP::MCP2521_Hardware_Handle_ESP(
|
||||
initSPIDevice(spi_host, cs);
|
||||
}
|
||||
|
||||
MCP2521_Hardware_Handle_ESP::MCP2521_Hardware_Handle_ESP(
|
||||
MCP2521_HardwareHandle_ESP::MCP2521_HardwareHandle_ESP(
|
||||
spi_host_device_t spi_host,
|
||||
spi_bus_config_t *bus_config,
|
||||
gpio_num_t cs,
|
||||
@@ -34,11 +34,11 @@ MCP2521_Hardware_Handle_ESP::MCP2521_Hardware_Handle_ESP(
|
||||
initSPIDevice(spi_host, cs);
|
||||
}
|
||||
|
||||
MCP2521_Hardware_Handle_ESP::~MCP2521_Hardware_Handle_ESP() {
|
||||
MCP2521_HardwareHandle_ESP::~MCP2521_HardwareHandle_ESP() {
|
||||
|
||||
}
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::initSPIBus(
|
||||
void MCP2521_HardwareHandle_ESP::initSPIBus(
|
||||
spi_host_device_t spi_host,
|
||||
gpio_num_t mosi,
|
||||
gpio_num_t miso,
|
||||
@@ -57,7 +57,7 @@ void MCP2521_Hardware_Handle_ESP::initSPIBus(
|
||||
spi_bus_initialize(spi_host, bus_config, SPI_DMA_CH_AUTO);
|
||||
}
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::initSPIDevice(
|
||||
void MCP2521_HardwareHandle_ESP::initSPIDevice(
|
||||
spi_host_device_t spi_host,
|
||||
gpio_num_t cs
|
||||
) {
|
||||
@@ -73,7 +73,7 @@ void MCP2521_Hardware_Handle_ESP::initSPIDevice(
|
||||
// Learned this the hard way
|
||||
.cs_ena_pretrans = 0,
|
||||
.cs_ena_posttrans = 0,
|
||||
.clock_speed_hz = 10000,
|
||||
.clock_speed_hz = 2000,
|
||||
|
||||
.spics_io_num = cs,
|
||||
.flags = SPI_DEVICE_NO_DUMMY,
|
||||
@@ -85,7 +85,7 @@ void MCP2521_Hardware_Handle_ESP::initSPIDevice(
|
||||
spiMutex = xSemaphoreCreateMutex();
|
||||
}
|
||||
|
||||
spi_bus_config_t * MCP2521_Hardware_Handle_ESP::getSPI_bus_config() {
|
||||
spi_bus_config_t * MCP2521_HardwareHandle_ESP::getSPI_bus_config() {
|
||||
return this->spi_bus_config;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
#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;
|
||||
MCP2521_HardwareHandle_ESP * handle = (MCP2521_HardwareHandle_ESP *)arg;
|
||||
handle->isr_can_interrupt();
|
||||
}
|
||||
|
||||
static void handleInteruptTaskCallerFn(void *arg) {
|
||||
MCP2521_Hardware_Handle_ESP * handle = (MCP2521_Hardware_Handle_ESP *)arg;
|
||||
MCP2521_HardwareHandle_ESP * handle = (MCP2521_HardwareHandle_ESP *)arg;
|
||||
handle->handleIntteruptTaskFn();
|
||||
}
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::initPins(
|
||||
void MCP2521_HardwareHandle_ESP::initPins(
|
||||
gpio_num_t int_pin
|
||||
) {
|
||||
canInterruptSemaphore = xSemaphoreCreateBinary();
|
||||
@@ -31,24 +31,25 @@ void MCP2521_Hardware_Handle_ESP::initPins(
|
||||
gpio_install_isr_service(0);
|
||||
gpio_isr_handler_add(int_pin, gpio_isr_can_handler, this);
|
||||
|
||||
xTaskCreate(
|
||||
xTaskCreatePinnedToCore(
|
||||
(TaskFunction_t)&handleInteruptTaskCallerFn,
|
||||
"canInterruptTask",
|
||||
2048,
|
||||
this,
|
||||
5,
|
||||
&canInterruptTaskHandle
|
||||
&canInterruptTaskHandle,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::handleIntteruptTaskFn() {
|
||||
void MCP2521_HardwareHandle_ESP::handleIntteruptTaskFn() {
|
||||
while(true) {
|
||||
xSemaphoreTake(canInterruptSemaphore, portMAX_DELAY);
|
||||
intHandler(intHandlerArg);
|
||||
}
|
||||
}
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::isr_can_interrupt() {
|
||||
void MCP2521_HardwareHandle_ESP::isr_can_interrupt() {
|
||||
BaseType_t wokenTask = pdFALSE;
|
||||
xSemaphoreGiveFromISR(canInterruptSemaphore, &wokenTask);
|
||||
|
||||
@@ -57,7 +58,7 @@ void MCP2521_Hardware_Handle_ESP::isr_can_interrupt() {
|
||||
}
|
||||
}
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::registerIntHandler(intHandlerFunction_t handler, void * arg) {
|
||||
void MCP2521_HardwareHandle_ESP::registerIntHandler(intHandlerFunction_t handler, void * arg) {
|
||||
intHandlerArg = arg;
|
||||
intHandler = handler;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/**
|
||||
* @file mcp2521_hardware_esp.hpp
|
||||
* @author AlexanderHD27
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2024-11-16
|
||||
*
|
||||
* @copyright Copyright (c) 2024
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include "mcp2521_hardware_handle.hpp"
|
||||
|
||||
@@ -8,24 +18,48 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
class MCP2521_Hardware_Handle_ESP : public MCP2521_Hardware_Handle {
|
||||
char spi_tmp_buffer;
|
||||
static void handleInteruptTaskCallerFn(void *arg);
|
||||
static void IRAM_ATTR gpio_isr_can_handler(void* arg);
|
||||
|
||||
spi_bus_config_t * spi_bus_config;
|
||||
spi_device_interface_config_t spi_device_config;
|
||||
spi_device_handle_t spi_device_handle;
|
||||
/**
|
||||
* @brief Hardware handle for MCP2521 over SPI on ESP32
|
||||
* This is should not be used if multiple MCP2521 are on the same SPI bus
|
||||
*/
|
||||
class MCP2521_HardwareHandle_ESP : public I_MCP2521_HardwareHandle {
|
||||
protected:
|
||||
void spi_transmit(spi_transaction_t *t);
|
||||
|
||||
/**
|
||||
* @brief Sempahore, that is set every time the MCP2521 triggers an interrupt by the canInterruptTaskHandle
|
||||
*/
|
||||
SemaphoreHandle_t canInterruptSemaphore = NULL;
|
||||
SemaphoreHandle_t spiMutex = NULL;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Handle to task that handles the MCP2521 interrupt
|
||||
* A Handle can be registered via the registerIntHandler method
|
||||
*/
|
||||
TaskHandle_t canInterruptTaskHandle = NULL;
|
||||
|
||||
void spi_transmit(spi_transaction_t *t);
|
||||
spi_device_handle_t spi_device_handle;
|
||||
|
||||
private:
|
||||
spi_bus_config_t * spi_bus_config;
|
||||
char spi_tmp_buffer;
|
||||
|
||||
spi_device_interface_config_t spi_device_config;
|
||||
|
||||
/**
|
||||
* @brief Sempahore, that protects the SPI bus from being accessed by multiple tasks at the same time
|
||||
*
|
||||
*/
|
||||
SemaphoreHandle_t spiMutex = NULL;
|
||||
|
||||
void * intHandlerArg = NULL;
|
||||
intHandlerFunction_t intHandler = NULL;
|
||||
|
||||
public:
|
||||
MCP2521_Hardware_Handle_ESP(
|
||||
MCP2521_HardwareHandle_ESP(
|
||||
spi_host_device_t spi_host,
|
||||
spi_bus_config_t *bus_config,
|
||||
gpio_num_t mosi,
|
||||
@@ -35,7 +69,7 @@ public:
|
||||
gpio_num_t int_pin
|
||||
);
|
||||
|
||||
MCP2521_Hardware_Handle_ESP(
|
||||
MCP2521_HardwareHandle_ESP(
|
||||
spi_host_device_t spi_host,
|
||||
spi_bus_config_t *bus_config,
|
||||
gpio_num_t cs,
|
||||
@@ -59,12 +93,22 @@ public:
|
||||
gpio_num_t int_pin
|
||||
);
|
||||
|
||||
~MCP2521_Hardware_Handle_ESP();
|
||||
~MCP2521_HardwareHandle_ESP();
|
||||
|
||||
spi_bus_config_t * getSPI_bus_config();
|
||||
|
||||
// ISR Stuff
|
||||
/**
|
||||
* @brief This function is called by the ISR, that is triggered by the MCP2521
|
||||
* This function just set the canInterruptSemaphore, that then unblocks the canInterruptTaskHandle.
|
||||
* So this function should be as short as possible, let the reset of the work be done in the canInterruptTaskHandle
|
||||
*/
|
||||
void isr_can_interrupt();
|
||||
|
||||
/**
|
||||
* This is the methode run as canInterruptTaskHandle.
|
||||
* It should continously aquire the canInterruptSemaphore and then call the intHandler
|
||||
*/
|
||||
void handleIntteruptTaskFn();
|
||||
|
||||
// Inherited from MCP2521_Hardware_Handle
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "mcp2521_hardware_esp.hpp"
|
||||
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/spi_master.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
struct spi_message_t {
|
||||
spi_transaction_t *transaction;
|
||||
QueueHandle_t queue;
|
||||
spi_device_handle_t spi_device_handle;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Hardware handle for MCP2521 over SPI in a multi-Bus-Setup on ESP32
|
||||
* This should not be created directly, use the MCP2521_HardwareHandleFactory_ESPBus instead
|
||||
*/
|
||||
class MCP2521_HardwareHandle_ESPBus : public MCP2521_HardwareHandle_ESP {
|
||||
using MCP2521_HardwareHandle_ESP::MCP2521_HardwareHandle_ESP;
|
||||
private:
|
||||
QueueHandle_t send_queue;
|
||||
QueueHandle_t receive_queue;
|
||||
|
||||
/**
|
||||
* @brief Wrapper around the spi_transmit function, that locks the spiMutex before calling spi_transmit.
|
||||
* The muxtex is shared with all other MCP2521_HardwareHandle_ESPBus instances created by the same MCP2521_HardwareHandleFactory_ESPBus
|
||||
* @overload
|
||||
*
|
||||
* @param t ESP32 SPI Transaction struct
|
||||
*/
|
||||
void spi_transmit(spi_transaction_t *t);
|
||||
public:
|
||||
MCP2521_HardwareHandle_ESPBus(
|
||||
QueueHandle_t send_queue,
|
||||
spi_host_device_t spi_host,
|
||||
spi_bus_config_t * bus_config,
|
||||
gpio_num_t cs,
|
||||
gpio_num_t int_pin
|
||||
);
|
||||
|
||||
void initPins(
|
||||
gpio_num_t int_pin
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "mcp2521_hardware_handle.hpp"
|
||||
#include "mcp2521_hardware_esp_bus.hpp"
|
||||
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/spi_master.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
|
||||
class MCP2521_HardwareHandleFactory_ESPBus {
|
||||
private:
|
||||
spi_bus_config_t bus_config;
|
||||
spi_host_device_t spi_host;
|
||||
|
||||
gpio_num_t mosi;
|
||||
gpio_num_t miso;
|
||||
gpio_num_t sclk;
|
||||
|
||||
QueueHandle_t spi_queue;
|
||||
TaskHandle_t transactionTaskHandle;
|
||||
|
||||
public:
|
||||
MCP2521_HardwareHandleFactory_ESPBus(
|
||||
spi_host_device_t spi_host,
|
||||
gpio_num_t mosi,
|
||||
gpio_num_t miso,
|
||||
gpio_num_t sclk
|
||||
);
|
||||
|
||||
void transactionTaskFn();
|
||||
|
||||
MCP2521_HardwareHandle_ESPBus create(
|
||||
gpio_num_t int_pin,
|
||||
gpio_num_t cs
|
||||
);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -2,23 +2,118 @@
|
||||
#include <cstdint>
|
||||
#include <strings.h>
|
||||
|
||||
/**
|
||||
* @brief Handler function pointer type
|
||||
*
|
||||
*/
|
||||
typedef void (*intHandlerFunction_t)(void *);
|
||||
|
||||
class MCP2521_Hardware_Handle {
|
||||
/**
|
||||
* @brief Hardware handle for MCP2521
|
||||
* @interface
|
||||
* This is an abstraction over the sepific hardware setup, eg. SPI@ESP32 or RP2040
|
||||
*
|
||||
*/
|
||||
class I_MCP2521_HardwareHandle {
|
||||
public:
|
||||
/**
|
||||
* @brief Registeres a function that is called when the MCP2521 triggers an interrupt
|
||||
*
|
||||
* @param handler This function is called when the MCP2521 triggers an interrupt
|
||||
* @param arg Arguments passed to the handler-function
|
||||
*/
|
||||
virtual void registerIntHandler(intHandlerFunction_t handler, void * arg) = 0;
|
||||
|
||||
/**
|
||||
* @overload
|
||||
* @brief justed sends a 8bit command to the MCP2521
|
||||
*
|
||||
* @param cmd command to send
|
||||
*/
|
||||
virtual void execute(uint8_t cmd) = 0;
|
||||
|
||||
/**
|
||||
* @overload
|
||||
* @brief executes a command (8 bit) with an address (8 bit)
|
||||
*
|
||||
* @param cmd 8 bit command
|
||||
* @param address 8 bit address
|
||||
*/
|
||||
virtual void execute(uint8_t cmd, uint8_t address) = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief Executes a read from the MCP2521 with command, data buffer, length and address
|
||||
* @overload
|
||||
*
|
||||
* @param cmd Command to MCP2521
|
||||
* @param data Data buffer to store the read data
|
||||
* @param length How many bytes to read
|
||||
* @param address Address to read from
|
||||
*/
|
||||
virtual void read(uint8_t cmd, uint8_t *data, size_t length, uint8_t address) = 0;
|
||||
|
||||
/**
|
||||
* @brief Executes a read from the MCP2521 with command, data buffer and length
|
||||
* @overload
|
||||
*
|
||||
* @param cmd Command to MCP2521
|
||||
* @param data Data buffer to store the read data
|
||||
* @param length How many bytes to read
|
||||
*/
|
||||
virtual void read(uint8_t cmd, uint8_t *data, size_t length) = 0;
|
||||
|
||||
/**
|
||||
* @brief Executes a read from the MCP2521 with command and address, returns just one byte
|
||||
*
|
||||
* @param cmd Command to MCP2521
|
||||
* @param address Address to read from
|
||||
* @return uint8_t
|
||||
*/
|
||||
virtual uint8_t read(uint8_t cmd, uint8_t address) = 0;
|
||||
|
||||
/**
|
||||
* @brief Executes a read from the MCP2521 with command, returns just one byte
|
||||
*
|
||||
* @param cmd Command to MCP2521
|
||||
* @return uint8_t
|
||||
*/
|
||||
virtual uint8_t read(uint8_t cmd) = 0;
|
||||
|
||||
/**
|
||||
* @brief Writes data to the MCP2521 with command, data buffer, length and address
|
||||
*
|
||||
* @param cmd Command to MCP2521
|
||||
* @param data Data buffer to write
|
||||
* @param length Length of the data buffer
|
||||
* @param address Where to write the data
|
||||
*/
|
||||
virtual void write(uint8_t cmd, uint8_t *data, size_t length, uint8_t address) = 0;
|
||||
|
||||
/**
|
||||
* @brief Wirites data to the MCP2521 with command, data buffer and length
|
||||
*
|
||||
* @param cmd Command to MCP2521
|
||||
* @param data Data buffer to write
|
||||
* @param length Length of the data buffer
|
||||
*/
|
||||
virtual void write(uint8_t cmd, uint8_t *data, size_t length) = 0;
|
||||
|
||||
/**
|
||||
* @brief Writes data to the MCP2521 with command, data (on byte) and address
|
||||
*
|
||||
* @param cmd Command to MCP2521
|
||||
* @param data Data byte to write
|
||||
* @param address Where to write the data
|
||||
*/
|
||||
virtual void write(uint8_t cmd, uint8_t data, uint8_t address) = 0;
|
||||
|
||||
/**
|
||||
* @brief Writes to the MCP2521 with command and data (one byte)
|
||||
*
|
||||
* @param cmd Command to MCP2521
|
||||
* @param data Data byte to write
|
||||
*/
|
||||
virtual void write(uint8_t cmd, uint8_t data) = 0;
|
||||
};
|
||||
|
||||
|
||||
BIN
motor-control/firmware/.gitignore
(Stored with Git LFS)
vendored
BIN
motor-control/firmware/.gitignore
(Stored with Git LFS)
vendored
Binary file not shown.
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"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
31
motor-control/firmware/.vscode/launch.json
vendored
@@ -1,31 +0,0 @@
|
||||
{
|
||||
// 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
79
motor-control/firmware/.vscode/settings.json
vendored
@@ -1,79 +0,0 @@
|
||||
{
|
||||
"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
165
motor-control/firmware/.vscode/tasks.json
vendored
@@ -1,165 +0,0 @@
|
||||
{
|
||||
"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": []
|
||||
},
|
||||
]
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
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
106
motor-control/firmware/Jenkinsfile
vendored
@@ -1,106 +0,0 @@
|
||||
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)
BIN
motor-control/firmware/README.md
(Stored with Git LFS)
Binary file not shown.
@@ -1,14 +0,0 @@
|
||||
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
|
||||
)
|
||||
@@ -1,16 +1,13 @@
|
||||
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
|
||||
)
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
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
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
doxygen ./firmware/docs/Doxyfile
|
||||
@@ -1,11 +0,0 @@
|
||||
#!/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
|
||||
BIN
motor-control/firmware/docs/tmc2209_datasheet_rev1.09.pdf
(Stored with Git LFS)
BIN
motor-control/firmware/docs/tmc2209_datasheet_rev1.09.pdf
(Stored with Git LFS)
Binary file not shown.
@@ -1,5 +0,0 @@
|
||||
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()
|
||||
@@ -1,101 +0,0 @@
|
||||
#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 */
|
||||
@@ -1,517 +0,0 @@
|
||||
#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;
|
||||
};
|
||||
@@ -1,78 +0,0 @@
|
||||
#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();
|
||||
@@ -1,125 +0,0 @@
|
||||
#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
|
||||
);
|
||||
|
||||
};
|
||||
Submodule motor-control/firmware/lib/FreeRTOS-Kernel deleted from 0240cd55f2
Submodule motor-control/firmware/lib/doxygen-awesome-css deleted from cc1bee0804
Submodule motor-control/firmware/lib/pico-sdk deleted from beb6f990a6
Submodule motor-control/firmware/lib/tinyusb deleted from 3eea46056e
File diff suppressed because one or more lines are too long
@@ -1,2 +0,0 @@
|
||||
cd build
|
||||
make -j10
|
||||
@@ -1,8 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
if ! scripts/build.sh; then
|
||||
exit
|
||||
else
|
||||
scripts/flash.exp main.elf
|
||||
fi
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
#!/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
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
openocd -f interface/cmsis-dap.cfg -c "adapter speed 5000" -f target/rp2040.cfg -c "program $1 verify reset exit"
|
||||
@@ -1,4 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
sudo openocd -f interface/cmsis-dap.cfg -c "adapter speed 5000" -f target/rp2040.cfg
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
minicom -D $1
|
||||
@@ -1,20 +0,0 @@
|
||||
#!/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
|
||||
@@ -1,12 +0,0 @@
|
||||
#!/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"
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user