Commit Graph

51 Commits

Author SHA1 Message Date
Blinker73 df79893dbc
linux: Update i2c.c (#5295)
Similarly to commit 8cf1b512 for SPI, the Rpi4 has more i2c busses to offer
This change allows klipper to use up to I2c bus 6
/boot/configtxt 
dtparam=i2c_arm=on
dtoverlay=i2c6

and 

pi@fluiddpi:~ $ ls -1 /dev/i2c*
/dev/i2c-1
/dev/i2c-6

Signed-off-by: Sylvain Dansereau <brutus_dansereau@hotmail.com>
2022-03-14 14:24:27 -04:00
Kevin O'Connor 913d099261 linux: Use Unix signals to notify when a timer is pending
Use Unix signals in software timer implementation.  This makes the
code a little more efficient.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2021-11-02 13:27:51 -04:00
Kevin O'Connor 8cf1b51223 linux: Support spidev4 through spidev7
The rpi4 has additional spi devices.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2021-09-15 11:06:10 -04:00
Kevin O'Connor d619796495 Revert "linux: Raise an error if configuring a pullup when that is not supported"
This reverts commit 70ea0806d9.

The above commit breaks software spi on linux hosts.  Revert that
commit until an improved error check can be implemented.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2021-05-27 11:33:24 -04:00
Kevin O'Connor 70ea0806d9 linux: Raise an error if configuring a pullup when that is not supported
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2021-04-25 11:54:11 -04:00
Kevin O'Connor 3dadcd3614 linux: Minor formatting, variable name, and error reporting changes
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2021-04-25 11:12:46 -04:00
Kevin O'Connor acd94909bc linux: Don't use timer_repeat_until for linux "irq" polling
Use a simpler counter system to prioritize tasks and irqs when busy.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2021-04-21 22:02:08 -04:00
Kevin O'Connor 8f9e497d69 linux: Rework timer_check_periodic() to use ticks
Avoid using a 'struct timespec' to simplify the code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2021-04-19 09:50:40 -04:00
Kevin O'Connor e0aba590f9 linux: Move timer fields into a struct
Storing the fields in a struct allows gcc to optimize memory pointers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2021-04-19 08:53:47 -04:00
Kevin O'Connor db0fb5d596 linux: Avoid calling timer_read_time() in timer_dispatch() when not needed
The timer_read_time() call can be expensive - when the next timer is
definitely pending, avoid making that call.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2021-04-18 13:12:32 -04:00
Kevin O'Connor 89af88d016 linux: Simplify timer dispatch code
Implement rescheduling math using the simple 32-bit timer instead of
the Unix timespec struct.  This makes the code simpler and doesn't
adversely impact the overall performance.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2021-04-18 12:25:50 -04:00
Kevin O'Connor d5c72e3693 linux: Fix local timer_repeat_until cache in timer.c
Make sure to update the local copy of timer_repeat_until when updating
it.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2021-04-18 12:17:00 -04:00
Evgeny Chukreev 8c369b54ab ds18b20: Segmentation fault on 64bit Raspberry Pi
Signed-off-by: Evgeny Chukreev <Evgeny.Chukreev@gmail.com>
2021-03-19 11:18:51 -04:00
Alan Lord 7d4df65920
ds18b20: new module for 1-wire temperature sensor (#3462)
Initial commit of code to support 1-wire (Dallas) sensors such
as the DS18B20. Requires Linux kernel drivers to create a file
in /sysfs which is read by this module, and temperature
typically returned to a temperature_fan.

Signed-off-by: Alan Lord <alanslists@gmail.com>
Signed-off-by: Josh Headapohl <joshhead@gmail.com>
2021-02-02 14:34:56 -05:00
Kevin O'Connor 9e293be5e0 pca9685: Use move queue for pwm updates
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-12-04 16:10:13 -05:00
Kevin O'Connor a560432041 command: Fix handling of buffer passing in args[] on 64bit mcu
If the buffer pointer can't fit in a uint32_t then pass a relative
buffer offset instead.  This fixes buffer handling on 64bit linux
mcus.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-10-30 14:04:12 -04:00
Kevin O'Connor ed5ce9cb37 linux: Fix spi handling with more than one spi device
Reported by @opensource-alt.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-10-25 10:14:15 -04:00
Kevin O'Connor 0f3b1bce66 linux: Set the SPI mode in spidev.c
Fix omission causing the SPI mode to not be set on the linux mcu.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-07-31 23:18:46 -04:00
Kevin O'Connor 5f2cb5436c linux: Disable hardware pwm when it is set to zero
Only write "1" to the "enable" file when a non-zero pwm width is
requested.  Write "0" to the "enable" file when a zero pwm width is
requested.

This fixes a problem on the replicape servo lines that prevented them
from being fully disabled.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-07-20 22:18:28 -04:00
Kevin O'Connor 06437c5892 linux: Wait in timer dispatch for up to 2us
Use 2us in the linux timer dispatch code to unify linux timer dispatch
logic with the common timer_irq.c code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-06-07 09:17:51 -04:00
Lucio Tarantino b7699d374a
linux: Ability to use multiple GPIO chips (#2935)
Signed-off-by: Lucio Tarantino <lucio.tarantino@gmail.com>
2020-06-06 12:47:11 -04:00
andryblack 8fd330c54e linux: userspace GPIO control
Allow use host GPIO pins for non-realtime purposes.

Signed-off-by: Andrey Kunitsyn <blackicebox@gmail.com>
2020-05-17 22:17:15 -04:00
Lucio Tarantino dac42efbd9
htu21d: Support for HTI21D family sensor on I2C bus (#2803)
Signed-off-by: Lucio Tarantino <lucio.tarantino@gmail.com>
2020-05-03 18:47:24 -04:00
Janne Grunau 0aa78ec76e
linux: Adapt servo0 channels for beagleboard kernel 4.14.108-ti (#2746)
The beagleboard TI kernel 4.14 and 4.19 contain a commit which change
the device names ("pwm: Create device class for pwm channels") from
pwmN to pwm-${chip}:N. This commit was never merged into the upstream
kernel.

Decrease the number of pwm channels to a more reasonable 16. Increase
the number of pwm chips to 8 since the replicape servo pwm outputs are
on pwmchip4.

Update replicape code to detect appropriate channel.

Signed-off-by: Janne Grunau <janne-gh@jannau.net>
2020-05-03 11:24:42 -04:00
andryblack db732e58db linux: change clock frequency
Increase timer resolution for linux mcu

Signed-off-by: Andrey Kunitsyn <blackicebox@gmail.com>
2020-05-02 16:38:56 -04:00
Arksine 20ba396466 linux: implement i2c
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2020-01-13 22:29:50 -05:00
Kevin O'Connor c2a08962b7 spicmds: Rework spi config commands
Rework the spi_config commands so that bus configuration and shutdown
message configuration is done separately from the main "config_spi"
command.  This makes the spi configuration more flexible.  It's now
possible to use software spi without a CS pin.  It's now possible to
define multiple SPI messages to send on a shutdown event.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-08-06 18:56:53 -04:00
Janne Grunau aab89e7f85 linux: add support for Linux hardware PWM
The replicape servo pins (P9_14/P9_16) are muxed to the SOCs hardware
PWM unit driven by a 13MHz GP timer. They have to be driven by the
linux host mcu. This commits adds hardware PWM support using the linux
sysfs user space interface.

Signed-off-by: Janne Grunau <janne-3d@jannau.net>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-04-05 19:06:15 -04:00
Kevin O'Connor f8bde6b1ef linux: Convert SPI to use enumerations
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-04-04 18:29:31 -04:00
Kevin O'Connor df6136802a linux: Use enumerations for pin mappings
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-17 19:38:18 -04:00
Kevin O'Connor b28e95ca1a command: Always pass a string to the DECL_CONSTANT() macro
Make it clear that the name of the constant being defined is a string.
When the value being defined is also a string, use a new
DECL_CONSTANT_STR() macro.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-17 19:38:18 -04:00
Ricardo Amezquita 940db6bd70 linux: Add support for bi-directional SPI communication
Signed-off-by: Ricardo Amézquita <ramezquitao@cihologramas.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-07-24 11:16:05 -04:00
Grigori Goronzy ebd9035325 SPI: introduce spi_prepare function
The SPI interface needs to be enabled and configured to the correct
settings of a given oid before CS is asserted. The new function
spi_prepare() allows ports to do that.

This port only introduces the new function in all ports with no
implementation and adds the call to the Klipper generic firmware code.
That means everything still works as before. Ports need to be changed
to fix the underlying issue.

Discussion about the motivation here:
https://github.com/KevinOConnor/klipper/pull/453#issuecomment-403131149

Signed-off-by: Grigori Goronzy <greg@chown.ath.cx>
2018-07-08 09:25:11 -04:00
Kevin O'Connor 528f9f7604 command: Add command_find_and_dispatch() helper
Add a helper function that calls command_find_block() followed by
command_dispatch().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-28 10:43:39 -04:00
Kevin O'Connor c8af3feee6 command: Add a command_encode_and_frame() helper
Add a helper function that calls command_encodef() followed by
command_add_frame().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-28 10:43:39 -04:00
Kevin O'Connor cb4e165071 command: Prefer uint8_t* for buffers; prefer uint8_fast_t for lengths
Prefer using 'uint8_t' buffers as it is too easy to run into C sign
extension problems with 'char' buffers.  Prefer using 'uint_fast8_t'
for buffer lengths as gcc does a better job compiling them on 32bit
mcus.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-28 10:43:39 -04:00
Kevin O'Connor 70068985a7 stepper: Introduce and use gpio_out_toggle_noirq()
The gpio_out_toggle() function in the sam3x8e and stm32f1 code was
only valid if it was called with irqs disabled.

Commits 018c5daa and 9c52ad43 enabled the lcd code which called
gpio_out_toggle() with irqs enabled.  This could cause corruption of
the gpio state.

Introduce a gpio_out_toggle_noirq() function that will only be invoked
with irqs disabled, and fix gpio_out_toggle() on sam3x8e and stm32f1
so that it safe to call even if irqs are enabled.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-15 17:09:11 -04:00
Kevin O'Connor f70fefa06f linux: Convert linux SPI code to use the generic spicmds.c code
Use the generic spi send/receive code on Linux.  Update the replicape
code to use the updated command format.

Also, update the replicape code to turn off the stepper motors on a
shutdown event.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-07 09:10:34 -04:00
Kevin O'Connor 03e97c2d95 linux: Remove unneeded includes from timer.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-23 22:20:53 -04:00
Kevin O'Connor cbd06f1433 linux: Fix typo causing config_reset to not fully restart
A typo in the code caused the wrong config_reset code to be run.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-15 21:05:08 -04:00
Kevin O'Connor 1c59a0d30a linux: Open watchdog device after console
Only open the watchdog device after the console has been opened.  The
machine should not reboot in the unlikely event the console can't be
opened.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-15 21:05:08 -04:00
Kevin O'Connor d222ec1024 linux: Make sure to close fd on analog/pca9685 init failure
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-14 00:22:21 -04:00
Kevin O'Connor 674f584190 pca9685: Fix missing devices_count increment
The devices_count was not being incremented on each device add.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-13 22:05:19 -04:00
Kevin O'Connor 3c4d14bfa9 pca9685: Support default values
Allow the pwm pin to have a non-zero default value.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 11:59:27 -04:00
Kevin O'Connor d03cf2b83f adccmds: Continue to query analog inputs after a shutdown
Continue to sample the ADC input pins even if the MCU goes into a
shutdown state.  This enables the printer to continue reporting
temperatures even on an mcu error.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 11:59:27 -04:00
Kevin O'Connor 744c6d114e sched: Don't shutdown on a "timer in the past" if already shutdown
A shutdown will not help if the mcu is already in a shutdown state.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 11:59:27 -04:00
Kevin O'Connor 5a85c1667a pru: Update installation and flash scripts
Update the scripts used to install and "flash" the pru
micro-controller code.  Also, add a "flash" script for the linux
micro-controller code.  This makes it easier to install Klipper on a
Beaglebone board that uses a Replicape.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 12:55:28 -04:00
Kevin O'Connor 16d2ec3a90 linux: Add support for analog IIO devices
Add support for reading analog values via the standard Linux IIO
interface.  This can be used on Replicape boards to sample analog
input pins.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 12:55:28 -04:00
Kevin O'Connor 4d60567bc6 linux: Add support for spidev devices
Add support for sending SPI messages to devices via the standard Linux
SPI interface.  This can be used to configure the shift registers on
Replicape boards.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 12:55:28 -04:00
Kevin O'Connor 73a1c9d249 linux: Add support for pca9685 i2c pwm devices
Add support for controlling pca9685 PWM drivers using the standard
Linux I2C interface.  The pca9685 device is found on Replicape boards.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 12:55:28 -04:00