Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@
.DS_Store
.idea
build
build-test
build-test-asan

*~
*#
.#*
18 changes: 18 additions & 0 deletions .vscode/cmake-kits.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"name": "Arduino UNO",
"toolchainFile": "cmake/toolchain/uno.toolchain.cmake"
},
{
"name": "Arduino Leonardo",
"toolchainFile": "cmake/toolchain/leonardo.toolchain.cmake"
},
{
"name": "Host",
"toolchainFile": "cmake/toolchain/host.toolchain.cmake",
"compilers": {
"CC": "clang",
"CXX": "clang++"
}
}
]
19 changes: 19 additions & 0 deletions .vscode/cmake-variants.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"buildType": {
"default": "Debug",
"choices": {
"Debug": {
"short": "Debug",
"buildType": "Debug"
},
"Asan": {
"short": "Asan",
"buildType": "Asan"
},
"MinSizeRel": {
"short": "MinSizeRel",
"buildType": "MinSizeRel"
}
}
}
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cmake.configureOnOpen": true
}
21 changes: 21 additions & 0 deletions Arduino-AVR-CMake-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 PieterP

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions Arduino/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_library(ArduinoMock INTERFACE)
target_include_directories(ArduinoMock INTERFACE .)
129 changes: 19 additions & 110 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,118 +1,27 @@
# CMake definition for VLCB-Arduino project
# This is necessary for working with the CLion IDE.

cmake_minimum_required(VERSION 3.25)
project(VLCB_Arduino)
cmake_minimum_required(VERSION 3.22.1)
project(VLCB_Arduino LANGUAGES C CXX ASM)

set(CMAKE_CXX_STANDARD 11)

include_directories(examples)
include_directories(examples/VLCB_1in1out)
include_directories(examples/VLCB_4in4out)
include_directories(examples/VLCB_empty)
include_directories(examples/VLCB_long_message_example)
include_directories(src)
include_directories(Arduino)

add_library(hardware_library OBJECT
src/CAN2515.cpp
src/CAN2515.h
src/LED.cpp
src/LED.h
src/Switch.cpp
src/Switch.h
src/CreateDefaultStorageForPlatform.cpp
src/DueEepromEmulationStorage.cpp
src/DueEepromEmulationStorage.h
src/EepromExternalStorage.cpp
src/EepromExternalStorage.h
src/EepromInternalStorage.cpp
src/EepromInternalStorage.h
src/FlashStorage.cpp
src/FlashStorage.h
src/LEDUserInterface.cpp
src/LEDUserInterface.h
src/SerialUserInterface.cpp
src/SerialUserInterface.h
src/SerialGC.h
src/SerialGC.cpp
)

add_library(core_library OBJECT
include(cmake/lto.cmake)
include(cmake/arduino_flags.cmake)

src/Controller.cpp
src/Controller.h
src/Configuration.cpp
src/Configuration.h
src/LongMessageService.cpp
src/Parameters.cpp
src/Parameters.h
src/Transport.h
src/CanTransport.h
src/Storage.h
src/Service.h
src/LongMessageService.h
src/MinimumNodeService.cpp
src/MinimumNodeService.h
src/CanService.cpp
src/CanService.h
src/EventConsumerService.cpp
src/EventConsumerService.h
src/EventTeachingService.cpp
src/EventTeachingService.h
src/EventProducerService.cpp
src/EventProducerService.h
src/NodeVariableService.cpp
src/NodeVariableService.h
src/vlcbdefs.hpp
src/ConsumeOwnEventsService.h
src/ConsumeOwnEventsService.cpp
src/GridConnect.cpp
src/GridConnect.h
src/CircularBuffer.h
)
add_subdirectory(src)

target_link_libraries(core_library PUBLIC)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "avr")
set(ARDUINO_PORT "/dev/ttyACM0" CACHE STRING
"The serial port for uploading using avrdude")

add_executable(VLCB_Arduino
$<TARGET_OBJECTS:core_library>
$<TARGET_OBJECTS:hardware_library>
include(cmake/arduino_sdk.cmake)

Arduino/Arduino.h
Arduino/Streaming.h
Arduino/SPI.h
Arduino/Wire.h
Arduino/ACAN2515.h
Arduino/EEPROM.h
examples/VLCB_1in1out/VLCB_1in1out.ino
examples/VLCB_empty/VLCB_empty.ino
examples/VLCB_long_message_example/VLCB_long_message_example.ino
examples/VLCB_SerialGC_1in1out/VLCB_SerialGC_1in1out.ino)
include(examples/VLCB_1in1out/VLCB_1in1out.cmake)
include(examples/VLCB_4in4out/VLCB_4in4out.cmake)
include(examples/VLCB_empty/VLCB_empty.cmake)
include(examples/VLCB_long_message_example/VLCB_long_message_example.cmake)
else()
add_subdirectory(Arduino)
add_subdirectory(test)

add_executable(testAll
$<TARGET_OBJECTS:core_library>

test/ArduinoMock.cpp
test/TestTools.cpp
test/testArduino.cpp
test/testAll.cpp
test/testMinimumNodeService.cpp
test/testNodeVariableService.cpp
test/testCanService.cpp
test/MockUserInterface.cpp
test/MockStorage.cpp
test/MockCanTransport.cpp
test/MockCanTransport.h
test/MockTransportService.cpp
test/MockTransportService.h
test/VlcbCommon.cpp
test/testEventProducerService.cpp
test/testEventConsumerService.cpp
test/testEventTeachingService.cpp
test/testConsumeOwnEventsService.cpp
test/testLongMessageService.cpp
test/testGridConnect.cpp
test/testConfiguration.cpp
test/testCircularBuffer.cpp
test/MockUserInterface.h
)
enable_testing()
add_test(NAME testAll COMMAND $<TARGET_FILE:testAll>)
endif()
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

# VLCB-Arduino
This project implements an Arduino library for [VLCB](https://github.com/Versatile-LCB/VLCB-documents) running over CAN bus.
VLCB is an extension of [CBUS](https://www.merg.org.uk/resources/cbus).
VLCB is an extension of [CBUS](https://www.merg.org.uk/resources/cbus).

CBUS(R) is a registered trademark of Dr. Michael Bolton.

This VLCB library code is based on a [CBUS library](https://github.com/MERG-DEV/CBUS) created by Duncan Greenwood
and extended by members of [MERG](https://www.merg.org.uk/).
and extended by members of [MERG](https://www.merg.org.uk/).
See below under Credits.

See [Design documents](docs/Design.md) for how this library is structured.
Expand Down Expand Up @@ -57,6 +57,14 @@ At the moment this library is still in early development and thus not fully supp
If you have any questions or suggestions please contact the library maintainers
by email to vlcb@rosvall.ie or create an issue in GitHub.

## Building

This code may be built in multiple ways:

* Using the Arduino IDE, treating this repository as a Library.
* Directly using CMake.
* Using an IDE (e.g. VSCode) and its CMake integration.

## Credits

* Duncan Greenwood - Created the CBUS library for Arduinos which this VLCB library is based on.
Expand All @@ -73,3 +81,9 @@ The code contained in this repository and the executable distributions are licen
[Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License](LICENSE.md).

If you have questions about licensing this library please contact [license@rosvall.ie](mailto:license@rosvall.ie)

## Arduino-AVR-CMake License

Portions of code in the `cmake` directory are Copyright (c) 2023 PieterP.

See the Arduino-AVR-CMake-LICENSE file in this repository.
15 changes: 15 additions & 0 deletions build-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
set -xe

# Tests
cmake -S. -Bbuild-test \
-D CMAKE_TOOLCHAIN_FILE=cmake/toolchain/host.toolchain.cmake \
-D CMAKE_BUILD_TYPE=Debug
(cd build-test && make && ctest)

# AVR binary
cmake -S. -Bbuild \
-D ARDUINO_PORT=/dev/ttyUSB0 \
-D CMAKE_TOOLCHAIN_FILE=cmake/toolchain/uno.toolchain.cmake \
-D CMAKE_BUILD_TYPE=MinSizeRel
(cd build && make)
8 changes: 8 additions & 0 deletions build-test-asan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
set -xe

# Tests with ASan/LeakSan/UBSan
cmake -S. -Bbuild-test-asan \
-D CMAKE_TOOLCHAIN_FILE=cmake/toolchain/clang.toolchain.cmake \
-D CMAKE_BUILD_TYPE=Asan
(cd build-test-asan && make && ctest)
16 changes: 16 additions & 0 deletions cmake/arduino_ACAN2515.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
if(NOT ARDUINO_PATH)
message(FATAL_ERROR "Arduino-specific variables are not set. \
Did you select the right toolchain file?")
endif()

add_library(ArduinoACAN2515 STATIC
${ARDUINO_USER_LIBS_PATH}/ACAN2515/src/ACAN2515.cpp
${ARDUINO_USER_LIBS_PATH}/ACAN2515/src/ACAN2515Settings.cpp
)
target_link_libraries(ArduinoACAN2515 PUBLIC ArduinoFlags)
target_link_libraries(ArduinoACAN2515 PUBLIC ArduinoCore)
target_link_libraries(ArduinoACAN2515 PUBLIC ArduinoLibs)

target_include_directories(ArduinoACAN2515 PUBLIC
${ARDUINO_USER_LIBS_PATH}/ACAN2515/src
)
15 changes: 15 additions & 0 deletions cmake/arduino_Bounce2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
if(NOT ARDUINO_USER_LIBS_PATH)
message(FATAL_ERROR "Arduino-specific variables are not set. \
Did you select the right toolchain file?")
endif()

add_library(ArduinoBounce2 STATIC
${ARDUINO_USER_LIBS_PATH}/Bounce2/src/Bounce2.cpp
)
target_link_libraries(ArduinoBounce2 PUBLIC ArduinoFlags)
target_link_libraries(ArduinoBounce2 PUBLIC ArduinoCore)
target_link_libraries(ArduinoBounce2 PUBLIC ArduinoLibs)

target_include_directories(ArduinoBounce2 PUBLIC
${ARDUINO_USER_LIBS_PATH}/Bounce2/src
)
10 changes: 10 additions & 0 deletions cmake/arduino_Streaming.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if(NOT ARDUINO_PATH)
message(FATAL_ERROR "Arduino-specific variables are not set. \
Did you select the right toolchain file?")
endif()

add_library(ArduinoStreaming INTERFACE)

target_include_directories(ArduinoStreaming INTERFACE
${ARDUINO_USER_LIBS_PATH}/Streaming/src
)
47 changes: 47 additions & 0 deletions cmake/arduino_core.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
if(NOT ARDUINO_PATH)
message(FATAL_ERROR "Arduino-specific variables are not set. \
Did you select the right toolchain file?")
endif()

# Arduino Core
add_library(ArduinoCore STATIC
${ARDUINO_CORE_PATH}/abi.cpp
${ARDUINO_CORE_PATH}/CDC.cpp
${ARDUINO_CORE_PATH}/HardwareSerial0.cpp
${ARDUINO_CORE_PATH}/HardwareSerial1.cpp
${ARDUINO_CORE_PATH}/HardwareSerial2.cpp
${ARDUINO_CORE_PATH}/HardwareSerial3.cpp
${ARDUINO_CORE_PATH}/HardwareSerial.cpp
${ARDUINO_CORE_PATH}/IPAddress.cpp
${ARDUINO_CORE_PATH}/main.cpp
${ARDUINO_CORE_PATH}/new.cpp
${ARDUINO_CORE_PATH}/PluggableUSB.cpp
${ARDUINO_CORE_PATH}/Print.cpp
${ARDUINO_CORE_PATH}/Stream.cpp
${ARDUINO_CORE_PATH}/Tone.cpp
${ARDUINO_CORE_PATH}/USBCore.cpp
${ARDUINO_CORE_PATH}/WMath.cpp
${ARDUINO_CORE_PATH}/WString.cpp
${ARDUINO_CORE_PATH}/hooks.c
${ARDUINO_CORE_PATH}/WInterrupts.c
${ARDUINO_CORE_PATH}/wiring_analog.c
${ARDUINO_CORE_PATH}/wiring.c
${ARDUINO_CORE_PATH}/wiring_digital.c
${ARDUINO_CORE_PATH}/wiring_pulse.c
${ARDUINO_CORE_PATH}/wiring_shift.c
${ARDUINO_CORE_PATH}/wiring_pulse.S
)
target_link_libraries(ArduinoCore PUBLIC ArduinoFlags)
target_compile_features(ArduinoCore PUBLIC cxx_std_11 c_std_11)
target_include_directories(ArduinoCore PUBLIC
${ARDUINO_CORE_PATH}
${ARDUINO_AVR_PATH}/variants/${ARDUINO_VARIANT}
)
if(ARDUINO_USB)
target_compile_definitions(ArduinoCore PUBLIC
USB_VID=${ARDUINO_USB_VID}
USB_PID=${ARDUINO_USB_PID}
USB_MANUFACTURER=\"Unknown\"
USB_PRODUCT=\"${ARDUINO_USB_PRODUCT}\"
)
endif()
Loading