Moved CAN Interface code to comment libary folder with symlink
This commit is contained in:
1
can-interface/components/mcp2521
Symbolic link
1
can-interface/components/mcp2521
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
/home/alexander/Projects/gobot/common-libaries/mcp2521
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include "mcp2521.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MCP2515 {
|
|
||||||
private:
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
MCP2515();
|
|
||||||
~MCP2515();
|
|
||||||
|
|
||||||
void reset();
|
|
||||||
|
|
||||||
// Interrupts
|
|
||||||
|
|
||||||
void register_rx_callback(void (*callback)(uint32_t id, uint8_t *data, size_t length));
|
|
||||||
void register_tx_callback(void (*callback)(MCP2521_TX_BUFFER buffer));
|
|
||||||
void register_error_callback(void (*callback)(uint8_t error_flags));
|
|
||||||
void register_message_error_callback(void (*callback)(uint8_t error_flags));
|
|
||||||
|
|
||||||
// Transmittion
|
|
||||||
void set_tx_id(MCP2521_TX_BUFFER buffer, uint32_t id);
|
|
||||||
void set_tx_data(MCP2521_TX_BUFFER buffer, uint8_t *data, size_t length);
|
|
||||||
void set_tx_priority(MCP2521_TX_BUFFER buffer, uint8_t priority);
|
|
||||||
void set_one_shot(MCP2521_TX_BUFFER buffer, bool one_shot);
|
|
||||||
|
|
||||||
void request_to_send(MCP2521_TX_BUFFER buffer);
|
|
||||||
void request_to_send(bool txb2, bool txb1, bool txb0);
|
|
||||||
|
|
||||||
void abort_tx(MCP2521_TX_BUFFER buffer);
|
|
||||||
void abort_all_tx();
|
|
||||||
|
|
||||||
TXBnCTRL_Register get_TXBnCTRL(MCP2521_TX_BUFFER buffer);
|
|
||||||
|
|
||||||
void transmit(MCP2521_TX_BUFFER buffer, uint32_t id, uint8_t *data, size_t length, uint8_t priority, bool one_shot);
|
|
||||||
|
|
||||||
// Reception
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t get_TransmitErrorCounter();
|
|
||||||
uint8_t get_ReceiveErrorCounter();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
1
can-interface/components/mcp2521_hardware_interface
Symbolic link
1
can-interface/components/mcp2521_hardware_interface
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
/home/alexander/Projects/gobot/common-libaries/mcp2521_hardware_interface
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
#define EXTERNAL_TRIGGER GPIO_NUM_26
|
#define EXTERNAL_TRIGGER GPIO_NUM_26
|
||||||
|
|
||||||
void onRX(void *arg) {
|
void onRX(void *arg) {
|
||||||
MCP2521_Command_Interface *mcp2521 = (MCP2521_Command_Interface *)arg;
|
MCP2521 *mcp2521 = (MCP2521 *)arg;
|
||||||
|
|
||||||
rx_info info = mcp2521->get_rx_id(MCP2521_RX_BUFFER::RXB0);
|
rx_info info = mcp2521->get_rx_id(MCP2521_RX_BUFFER::RXB0);
|
||||||
uint8_t data[8];
|
uint8_t data[8];
|
||||||
@@ -70,7 +70,7 @@ extern "C" void app_main() {
|
|||||||
CAN_INT_PIN
|
CAN_INT_PIN
|
||||||
);
|
);
|
||||||
|
|
||||||
MCP2521_Command_Interface mcp2521(&hardware_mcp2521);
|
MCP2521 mcp2521(&hardware_mcp2521);
|
||||||
|
|
||||||
uint8_t data[4] = {0xf0, 0x42, 0x13, 0x37};
|
uint8_t data[4] = {0xf0, 0x42, 0x13, 0x37};
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
idf_component_register(SRCS
|
idf_component_register(SRCS
|
||||||
"interface_commands.cpp"
|
"interface_commands.cpp"
|
||||||
"interface_commands_complex.cpp"
|
|
||||||
"interface_interrupts.cpp"
|
"interface_interrupts.cpp"
|
||||||
|
"toplevel_commands.cpp"
|
||||||
INCLUDE_DIRS "include"
|
INCLUDE_DIRS "include"
|
||||||
REQUIRES driver
|
REQUIRES driver
|
||||||
REQUIRES mcp2521_hardware_interface
|
REQUIRES mcp2521_hardware_interface
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "mcp2521_toplevel.hpp"
|
||||||
#include "mcp2521_command.hpp"
|
#include "mcp2521_command.hpp"
|
||||||
#include "mcp2521_hardware_esp.hpp"
|
#include "mcp2521_hardware_esp.hpp"
|
||||||
#include "mcp2521_addresses.hpp"
|
#include "mcp2521_addresses.hpp"
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "mcp2521_addresses.hpp"
|
#include "mcp2521_addresses.hpp"
|
||||||
|
#include "mcp2521_hardware_handle.hpp"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "mcp2521_hardware_handle.hpp"
|
|
||||||
|
|
||||||
enum MCP2521_RX_BUFFER {
|
enum MCP2521_RX_BUFFER {
|
||||||
RXB0 = 0,
|
RXB0 = 0,
|
||||||
RXB1 = 1
|
RXB1 = 1
|
||||||
@@ -90,36 +89,6 @@ public:
|
|||||||
|
|
||||||
void bit_modify(uint8_t address, uint8_t mask, uint8_t data);
|
void bit_modify(uint8_t address, uint8_t mask, uint8_t data);
|
||||||
|
|
||||||
// More Complex Commands
|
|
||||||
void set_tx_id(MCP2521_TX_BUFFER buffer, uint16_t id, bool extended);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Loads the Data Length Code register for the specified buffer
|
|
||||||
*
|
|
||||||
* @param buffer What Buffer to load the DLC register for
|
|
||||||
* @param length How many bytes are in the message (0-8)
|
|
||||||
* @param rtr: Remote Transmission Request
|
|
||||||
*/
|
|
||||||
void set_DLC_reg(MCP2521_TX_BUFFER buffer, uint8_t length, bool rtr);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Loads the data and id into the specified buffer
|
|
||||||
*
|
|
||||||
* @param buffer
|
|
||||||
* @param id
|
|
||||||
* @param data
|
|
||||||
* @param length
|
|
||||||
*/
|
|
||||||
void prepare_tx(MCP2521_TX_BUFFER buffer, uint32_t id, uint8_t *data, size_t length, bool rtr, bool extended);
|
|
||||||
|
|
||||||
void set_mode_of_operation(MCP2521_OPERATION_MODE mode, bool singleshot);
|
|
||||||
void set_singleshot_mode(bool enable);
|
|
||||||
|
|
||||||
void enable_interrupts(bool MessageError, bool ErrorInterrupt, bool WakeUp, bool TXB0, bool TXB1, bool TXB2, bool RXB0, bool RXB1);
|
|
||||||
rx_info get_rx_id(MCP2521_RX_BUFFER buffer);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Registering Handlers for Interrupts
|
// Registering Handlers for Interrupts
|
||||||
void register_rx0_handler(intHandlerFunction_t handler, void * arg);
|
void register_rx0_handler(intHandlerFunction_t handler, void * arg);
|
||||||
void register_rx1_handler(intHandlerFunction_t handler, void * arg);
|
void register_rx1_handler(intHandlerFunction_t handler, void * arg);
|
||||||
38
common-libaries/mcp2521/include/mcp2521_toplevel.hpp
Normal file
38
common-libaries/mcp2521/include/mcp2521_toplevel.hpp
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "mcp2521.hpp"
|
||||||
|
#include "mcp2521_command.hpp"
|
||||||
|
#include "mcp2521_addresses.hpp"
|
||||||
|
|
||||||
|
class MCP2521 : public MCP2521_Command_Interface {
|
||||||
|
private:
|
||||||
|
public:
|
||||||
|
void set_tx_id(MCP2521_TX_BUFFER buffer, uint16_t id, bool extended);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Loads the Data Length Code register for the specified buffer
|
||||||
|
*
|
||||||
|
* @param buffer What Buffer to load the DLC register for
|
||||||
|
* @param length How many bytes are in the message (0-8)
|
||||||
|
* @param rtr: Remote Transmission Request
|
||||||
|
*/
|
||||||
|
void set_DLC_reg(MCP2521_TX_BUFFER buffer, uint8_t length, bool rtr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Loads the data and id into the specified buffer
|
||||||
|
*
|
||||||
|
* @param buffer
|
||||||
|
* @param id
|
||||||
|
* @param data
|
||||||
|
* @param length
|
||||||
|
*/
|
||||||
|
void prepare_tx(MCP2521_TX_BUFFER buffer, uint32_t id, uint8_t *data, size_t length, bool rtr, bool extended);
|
||||||
|
|
||||||
|
void set_mode_of_operation(MCP2521_OPERATION_MODE mode, bool singleshot);
|
||||||
|
void set_singleshot_mode(bool enable);
|
||||||
|
|
||||||
|
void enable_interrupts(bool MessageError, bool ErrorInterrupt, bool WakeUp, bool TXB0, bool TXB1, bool TXB2, bool RXB0, bool RXB1);
|
||||||
|
rx_info get_rx_id(MCP2521_RX_BUFFER buffer);
|
||||||
|
|
||||||
|
};
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
#include "mcp2521.hpp"
|
#include "mcp2521.hpp"
|
||||||
#include "mcp2521_addresses.hpp"
|
#include "mcp2521_addresses.hpp"
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
void MCP2521_Command_Interface::register_rx0_handler(intHandlerFunction_t handler, void* args) {
|
void MCP2521_Command_Interface::register_rx0_handler(intHandlerFunction_t handler, void* args) {
|
||||||
rx0_handler = handler;
|
rx0_handler = handler;
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "mcp2521.hpp"
|
#include "mcp2521.hpp"
|
||||||
#include "mcp2521_addresses.hpp"
|
#include "mcp2521_addresses.hpp"
|
||||||
|
|
||||||
void MCP2521_Command_Interface::set_tx_id(MCP2521_TX_BUFFER buffer, uint16_t id, bool extended) {
|
void MCP2521::set_tx_id(MCP2521_TX_BUFFER buffer, uint16_t id, bool extended) {
|
||||||
uint8_t addr_offset = 0;
|
uint8_t addr_offset = 0;
|
||||||
switch (buffer)
|
switch (buffer)
|
||||||
{
|
{
|
||||||
@@ -30,11 +30,7 @@ void MCP2521_Command_Interface::set_tx_id(MCP2521_TX_BUFFER buffer, uint16_t id,
|
|||||||
write_reg(MCP2521_TXB0SIDL | addr_offset, lower_id);
|
write_reg(MCP2521_TXB0SIDL | addr_offset, lower_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 00110101 0x35
|
void MCP2521::set_DLC_reg(MCP2521_TX_BUFFER buffer, uint8_t length, bool rtr) {
|
||||||
// 01000101 0x45
|
|
||||||
// 01010101 0x55
|
|
||||||
|
|
||||||
void MCP2521_Command_Interface::set_DLC_reg(MCP2521_TX_BUFFER buffer, uint8_t length, bool rtr) {
|
|
||||||
uint8_t data = length;
|
uint8_t data = length;
|
||||||
|
|
||||||
if (rtr)
|
if (rtr)
|
||||||
@@ -57,19 +53,19 @@ void MCP2521_Command_Interface::set_DLC_reg(MCP2521_TX_BUFFER buffer, uint8_t le
|
|||||||
write_reg(reg_address, data);
|
write_reg(reg_address, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCP2521_Command_Interface::set_mode_of_operation(MCP2521_OPERATION_MODE mode, bool singleshot) {
|
void MCP2521::set_mode_of_operation(MCP2521_OPERATION_MODE mode, bool singleshot) {
|
||||||
|
|
||||||
uint8_t single = singleshot ? 0b00001000 : 0x0;
|
uint8_t single = singleshot ? 0b00001000 : 0x0;
|
||||||
|
|
||||||
bit_modify(MCP2521_CANCTRL, 0b11101000 , (mode << 5) | single);
|
bit_modify(MCP2521_CANCTRL, 0b11101000 , (mode << 5) | single);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCP2521_Command_Interface::set_singleshot_mode(bool enable) {
|
void MCP2521::set_singleshot_mode(bool enable) {
|
||||||
uint8_t data = enable ? 0x08 : 0x00;
|
uint8_t data = enable ? 0x08 : 0x00;
|
||||||
bit_modify(MCP2521_CANCTRL, 0x08, data);
|
bit_modify(MCP2521_CANCTRL, 0x08, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCP2521_Command_Interface::enable_interrupts(bool MessageError, bool ErrorInterrupt, bool WakeUp, bool TXB0, bool TXB1, bool TXB2, bool RXB0, bool RXB1) {
|
void MCP2521::enable_interrupts(bool MessageError, bool ErrorInterrupt, bool WakeUp, bool TXB0, bool TXB1, bool TXB2, bool RXB0, bool RXB1) {
|
||||||
uint8_t interrupt_flags = 0;
|
uint8_t interrupt_flags = 0;
|
||||||
|
|
||||||
if (MessageError) interrupt_flags |= 0b10000000;
|
if (MessageError) interrupt_flags |= 0b10000000;
|
||||||
@@ -84,7 +80,7 @@ void MCP2521_Command_Interface::enable_interrupts(bool MessageError, bool ErrorI
|
|||||||
write_reg(MCP2521_CANINTE, interrupt_flags);
|
write_reg(MCP2521_CANINTE, interrupt_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
rx_info MCP2521_Command_Interface::get_rx_id(MCP2521_RX_BUFFER buffer) {
|
rx_info MCP2521::get_rx_id(MCP2521_RX_BUFFER buffer) {
|
||||||
uint8_t data[5];
|
uint8_t data[5];
|
||||||
uint8_t addr_offset = MCP2521_RXB0SIDH;
|
uint8_t addr_offset = MCP2521_RXB0SIDH;
|
||||||
|
|
||||||
@@ -110,7 +106,7 @@ rx_info MCP2521_Command_Interface::get_rx_id(MCP2521_RX_BUFFER buffer) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCP2521_Command_Interface::prepare_tx(
|
void MCP2521::prepare_tx(
|
||||||
MCP2521_TX_BUFFER buffer,
|
MCP2521_TX_BUFFER buffer,
|
||||||
uint32_t id,
|
uint32_t id,
|
||||||
uint8_t *data,
|
uint8_t *data,
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
#include "mcp2521_hardware_handle.hpp"
|
#include "mcp2521_hardware_handle.hpp"
|
||||||
|
|
||||||
|
|
||||||
const uint8_t null_buffer[32] = {0};
|
|
||||||
|
|
||||||
#ifdef ESP_PLATFORM
|
#ifdef ESP_PLATFORM
|
||||||
#include "mcp2521_hardware_esp.hpp"
|
#include "mcp2521_hardware_esp.hpp"
|
||||||
|
|
||||||
|
const uint8_t null_buffer[32] = {0};
|
||||||
|
|
||||||
void MCP2521_Hardware_Handle_ESP::spi_transmit(spi_transaction_t *t) {
|
void MCP2521_Hardware_Handle_ESP::spi_transmit(spi_transaction_t *t) {
|
||||||
xSemaphoreTake(spiMutex, portMAX_DELAY);
|
xSemaphoreTake(spiMutex, portMAX_DELAY);
|
||||||
spi_device_transmit(this->spi_device_handle, t);
|
spi_device_transmit(this->spi_device_handle, t);
|
||||||
Reference in New Issue
Block a user