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

Allow using SX1509 and MCP23017 IO expander for buttons #382

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

idubrov
Copy link

@idubrov idubrov commented Aug 15, 2024

Allow using I2C IO expanders to be used as inputs for buttons / filament sensors / etc.

The implementation relies on an interrupt pin provided by the I2C expander board to detect change in the input pins. Once change is detected, Klipper would read the state of the buttons via I2C and invoke callbacks as needed.

To integrate with the existing buttons support, simulates MCU and handles the commands used to setup buttons (config_buttons, buttons_add, buttons_ack, buttons_query and buttons_state). The motivation of this approach is that it does not require changes to Klipper code.

The I2C board thus requires three GPIO pins to be connected to any Klipper board: two pins for I2C (SDA and SCL) and one GPIO pin for the interrupt.

Add support for inputs pins to SX1509 implementation. The new implementation uses configuration name [mmu_sx1509 ...].

Also, implement support for MCP23017 I2C expander board. This implementation uses configuration name [mmu_mcp23017 ...].

Example configuration for the SX1509:

[mmu_sx1509 expander]
i2c_mcu: mmb
i2c_address: 62
i2c_bus: i2c3_PB3_PB4
interrupt_pin: !mmb:PC15
[filament_switch_sensor gate5]
switch_pin: ^mmu_sx1509_expander:PIN_5
pause_on_runout: False

Example configuration for the MCP23017:

[mmu_mcp23017 expander]
i2c_mcu: mmb
i2c_address: 32
i2c_bus: i2c3_PB3_PB4
interrupt_pin: !mmb:PC15
[filament_switch_sensor gate3]
switch_pin: ^mmu_mcp23017_expander:PIN_3
pause_on_runout: False

Allow using I2C IO expanders to be used as inputs for buttons / filament
sensors / etc.

The implementation relies on an interrupt pin provided by the I2C
expander board to detect change in the input pins. Once change is
detected, Klipper would read the state of the buttons via I2C and invoke
callbacks as needed.

To integrate with the existing buttons support, simulates MCU and handles
the commands used to setup buttons (`config_buttons`, `buttons_add`,
`buttons_ack`, `buttons_query` and `buttons_state`). The motivation of
this approach is that it does not require changes to Klipper code.

The I2C board thus requires three GPIO pins to be connected to any
Klipper board: two pins for I2C (SDA and SCL) and one GPIO pin for the
interrupt.

Add support for inputs pins to SX1509 implementation. The new
implementation uses configuration name `[mmu_sx1509 ...]`.

Also, implement support for MCP23017 I2C expander board. This
implementation uses configuration name [`mmu_mcp23017 ...`].

Example configuration for the SX1509:

```
[mmu_sx1509 expander]
i2c_mcu: mmb
i2c_address: 62
i2c_bus: i2c3_PB3_PB4
interrupt_pin: !mmb:PC15
[filament_switch_sensor gate5]
switch_pin: ^mmu_sx1509_expander:PIN_5
pause_on_runout: False
```

Example configuration for the MCP23017:
```
[mmu_mcp23017 expander]
i2c_mcu: mmb
i2c_address: 32
i2c_bus: i2c3_PB3_PB4
interrupt_pin: !mmb:PC15
[filament_switch_sensor gate3]
switch_pin: ^mmu_mcp23017_expander:PIN_3
pause_on_runout: False
```
@idubrov
Copy link
Author

idubrov commented Aug 15, 2024

This is draft -- I only did a very basic testing. Just to create awareness & maybe allow others to test.

@moggieuk
Copy link
Owner

This is great!! It would be good to have folks test and validate. It would be a nice addition for MMU with lots of gates / switches.

You might have to keep asking for testing help in the forums...

@moggieuk moggieuk added the feature request New feature or request label Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants