Commit Graph

14 Commits

Author SHA1 Message Date
Lephe 18e0db3886
usb: improve driver with updated knowledge and prepare reading
* Finish updating the register list
* Use RTC-based timeouts to not involve more interrupts
* Be a lot more conservative about PID=BUF
* Start setting up parameters and checking invariants for future
  bidirectional communications
2023-01-31 16:04:35 +01:00
Lephe 42853103aa
usb: remove incorrectly-ordered bits in USB registers 2023-01-25 16:28:20 +01:00
Lephe a4cf3516e7
usb: fix some messages being lost after a post-world-switch reconnect 2022-12-03 11:05:35 +01:00
Lephe 177879d432
usb: add a USB_TRACE() debugging mechanism 2022-12-03 11:04:43 +01:00
Lephe feb74a38ec
usb: hide USB_LOG() behind a compile-time debug option 2022-11-29 20:03:03 +01:00
Lephe 5e35871c98
usb: add timeout variants for functions
We're not using them yet (specifically in fxlink) because timeouts
leave the pipes in undesirable states that currently end up crashing.
Some reset mechanism is needed, plus support from the protocol for
canceling messages, etc.
2022-11-13 08:56:59 +01:00
Lephe 5f9553f3b8
usb: fix transmissions resuming early after world switch
When the driver goes through a world switch a reconnection with the host
is needed before operations can resume. This requires usb_open_status to
be reset.

Also: bind a FIFO before a commit that involves data transfer, mirroring
what happens in writes. This ensures that PID is set to BUF, mainly.
2022-11-12 14:51:00 +01:00
Lephe d110ab608e
usb: fix freeze on sync commit for inactive pipes
Performing an asynchronous commit on an inactive pipe would yield
USB_COMMIT_INACTVE and *not* invoke the callback (as intended),
which usb_commit_sync() ignored, causing a freeze.

This issue appeared after a world switch, which (for reasons not yet
known) appear to fail the first writes until a commit, and that commit
would then hit an inactive pipe.
2022-11-11 17:47:29 +01:00
Lephe 8e730c2f78
replace gint/std headers with standard ones 2021-06-08 11:01:27 +02:00
Lephe 31dcc6fd6c
usb: enable writing with DMA
Nothing particular to change, simply make sure that the DMA channels
have higher priority than the USB module, otherwise the BEMP interrupt
might be executed before the DMA frees the channel, resulting in the
transfer failing because the channel is still busy.

Also reduce BUSWAIT since it works even on high overclock levels, and
keeping it high won't help increase performance.
2021-05-12 09:17:25 +02:00
Lephe a547235f8f
usb: FIFO controllers and fxlink API
This changes fixes the way gint uses the FIFO controllers D0F and D1F
to access the FIFO. It previously used D0F in the main thread and D1F
during interrupt handling, but this is incorrect for several reasons,
mainly the possible change of controllers between a write and a commit,
and numerous instances of two FIFOs managing the same pipe caused by
the constant switching.

gint now treats FIFO controllers as resources allocated to pipes for
the duration of a commit-terminated sequence of writes. The same
controller is used for a single pipe in both normal and interrupt
modes, and released when the pipe is committed. If no controller is
available, asynchronous writes fail and synchronous ones wait.

The fxlink API is also added with a small amount of functions, namely
to transfer screenshots and raw text. Currently these are synchronous
and do not use the DMA, this will be improved later.

Finally:
* Removed pipe logic from src/usb/setup.c, instead letting pipes.c
  handle the special case of the DCP (which might be regularized later)
* Removed the usb_pipe_mode_{read,write} functions as they're actually
  about FIFo controllers and it's not clear yet how a pipe with both
  read and write should be handled. This is left for the future.
* Clarified end-of-sequence semantics after a successful commit.
2021-05-12 09:17:25 +02:00
Lephe 392d033e4a
usb: improve and expose the sync/async write API
* Properly define the callback time of a write/commit as the time when
  the pipe is available again for further writing.
* Refuse commits when writes are pending; instead, enforce a strict
  order of finishing writes before committing, which makes sense since
  consecutive writes are ordered this way already.
* Properly support callbacks for writes and for commits.
* Define the synchronous APIs in terms of waiting until the callbacks
  for equivalent asynchronous functions are invoked (plus initial
  waiting for pipes to be ready).
2021-05-12 09:17:24 +02:00
Lephe 770b4e0117
gint: rename the callbacks GINT_CALL, as there are synchronous ones
This will be useful for world switch calls which are not "callbacks" but
simply polymorphic function pointers.
2021-04-20 17:51:53 +02:00
Lephe 1315c26099
usb: USB 2.0 function driver (WIP)
* Add the power management functions (mostly stable even under
  overclock; requires some testing, but no known issue)

* Add a dynamic configuration system where interfaces can declare
  descriptors with arbitrary endpoint numbers and additional
  parameters, and the driver allocates USB resources (endpoints, pipes
  and FIFO memory) between interfaces at startup. This allows
  implementations of different classes to be independent from each
  other.

* Add responses to common SETUP requests.

* Add pipe logic that allows programs to write data synchronously or
  asynchronously to pipes, in a single or several fragments, regardless
  of the buffer size (still WIP with a few details to polish and the
  API is not public yet).

* Add a WIP bulk IN interface that allows sending data to the host.
  This will eventually support the fxlink protocol.
2021-04-11 19:04:54 +02:00