PseudoGPIO is a C++ library that allows an application running on a computer to control and use GPIO pins of an Arduino (or similar) board connected through USB through an API similar to the Arduino/Wiring one.
PseudoGPIO is based on a simple protocol based on the exchange of single-byte packets through a serial port.
The protocol allows for 8 different commands, encoded in the 3 higher-order bits of the packet. The remaining bits shall be interpreted differently, according to the command being issued.
Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|
Meaning | Command | [Command-Dependent] |
No reply from the target shall be expected for any command, except where indicated.
Commands that do not provide a reply shall be assumed to have been executed correctly.
Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|
Meaning | 0 | 0 | 0 | Don't Care |
This command checks if the target board is alive and interpreting commands correctly. It also allows to retrieve the protocol version implemented by the board. The reply shall be a single byte with the following format:
Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|
Meaning | 1 | 1 | 0 | 1 | Protocol Version |
Currently, only version 1 of the protocol is defined.
Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|
Meaning | 0 | 0 | 1 | Pseudopin # | Mode |
This command sets the mode of a pseudopin. Mode
shall be interpreted as follows:
- 0: Input
- 1: Output
Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|
Meaning | 0 | 1 | 0 | Pseudopin # | Don't Care |
This command requests the status of a digital pseudopin. The reply is a single byte, of which only the LSB shall be interpreted as follows:
- 0: Low Level
- 1: High Level
Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|
Meaning | 0 | 1 | 1 | Pseudopin # | Level |
This command sets the level of a digital pseudopin. Level
shall be interpreted as in the DigitalRead
command, i.e.:
- 0: Low Level
- 1: High Level
All commands involving a pseudopin number expect an integer in the range 0-15, which is generally mapped to the correspondingly numbered physical pin on the target board, but there might be exceptions depending on the particular target.
- Arduino Uno/Nano and other ATmega328-based Arduinos: Pseudopins are mapped to the correspondingly numbered pins
- Pins 0 and 1 are used by the serial port and thus are not available
- Pins 14 and 15 do not exist
- Thus pseudopins 0/1/14/15 have no meaning on these boards
- STM32F103xx-based boards, such as Blue Pill, Black Pill, etc: Pseudopins 0-15 are mapped to physical pins PA0-PA15, with the following exceptions:
- PA11 and PA12 are used by the USB connection, thus pseudopins 11 and 12 are mapped to PB11 and PB12
- Note that PB12 drives the onboard led on the Black Pill (with inverted logic)
- PA13 and PA14 are only available through the SWD header on the Black Pill
- PA11 and PA12 are used by the USB connection, thus pseudopins 11 and 12 are mapped to PB11 and PB12