en:pfw:usb_cdc_driver_for_rp2040
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:pfw:usb_cdc_driver_for_rp2040 [2025-12-27 13:58] – [Pseudo code] willem | en:pfw:usb_cdc_driver_for_rp2040 [2026-01-13 18:16] (current) – [The idea] willem | ||
|---|---|---|---|
| Line 37: | Line 37: | ||
| Reserve 64 bytes RAM as scratchpad area | Reserve 64 bytes RAM as scratchpad area | ||
| - | Function: EP0 | + | Function: EP0 ( -- a ) |
| - | Function: EP1 | + | Function: EP1 ( -- a ) |
| - | Function: EP2 | + | Function: EP2 ( -- a ) |
| - | Function: EP3 | + | Function: EP3 ( -- a ) |
| Seven cells data structures to control endpoint-0, 1, 2 & 3 | Seven cells data structures to control endpoint-0, 1, 2 & 3 | ||
| The first four cells a variable data | The first four cells a variable data | ||
| The three cells thereafter contain USB pointers & register addresses | The three cells thereafter contain USB pointers & register addresses | ||
| - | ... | + | Function: @VAL ( -- +n ) |
| + | Read the wValue from any eight bytes setup packet | ||
| + | Function: @LEN ( -- +n ) | ||
| + | Read the wLength from any eight bytes setup packet | ||
| + | |||
| + | Function: > | ||
| + | Store the ASCII string to a unicode string tailored for USB | ||
| + | |||
| + | Function: > | ||
| + | Function: > | ||
| + | Function: > | ||
| + | Function: > | ||
| + | Function: > | ||
| + | Function: > | ||
| + | Function: > | ||
| + | Seven functions that calculate the address of each field in the | ||
| + | endpoint data structures | ||
| + | |||
| + | Function: EP-IN ( ep -- org buf pkt ) | ||
| + | Calculate data to send for ' | ||
| + | |||
| + | Function: PREPARE | ||
| + | Prepare data packet from address ' | ||
| + | |||
| + | Function: > | ||
| + | Get next packet size for ' | ||
| + | data to send | ||
| + | |||
| + | Function: !PKT ( pkt ep -- ictrl ) | ||
| + | Store next packet to send for ' | ||
| + | |||
| + | Function: PREP-RCV ( ep -- ) | ||
| + | Enable endpoint ' | ||
| + | |||
| + | Function: GONE? ( ep -- f ) | ||
| + | Leave true when the data in ' | ||
| + | |||
| + | Function: USB? ( -- +n ) | ||
| + | Leave three when the host & device are connected | ||
| + | |||
| + | Function: USB-SEND ( ep -- ) | ||
| + | Transmit the prepared data packet to ' | ||
| + | |||
| + | Function: USB-RCV | ||
| + | Enable the receiving of a data packet on ' | ||
| + | from the stack | ||
| + | |||
| + | Function: BUS=RESET ( -- ) | ||
| + | Handle a USB bus reset, clearing the device address to zero, the USB | ||
| + | state to zero, reinitialise the receiving & transmitting endpoints | ||
| + | |||
| + | Function: SETUP> | ||
| + | Handle the answer data packet ' | ||
| + | When done wait for a ZLP from the host to signal a correct answer | ||
| + | |||
| + | Function: XTABLE | ||
| + | Define an execution table entry for ' | ||
| + | Define: | ||
| + | Create a table with " | ||
| + | Action: | ||
| + | Execute the action for ' | ||
| + | when the ' | ||
| + | |||
| + | Function: ZLP> | ||
| + | Send a zero length package through endpoint zero. This is used | ||
| + | to signal the handling of a request that sends no data back | ||
| + | |||
| + | Define four action in front that leave their execution tokens on the stack | ||
| + | 0302 action xt | ||
| + | 0300 action xt | ||
| + | 0200 action xt | ||
| + | 0100 action xt | ||
| + | Function: HANDLE-SETUP ( req0 .. req3 4 -- ) | ||
| + | |||
| + | 2221 action xt | ||
| + | 21A1 action xt | ||
| + | 2021 action xt | ||
| + | 0900 action xt | ||
| + | 0880 action xt | ||
| + | 0680 action xt | ||
| + | 0500 action xt | ||
| + | Function: HANDLE-REQ) | ||
| + | |||
| + | Function: HANDLE-REQ | ||
| + | Reset setup request interrupt, read bmrequest type and do HANDLE-REQ) | ||
| + | |||
| + | Function: #L ( -- +n ) | ||
| + | Ring buffer size, must be a power of two | ||
| + | Function: #R ( -- +n ) | ||
| + | this is equal to #L - 1 | ||
| + | |||
| + | Function: #RX ( -- +n ) | ||
| + | Leave number of characters in receive buffer | ||
| + | Function: #TX ( -- +n ) | ||
| + | Leave number of characters in transmit buffer | ||
| + | |||
| + | Function: > | ||
| + | Store character ' | ||
| + | Function: > | ||
| + | Store character ' | ||
| + | |||
| + | Function: RX> | ||
| + | Read character ' | ||
| + | Function: TX> | ||
| + | Read character ' | ||
| + | |||
| + | Function: IFLAG | ||
| + | Reserve one cell space for receive interrupt flag | ||
| + | |||
| + | Function: ENDPOINTS | ||
| + | Handle EP1 & EP3 endpoints, save received data interrupt flag in IFLAG | ||
| + | Release all interrupt flags | ||
| + | |||
| + | Function: REQUESTS | ||
| + | Handle all USB interrupts, that are the USB bus reset, setup requests & endpoints | ||
| + | |||
| + | Function: USB-HANDLER | ||
| + | Handle the receiving of the RX data using iFLAG and use the low level USB | ||
| + | ACK/NAK handshake to move data from an endpoint to the RX ring buffer in a controlled way. | ||
| + | Handle the transmitting of TX data, but only when a connection is made. Before filling | ||
| + | the TX endpoint check if the previous data packet was sent too. | ||
| + | |||
| + | Function: USB-KEY? | ||
| + | Leave true flag when there is data in the RX ring buffer, otherwise false | ||
| + | Call the USB-HANDLER once too | ||
| + | |||
| + | Function: USB-KEY | ||
| + | Leave character ' | ||
| + | Call the USB-HANDLER waiting for space in the RX ring buffer | ||
| + | |||
| + | Function: USB-EMIT | ||
| + | Store character ' | ||
| + | Call the USB-HANDLER waiting for space in the TX ring buffer | ||
| + | |||
| + | Function: USB-ON | ||
| + | Initialise the USB DPRAM, call START-USB, clear USB-STATE & IFLAG | ||
| + | finally initialse the KEY?, KEY and EMIT vectors of the used system. | ||
| </ | </ | ||
| - | ===== Implementation | + | ===== Generic Forth implementation |
| <code forth> | <code forth> | ||
| Line 286: | Line 422: | ||
| </ | </ | ||
| + | ===== Implementations ===== | ||
| + | |||
| + | [[https:// | ||
en/pfw/usb_cdc_driver_for_rp2040.1766840324.txt.gz · Last modified: 2025-12-27 13:58 by willem