From f47c6b6d370b4dcce982370c44f1a6b53ac9d2b2 Mon Sep 17 00:00:00 2001 From: Joe Inman Date: Mon, 20 Jan 2025 15:23:11 +0000 Subject: [PATCH 01/11] Added CMake Support --- CMakeLists.txt | 30 ++++++++++++++++++++++++++++ src/ArduinoMCP2515.cpp | 4 ++-- src/ArduinoMCP2515.h | 12 +---------- src/MCP2515/MCP2515_Config.cpp | 8 +++----- src/MCP2515/MCP2515_Config.h | 4 +++- src/MCP2515/MCP2515_Control.cpp | 3 +-- src/MCP2515/MCP2515_Io.cpp | 12 +++++++---- src/MCP2515/MCP2515_Io.h | 4 +++- src/MCP2515/MCP2515_Types.h | 35 +++++++++++++++++++++++++++++++++ 9 files changed, 86 insertions(+), 26 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 src/MCP2515/MCP2515_Types.h diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b445589 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,30 @@ +########################################################################## +cmake_minimum_required(VERSION 3.28) +########################################################################## +project("libmcp2515") +########################################################################## +if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 11) + message(WARNING "GNU C compiler version ${CMAKE_C_COMPILER_VERSION} is too old and is unsupported. Version 11+ is required.") +endif() +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11) + message(WARNING "GNU C++ compiler version ${CMAKE_CXX_COMPILER_VERSION} is too old and is unsupported. Version 11+ is required.") +endif() +########################################################################## +set(CMAKE_VERBOSE_MAKEFILE OFF) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +########################################################################## +add_library(${PROJECT_NAME} STATIC + "src/ArduinoMCP2515.cpp" + "src/MCP2515/MCP2515_Config.cpp" + "src/MCP2515/MCP2515_Const.cpp" + "src/MCP2515/MCP2515_Control.cpp" + "src/MCP2515/MCP2515_Io.cpp" +) +########################################################################## +target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror) +########################################################################## +target_include_directories(${PROJECT_NAME} PUBLIC + "src" +) +target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) +########################################################################## diff --git a/src/ArduinoMCP2515.cpp b/src/ArduinoMCP2515.cpp index 2a058b3..838a4e9 100644 --- a/src/ArduinoMCP2515.cpp +++ b/src/ArduinoMCP2515.cpp @@ -90,8 +90,8 @@ ArduinoMCP2515::ArduinoMCP2515(SpiSelectFunc select, OnTransmitBufferEmptyFunc on_tx_buf_empty, OnCanErrorFunc on_error, OnCanWarningFunc on_warning) -: _io{select, deselect, transfer} -, _cfg{_io} +: _io{select, deselect, transfer, micros} +, _cfg{_io, micros} , _ctrl{_io} , _micros{micros} , _on_rx_buf_full{on_rx_buf_full} diff --git a/src/ArduinoMCP2515.h b/src/ArduinoMCP2515.h index 5f7cac3..69a3baf 100644 --- a/src/ArduinoMCP2515.h +++ b/src/ArduinoMCP2515.h @@ -18,6 +18,7 @@ #include "MCP2515/MCP2515_Io.h" #include "MCP2515/MCP2515_Config.h" #include "MCP2515/MCP2515_Control.h" +#include "MCP2515/MCP2515_Types.h" #undef min #undef max @@ -82,17 +83,6 @@ enum class CanBitRate : size_t BR_1000kBPS_12MHZ }; -typedef std::function MicroSecondFunc; -#if LIBCANARD -typedef std::function OnReceiveBufferFullFunc; -#else -typedef std::function OnReceiveBufferFullFunc; -#endif -class ArduinoMCP2515; -typedef std::function OnTransmitBufferEmptyFunc; -typedef std::function OnCanErrorFunc; -typedef std::function OnCanWarningFunc; - /************************************************************************************** * CLASS DECLARATION **************************************************************************************/ diff --git a/src/MCP2515/MCP2515_Config.cpp b/src/MCP2515/MCP2515_Config.cpp index 9412b55..fb017ab 100644 --- a/src/MCP2515/MCP2515_Config.cpp +++ b/src/MCP2515/MCP2515_Config.cpp @@ -11,8 +11,6 @@ #include "MCP2515_Config.h" -#include - /************************************************************************************** * NAMESPACE **************************************************************************************/ @@ -24,10 +22,10 @@ namespace MCP2515 * CTOR/DTOR **************************************************************************************/ -MCP2515_Config::MCP2515_Config(MCP2515_Io & io) +MCP2515_Config::MCP2515_Config(MCP2515_Io & io, MicroSecondFunc micros) : _io{io} +, _micros{micros} { - } /************************************************************************************** @@ -40,7 +38,7 @@ bool MCP2515_Config::setMode(Mode const mode) _io.modifyRegister(Register::CANCTRL, CANCTRL_REQOP_MASK, mode_val); - for(unsigned long const start = millis(); (millis() - start) < 10; ) + for(unsigned long const start = _micros(); (_micros()- start) < 10000; ) { uint8_t const canstat_op_mode = (_io.readRegister(Register::CANSTAT) & CANSTAT_OP_MASK); if(canstat_op_mode == mode_val) { diff --git a/src/MCP2515/MCP2515_Config.h b/src/MCP2515/MCP2515_Config.h index 2a5e457..1924662 100644 --- a/src/MCP2515/MCP2515_Config.h +++ b/src/MCP2515/MCP2515_Config.h @@ -13,6 +13,7 @@ **************************************************************************************/ #include "MCP2515_Io.h" +#include "MCP2515_Types.h" /************************************************************************************** * NAMESPACE @@ -92,7 +93,7 @@ static CanBitRateConfig constexpr BitRate_1000kBPS_12MHz = {0x00, 0x88, 0x01}; class MCP2515_Config { public: - MCP2515_Config(MCP2515_Io & io); + MCP2515_Config(MCP2515_Io & io, MicroSecondFunc micros); bool setMode (Mode const mode); @@ -117,6 +118,7 @@ class MCP2515_Config private: MCP2515_Io & _io; + MicroSecondFunc _micros; void setFilterId (Register const rxf_n_sidh, uint32_t const id); void setFilterMask(Register const rxm_n_sidh, uint32_t const mask); diff --git a/src/MCP2515/MCP2515_Control.cpp b/src/MCP2515/MCP2515_Control.cpp index c2944e3..077cd48 100644 --- a/src/MCP2515/MCP2515_Control.cpp +++ b/src/MCP2515/MCP2515_Control.cpp @@ -11,11 +11,10 @@ #include "MCP2515_Control.h" -#include - #undef min #undef max #include +#include /************************************************************************************** * NAMESPACE diff --git a/src/MCP2515/MCP2515_Io.cpp b/src/MCP2515/MCP2515_Io.cpp index 7a17ca6..c34df86 100644 --- a/src/MCP2515/MCP2515_Io.cpp +++ b/src/MCP2515/MCP2515_Io.cpp @@ -11,8 +11,6 @@ #include "MCP2515_Io.h" -#include - #include /************************************************************************************** @@ -50,10 +48,11 @@ static Instruction const TABLE_READ_RX_BUFFER[] = * CTOR/DTOR **************************************************************************************/ -MCP2515_Io::MCP2515_Io(SpiSelectFunc select, SpiDeselectFunc deselect, SpiTransferFunc transfer) +MCP2515_Io::MCP2515_Io(SpiSelectFunc select, SpiDeselectFunc deselect, SpiTransferFunc transfer, MicroSecondFunc micros) : _select{select} , _deselect{deselect} , _transfer{transfer} +, _micros{micros} { } @@ -70,7 +69,12 @@ void MCP2515_Io::reset() _transfer(instruction); _deselect(); - delay(10); + /* Delay 10 ms. */ + auto const start_time = _micros(); + while ((_micros() - start_time) < (10*1000UL)) + { + asm volatile("nop"); + } } uint8_t MCP2515_Io::status() diff --git a/src/MCP2515/MCP2515_Io.h b/src/MCP2515/MCP2515_Io.h index 540680e..b4cbf4a 100644 --- a/src/MCP2515/MCP2515_Io.h +++ b/src/MCP2515/MCP2515_Io.h @@ -19,6 +19,7 @@ #include #include "MCP2515_Const.h" +#include "MCP2515_Types.h" /************************************************************************************** * NAMESPACE @@ -85,7 +86,7 @@ class MCP2515_Io public: - MCP2515_Io(SpiSelectFunc select, SpiDeselectFunc deselect, SpiTransferFunc transfer); + MCP2515_Io(SpiSelectFunc select, SpiDeselectFunc deselect, SpiTransferFunc transfer, MicroSecondFunc micros); static uint8_t constexpr TX_BUF_SIZE = 5 + 8; @@ -110,6 +111,7 @@ class MCP2515_Io SpiSelectFunc _select; SpiDeselectFunc _deselect; SpiTransferFunc _transfer; + MicroSecondFunc _micros; }; diff --git a/src/MCP2515/MCP2515_Types.h b/src/MCP2515/MCP2515_Types.h new file mode 100644 index 0000000..809d963 --- /dev/null +++ b/src/MCP2515/MCP2515_Types.h @@ -0,0 +1,35 @@ +/** + * This software is distributed under the terms of the MIT License. + * Copyright (c) 2020 LXRobotics. + * Author: Alexander Entinger + * Contributors: https://github.com/107-systems/107-Arduino-MCP2515/graphs/contributors. + */ + +#ifndef ARDUINO_MCP2515_TYPES_H_ +#define ARDUINO_MCP2515_TYPES_H_ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include +#include + +#include "MCP2515/MCP2515_Const.h" + +/************************************************************************************** + * TYPEDEF + **************************************************************************************/ + +typedef std::function MicroSecondFunc; +#if LIBCANARD +typedef std::function OnReceiveBufferFullFunc; +#else +typedef std::function OnReceiveBufferFullFunc; +#endif +class ArduinoMCP2515; +typedef std::function OnTransmitBufferEmptyFunc; +typedef std::function OnCanErrorFunc; +typedef std::function OnCanWarningFunc; + +#endif /* ARDUINO_MCP2515_TYPES_H_ */ From 94f1eff33e649e4ddd1f86e06a67f59ccc9723bf Mon Sep 17 00:00:00 2001 From: Eduard Rius Martinez Date: Mon, 20 Jan 2025 16:38:16 +0000 Subject: [PATCH 02/11] Add smoke test --- .github/workflows/smoke-test.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/smoke-test.yml diff --git a/.github/workflows/smoke-test.yml b/.github/workflows/smoke-test.yml new file mode 100644 index 0000000..dd277bc --- /dev/null +++ b/.github/workflows/smoke-test.yml @@ -0,0 +1,32 @@ +name: Build + +on: + push: + pull_request: + schedule: + # Run every Tuesday at 1 AM UTC + - cron: "0 1 * * TUE" + workflow_dispatch: + repository_dispatch: + +permissions: + contents: read + +jobs: + smoke-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install CMake + uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.28.0" + + - name: Configure the build + run: mkdir build && cmake -B build/ ./ + + - name: Build library + run: cmake --build build/ \ No newline at end of file From 4f1a31a55f6bb17c43016fab09786350b0ab7625 Mon Sep 17 00:00:00 2001 From: Eduard Rius Martinez Date: Mon, 20 Jan 2025 16:40:17 +0000 Subject: [PATCH 03/11] Lint --- .github/workflows/smoke-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/smoke-test.yml b/.github/workflows/smoke-test.yml index dd277bc..b2be79e 100644 --- a/.github/workflows/smoke-test.yml +++ b/.github/workflows/smoke-test.yml @@ -29,4 +29,4 @@ jobs: run: mkdir build && cmake -B build/ ./ - name: Build library - run: cmake --build build/ \ No newline at end of file + run: cmake --build build/ From b39788c9c4ce3aaff59df08a31443dbe7bb8cf84 Mon Sep 17 00:00:00 2001 From: Eduard Rius Martinez Date: Mon, 20 Jan 2025 16:47:13 +0000 Subject: [PATCH 04/11] Add build badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index dcebae3..c670527 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ [![Check keywords.txt](https://github.com/107-systems/107-Arduino-MCP2515/actions/workflows/check-keywords-txt.yml/badge.svg)](https://github.com/107-systems/107-Arduino-MCP2515/actions/workflows/check-keywords-txt.yml) [![General Formatting Checks](https://github.com/107-systems/107-Arduino-MCP2515/workflows/General%20Formatting%20Checks/badge.svg)](https://github.com/107-systems/107-Arduino-MCP2515/actions?workflow=General+Formatting+Checks) [![Spell Check](https://github.com/107-systems/107-Arduino-MCP2515/workflows/Spell%20Check/badge.svg)](https://github.com/107-systems/107-Arduino-MCP2515/actions?workflow=Spell+Check) +[![Build Status](https://github.com/Ross-Robotics/107-Arduino-MCP2515/workflows/Smoke%20Test/badge.svg)](https://github.com/Ross-Robotics/107-Arduino-MCP2515/actions?query=workflow%3A"Smoke+Test")

From 3d37e590f89f86ddb9b04a45b121d79fbc04d488 Mon Sep 17 00:00:00 2001 From: Eduard Rius Martinez Date: Mon, 20 Jan 2025 16:49:55 +0000 Subject: [PATCH 05/11] Fix badge link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c670527..e2a79f6 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![Check keywords.txt](https://github.com/107-systems/107-Arduino-MCP2515/actions/workflows/check-keywords-txt.yml/badge.svg)](https://github.com/107-systems/107-Arduino-MCP2515/actions/workflows/check-keywords-txt.yml) [![General Formatting Checks](https://github.com/107-systems/107-Arduino-MCP2515/workflows/General%20Formatting%20Checks/badge.svg)](https://github.com/107-systems/107-Arduino-MCP2515/actions?workflow=General+Formatting+Checks) [![Spell Check](https://github.com/107-systems/107-Arduino-MCP2515/workflows/Spell%20Check/badge.svg)](https://github.com/107-systems/107-Arduino-MCP2515/actions?workflow=Spell+Check) -[![Build Status](https://github.com/Ross-Robotics/107-Arduino-MCP2515/workflows/Smoke%20Test/badge.svg)](https://github.com/Ross-Robotics/107-Arduino-MCP2515/actions?query=workflow%3A"Smoke+Test") +[![Build Status](https://github.com/Ross-Robotics/107-Arduino-MCP2515/workflows/Smoke%20Test/badge.svg)](https://github.com/Ross-Robotics/107-Arduino-MCP2515/actions?workflow=Smoke+Test)

From 49da972f0ac6072577f1a459619424133ecd89d4 Mon Sep 17 00:00:00 2001 From: Eduard Rius Martinez Date: Mon, 20 Jan 2025 16:50:42 +0000 Subject: [PATCH 06/11] Change workflow name --- .github/workflows/smoke-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/smoke-test.yml b/.github/workflows/smoke-test.yml index b2be79e..eafbdc8 100644 --- a/.github/workflows/smoke-test.yml +++ b/.github/workflows/smoke-test.yml @@ -1,4 +1,4 @@ -name: Build +name: Smoke Test on: push: From 89c2fc9d28d5cce1d3e423aa2897dd13c82e7bfe Mon Sep 17 00:00:00 2001 From: Eduard Rius Martinez Date: Mon, 20 Jan 2025 16:56:10 +0000 Subject: [PATCH 07/11] Remove scheduled job --- .github/workflows/smoke-test.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/smoke-test.yml b/.github/workflows/smoke-test.yml index eafbdc8..22fb039 100644 --- a/.github/workflows/smoke-test.yml +++ b/.github/workflows/smoke-test.yml @@ -3,9 +3,6 @@ name: Smoke Test on: push: pull_request: - schedule: - # Run every Tuesday at 1 AM UTC - - cron: "0 1 * * TUE" workflow_dispatch: repository_dispatch: From 28f719dafab05eaf3d224f93951713d7162e121c Mon Sep 17 00:00:00 2001 From: Joe Inman Date: Mon, 3 Feb 2025 15:14:38 +0000 Subject: [PATCH 08/11] Updated README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e2a79f6..a916307 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![Check keywords.txt](https://github.com/107-systems/107-Arduino-MCP2515/actions/workflows/check-keywords-txt.yml/badge.svg)](https://github.com/107-systems/107-Arduino-MCP2515/actions/workflows/check-keywords-txt.yml) [![General Formatting Checks](https://github.com/107-systems/107-Arduino-MCP2515/workflows/General%20Formatting%20Checks/badge.svg)](https://github.com/107-systems/107-Arduino-MCP2515/actions?workflow=General+Formatting+Checks) [![Spell Check](https://github.com/107-systems/107-Arduino-MCP2515/workflows/Spell%20Check/badge.svg)](https://github.com/107-systems/107-Arduino-MCP2515/actions?workflow=Spell+Check) -[![Build Status](https://github.com/Ross-Robotics/107-Arduino-MCP2515/workflows/Smoke%20Test/badge.svg)](https://github.com/Ross-Robotics/107-Arduino-MCP2515/actions?workflow=Smoke+Test) +[![Build Status](https://github.com/107-systems/107-Arduino-MCP2515/workflows/Smoke%20Test/badge.svg)](https://github.com/Ross-Robotics/107-Arduino-MCP2515/actions?workflow=Smoke+Test)

From 577a29d717ece5b3fb4fa56d1ff8a169a5be5982 Mon Sep 17 00:00:00 2001 From: Joe Inman Date: Tue, 4 Feb 2025 10:03:20 +0000 Subject: [PATCH 09/11] Updated README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a916307..0f02b16 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![Check keywords.txt](https://github.com/107-systems/107-Arduino-MCP2515/actions/workflows/check-keywords-txt.yml/badge.svg)](https://github.com/107-systems/107-Arduino-MCP2515/actions/workflows/check-keywords-txt.yml) [![General Formatting Checks](https://github.com/107-systems/107-Arduino-MCP2515/workflows/General%20Formatting%20Checks/badge.svg)](https://github.com/107-systems/107-Arduino-MCP2515/actions?workflow=General+Formatting+Checks) [![Spell Check](https://github.com/107-systems/107-Arduino-MCP2515/workflows/Spell%20Check/badge.svg)](https://github.com/107-systems/107-Arduino-MCP2515/actions?workflow=Spell+Check) -[![Build Status](https://github.com/107-systems/107-Arduino-MCP2515/workflows/Smoke%20Test/badge.svg)](https://github.com/Ross-Robotics/107-Arduino-MCP2515/actions?workflow=Smoke+Test) +[![Build Status](https://github.com/107-systems/107-Arduino-MCP2515/workflows/Smoke%20Test/badge.svg)](https://github.com/107-systems/107-Arduino-MCP2515/actions?workflow=Smoke+Test)

From b32a77e57d1dbc4833f49ac081fd065348e7f2ca Mon Sep 17 00:00:00 2001 From: Joe Inman Date: Wed, 5 Feb 2025 13:11:34 +0000 Subject: [PATCH 10/11] Added Millis --- src/ArduinoMCP2515.cpp | 3 ++- src/ArduinoMCP2515.h | 4 +++- src/MCP2515/MCP2515_Config.cpp | 6 +++--- src/MCP2515/MCP2515_Config.h | 4 ++-- src/MCP2515/MCP2515_Types.h | 1 + 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/ArduinoMCP2515.cpp b/src/ArduinoMCP2515.cpp index 838a4e9..1f33385 100644 --- a/src/ArduinoMCP2515.cpp +++ b/src/ArduinoMCP2515.cpp @@ -86,12 +86,13 @@ ArduinoMCP2515::ArduinoMCP2515(SpiSelectFunc select, SpiDeselectFunc deselect, SpiTransferFunc transfer, MicroSecondFunc micros, + MilliSecondFunc millis, OnReceiveBufferFullFunc on_rx_buf_full, OnTransmitBufferEmptyFunc on_tx_buf_empty, OnCanErrorFunc on_error, OnCanWarningFunc on_warning) : _io{select, deselect, transfer, micros} -, _cfg{_io, micros} +, _cfg{_io, millis} , _ctrl{_io} , _micros{micros} , _on_rx_buf_full{on_rx_buf_full} diff --git a/src/ArduinoMCP2515.h b/src/ArduinoMCP2515.h index 69a3baf..5882a98 100644 --- a/src/ArduinoMCP2515.h +++ b/src/ArduinoMCP2515.h @@ -96,6 +96,7 @@ class ArduinoMCP2515 MCP2515::SpiDeselectFunc deselect, MCP2515::SpiTransferFunc transfer, MicroSecondFunc micros, + MilliSecondFunc millis, OnReceiveBufferFullFunc on_rx_buf_full, OnTransmitBufferEmptyFunc on_tx_buf_empty, OnCanErrorFunc on_error, @@ -105,9 +106,10 @@ class ArduinoMCP2515 MCP2515::SpiDeselectFunc deselect, MCP2515::SpiTransferFunc transfer, MicroSecondFunc micros, + MilliSecondFunc millis, OnReceiveBufferFullFunc on_rx_buf_full, OnTransmitBufferEmptyFunc on_tx_buf_empty) - : ArduinoMCP2515{select, deselect, transfer, micros, on_rx_buf_full, on_tx_buf_empty, nullptr, nullptr} + : ArduinoMCP2515{select, deselect, transfer, micros, millis, on_rx_buf_full, on_tx_buf_empty, nullptr, nullptr} { } diff --git a/src/MCP2515/MCP2515_Config.cpp b/src/MCP2515/MCP2515_Config.cpp index fb017ab..184696e 100644 --- a/src/MCP2515/MCP2515_Config.cpp +++ b/src/MCP2515/MCP2515_Config.cpp @@ -22,9 +22,9 @@ namespace MCP2515 * CTOR/DTOR **************************************************************************************/ -MCP2515_Config::MCP2515_Config(MCP2515_Io & io, MicroSecondFunc micros) +MCP2515_Config::MCP2515_Config(MCP2515_Io & io, MilliSecondFunc millis) : _io{io} -, _micros{micros} +, _millis{millis} { } @@ -38,7 +38,7 @@ bool MCP2515_Config::setMode(Mode const mode) _io.modifyRegister(Register::CANCTRL, CANCTRL_REQOP_MASK, mode_val); - for(unsigned long const start = _micros(); (_micros()- start) < 10000; ) + for(unsigned long const start = _millis(); (_millis()- start) < 10; ) { uint8_t const canstat_op_mode = (_io.readRegister(Register::CANSTAT) & CANSTAT_OP_MASK); if(canstat_op_mode == mode_val) { diff --git a/src/MCP2515/MCP2515_Config.h b/src/MCP2515/MCP2515_Config.h index 1924662..1c30f52 100644 --- a/src/MCP2515/MCP2515_Config.h +++ b/src/MCP2515/MCP2515_Config.h @@ -93,7 +93,7 @@ static CanBitRateConfig constexpr BitRate_1000kBPS_12MHz = {0x00, 0x88, 0x01}; class MCP2515_Config { public: - MCP2515_Config(MCP2515_Io & io, MicroSecondFunc micros); + MCP2515_Config(MCP2515_Io & io, MilliSecondFunc millis); bool setMode (Mode const mode); @@ -118,7 +118,7 @@ class MCP2515_Config private: MCP2515_Io & _io; - MicroSecondFunc _micros; + MilliSecondFunc _millis; void setFilterId (Register const rxf_n_sidh, uint32_t const id); void setFilterMask(Register const rxm_n_sidh, uint32_t const mask); diff --git a/src/MCP2515/MCP2515_Types.h b/src/MCP2515/MCP2515_Types.h index 809d963..d854003 100644 --- a/src/MCP2515/MCP2515_Types.h +++ b/src/MCP2515/MCP2515_Types.h @@ -22,6 +22,7 @@ **************************************************************************************/ typedef std::function MicroSecondFunc; +typedef std::function MilliSecondFunc; #if LIBCANARD typedef std::function OnReceiveBufferFullFunc; #else From ee429412ebc1fdf868ada732be61e0c31ac23eb8 Mon Sep 17 00:00:00 2001 From: Joe Inman Date: Wed, 5 Feb 2025 14:36:24 +0000 Subject: [PATCH 11/11] Fixed examples --- examples/MCP2515-CAN-Sniffer/MCP2515-CAN-Sniffer.ino | 1 + examples/MCP2515-Filter/MCP2515-Filter.ino | 1 + examples/MCP2515-Loopback/MCP2515-Loopback.ino | 1 + 3 files changed, 3 insertions(+) diff --git a/examples/MCP2515-CAN-Sniffer/MCP2515-CAN-Sniffer.ino b/examples/MCP2515-CAN-Sniffer/MCP2515-CAN-Sniffer.ino index e69614f..14fa6d0 100644 --- a/examples/MCP2515-CAN-Sniffer/MCP2515-CAN-Sniffer.ino +++ b/examples/MCP2515-CAN-Sniffer/MCP2515-CAN-Sniffer.ino @@ -37,6 +37,7 @@ ArduinoMCP2515 mcp2515([]() { digitalWrite(MKRCAN_MCP2515_CS_PIN, LOW); }, []() { digitalWrite(MKRCAN_MCP2515_CS_PIN, HIGH); }, [](uint8_t const d) { return SPI.transfer(d); }, micros, + millis, onReceiveBufferFull, nullptr, [](MCP2515::EFLG const err_flag) { Serial.print("MCP2515::OnError, error code = "); Serial.println(MCP2515::toStr(err_flag)); }, diff --git a/examples/MCP2515-Filter/MCP2515-Filter.ino b/examples/MCP2515-Filter/MCP2515-Filter.ino index b8cbc9d..26cd86c 100644 --- a/examples/MCP2515-Filter/MCP2515-Filter.ino +++ b/examples/MCP2515-Filter/MCP2515-Filter.ino @@ -37,6 +37,7 @@ ArduinoMCP2515 mcp2515([]() { digitalWrite(MKRCAN_MCP2515_CS_PIN, LOW); }, []() { digitalWrite(MKRCAN_MCP2515_CS_PIN, HIGH); }, [](uint8_t const d) { return SPI.transfer(d); }, micros, + millis, onReceiveBufferFull, nullptr); diff --git a/examples/MCP2515-Loopback/MCP2515-Loopback.ino b/examples/MCP2515-Loopback/MCP2515-Loopback.ino index cf4c22f..3b10bdf 100644 --- a/examples/MCP2515-Loopback/MCP2515-Loopback.ino +++ b/examples/MCP2515-Loopback/MCP2515-Loopback.ino @@ -71,6 +71,7 @@ ArduinoMCP2515 mcp2515([]() { digitalWrite(MKRCAN_MCP2515_CS_PIN, LOW); }, []() { digitalWrite(MKRCAN_MCP2515_CS_PIN, HIGH); }, [](uint8_t const d) { return SPI.transfer(d); }, micros, + millis, onReceiveBufferFull, nullptr);