The following detail the lio functionality for accessing the core IO features of phatIO, sending and receiving data from the pins.
See the Introduction to IO section for more information on the input/output modes.
The default, initial pin mode is IN.
(pinmode <pin> <mode> [opt value])
Set the specified pin to the mode, if a third argument is given it is used as the initial value. This is equivalent to writing to the “
PHATIO/io/mode/<pin>” files for the pin.
(setpin <pin> 1)will connect the output to 5V,
(setpin <pin> 0)to 0V. getpin will return 0.
Pin behaves as a PWM output,
(setpin <pin> <value>) will set the PWM intensity of the pin: 0 always off 255 always on. getpin will return 0.
For example, to set pin 0 to an output and turn off:
(pinmode 0 OUT 0)
Note that the mode value is case insensitive and only the first character is used to determine the mode: “
Indigo” are all equivalent and would set the mode to IN
(setpin <pin> <value>)
Set the value of the pin depending on pinmode - see pinmode for the effect in each mode.
Gets the value of the pin depending on pinmode - see pinmode for what is returned in each mode.
(port <value> <pin1> <pin2> ...)
This is the first version of a more sophisticated port functionality, currently when called,
port will just output each bit of value to the pins: bit 0 (LSB) to pin1, bit 1 to pin2, bit 3 to pin3 etc. for as many pins as have been passed (upto 16). This is equivalent to the following:
(setpin pin1 (& value (0x01)) (setpin pin2 (& value (0x02)) (setpin pin3 (& value (0x04)) ...
This version is likely to be retired for a more capable port functionality in the future. For now it offers a slightly more succinct and efficient way of writing to multiple pins.
(led <RED|GREEN> [1|0])
Turns the named phatIO built in LED on (1) or off (0). Note that after using
(led) on an LED it will no longer flash to indicate disk activity or error, to reenable this call with no value argument (e.g.
For example the following maps the LEDs to device files
PHATIO/io/dev/green allowing controlling the LEDs by writing “0” and “1” to those files
(driver green (led GREEN (read_hexbyte 0))) (driver red (led RED (read_hexbyte 0)))
(peek <register address>)
Returns the value of the MCU register at the given address. See Section 31 Register Summary Atmega32u4 datasheet for the address of the registers. The following would print the values of the DDRD and PORTD registers:
(keyboard (fmt "DDRD=0x%02X " (peek 0x2A)) (fmt "PORTD=0x%02X" (peek 0x2B)))
(poke <register address> <value>)
Sets the value of the MCU register at the given address. Obviously Care should be taken in doing this. See Section 31 Register Summary Atmega32u4 datasheet for the address of the registers.
The following would provide 2 drivers “
PHATIO/io/dev/DDRD” and “
PHATIO/io/dev/PORTD” that map DDRD and PORTD to files. Writing “FF” to them would set the registers to 0xFF turning PORT D to output and setting the pins high (these are mapped to pins 13..20).
(driver DDRD (poke 0x2A (read_hexbyte 0))) (driver PORTD (poke 0x2B (read_hexbyte 0)))