The two lines of the auxiliary USB-C port, the one with the lightning icon. They are the SoC's UART3 pads, which the NanoKVM-Go system's kernel makes a UART, GPIOs, PWM outputs or an I2C bus; Sipeed's Finger Robot is a servo on them. Both are inputs pulled down until a mode is set:
| Mode | Line 0 | Line 1 |
|---|---|---|
:off | input, pulled down | input, pulled down |
:uart | UART TXD ("ttyS3") | UART RXD |
:gpio | GPIO | GPIO |
:pwm | PWM output | PWM output |
:pwm_gpio | PWM output | GPIO |
:gpio_pwm | GPIO | PWM output |
:i2c | I2C SDA ("i2c-2") | I2C SCL |
NanoKVMGo.Expansion.set_mode(:pwm_gpio)
NanoKVMGo.Expansion.set_pwm(0, 20_000_000, 1_500_000)
NanoKVMGo.Expansion.subscribe()
NanoKVMGo.Expansion.read(1)
#=> {:ok, 0}Subscribers get {NanoKVMGo.Expansion, {:edge, line, value, timestamp}}
for each edge of a GPIO input, the timestamp in nanoseconds of the
monotonic clock. A line becomes an output with write/3 and an input
again with read/2 or subscribe/1.
The mode persists in the U-Boot environment, nanokvm_expansion, and is
set again when this process starts; with persist: false it lasts until
the next boot only. The GPIOs and PWM channels this process opened are given back
before the mode changes, and the kernel refuses a mode change with
{:error, :busy} while other code holds them. Use Circuits.UART on
"ttyS3" in the :uart mode and Circuits.I2C on "i2c-2" in the
:i2c mode; the I2C bus is bit-banged at about 50 kHz and needs pull-ups
on the other side.
Which USB-C contacts carry the lines, SBU1/SBU2 or D+/D-, and at what voltage, most likely 3.3 V, is not known yet. Measure before connecting anything but the Finger Robot. On SBU, flipping the plug swaps the lines.
Options
:name- the name to register,NanoKVMGo.Expansionby default:device- the kernel driver's sysfs directory,/sys/devices/platform/expansionby default:pwm_chip- the PWM chip's sysfs directory, by default the one of the SoC's PWM1 (6061000.pwm):kv- the U-Boot environment, where the mode persists,Nerves.Runtime.KV(ofnerves_runtime) by default:gpio- the GPIO library,Circuits.GPIOby default
Summary
Types
A message to subscribers, see the module documentation.
Functions
Returns a specification to start this module under a supervisor.
The mode, the modes the kernel offers and what each line is: a GPIO's direction and value, a PWM's period and duty cycle in nanoseconds, while this process has them.
Reads a GPIO line, making it an input.
Sets the mode, persisted for the next boots unless persist: false:
set_mode(:uart), set_mode(server, :uart) or
set_mode(server, :uart, persist: false). A mode the kernel does not
offer gives {:error, {:unknown_mode, mode}}, and one set but not
persisted {:error, {:not_kept, reason}}.
Runs a PWM line: high for duty_cycle of every period nanoseconds. The
timer counts 24 MHz, in steps of 41.7 ns; a change starts a new period.
Starts the process and sets the persisted mode. See the module documentation for the options.
Stops a PWM line and gives its channel back.
Sends the caller the edges of the GPIO inputs, now and after mode changes.
Stops sending the caller edges.
Drives a GPIO line, making it an output.
Types
@type line() :: 0 | 1
@type line_info() :: %{ line: line(), role: role(), gpio: %{direction: :input | :output, value: 0 | 1} | nil, pwm: %{period: pos_integer(), duty_cycle: non_neg_integer()} | nil }
A message to subscribers, see the module documentation.
@type mode() :: :off | :uart | :gpio | :pwm | :pwm_gpio | :gpio_pwm | :i2c
@type option() :: {:name, GenServer.name()} | {:device, Path.t()} | {:pwm_chip, Path.t()} | {:kv, module()} | {:gpio, module()}
@type role() :: :off | :uart_txd | :uart_rxd | :gpio | :pwm | :i2c_sda | :i2c_scl
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec info(GenServer.server()) :: {:ok, info()} | {:error, term()}
The mode, the modes the kernel offers and what each line is: a GPIO's direction and value, a PWM's period and duty cycle in nanoseconds, while this process has them.
@spec read(GenServer.server(), line()) :: {:ok, 0 | 1} | {:error, term()}
Reads a GPIO line, making it an input.
@spec set_mode(GenServer.server(), mode(), [{:persist, boolean()}]) :: :ok | {:error, term()}
Sets the mode, persisted for the next boots unless persist: false:
set_mode(:uart), set_mode(server, :uart) or
set_mode(server, :uart, persist: false). A mode the kernel does not
offer gives {:error, {:unknown_mode, mode}}, and one set but not
persisted {:error, {:not_kept, reason}}.
@spec set_pwm(GenServer.server(), line(), pos_integer(), non_neg_integer()) :: :ok | {:error, term()}
Runs a PWM line: high for duty_cycle of every period nanoseconds. The
timer counts 24 MHz, in steps of 41.7 ns; a change starts a new period.
@spec start_link([option()]) :: GenServer.on_start()
Starts the process and sets the persisted mode. See the module documentation for the options.
@spec stop_pwm(GenServer.server(), line()) :: :ok | {:error, term()}
Stops a PWM line and gives its channel back.
@spec subscribe(GenServer.server()) :: :ok
Sends the caller the edges of the GPIO inputs, now and after mode changes.
@spec unsubscribe(GenServer.server()) :: :ok
Stops sending the caller edges.
@spec write(GenServer.server(), line(), 0 | 1) :: :ok | {:error, term()}
Drives a GPIO line, making it an output.