aboutsummaryrefslogtreecommitdiff
path: root/embassy-rp/src/pio.rs
Commit message (Collapse)AuthorAgeFilesLines
* docs: embassy-rp rustdoc and refactoringUlf Lilleengen2023-12-191-1121/+0
|
* rp: remove paste macro.Dario Nieuwenhuis2023-09-181-8/+33
|
* rp: rename gpio::Pin::io to gpio::Pin::gpiopennae2023-07-311-1/+1
| | | | | | we'll need access to the pin io bank registers for an upcoming fix, and having both `io` and `io_bank` or similar can get confusing quickly. rename `io` to `gpio` to avoid this, and also match the type while there.
* rp: relocate programs implicitly during loadpennae2023-07-281-8/+52
| | | | | | | | | | | this removed the RelocatedProgram construction step from pio uses. there's not all that much to be said for the extra step because the origin can be set on the input program itself, and the remaining information exposed by RelocatedProgram can be exposed from LoadedProgram instead (even though it's already available on the pio_asm programs, albeit perhaps less convenient). we do lose access to the relocated instruction iterator, but we also cannot think of anything this iterator would actually be useful for outside of program loading.
* Rename embassy-hal-common to embassy-hal-internal, document it's for ↵Dario Nieuwenhuis2023-07-281-1/+1
| | | | internal use only. (#1700)
* rp/pio: use bind_interrupts for irqspennae2023-07-071-46/+32
| | | | closes #1338
* Update rp-pac.Dario Nieuwenhuis2023-06-291-2/+2
|
* rp: update rp-pac.Dario Nieuwenhuis2023-06-161-259/+191
|
* Add `rt` feature to HALs, cfg out interrupt handling when not set.Dario Nieuwenhuis2023-06-081-0/+2
|
* Make interrupt module more standard.Dario Nieuwenhuis2023-06-081-7/+7
| | | | | | | | | | | | - Move typelevel interrupts to a special-purpose mod: `embassy_xx::interrupt::typelevel`. - Reexport the PAC interrupt enum in `embassy_xx::interrupt`. This has a few advantages: - The `embassy_xx::interrupt` module is now more "standard". - It works with `cortex-m` functions for manipulating interrupts, for example. - It works with RTIC. - the interrupt enum allows holding value that can be "any interrupt at runtime", this can't be done with typelevel irqs. - When "const-generics on enums" is stable, we can remove the typelevel interrupts without disruptive changes to `embassy_xx::interrupt`.
* cortex-m: remove owned interrupts.Dario Nieuwenhuis2023-06-011-9/+7
|
* rp: don't use SetConfig trait in PWM and PIO.Dario Nieuwenhuis2023-05-131-7/+2
| | | | | | It was intended to allow changing baudrate on shared spi/i2c. There's no advantage in using it for PWM or PIO, and makes it less usable because you have to have `embassy-embedded-hal` as a dep to use it.
* rp/pio: make sure gpio() asserts are compiled outpennae2023-05-061-1/+2
| | | | | we'll have to touch pio one way or other if the number of gpio pins ever increases. may as well make sure an assert never fires until that happens.
* rp/pio: allow wrap-around program loadingpennae2023-05-061-5/+6
| | | | | | execution wraps around after the end of instruction memory and wrapping works with this, so we may as well allow program loading across this boundary. could be useful for reusing chunks of instruction memory.
* rp/pio: mark exec_instr as unsafepennae2023-05-061-4/+2
| | | | because it most definitely is.
* rp/pio: add sm batch operationspennae2023-05-061-0/+41
| | | | | | sometimes state machines need to be started, restarted, or synchronized at exactly the same time. the current interface does not allow this but the hardware does, so let's expose that.
* rp/pio: configure state machines with Config structpennae2023-05-061-221/+217
| | | | | | the many individual sets aren't very efficient, and almost no checks were done to ensure that the configuration written to the hardware was actually valid. this adresses both of these.
* rp/pio: add set-pin-{values,dirs} convenience functionspennae2023-05-061-1/+59
| | | | | these are needed a lot during state machine setup, it makes sense to provide convenience functions for them.
* rp/pio: add load_program, use_programpennae2023-05-061-67/+61
| | | | | | | | programs contain information we could pull from them directly and use to validate other configuration of the state machine instead of asking the user to pull them out and hand them to us bit by bit. unfortunately programs do not specify how many in or out bits they use, so we can only handle side-set and wrapping jumps like this. it's still something though.
* rp/pio: only clear diag bits if they're setpennae2023-05-051-4/+12
| | | | | otherwise we may lose a bit being raised after it was read, but before it was cleared.
* rp/pio: tighten variance of particle structspennae2023-05-051-7/+9
| | | | | all of these exist in 1:1 correspondence to their parent hal objects, so let's make all of their lifetimes invariant.
* rp/pio: remove critical section in IrqFuture::pollpennae2023-05-051-10/+3
| | | | | | | | | | | | | there's nothing this critical section protects against. both read and write-to-clear are atomic and don't interfere with other irq futures, only potentially with setting/clearing an irq flag from an arm core. neither have ever been synchronized, and both have the same observable effects under atomic writes and critical sections. (for both setting and clearing an irq flag observable differences could only happen if the set/clear happened after the poll read, but before the write. if it's a clear we observe the same effects as sequencing the clear entirely after the poll, and if it's a set we observe the same effects as sequencing the set entirely before the poll)
* rp/pio: drop Pio prefix from almost all namespennae2023-05-051-79/+79
| | | | | | it's only any good for PioPin because there it follows a pattern of gpio pin alternate functions being named like that, everything else can just as well be referred to as `pio::Thing`
* rp/pio: wrap sm rx, tx in structs and allow splittingpennae2023-05-031-143/+177
| | | | | | | this *finally* allows sound implementions of bidirectional transfers without blocking. the futures previously allowed only a single direction to be active at any given time, and the dma transfers didn't take a mutable reference and were thus unsound.
* rp/pio: move irq flag handling to own structpennae2023-05-031-22/+40
| | | | | | | | this way we can share irq handling between state machines and common without having to duplicate the methods. it also lets us give irq flag access to places without having to dedicate a state machine or the common instance to those places, which can be very useful to eg trigger an event and wait for a confirmation using an irq wait object.
* rp/pio: split irqs from state machinespennae2023-05-031-18/+27
| | | | | | | | | we can only have one active waiter for any given irq at any given time. allowing waits for irqs on state machines bypasses this limitation and causes lost events for all but the latest waiter for a given irq. splitting this out also allows us to signal from state machines to other parts of the application without monopolizing state machine access for the irq wait, as would be necessary to make irq waiting sound.
* rp/pio: remove PioStateMachineInstancepennae2023-05-031-147/+124
| | | | | | | move all methods into PioStateMachine instead. the huge trait wasn't object-safe and thus didn't have any benefits whatsoever except for making it *slightly* easier to write bounds for passing around state machines. that would be much better solved with generics-less instances.
* rp/pio: PioStateMachine{Instance, => ,Instance}pennae2023-05-031-22/+22
| | | | next step: get rid of the insance trait entirely
* rp/pio: hide pio/sm numberspennae2023-05-031-13/+1
| | | | | nothing should care which number pio it is running on, and the state machine index could always be extracted from type information.
* rp/pio: wrap PioPins from ref, like everything elsepennae2023-05-031-18/+13
| | | | | also store peripheral refs instead of a raw pin/bank number, like everything else.
* rp/pio: add PioPin traitpennae2023-05-031-10/+31
| | | | | pio can only access pins in bank 0, so it doesn't make sense to even allow wrapping of other banks' pins.
* rp/pio: disable state machines on droppennae2023-05-031-0/+3
|
* rp/pio: revert pio pin funcsel to null on pio+sms droppennae2023-05-031-4/+63
| | | | | | | | | | | once all sharing owners of pio pins have been dropped we should reset the pin for use by other hal objects. unfortunately this needs an atomic state per pio block because PioCommon and all of the state machines really do share ownership of any wrapped pins. only PioCommon can create them, but all state machines can keep them alive. since state machines can be moved to core1 we can't do reference counting in relaxed mode, but we *can* do relaxed pin accounting (since only common and the final drop can modify this).
* rp/pio: make free_instr unsafepennae2023-05-031-2/+4
| | | | | | we can't prove that some instruction memory is not used as long as state machines are alive, and we can pass instance memory handles between instances as well. mark free_instr unsafe, with documentation for this caveat.
* rp/pio: drop SmInstance{,Base}pennae2023-05-021-82/+48
| | | | these are just overly convoluted ways of writing down numbers.
* rp/pio: make PioCommon a structpennae2023-05-021-37/+22
| | | | | the PioCommon trait does not serve much of a purpose; there can be only two implementations and they only differ in a few associated constants.
* rp/pio: PioInstance::split -> Pio::newpennae2023-05-021-41/+43
| | | | | | | not requiring a PioInstance for splitting lets us split from a PeripheralRef or borrowed PIO as well, mirroring every other peripheral in embassy_rp. pio pins still have to be constructed from owned pin instances for now.
* rp/pio: fix PioPin::set_pull, set_schmitt commentpennae2023-05-021-5/+4
|
* rp/pio: remove PioPeripheralpennae2023-05-021-44/+20
| | | | | | merge into PioInstance instead. PioPeripheral was mostly a wrapper around PioInstance anyway, and the way the wrapping was done required PioInstanceBase<N> types where PIO{N} could've been used instead.
* rp/pio: don't use modify on shared registerspennae2023-05-021-15/+19
| | | | | | | | | | pio control registers are notionally shared between state machines as well. state machine operations that change these registers must use atomic accesses (or critical sections, which would be overkill). notably PioPin::set_input_sync_bypass was even wrong, enabling the bypass on a pin requires the corresponding bit to be set (not cleared). the PioCommon function got it right.
* rp/pio: avoid sm(SM_NO) indexingpennae2023-05-021-116/+43
| | | | | accessing the current state machine is an extremely common operation that shouldn't have its specifics repeated myriad times.
* rp/pio: add funcsel values to PioInstancepennae2023-05-021-11/+4
| | | | | makes code setting funcsels easier to read and should make it easier to hook up more pio blocks, should they ever appear
* rp/pio: fix dmapennae2023-05-021-7/+9
| | | | | | | | | | fixing the dma word size to 32 makes it impossible to implement any peripheral that takes its data in smaller chunks, eg uart, spi, i2c, ws2812, the list goes on. compiler barriers were also not set correctly; we need a SeqCst barrier before starting a transfer as well to avoid reordering of accesses into a buffer after dma has started.
* rp/pio: write instr memory only from commonpennae2023-05-011-64/+40
| | | | | | | | | | | | | | | instruction memory is a shared resource. writing it only from PioCommon clarifies this, and perhaps makes it more obvious that multiple state machines can share the same instructions. this also allows *freeing* of instruction memory to reprogram the system, although this interface is not entirely safe yet. it's safe in the sense rusts understands things, but state machines may misbehave if their instruction memory is freed and rewritten while they are running. fixing this is out of scope for now since it requires some larger changes to how state machines are handled. the interface provided currently is already unsafe in that it lets people execute instruction memory that has never been written, so this isn't much of a drawback for now.
* rp/pio: remove a bunch of unnecessary let _ = selfpennae2023-05-011-13/+0
|
* rp/pio: move non-sm-specific methods to PioCommonpennae2023-05-011-33/+28
| | | | | | | | | | pin and irq operations affect the entire pio block. with pins this is not very problematic since pins themselves are resources, but irqs are not treated like that and can thus interfere across state machines. the ability to wait for an irq on a state machine is kept to make synchronization with user code easier, and since we can't inspect loaded programs at build time we wouldn't gain much from disallowing waits from state machines anyway.
* rp/pio: remove top-level PIOS arraypennae2023-05-011-162/+90
| | | | | | this mainly removes the need for explicit indexing to get the pac object. runtime effect is zero, but arguably things are a bit easier to read with less indexing.
* rp/pio: seal PioInstance, SmInstancepennae2023-05-011-20/+41
| | | | seems prudent to hide access to the internals.
* rp/pio: don't call dma::init so muchpennae2023-05-011-3/+1
| | | | | | | | | | this is already done during platform init. it wasn't even sound in the original implementation because futures would meddle with the nvic in critical sections, while another (interrupt) executor could meddle with the nvic without critical sections here. it is only accidentally sound now and only if irq1 of both pios isn't used by user code. luckily the worst we can expect to happen is interrupt priorities being set wrong, but wrong is wrong is wrong.
* rp/pio: enable pio interrupts only oncepennae2023-05-011-36/+14
| | | | | | | | | since we never actually *disable* these interrupts for any length of time we can simply enable them globally. we also initialize all pio interrupt flags to not cause system interrupts since state machine irqa are not necessarily meant to cause a system interrupt when set. the fifo interrupts are sticky and can likewise only be cleared inside the handler by disabling them.