Skip to content

Add hardware CAN hooks and slave-mode toggles - #95

Open
Fajdiga wants to merge 4 commits into
vedderb:mainfrom
Fajdiga:pr/hw-can-hooks-slave-toggles
Open

Add hardware CAN hooks and slave-mode toggles#95
Fajdiga wants to merge 4 commits into
vedderb:mainfrom
Fajdiga:pr/hw-can-hooks-slave-toggles

Conversation

@Fajdiga

@Fajdiga Fajdiga commented May 14, 2026

Copy link
Copy Markdown

This PR adds optional hardware configuration hooks used by headless and private-CAN hardware variants.

Changes:

  • Adds HW_CAN_PING_SCAN_ENABLED to let hardware configs opt out of CAN ping scans.
  • Adds HW_CAN_NO_ACK_MODE for hardware that needs CAN no-ack mode.
  • Adds optional hardware CAN filter and RX hooks.
  • Adds HW_IS_SLAVE for headless variants that should not initialize the full normal application role.

Motivation:
These are compile-time hooks with default behavior unchanged for existing hardware. They make it possible to support simpler/headless CAN devices without adding board-specific conditionals to common code.

Compatibility:
Existing hardware targets keep the previous behavior unless they define the new macros.

Testing:

  • Split from the tested cleanup/upstream-ready branch.
  • Tested with the JFBMS slave hardware variant that depends on these hooks.

Copilot AI review requested due to automatic review settings May 14, 2026 16:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Jerne Fajdiga added 4 commits May 25, 2026 13:44
Adds an optional hwconf macro that lets a board opt out of the
COMM_PING_CAN broadcast scan. The default in main/hwconf/hw.h is 1
to preserve the existing behavior; a hwconf header can override it
to 0 to skip the scan loop in commands.c.

Useful for headless variants that share a CAN bus with a master and
should never participate in VESC ping discovery.
Adds an optional hwconf macro that switches the TWAI driver into
TWAI_MODE_NO_ACK at init. The default in main/hwconf/hw.h is 0, so
the existing TWAI_MODE_NORMAL behavior is preserved unless a hwconf
header opts in.

Useful for bench / diagnostic builds that need to observe a live CAN
bus without generating ACKs.
Adds HW_CAN_FILTER_CONFIG in main/hwconf/hw.h so a hwconf header can override the default TWAI acceptance filter. The default expands to false, so behavior remains TWAI_FILTER_CONFIG_ACCEPT_ALL() when no hardware provides an override.

The filter is re-applied on both initial CAN bring-up and after comm_can_update_baudrate() so a hwconf override survives baud changes. f_config is made non-const so update_filter() can replace it.

Also dispatches an optional weak hw_can_rx_hook() from the CAN process task after Lisp CAN processing and before the normal VESC/BMS decoder path. Hardware variants such as JFBMS_SLAVE can use this to consume custom 11-bit protocol frames without changing generic CAN decoding.

Matches the existing HW_INIT_HOOK() / HW_POST_LISPIF_HOOK() pattern: a hwconf header declares its hardware-specific function and wires it through a small macro or weak-symbol implementation.
Adds a hwconf-defined HW_IS_SLAVE flag that suppresses two pieces of
boot-time behavior in main.c:

- BLE and WiFi initialization. A slave variant has no user-facing radios;
  running these only wastes RAM and adds attack surface.
- main_store_backup_data() copying controller_id and can_baud_rate from
  the live config into the persisted backup. Headless slave builds use
  their own slave-specific config and should not mirror these shared
  VESC Express compatibility fields back into backup storage.

When HW_IS_SLAVE is not defined, behavior is unchanged. The flag is
expected to be set in a hwconf header alongside HW_NAME and the other
HW_* macros.
@Fajdiga
Fajdiga force-pushed the pr/hw-can-hooks-slave-toggles branch from 3b7d0c8 to bb9fbac Compare May 25, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants