|
4 | 4 |
|
5 | 5 | //! ## `humility lpc55gpio` |
6 | 6 | //! |
7 | | -//! The LPC55-equivalent of `humility gpio`. |
| 7 | +//! The LPC55-equivalent of `humility gpio`, allowing for GPIO pins to |
| 8 | +//! be set, reset, queried or configured on LPC55 targets. Commands: |
| 9 | +//! |
| 10 | +//! - `--set` (`-s`): Sets a pin (sets it high) |
| 11 | +//! - `--reset` (`-r`): Resets a pin (sets it low) |
| 12 | +//! - `--toggle` (`-t`): Toggles a pin (sets it high if low, low if high) |
| 13 | +//! - `--input` (`-i`): Queries the state of a pin (or all pins if no pin |
| 14 | +//! is specified) |
| 15 | +//! - `--configure` (`-c`): Configures a pin |
| 16 | +//! - `--direction` (`-d`): Configure the direction of a pin |
| 17 | +//! |
| 18 | +//! ### Set, reset, toggle |
| 19 | +//! |
| 20 | +//! To change the state of a pin (or pins), specify the pin (or pins) and |
| 21 | +//! the desired command. For example, to toggle the state on pin PIO0_17: |
| 22 | +//! |
| 23 | +//! ```console |
| 24 | +//! $ humility lpc55gpio --toggle --pins PIO0_17 |
| 25 | +//! humility: attached via CMSIS-DAP |
| 26 | +//! [Ok([])] |
| 27 | +//! ``` |
| 28 | +//! |
| 29 | +//! To set pins PIO0_15, PIO0_16 and PIO0_17: |
| 30 | +//! |
| 31 | +//! ```console |
| 32 | +//! $ humility lpc55gpio --set --pins PIO0_15,PIO0_16,PIO0_17 |
| 33 | +//! humility: attached via CMSIS-DAP |
| 34 | +//! [Ok([]), Ok([]), Ok([])] |
| 35 | +//! ``` |
| 36 | +//! |
| 37 | +//! To reset pin PIO0_17: |
| 38 | +//! |
| 39 | +//! ```console |
| 40 | +//! $ humility lpc55gpio --reset --pins PIO0_17 |
| 41 | +//! humility: attached via CMSIS-DAP |
| 42 | +//! [Ok([])] |
| 43 | +//! ``` |
| 44 | +//! |
| 45 | +//! ### Input |
| 46 | +//! |
| 47 | +//! To get input values for a particular pin: |
| 48 | +//! |
| 49 | +//! ```console |
| 50 | +//! $ humility lpc55gpio --input --pins PIO0_10,PIO0_11,PIO1_0 |
| 51 | +//! humility: attached via CMSIS-DAP |
| 52 | +//! PIO0_10 = 0 |
| 53 | +//! PIO0_11 = 1 |
| 54 | +//! PIO1_0 = 0 |
| 55 | +//! ``` |
| 56 | +//! |
| 57 | +//! To get input values for all pins, leave the pin unspecified: |
| 58 | +//! |
| 59 | +//! ```console |
| 60 | +//! $ humility lpc55gpio --input |
| 61 | +//! humility: attached via ST-Link V3 |
| 62 | +//! humility: attached to 1fc9:0143:12UNOSLDXOK51 via CMSIS-DAP |
| 63 | +//! PIO0_0 = 0 |
| 64 | +//! PIO0_1 = 0 |
| 65 | +//! PIO0_2 = 0 |
| 66 | +//! PIO0_3 = 0 |
| 67 | +//! PIO0_4 = 0 |
| 68 | +//! PIO0_5 = 1 |
| 69 | +//! PIO0_6 = 0 |
| 70 | +//! PIO0_7 = 0 |
| 71 | +//! PIO0_8 = 0 |
| 72 | +//! PIO0_9 = 1 |
| 73 | +//! PIO0_10 = 0 |
| 74 | +//! PIO0_11 = 1 |
| 75 | +//! PIO0_13 = 0 |
| 76 | +//! ... |
| 77 | +//! ``` |
| 78 | +//! |
| 79 | +//! ### Configure, direction |
| 80 | +//! |
| 81 | +//! To configure a pin, the configuration should be specified as a |
| 82 | +//! colon-delimited 6-tuple consisting of: |
| 83 | +//! |
| 84 | +//! - Alternate function: one of `Alt0` through `Alt9` |
| 85 | +//! - Mode: `NoPull`, `PullDown`, `PullUp`, or `Repeater` |
| 86 | +//! - Slew: `Standard` or `Fast` |
| 87 | +//! - Invert: `Disable`, or `Enabled` |
| 88 | +//! - Digital mode: `Analog` or `Digital` |
| 89 | +//! - Open drain: `Normal` or `OpenDrain` |
| 90 | +//! |
| 91 | +//! Note that the direction of the pin should also likely be configured; |
| 92 | +//! this is done via the `--direction` option, specifying either `Input` or |
| 93 | +//! `Output`. For example, to configure pin PIO0_17 to be an output: |
| 94 | +//! |
| 95 | +//! ```console |
| 96 | +//! $ humility lpc55gpio -c Alt0:NoPull:Standard:Disable:Digital:Normal -p PIO0_17 |
| 97 | +//! humility: attached via CMSIS-DAP |
| 98 | +//! [Ok([])] |
| 99 | +//! $ humility lpc55gpio -p PIO0_17 --direction Output |
| 100 | +//! humility: attached via CMSIS-DAP |
| 101 | +//! [Ok([])] |
| 102 | +//! ``` |
8 | 103 | //! |
9 | 104 |
|
10 | 105 | use humility_cli::{ExecutionContext, Subcommand}; |
@@ -64,7 +159,7 @@ struct GpioArgs { |
64 | 159 | direction: Option<String>, |
65 | 160 |
|
66 | 161 | /// specifies GPIO pins on which to operate |
67 | | - #[clap(long, short, value_name = "pins")] |
| 162 | + #[clap(long, short, value_name = "pins", use_value_delimiter = true)] |
68 | 163 | pins: Option<Vec<String>>, |
69 | 164 | } |
70 | 165 |
|
@@ -137,9 +232,9 @@ fn gpio(context: &mut ExecutionContext) -> Result<()> { |
137 | 232 |
|
138 | 233 | if let Some(ref pins) = subargs.pins { |
139 | 234 | for pin in pins { |
140 | | - let pin = gpio_toggle.lookup_argument(hubris, "pin", 0, pin)?; |
| 235 | + let p = gpio_toggle.lookup_argument(hubris, "pin", 0, pin)?; |
141 | 236 |
|
142 | | - args.push((pin, pin.to_string())); |
| 237 | + args.push((p, pin.to_string())); |
143 | 238 | } |
144 | 239 | } |
145 | 240 |
|
|
0 commit comments