Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add definitions for bit timings and remove emergencyStop API #12

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ on:
branches: [master]

jobs:
arm-none-eabi-gcc:
uses: ZIMO-Elektronik/.github-workflows/.github/workflows/arm-none-eabi-gcc.yml@v0.0.4
with:
arch: -mcpu=cortex-m7
target: DCCStm32Decoder DCCStm32CommandStation

esp-elf-gcc:
uses: ZIMO-Elektronik/.github-workflows/.github/workflows/esp-elf-gcc.yml@v0.0.4
with:
path: examples/rmt
path: examples/esp32
target: esp32

x86_64-linux-gnu-gcc:
Expand Down
6 changes: 6 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "CMake DCCStm32*",
"type": "shell",
"isBackground": true,
"command": "cmake -Bbuild -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DARCH=\"-mcpu=cortex-m7 -mfloat-abi=hard\" -DCMAKE_TOOLCHAIN_FILE=CMakeModules/cmake/toolchain-arm-none-eabi-gcc.cmake"
},
{
"label": "CMake DCCTests",
"type": "shell",
Expand Down
40 changes: 24 additions & 16 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# Changelog

##
- Add datagram method to `rx::bidi::CrtpBase` to queue dyn (ID7) datagrams
- Replace `int32_t` direction (1, -1) with `bool` (1, 0)
- Remove decoders `emergencyStop` API and replace it with `speed(-1)`
- Add `Direction` and `Speed` enumerations
- Rename `bidi::Speed` to `bidi::Kmh` to avoid ambiguity
- Rename `tx::Config::preamble_bits` to `num_preamble` to match RMT configuration

## 0.33.1
- Add `DCC_TX_MAX_PREAMBLE_BITS` definition

## 0.33.0
- Limit number of preamble bits of RMT encoder to 30
- Rename dcc_encoder_config_t::cutoutbit_duration to bidibit_duration
- Rename `dcc_encoder_config_t::cutoutbit_duration` to `bidibit_duration`
- Remove optional mduEntry
- Bugfix standard compliant CV28
- Logon must be enabled by CV28:7 and ignores CV28:1 and CV28:0
Expand All @@ -15,17 +23,17 @@
- Logon address is only temporary

## 0.32.0
- Individual timings for namespace dcc::rx and dcc::tx
- Move time2bit to namespace dcc::rx
- Individual timings for namespace `dcc::rx` and `dcc::tx`
- Move `time2bit` to namespace `dcc::rx`
- Bugfix RMT encoder [#13032](https://github.com/espressif/esp-idf/issues/13032)

## 0.31.0
- Changes to namespace dcc::tx
- Rename raw2timings to bytes2timings
- Rename CrtpBase::raw to CrtpBase::bytes
- Changes to namespace `dcc::tx`
- Rename `raw2timings` to `bytes2timings`
- Rename `CrtpBase::raw` to `CrtpBase::bytes`

## 0.30.0
- Use 'speed' instead of 'notch'
- Use `speed` instead of `notch`
- Update to ZTL 0.18.0

## 0.29.1
Expand All @@ -52,26 +60,26 @@
- API changes to bytewise CV read

## 0.26.1
- Bugfix QoS message not written to deque
- Bugfix QoS datagram not written to deque

## 0.26.0
- API changes to bitwise CV read

## 0.25.0
- BiDi dyn messages get added from execute method
- Add BiDi temperature message (ID7, subindex 26)
- BiDi dyn datagrams get added from execute method
- Add BiDi temperature datagram (ID7, subindex 26)
- CV15/16 the values 0 can no longer activate the lock

## 0.24.1
- Short and long addresses are considered equal if their values are
- make_*_packet functions
- Bugfix QoS message wasn't thread safe
- `make_*_packet` functions
- Bugfix QoS datagram wasn't thread safe

## 0.24.0
- Rename serviceMode to serviceModeHook
- Rename `serviceMode` to `serviceModeHook`

## 0.23.0
- time2bit returns Bit enum instead of std::optional (overhead is pretty significant)
- `time2bit` returns `Bit` enum instead of `std::optional` (overhead is pretty significant)

## 0.22.2
- Use CPM.cmake
Expand All @@ -95,15 +103,15 @@
- LOGON_ASSIGN CRC must be calculated before 6/8 encoding

## 0.21.0
- Mainline RCN218
- Mainline RCN-218
- LOGON_ENABLE does not have CRC
- LOGON_SELECT uses 6/8 encoding

## 0.20.1
- Add proprietary CV20

## 0.20.0
- Minimal implementation of (crippled) RCN218
- Minimal implementation of (crippled) RCN-218
- Update to ZTL 0.15.0

## 0.19.0
Expand Down
49 changes: 40 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ include(FetchContent)
if(ESP_PLATFORM)
file(GLOB_RECURSE SRC src/*.c)
idf_component_register(SRCS ${SRC} INCLUDE_DIRS include REQUIRES driver)
# Change OUTPUT_NAME from DCC to lib__idf_DCC to avoid conflicts
set_target_properties(${COMPONENT_LIB} PROPERTIES PREFIX "")
set_target_properties(
${COMPONENT_LIB} PROPERTIES OUTPUT_NAME
Expand All @@ -14,19 +15,31 @@ endif()
FetchContent_Declare(
CMakeModules
GIT_REPOSITORY "https://github.com/ZIMO-Elektronik/CMakeModules"
GIT_TAG v0.8.0
GIT_TAG v0.9.1
SOURCE_DIR ${CMAKE_BINARY_DIR}/CMakeModules)
FetchContent_MakeAvailable(CMakeModules)

version_from_git()
project(
DCC
VERSION ${VERSION_FROM_GIT}
LANGUAGES C CXX)
LANGUAGES ASM C CXX)

set(DCC_MAX_PACKET_SIZE
18u
CACHE STRING "Maximum size of a packet in bytes")
set(DCC_RX_MIN_BIT_1_TIMING
52u
CACHE STRING "Minimum duration of a 1 bit of decoder")
set(DCC_RX_MAX_BIT_1_TIMING
64u
CACHE STRING "Maximum duration of a 1 bit of decoder")
set(DCC_RX_MIN_BIT_0_TIMING
90u
CACHE STRING "Minimum duration of a 0 bit of decoder")
set(DCC_RX_MAX_BIT_0_TIMING
119u
CACHE STRING "Maximum duration of a 0 bit of decoder")
set(DCC_RX_MIN_PREAMBLE_BITS
10u
CACHE STRING "Minimum number of preambel bits of decoder")
Expand All @@ -36,6 +49,18 @@ set(DCC_RX_DEQUE_SIZE
set(DCC_RX_BIDI_DEQUE_SIZE
7u
CACHE STRING "Size of the sender deque of decoder")
set(DCC_TX_MIN_BIT_1_TIMING
56u
CACHE STRING "Minimum duration of a 1 bit of command station")
set(DCC_TX_MAX_BIT_1_TIMING
60u
CACHE STRING "Maximum duration of a 1 bit of command station")
set(DCC_TX_MIN_BIT_0_TIMING
97u
CACHE STRING "Minimum duration of a 0 bit of command station")
set(DCC_TX_MAX_BIT_0_TIMING
114u
CACHE STRING "Maximum duration of a 0 bit of command station")
set(DCC_TX_MIN_PREAMBLE_BITS
17u
CACHE STRING "Minimum number of preambel bits of command station")
Expand All @@ -54,17 +79,23 @@ target_compile_features(DCC INTERFACE cxx_std_23)
target_compile_definitions(
DCC
INTERFACE DCC_MAX_PACKET_SIZE=${DCC_MAX_PACKET_SIZE}
DCC_RX_MIN_BIT_1_TIMING=${DCC_RX_MIN_BIT_1_TIMING}
DCC_RX_MAX_BIT_1_TIMING=${DCC_RX_MAX_BIT_1_TIMING}
DCC_RX_MIN_BIT_0_TIMING=${DCC_RX_MIN_BIT_0_TIMING}
DCC_RX_MAX_BIT_0_TIMING=${DCC_RX_MAX_BIT_0_TIMING}
DCC_RX_MIN_PREAMBLE_BITS=${DCC_RX_MIN_PREAMBLE_BITS}
DCC_RX_DEQUE_SIZE=${DCC_RX_DEQUE_SIZE}
DCC_RX_BIDI_DEQUE_SIZE=${DCC_RX_BIDI_DEQUE_SIZE}
DCC_TX_MIN_BIT_1_TIMING=${DCC_TX_MIN_BIT_1_TIMING}
DCC_TX_MAX_BIT_1_TIMING=${DCC_TX_MAX_BIT_1_TIMING}
DCC_TX_MIN_BIT_0_TIMING=${DCC_TX_MIN_BIT_0_TIMING}
DCC_TX_MAX_BIT_0_TIMING=${DCC_TX_MAX_BIT_0_TIMING}
DCC_TX_MIN_PREAMBLE_BITS=${DCC_TX_MIN_PREAMBLE_BITS}
DCC_TX_MAX_PREAMBLE_BITS=${DCC_TX_MAX_PREAMBLE_BITS}
DCC_TX_DEQUE_SIZE=${DCC_TX_DEQUE_SIZE})

if(PROJECT_IS_TOP_LEVEL AND CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME)
if(PROJECT_IS_TOP_LEVEL)
target_include_directories(DCC INTERFACE include)
target_compile_options(DCC
INTERFACE -Werror;-Wno-error=deprecated-declarations)
else()
target_include_directories(DCC SYSTEM INTERFACE include)
endif()
Expand All @@ -76,7 +107,7 @@ if(NOT TARGET static_math)
NAME
static_math
GITHUB_REPOSITORY
Morwenn/static_math
"Morwenn/static_math"
GIT_TAG
master
SYSTEM
Expand All @@ -86,23 +117,23 @@ if(NOT TARGET static_math)
endif()

if(NOT TARGET ZTL::ZTL)
cpmaddpackage(gh:ZIMO-Elektronik/ZTL@0.19.0)
cpmaddpackage("gh:ZIMO-Elektronik/ZTL@0.19.0")
endif()

target_link_libraries(DCC INTERFACE static_math ZTL::ZTL)

if(PROJECT_IS_TOP_LEVEL)
include(CTest)
add_subdirectory(examples)
file(
DOWNLOAD
https://raw.githubusercontent.com/ZIMO-Elektronik/.clang-format/master/.clang-format
"https://github.com/ZIMO-Elektronik/.clang-format/raw/master/.clang-format"
${CMAKE_CURRENT_LIST_DIR}/.clang-format)
file(GLOB_RECURSE SRC examples/*.[ch]pp include/*.[ch]pp src/*.[ch]pp
tests/*.[ch]pp)
add_clang_format_target(DCCFormat OPTIONS -i FILES ${SRC})
endif()

if(BUILD_TESTING AND CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME)
add_subdirectory(examples)
add_subdirectory(tests)
endif()