The code in Cortex\Drivers\gpioLPC17xx.fth provides tools to access the GPIO/FIO pins on a bit by bit basis. The code is written for ease of use rather than performance.
There are similar files in the Cortex\Drivers directory for different CPU families. They all use a very similar set of words. Do not be afraid to browse the supplied source code!
The equates in this block are defaults used if the equates have not been defined before this file is compiled.
_FIO0 equ PortBase \ -- addr
Base address of port definitions.
$20 equ /PortBlock \ -- len
Number of bytes per port for peripheral registers.
5 equ #PortShift \ -- u
Number of bits to shift to offset by /PortBlock
.
FIO/GPIO acess is defined using a bit number. Bits 0..31 form P0.0 to P0.31, bits 32..63 form P1.0 to P1.31 and so on.
: PIO: \ port# bit# -- ; -- iobit#
Define a port I/O bit by name. For example
2 11 PIO: P2.11
: setPin \ iobit# --
Set the pin high.
: clrPin \ iobit# --
Set the pin low.
: getPin \ iobit# -- 0/1
Read the pin state.
: isInput \ iobit# --
Set the pin as an input.
: isOutput \ iobit# --
Set the pin as an input.
: isPinsel \ sel# iobit# --
Set the pin configuration 0..3. By default, nearly all pins
are in I/O pin mode after reset.
: isPinmode \ mode# iobit# --
Set the pin mode 0..3. Not available for CPUs that do not
have PINMODE
registers.
0 constant PulledUp \ -- mode#
Used as the mode# with isPinMode
above to define how
the pin operates as an input.
2 constant NotPulled \ -- mode#
Used as the mode# with isPinMode
above to define how
the pin operates as an input.
3 constant PulledDown \ -- mode#
Used as the mode# with isPinMode
above to define how
the pin operates as an input.
decimal 1 25 pio: led1 0 4 pio: led2 1 18 pio: Usb_Link_Led 2 9 pio: Usb_Connect_Led 0 23 pio: But1 2 13 pio: But2 : tled1 \ -- led1 isOutput begin led1 clrPin 200 ms led1 setPin 200 ms key? until ; : tled2 \ -- led2 isOutput begin led2 clrPin 200 ms led2 setPin 200 ms key? until ;