The purpose of this project is to build a general purpose, interactive computer
out of an rp2040, while learning practical programming using the Forth language.
-## GPIO
+[Documentation](doc/index.md)
-*file: gpio.fs*
-
-### pin ( n -- addr )
-
-Given a pin number, return the pin's address on the IO bank.
-
-```forth
-13 pin
-```
-
-### funcsel@ ( addr -- n ) *funcsel fetch*
-
-Given a pin address, leave the number of the currently selected pin function on
-the stack.
-
-```forth
-13 pin funcsel@
-```
-
-### funcsel! ( addr n -- ) *funcsel set*
-
-Given a pin address and a function number (see GPIO pin constants), set the
-selected pin's function.
-
-```forth
-13 pin SIO funcsel!
-```
-
-### pins ( -- )
-
-Display a list of all GPIO pins and their currently selected function.
-
-```forth
-pins
-```
-
-### output-enable ( n -- ), output-disable ( n -- )
-
-Given a pin number, enable or disable that pin for output.
-
-```forth
-13 output-enable
-13 output-disable
-```
-
-### output-enabled? ( n -- flag )
-
-Given a pin number, leave a flag on the stack indicating whether or not output
-is enabled.
-
-```forth
-13 output-enabled?
-```
-
-### output-enabled. ( -- )
-
-Display a table of pins and their output status.
-
-```forth
-output-enabled.
-```
-
-## Terminal
-
-*file: terminal.fs*
## TODO
* Timers
* Blocks
+* UART
* SPI
* U2F image
--- /dev/null
+---
+title: GPIO
+file: gpio.fs
+---
+
+The GPIO library provides a number of constants and words for working directly
+with the GPIO pins of the rp2040.
+
+## Function Selection
+
+The Raspberry Pi Pico has 30 programmable pins. Each of these pins may be used
+for a number of functions as defined the the rp2040 datasheet.
+
+### pin ( n -- addr )
+
+Given a pin number, return the pin's address on the IO bank.
+
+```forth
+13 pin
+```
+
+### funcsel@ ( addr -- n ) *funcsel fetch*
+
+Given a pin address, leave the number of the currently selected pin function on
+the stack.
+
+```forth
+13 pin funcsel@
+```
+
+### funcsel! ( addr n -- ) *funcsel set*
+
+Given a pin address and a function number (see GPIO pin constants), set the
+selected pin's function.
+
+```forth
+13 pin SIO funcsel!
+```
+
+### pins ( -- )
+
+Display a list of all GPIO pins and their currently selected function.
+
+```forth
+pins
+```
+
+## Output
+
+### output-enable ( n -- ), output-disable ( n -- )
+
+Given a pin number, enable or disable that pin for output.
+
+```forth
+13 output-enable
+13 output-disable
+```
+
+### output-enabled? ( n -- flag )
+
+Given a pin number, leave a flag on the stack indicating whether or not output
+is enabled.
+
+```forth
+13 output-enabled?
+```
+
+### output-enabled. ( -- )
+
+Display a table of pins and their output status.
+
+```forth
+output-enabled.
+```
--- /dev/null
+---
+title: Documentation
+---
+
+* [GPIO](gpio.md)
SYSINFO_BASE $00 + constant CHIP_ID
SYSINFO_BASE $04 + constant PLATFORM
SYSINFO_BASE $40 + constant GITREF_RP2040
+
+: fpga? ( -- ) PLATFORM @ 1 0 lshift AND 0 > ;
+: asic? ( -- ) PLATFORM @ 1 1 lshift AND 0 > ;
+: platform. ( -- ) fpga? IF ." FPGA" ELSE ." ASIC" THEN ;
+
+: chipid. ( -- ) CHIP_ID @ hex u. ;
+: gitref. ( -- ) GITREF_RP2040 @ hex u. ;
\ Addressed registers
UART0_BASE UARTCR + constant UART0_CR
+UART1_BASE UARTCR + constant UART1_CR
-\ *NOTE* This is getting interesting enough
-\ to put on a slide presentation, perhaps for Denhac
+\ Determine if UART is enabled at this interface
+\ example: UART0_CR enabled?
+: enabled? ( addr -- flag ) @ 1 AND 0 > ;
+: transmit-enabled? ( addr -- flag ) @ 1 8 lshift AND 0 > ;
-\ ?? What is the difference between CTS and RTS?
-\ Clear to Send
-\ Ready to Send
+\ Hardware Flow Control
+: rts-enabled? ( addr -- flag ) @ 1 14 lshift AND 0 > ;
+: cts-enabled? ( addr -- flag ) @ 1 15 lshift AND 0 > ;
-: transfer-enabeled? ( n -- flag ) ;
+: rts-toggle ( addr -- flag ) dup @ 1 14 lshift XOR swap ! ;
+: cts-toggle ( addr -- flag ) dup @ 1 15 lshift XOR swap ! ;