Commit Graph
1335 Commits
Author SHA1 Message Date
Kevin O'Connor 9c3ba2e3a5 trigger_analog: Automatically determine frac_bits in MCU_SosFilter
The coeff_frac_bits and scale_frac_bits can be automatically
calculated, so there's no need for the callers to specify this
information.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-04-15 10:15:24 -04:00
Timofey Titovets 959a3cfb6c stm32: G4 enable katapult request
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2026-04-12 12:05:05 -04:00
Timofey Titovets 35ace52976 stm32: define hard pwm PB pins for stm32g4
PB6 used on cartographer v4

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2026-04-09 22:45:22 -04:00
Timofey Titovets 2f05309d59 stm32: usbotg block next bulk_in if buffer not empty
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-03-24 16:30:42 -04:00
Kevin O'Connor 9ebff0cc84 rp2040: Avoid run-time divide in i2c.c
Rework the code slightly to avoid an expensive software divide when
calculating the rate in i2c.c .

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-03-24 12:55:51 -04:00
Nicolás A. Méndez 0c2416ea7f avr: Fix missing SP definition in newer avr-libc and missing include in adc.c (#7233)
compatibility fix for newer avr-libc - define stack pointer

add missing avr/io.h include to adc.c

add missing avr/io.h include to spi.c

Signed-off-by: Nicolás Méndez <9phhsyrbm@relay.firefox.com>
2026-03-24 12:51:44 -04:00
Kevin O'Connor 594ec7e120 rp2040: Improve accuracy of hardware pwm cycle time
Use a different method of setting the hardware pwm registers so that
the actual cycle_time is much closer to the requested cycle_time.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-03-21 11:23:01 -04:00
Kevin O'Connor 9fb7604353 rp2040: Avoid run-time division in hard_pwm.c
Use a MAX_PWM of 256 (instead of 255) to avoid an expensive run-time
divide operation.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-03-21 11:23:01 -04:00
Kevin O'Connor bfc624ac07 rp2040: Simplify cycle_time handling in hard_pwm.c
There is no need for elaborate math scaling of the cycle_time value to
the local clock ticks.  Just hardcode a scale of 16, which simplifies
the math calculations.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-03-21 11:22:58 -04:00
Kevin O'Connor 3115d698de rp2040: Replace divide with a multiply in spi.c
Rework the comparison to avoid using an expensive divide operation.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-03-20 19:54:57 -04:00
Kevin O'Connor 9e962ee3f4 adccmds: Add support for homing/probing triggering with regular mcu adc pins
Add support for trigger_analog to adccmds.c .

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-02-23 21:24:38 -05:00
Kevin O'Connor a44e905ffe trigger_analog: Support not compiling trigger_analog on small flash builds
Allow the user to deselect CONFIG_WANT_TRIGGER_ANALOG even if one of
the sensors could utilize the support.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-02-23 21:24:38 -05:00
Kevin O'Connor 41bc240b16 adccmds: Support batching multiple reports into a single message
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-02-23 21:24:38 -05:00
FranciscoStephens 8a210d23fe bmi160: Add support for BMI160 accelerometer
This adds host and firmware support for the Bosch BMI160 IMU. It includes support for both SPI and I2C communication protocols.

The firmware implementation includes a specific SPI wake-up sequence (dummy read) required to switch the sensor interface mode reliably. Validated on Linux MCU (SPI) and RP2040 (I2C) with stable 1600Hz ODR.

Signed-off-by: FranciscoStephens <francisco.stephens.g@gmail.com>
2026-02-12 17:46:33 -05:00
Tom ce97c514ba linux: fixed array out of bounds access for GPIO setup in linux process (#7196)
Signed-off-by: Tom Mittendorf <tom.mittendorf@web.de>
2026-02-10 10:52:32 -05:00
Timofey Titovets 0c2c1dd13b bus: allow mark i2c as write only
If the bus is write only, with new i2c_transfer code
it is possible to at least provide some feedback on error

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2026-02-07 14:01:45 -05:00
Timofey Titovets 8965958a8b bus: raise I2C errors on the host side
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2026-02-07 14:01:45 -05:00
Kevin O'Connor 1fe9fb3ad4 trigger_analog: Don't report trigger time as the peak time
There are some rare corner cases where reporting the peak time could
cause hard to debug issues (for example, the peak time could
theoretically be a significant time prior to the actual trigger time,
which could possibly cause unexpected clock rollover issues).  Now
that the host code does not utilize the peak time for "tap" detection,
it can be removed from the mcu code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-29 20:57:55 -05:00
Kevin O'Connor c9d904aa9d trigger_analog: Add initial support for detecting "tap" events
Add a new "diff_peak_gt" trigger type.  This will be useful with
detecting ldc1612 "tap" events.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:55:39 -05:00
Kevin O'Connor 9a97ade74f sos_filter: Implement auto_offset feature
Add a setting that will enable the mcu sos_filter code to
automatically set an offset using the first read measurement.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:55:39 -05:00
Kevin O'Connor 58cc059e31 sensor_ldc1612: Convert homing code to use trigger_analog system
Remove the homing code from sensor_ldc1612.c and utilize the generic
homing support found in trigger_analog.c .

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor 147022dee2 trigger_analog: Update to support generic trigger types
Rework the trigger_analog code to support different "trigger"
conditions.  This merges in features of ldc1612.c into
trigger_analog.c, such as error code reporting in the MCU.  This is in
preparation for using trigger_analog with ldc1612.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor 73a6184407 trigger_analog: Check if trigger_analog is allocated in trigger_analog_update()
Check if the trigger_analog struct has been allocated in
trigger_analog_update() itself.  This makes the code easier to use in
the sensor code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor 7ec82baca3 sos_filter: Move offset/scale support from trigger_analog.c to sos_filter.c
Support offsetting and scaling the initial raw value prior to
processing in the sos_filter.

Remove that support from trigger_analog.c .

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor 109f13c797 sos_filter: Consistently use "frac_bits" instead of "int_bits"
Internally describe the Qx.y format using the number of fractional
bits.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor 40242b2e33 sos_filter: Propagate overflow errors instead of a shutdown
Pass an overflow error back to the caller instead of invoking a
shutdown().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor fd195ff4ce sos_filter: Remove unnecessary "const" declarations
A "const" declaration on a local integer does not do anything in C
code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor 667c57e444 sos_filter: Remove unnecessary is_active flag
It's reasonable to deactivate the filter by setting n_sections=0, and
this makes the code a little easier to use when the host doesn't
actually need any filtering.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor ec08ff5a1e trigger_analog: Rename load_cell_probe.c to trigger_analog.c
Rename the mcu based load_cell_probe code to trigger_analog.  This is
a rename of the C code files, struct names, and command names.  There
is no change in behavior (other than naming) with this change.

This is in preparation for using the load_cell_probe functionality
with other sensors.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Timofey Titovets 2e0d746172 ldc1612: trigger error on high frequency
If the sensor coil is disconnected, the frequency is equal to the reference.
If the sensor is misconfigured or damaged, the coil frequency is
greater than 1/4 of the reference frequency.

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2026-01-08 12:00:45 -05:00
Timofey Titovets c6c7614972 ldc1612: ignore amplitude errors during homing
Amplitude errors are useful but often too aggressive.
On some sensors, it is not possible to avoid them completely.
Make them non-critical for homing.

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2026-01-08 12:00:45 -05:00
Timofey Titovets f7ddb40037 ldc1612: handle i2c errors
I2C error means we don't know the sensor status.
Force data output to the host and cancel homing.

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-08 12:00:45 -05:00
Kevin O'Connor e605fd1856 stm32: Improve accuracy of hardware pwm cycle time
Use a different method of setting the hardware pwm registers so that
the actual cycle_time is much closer to the requested cycle_time.

Also, remove the now unused stm32_timer_output command, as the main
hardware pwm interface provides the same accuracy.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-06 21:53:29 -05:00
Kevin O'Connor e60fe3d99b stm32: Fix off-by-one error in the prescaler calculation in hard_pwm.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-02 14:35:08 -05:00
Kevin O'Connor 74a15f4834 stm32: Minor comment and code organization changes to hard_pwm.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-02 14:35:08 -05:00
Timofey Titovets 05ce956456 stm32: fix static clock output for faster chips
If pcycle_time is scaled, the value should be scaled as well

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2025-12-31 12:03:54 -05:00
Kevin O'Connor ae3eb30f28 stm32: Enable MOE bit in hard_pwm.c for all stm32 chips
Always enable the MOE bit.  Reported by @tt33415366.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-31 11:34:15 -05:00
Kyoungkyu Park dd625933f7 avr: add lgt8f328p support
Signed-off-by: Kyoungkyu Park <choryu.park@choryu.space>
2025-12-30 21:51:15 -05:00
Kevin O'Connor 7377da63b7 stm32: Declare gpio_timer_setup() as static in hard_pwm.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-30 18:16:40 -05:00
Timofey Titovets ec0eb4a8bf stm32: hard pwm allow scale PWM frequency
To support the cartographer, it is required to output 24 MHz.
With current defaults max output frequency is:
48 MHz/256 = 187.5 KHz
Adjusting the PWM scale allows for ramping up the frequency.

To not mess up with existing PWM users,
define the STM32-specific command.

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2025-12-30 18:14:37 -05:00
Timofey Titovets 12cc944fa0 stm32: F042 define PB4 HW PWM
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2025-12-30 18:14:37 -05:00
Kevin O'Connor dc622f4ac3 stm32: Allow disabling double buffering transmit in usbfs.c
Only enable double buffering transmit if
CONFIG_STM32_USB_DOUBLE_BUFFER_TX is set.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-18 20:57:50 -05:00
Kevin O'Connor c3b660dfbe stm32: Simplify USBx_IRQn per-chip definitions in usbfs.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-18 20:57:50 -05:00
Kevin O'Connor 59a754c48c stm32: Implement manual double buffering tx for usbotg
It is possible for USB host controllers to send back-to-back IN tokens
which only gives the MCU ~3us to queue the next USB packet in the
hardware.  That can be difficult to do if the MCU has to wake up the
task code.  The stm32 "usbotg" hardware does not support a builtin
generic double buffering transmit capability, but it is possible to
load the next packet directly from the irq handler code.  This change
adds support for queuing the next packet destined for the host so that
the USB irq handler can directly load it into the hardware.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-18 20:57:50 -05:00
Kevin O'Connor a3e24d2172 rp2040: Add support for ADC on rp2350b chips
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-18 20:56:13 -05:00
Kevin O'Connor 3a3e9fa2f1 rp2040: Support rp2350b extra gpios
Add support for gpio31 through gpio47 on rp2350, as these pins are
available on the rp2350b chips.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-18 20:56:13 -05:00
Kevin O'Connor 3f72e519ed atsamd: Fix possible buffer overflow in usbserial.c
The USB buffer size register PCKSIZE.SIZE was not being assigned
correctly.  As a result, it was possible for an incoming USB
transmission to write past the allocated buffer space, which could
corrupt memory of other storage.  In particular, in some cases gcc may
layout ram in such a way that the trailing bytes of an incoming
message might overlap the buffer for an outgoing message.  This could
cause sporadic transmit errors and unstable connections.

Fix by correctly configuring the PCKSIZE.SIZE register.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-17 10:18:39 -05:00
Kevin O'Connor d92dda439e lib: Update pico-sdk to v2.2.0
The new rp2350 chips with A4 stepping require pico-sdk v2.2.0 .

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-17 10:12:52 -05:00
Kevin O'Connor a6a6b21e4d armcm_timer: Use a static instruction count for TIMER_MIN_TRY_TICKS
Change TIMER_MIN_TRY_TICKS from 2us to 90 instructions.

On newer chips 2us is a large amount of time - for example on the
520Mhz stm32h723 it would be 1040 instructions.  Using a large time
can result in "busy waiting" in the irq handler when the cpu may be
better spent running tasks.

The armcm_timer.c code is used on most ARM cortex-M chips and on all
of these chips the SysTick timer should be tied directly to the
instruction counter.  This change should be safe because it should not
take more than 90 instructions to reschedule the timer on any of these
chips.  Also, all of these chips should be able to exit the irq
handler and reenter it in less than 90 instructions allowing more time
for tasks to run if the next timer is more than 90 timer ticks in the
future.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-03 17:47:50 -05:00
Kevin O'Connor 3a700a5f62 timer_irq: Remove TIMER_IDLE_REPEAT_TICKS special case
The TIMER_IDLE_REPEAT_TICKS was intended to reduce the number of cases
where timers would defer to tasks when tasks are mostly idle.
However, with commit ea546c78 this became less important because
timers now only defer to tasks if tasks are consistently busy for two
consecutive calls to sched_check_set_tasks_busy().

The TIMER_IDLE_REPEAT_TICKS mechanism could result in extended task
delays if timers do become busy.  Timers can become busy in normal
operation if timers are scheduled to run more than 500,000 times a
second (every 2us or faster).  This can occur on stepper movement when
using high microstep settings.  If timers become busy, it could take
up to 1ms for tasks to next be given an opportunity to run (two calls
to sched_check_set_tasks_busy() at 500us per call).  This wouldn't
typically be an issue if tasks are also busy, but in some loads tasks
may need to run periodically in such a way that the task status
alternates between idle and busy.  In this case, the
TIMER_IDLE_REPEAT_TICKS mechanism could effectively limit the number
of task wakeups to only ~1000 per second.

The "USB to canbus bridge" code uses tasks to transfer data to/from
USB and canbus.  If timers become busy, the limiting of task wakeups
could lead to a situation where the effective bandwidth becomes
severely constrained.  In particular, this can be an issue on USB
implementations that do not support "double buffering" (such as the
stm32 usbotg code).  There are reports of "Timer too close" errors on
"USB to canbus bridge" mode as a result of this issue.

Fix by removing the TIMER_IDLE_REPEAT_TICKS check.  Check for busy
tasks every TIMER_REPEAT_TICKS instead (100us).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-03 17:47:50 -05:00