-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
GPIO: Add support for active low #28187
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,11 +24,15 @@ type gpio struct { | |
| // NewGpioPluginFromConfig creates a GPIO provider | ||
| func NewGpioPluginFromConfig(ctx context.Context, other map[string]any) (Plugin, error) { | ||
| cc := struct { | ||
| Function GpioType | ||
| Pin int | ||
| Chip string | ||
| Function GpioType | ||
| Pin int | ||
| ActiveLow bool | ||
| Bias GpioBias | ||
| Chip string | ||
| }{ | ||
| Chip: "gpiochip0", | ||
| ActiveLow: false, | ||
| Bias: -1, | ||
| Chip: "gpiochip0", | ||
| } | ||
|
|
||
| if err := util.DecodeOther(other, &cc); err != nil { | ||
|
|
@@ -38,13 +42,34 @@ func NewGpioPluginFromConfig(ctx context.Context, other map[string]any) (Plugin, | |
| var opts []gpiocdev.LineReqOption | ||
| switch cc.Function { | ||
| case GpioTypeRead: | ||
| opts = append(opts, gpiocdev.AsInput, gpiocdev.WithPullUp) | ||
| opts = append(opts, gpiocdev.AsInput) | ||
| case GpioTypeWrite: | ||
|
Comment on lines
42
to
46
|
||
| opts = append(opts, gpiocdev.AsOutput(0)) | ||
| default: | ||
| return nil, fmt.Errorf("invalid type: %s", cc.Function) | ||
| } | ||
|
|
||
| switch cc.Bias { | ||
| case -1: | ||
| if cc.Function == GpioTypeRead { | ||
| opts = append(opts, gpiocdev.WithPullUp) | ||
| } | ||
| case GpioBiasAsIs: | ||
| opts = append(opts, gpiocdev.WithBiasAsIs) | ||
| case GpioBiasDisabled: | ||
| opts = append(opts, gpiocdev.WithBiasDisabled) | ||
| case GpioBiasPullUp: | ||
| opts = append(opts, gpiocdev.WithPullUp) | ||
| case GpioBiasPullDown: | ||
| opts = append(opts, gpiocdev.WithPullDown) | ||
| default: | ||
|
Comment on lines
+52
to
+65
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question (bug_risk): Consider whether bias options should be applied for output lines as well as inputs. The shared |
||
| return nil, fmt.Errorf("invalid bias: %s", cc.Bias) | ||
| } | ||
|
|
||
| if cc.ActiveLow { | ||
| opts = append(opts, gpiocdev.AsActiveLow) | ||
| } | ||
|
|
||
| line, err := gpiocdev.RequestLine(cc.Chip, cc.Pin, opts...) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to open GPIO: %w", err) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package plugin | ||
|
|
||
| type GpioBias int | ||
|
|
||
| //go:generate go tool enumer -type GpioBias -trimprefix GpioBias -transform=kebab -text | ||
| const ( | ||
| GpioBiasAsIs GpioBias = iota | ||
| GpioBiasDisabled | ||
| GpioBiasPullUp | ||
| GpioBiasPullDown | ||
| ) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.