braking is handled behind the patterns inside pattern.c
See the comment above pwmled_update_mode():
This is tricky: we use a single pattern for all three pwmleds,
but on some occasions, we want to be able to modify only a single
pwmled status without affecting other outputs. For example, during
braking, we want to modify only the rear pwmled status. We don't
use a separate "braking" pattern for every other pattern used, but instead
we change the pwmled0 status regardless of the original value when
braking. The rule is the following:
- if during braking the pwmled2 (front) is at mode 2, we switch it to
mode 3 (which has the same target current) to avoid flicker.
- if pwmled0 (rear) is off, we set it to mode 2
(if it is with mode 1, we keep it at mode 1)
TODO: something similar should be done for the "entering the dark area"
condition, where we want to switch pwmled2 (front) on, to mode 2.