the hardware driver is compile-clean, but everything is just
a stub. But at least we have the API thunks laid bare which
gives us a roadmap for the next steps.
a lot of re-import warnings have cropped up. While I appreciate
their studiousness on this, the problem is that removing some
of these exports in the API crate could mean that future users
who want access to some API features that aren't used in this
configuration are now unaccessible.
I think it's not a huge problem at the moment, just spam-cleaning
the warnings because there are too many to deal with carefully
at the moment.
Simpler API, easier to understand and audit.
The UsbDevice and UsbHidClass are stored in AppHID directly, so that callers have less things to worry about: just provide an UsbBusAllocator.
This way we streamline the control flow within main_hw.rs, which is already pretty intricated.
I still have to manage errors from usb-device-xous server to lib.rs, but that will come later.
Box can't be applied to this crate because of interoperability
issues with the USB driver crate when it is applied.
Still, it seems to "work" because deferred-init pins down the
address of the hardware management structure (for now).
- make the "base" field no longer public. It is accessible, but only
through an `unsafe` method, because, it is unsafe.
- add accessors to offest/mask fields. Because, it's not at all
unsafe to access these, and it can be useful for bit-ops that are
not part of the generic set of UTRA.
- add Arc to AtomicCSR, and require `std` for AtomicCSR types.
This should not break anything, I checked inside @foundation-devices
keyOS and they don't seem to be using AtomicCSR anywhere.
The Arc makes it a bit safer to clone the AtomicCSR base pointer
and share it between threads, but it will have an impact on performance.
The USB stack (which requires AtomicCSR) was regression testing and the
impact seems minimal.
Recall that the main purpose of AtomicCSR is to provide a CSR accessor
that does not require a mutable reference to the base object. This
can make certain Rust idioms a bit cleaner. We wrap the base accessor
in Arc+Atomic to try and improve the safety of throwing the borrow
checker under the bus, but it's still not perfect because hardware
mutable state can have side-effects within hardware itself that cannot
be modeled or checked by Rust's borrow checker.
The original implementation didn't keep around some key data,
so we had to read the old version of the record and update parameters
assuming that the USB descriptors didn't change too much.
Unfortunately with the mass storage option, the description can
change quite a bit, so we have to reconsitute it from scratch.
Basically, we re-do the `alloc()` call in the reset routine,
playing it reverse so that we setup all the higher-number
endpoints before doing ep0 last.
This hopefully fixes a stability issue for usb hid mode when
mass storage is enabled as a build option.
- use new SpinalUsbDevice::new() interface instead of cloning
- put the blank "key-up" event on keyboard events after the
core is switched to, instead of at boot.
- add some more appropriate debug statements to help track
view switching in debug logs
Instead of making it once and then cloning it (which is a bit
unclear what's going on), make it so that the shared memory
ranges are allocated in the caller's scope, and then create
the structure "clean".
Also add a static AtomicBool to track interrupt init state,
since that can be only called once.
bulk endpoints have a different behavior now than interrupt
endpoints; bulk endpoints have chained descriptors so that the
hardware automatically responds to multiple USB packets quickly.
interrupt endpoints also have subtly different way of handling
data readiness, which is incompatible with the block device layer
as implemented.
since we don't have a clear use case for this yet and it's just
for testing on bleeding-edge, make a very small disk just so it's
easier for people to do testing, but not so big that it's a burden
on the system.
later on we can make this dynamically sizeable/allocateable only
e.g., only when the disk is required
before we were looking at the amount of data transferred and
seeing if it matches the expected amount
I just realized that we can just look at the descriptor pointer in
the status region; if it is non-zero, then the descriptor set
is "live" and needs to be filled.
if it's zero, then a packet came in.
use this to fix the wait conditions for accepting new commands.
IN descriptors now chain up to 512 bytes long
OUT descriptors still need to be worked up
However, there is an issue where the system is injecting the
ZLP/CSW immediately after the bulk response is queued up, and this
is getting sent before the bulk data is issued. Need to figure out
this race condition.