Skip to content

Latest commit

 

History

History
81 lines (62 loc) · 3.75 KB

INSTRUCTIONS.md

File metadata and controls

81 lines (62 loc) · 3.75 KB

GPIO opcodes (gpioASM)

Binary executables can be compiled from gpioASM for tasks like power a motor until an endstop is reached, toggle an LED with a button press, turn a stepper motor until a hall sensor is triggered and many more.

Here are the available instructions:

command opcode arguments
write_digital 0b0000---- digital bits
write_analog_channel_0 0b00010000 uint16_t
write_analog_channel_1 0b00010001 uint16_t
write_analog_channel_2 0b00010010 uint16_t
write_analog_channel_3 0b00010011 uint16_t
sleep_ms 0b00100000 varint
sleep_match_all 0b0011---- digital bits
sleep_match_any 0b0100---- digital bits
sleep_match_all_timeout 0b0101---- digital bits
sleep_match_any_timeout 0b0110---- digital bits
jump 0b01110000 varint
check_bytecode_version 0b10000000 varint
jump_match_all 0b1001---- varint, digital bits
jump_match_any 0b1010---- varint, digital bits
jump_count 0b10110000 varint, varint
exit 0b11000000

If an opcode contains dashes (----), those bits are filled with the size of the argument in bytes. write_digital 01010 for example contains 5 pins, and since 2 bits are needed for each pin, this argument requires 2 bytes. The resulting opcode will be 0b00000010.

Datatypes

digital bits

Digital bits represent logical states of digital GPIO pins. Every digital pin can be in one of four states:

state bits state description
0b00 pin is LOW
0b01 pin is HIGH
0b10 pin is high-impedance
0b11 pin is not available or ignored

Pin states are represented via bytes. Every byte can house up to four pin states, unconfigured pin bits are set to 0b11. For example, five pins, states [HIGH, LOW, LOW, LOW, HIGH] are represented by two bytes, and look like this:

0b01000000 01111111

The amount of bytes to send depends on the amount of configured digital output pins. If the chip boots with 6 digital output pins configured, it always expects a digital payload sized 2 bytes (CEIL(pin_count / 4)).

varint

Varints are encoded integers that grow bytewise in size with higher integer values. Best described here.

uint16_t

unsigned integers, range from 0 - 65535, encoded as 16-bit little-endian.

Code structure

Every command is encoded as its opcode and the arguments. No length or padding is encoded along.

write_digital 1001 becomes 0b00000000 01000001. write_analog_channel_1 1000 becomes 0b00000000 00000011 11101000.

label start
write_digital 1
sleep_ms 100
write_digital 0
sleep_ms 100
jump start

becomes

wr.-dig.   pin#0 1  sleep    100ms    wr.-dit. pin#0 0  sleep    100ms    jump     addr 0
0b00000001 01111111 00100000 01100100 00000001 00111111 00100000 01100100 01000000 00000000