Files
gobot/common-libaries/mcp2521/interface_commands.cpp
AlexanderHD27 e091d4df18 Squashed commit of the following:
commit c6fd825e39
Author: AlexanderHD27 <alexander@hal>
Date:   Wed Nov 6 23:14:14 2024 +0100

    Moved CAN Interface code to comment libary folder with symlink

commit e7a0035041
Author: AlexanderHD27 <alexander@hal>
Date:   Wed Nov 6 22:01:28 2024 +0100

    Got MCP2521 to work

commit 4bfb1f533e
Author: AlexanderHD27 <alexander@hal>
Date:   Wed Oct 16 21:29:35 2024 +0200

    Did something to YGantryMount. It works. trust me

commit 5683168a47
Author: AlexanderHD27 <alexander@hal>
Date:   Wed Oct 16 21:28:36 2024 +0200

    Implemented Command-Level Interaction with CAN Interface

commit 9c0c676be8
Author: AlexanderHD27 <alexander@hal>
Date:   Mon Oct 14 09:20:37 2024 +0200

    Added Vscode Profile file

commit b150a905a3
Author: AlexanderHD27 <alexander@hal>
Date:   Mon Oct 14 09:19:00 2024 +0200

    Implemented Low Level Compunications

commit 7eebf619ae
Author: AlexanderHD27 <alexander@hal>
Date:   Mon Oct 7 14:46:15 2024 +0200

    Created Head Pipe Mount

commit 93c40e1805
Author: AlexanderHD27 <alexander@hal>
Date:   Mon Oct 7 14:44:11 2024 +0200

    First Revision of YGantryMount

commit 91c2125458
Author: AlexanderHD27 <alexander@hal>
Date:   Thu Oct 3 19:52:37 2024 +0200

    Added Kicad Backups 2 gitignore

commit 096a6c18d6
Author: AlexanderHD27 <alexander@hal>
Date:   Thu Oct 3 19:49:21 2024 +0200

    Created ESP-IDF for can-interface

commit 48fded7981
Author: AlexanderHD27 <alexander@hal>
Date:   Sat Sep 28 19:54:29 2024 +0200

    Added files from Pico sdk to gitignore

commit ec5e5cbf13
Author: AlexanderHD27 <alexander@hal>
Date:   Sat Sep 14 21:09:50 2024 +0200

    Create Marker for position Calibration

commit 58d31964b2
Author: AlexanderHD27 <alexander@hal>
Date:   Wed Sep 11 23:32:55 2024 +0200

    Upgrade to pico SDK 2.0.0
2024-11-06 23:18:12 +01:00

100 lines
3.1 KiB
C++

#include <cstring>
#include "mcp2521.hpp"
#include "mcp2521_addresses.hpp"
void runIntHandler(void *arg) {
MCP2521_Command_Interface *command_interface = (MCP2521_Command_Interface *)arg;
command_interface->handleInterrupt();
}
MCP2521_Command_Interface::MCP2521_Command_Interface(
MCP2521_Hardware_Handle * hardware_handle
) {
this->hardware_handle = hardware_handle;
this->hardware_handle->registerIntHandler(runIntHandler, (void *)this);
rx0_handler = NULL;
rx1_handler = NULL;
tx0_handler = NULL;
tx1_handler = NULL;
tx2_handler = NULL;
error_handler = NULL;
wakeup_handler = NULL;
message_error_handler = NULL;
rx0_handler_arg = NULL;
rx1_handler_arg = NULL;
tx0_handler_arg = NULL;
tx1_handler_arg = NULL;
tx2_handler_arg = NULL;
error_handler_arg = NULL;
wakeup_handler_arg = NULL;
message_error_handler_arg = NULL;
}
void MCP2521_Command_Interface::reset() {
hardware_handle->execute(MCP2521_OP_RESET);
}
void MCP2521_Command_Interface::read_reg(uint8_t address, uint8_t *data, size_t length) {
hardware_handle->read(MCP2521_OP_READ, data, length, address);
}
uint8_t MCP2521_Command_Interface::read_reg(uint8_t address) {
return hardware_handle->read(MCP2521_OP_READ, address);
}
void MCP2521_Command_Interface::read_rx_buf(MCP2521_RX_BUFFER buffer, MCP2521_BUFFER_TYPE type, uint8_t *data, size_t length) {
uint8_t address = (buffer << 1) | (type << 2);
hardware_handle->read(MCP2521_OP_READ_RX_BUFFER | address, data, length);
}
void MCP2521_Command_Interface::write_reg(uint8_t address, uint8_t *data, size_t length) {
hardware_handle->write(MCP2521_OP_WRITE, data, length, address);
}
void MCP2521_Command_Interface::write_reg(uint8_t address, uint8_t data) {
hardware_handle->write(MCP2521_OP_WRITE, data, address);
}
void MCP2521_Command_Interface::write_tx_buf(MCP2521_TX_BUFFER buffer, MCP2521_BUFFER_TYPE type, uint8_t *data, size_t length) {
uint8_t address = (buffer << 1) | (type);
hardware_handle->write(MCP2521_OP_LOAD_TX_BUFFER | address, data, length);
}
void MCP2521_Command_Interface::request_to_send(bool txb2, bool txb1, bool txb0) {
uint8_t data = (txb2 << 2) | (txb1 << 1) | txb0;
hardware_handle->execute(MCP2521_OP_RTS | data);
}
void MCP2521_Command_Interface::request_to_send(MCP2521_TX_BUFFER buffer) {
uint8_t mask = 0;
switch (buffer) {
case MCP2521_TX_BUFFER::TXB0:
mask = 0b001;
break;
case MCP2521_TX_BUFFER::TXB1:
mask = 0b010;
break;
case MCP2521_TX_BUFFER::TXB2:
mask = 0b100;
break;
}
hardware_handle->execute(MCP2521_OP_RTS | mask);
}
uint8_t MCP2521_Command_Interface::read_status() {
return hardware_handle->read(MCP2521_OP_READ_STATUS);
}
uint8_t MCP2521_Command_Interface::read_rx_status() {
return hardware_handle->read(MCP2521_OP_RX_STATUS);
}
void MCP2521_Command_Interface::bit_modify(uint8_t address, uint8_t mask, uint8_t data) {
uint8_t data_array[3] = {address, mask, data};
hardware_handle->write(MCP2521_OP_BIT_MODIFY, data_array, 3);
}