From: Adam Shamblin Date: Sun, 26 Jun 2022 21:11:54 +0000 (-0600) Subject: baby steps w/ UART, start moving docs X-Git-Url: https://git.vexinglabs.com/?a=commitdiff_plain;h=0dfdbff13c5d7e9aa2b6b1bbf189a1d52d5f291e;p=forthdeck.git baby steps w/ UART, start moving docs --- diff --git a/README.md b/README.md index 2a09036..262677a 100644 --- a/README.md +++ b/README.md @@ -12,77 +12,13 @@ keywords: 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 diff --git a/doc/gpio.md b/doc/gpio.md new file mode 100644 index 0000000..f9240dd --- /dev/null +++ b/doc/gpio.md @@ -0,0 +1,74 @@ +--- +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. +``` diff --git a/doc/index.md b/doc/index.md new file mode 100644 index 0000000..a50ead8 --- /dev/null +++ b/doc/index.md @@ -0,0 +1,5 @@ +--- +title: Documentation +--- + +* [GPIO](gpio.md) diff --git a/src/sysinfo.fs b/src/sysinfo.fs index 9189cb3..15aed85 100644 --- a/src/sysinfo.fs +++ b/src/sysinfo.fs @@ -4,3 +4,10 @@ $40000000 constant SYSINFO_BASE 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. ; diff --git a/src/uart.fs b/src/uart.fs index 62b90f3..5d6765e 100644 --- a/src/uart.fs +++ b/src/uart.fs @@ -9,12 +9,16 @@ $030 constant UARTCR \ 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 ! ;