Commit Graph

140 Commits

Author SHA1 Message Date
Dario Nieuwenhuis
9a6d11281d Add some comments on the example. 2022-04-06 05:38:11 +02:00
Dario Nieuwenhuis
0320500f0f Working CDC-ACM device->host 2022-04-06 05:38:11 +02:00
Dario Nieuwenhuis
77ceced036 Working CDC-ACM host->device 2022-04-06 05:38:11 +02:00
Dario Nieuwenhuis
37598a5b37 wip: experimental async usb stack 2022-04-06 05:38:11 +02:00
Dario Nieuwenhuis
27a1b0ea73 Simpler Channel.
- Allow initializing in a static, without Forever.
- Remove ability to close, since in embedded enviromnents channels usually live forever and don't get closed.
- Remove MPSC restriction, it's MPMC now. Rename "mpsc" to "channel".
- `Sender` and `Receiver` are still available if you want to enforce a piece of code only has send/receive access, but are optional: you can send/receive directly into the Channel if you want.
2022-04-06 01:34:08 +02:00
Dario Nieuwenhuis
82803bffda Use embassy/defmt-timestamp-uptime in all examples. 2022-04-02 04:35:06 +02:00
Dario Nieuwenhuis
9bad9365dc Update rust nightly, embedded-hal 1.0, embedded-hal-async. 2022-03-11 00:38:07 +01:00
huntc
3990f09b29 Simplifies the API by taking in the TIMER and PPI channels 2022-03-07 14:51:17 +11:00
huntc
98bdac51fe Improve nRF Saadc sampling
Starting the sampling task prior to starting the SAADC peripheral can lead to unexpected buffer behaviour with multiple channels. We now provide an init callback at the point where the SAADC has started for the first time. This callback can be used to kick off sampling via PPI.

We also need to trigger the SAADC to start sampling the next buffer when the previous one is ended so that we do not drop samples - the major benefit of double buffering.

As a bonus we provide a calibrate method as it is recommended to use before starting up the sampling.

The example has been updated to illustrate these new features.
2022-03-07 14:51:17 +11:00
bors[bot]
e728a32672
Merge #613
613: Rust stable support r=Dirbaio a=Dirbaio

This PR adds (limited) stable Rust support!

The drawbacks are: 

- No `#[embassy::task]`, `#[embassy::main]`. (requires `type_alias_impl_trait`). You have to manually allocate the tasks somewhere they'll live forever. See [example](https://github.com/embassy-rs/embassy/blob/master/examples/nrf/src/bin/raw_spawn.rs)
- No async trait impls (requires GATs). Note that the full API surface of HALs is still available through inherent methods: #552 #581 
- Some stuff is not constructible in const (requires `const_fn_trait_bound`), although there's an (ugly) workaround for the generic `Mutex`.

So it's not that bad in the end, it's fully usable for shipping production-ready firmwares. We'll still recommend nightly as the default, until GATs and `type_alias_impl_trait` are stable.

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2022-02-12 00:30:47 +00:00
Dario Nieuwenhuis
20e14b8edb embassy, embassy-nrf: add nightly Cargo feature to gate nightly-only features. 2022-02-12 01:16:31 +01:00
Dario Nieuwenhuis
6c925b2342 blocking_mutex: refactor to work on stable. No GATs, and can be constructed in const. 2022-02-12 01:16:31 +01:00
Dario Nieuwenhuis
6de02bb23e nrf: remove OptionalPin 2022-02-12 01:07:02 +01:00
Ulf Lilleengen
f79624c3e6 Upgrade to embedded-storage 0.3.0 2022-02-07 12:35:58 +01:00
bors[bot]
a1d6077446
Merge #591
591: PWM WS2812B example and flexible sequence config r=Dirbaio a=huntc

I've permitted the PWM sequences to be mutated on stopping the PWM by associating them with a new  `SingleSequencer` structure. This is so that we can perform effects on the LEDs (and other use-cases, I'm sure!). The example has been updated to illustrate the use of this by flashing a WS2812B LED.

There's also a `Sequencer` structure for more sophisticated PWM interactions, along with a `pwm_double_sequence`  example to illustrate.

These changes should make it possible to attain all of the nRF PWM functionality available.

Co-authored-by: huntc <huntchr@gmail.com>
2022-02-05 02:20:13 +00:00
huntc
df5ba727f2 Further API simplification for the single seq scenario 2022-02-05 08:05:23 +11:00
huntc
81d31e43eb Removed unrequired clone 2022-02-04 19:18:10 +11:00
huntc
965a5f2c3f Introduced the SingleSequencer and a more complex Sequencer 2022-02-04 19:11:15 +11:00
huntc
9e36ede363 Small correction to times 2022-02-04 16:48:26 +11:00
huntc
e9e4d058d1 Revert the use of forever 2022-02-04 16:39:14 +11:00
huntc
81f98c32aa Update another example 2022-02-04 16:34:25 +11:00
huntc
fe5501293f Expose PWM 2022-02-04 16:26:23 +11:00
huntc
1af6b23f97 Introduces a Sequences struct 2022-02-04 13:04:55 +11:00
huntc
986295998a Some more doco 2022-01-30 16:26:09 +11:00
huntc
1c67bd4643 Revert "Own the sequence buffer"
This reverts commit 482389a691.
2022-01-30 16:21:23 +11:00
huntc
482389a691 Own the sequence buffer
This approach owns the sequence buffers which, while introducing an extra move, it eliminates the need to guard the lifetime of the sequence buffer. Given ownership, the buffer will be retained until the PWM sequence task is stopped.
2022-01-29 18:01:06 +11:00
huntc
9ac52a768b Now permits sequences to be mutated subsequently 2022-01-28 16:32:58 +11:00
huntc
12ce024574 Make the sequence a little nicer to pass around 2022-01-28 13:38:20 +11:00
huntc
47aeab152f PWM WS2812B example and per sequence config
Demonstrates how to set the colour of a WS2812B to blue using PWM, and the use of multiple sequences along with their own config. This required an API change.
2022-01-28 11:20:04 +11:00
Dario Nieuwenhuis
0719b05d63 traits: migrate Delay to embedded-hal 1.0+async, remove Rng and Flash. 2022-01-27 00:08:02 +01:00
huntc
c9f29534d6 Stop PWM before assigning the new sequence
I had introduced a small bug in my last PR where I assigned the sequence before stopping the PWM. I now stop the PWM before doing that now.

Also, corrected a math comment.
2022-01-25 16:51:24 +11:00
huntc
48afef28a0 Strengthen the borrow
The start method is now safe. Because it has the potential of borrowing the sequence and mutating itself, the sequence must outlive the Pwm struct.
2022-01-24 17:22:35 +11:00
huntc
7598b8a40f Permit many sequences to be passed
Sequences are now passed in via the start method to avoid having to stop the PWM and restart it. Sequences continue to be constrained with the same lifetime of the Pwm object itself. The pwm_sequence example has been extended to illustrate multiple sequences being passed around.
2022-01-23 16:29:52 +11:00
Dario Nieuwenhuis
7997687f3b nrf: impl embedded-hal 1.0 and embedded-hal-async traits. 2022-01-13 23:56:39 +01:00
Dario Nieuwenhuis
6eec3d8acc nrf/rng: expose all functionality as inherent methods. 2022-01-13 23:56:39 +01:00
Dario Nieuwenhuis
df00c83984 nrf/qspi: expose all functionality as inherent methods. 2022-01-13 23:56:39 +01:00
Dario Nieuwenhuis
3e503e7335 nrf/uarte: expose all functionality as inherent methods. 2022-01-13 23:56:39 +01:00
Dario Nieuwenhuis
c432d036c7 nrf/gpiote: expose all functionality as inherent methods. 2022-01-13 23:56:39 +01:00
Dario Nieuwenhuis
ecb4f8fb00 nrf/twim: expose all functionality as inherent methods. 2022-01-13 23:56:39 +01:00
Dario Nieuwenhuis
a287fef687 nrf/spim: expose all functionality as inherent methods. 2022-01-13 23:56:39 +01:00
huntc
d5d8897c84 Remove unsafe from new on RND
Unsafe is not required here given that all futures are required to live longer than their global peripheral instances. There are other occurrences of unsafe being used on new that should be removed. I started to do that but then went down a bit of a rabbit hole.
2022-01-06 09:59:28 +11:00
bors[bot]
f744b74e90
Merge #539
539: nrf: async usb r=Dirbaio a=jacobrosenthal

Frankensteined together from this old pr https://github.com/embassy-rs/embassy/pull/115 and nrf-usdb

~Doesnt currently work..~

Co-authored-by: Jacob Rosenthal <jacobrosenthal@gmail.com>
2022-01-04 07:41:54 +00:00
Dario Nieuwenhuis
22bc1e4ae1 nrf/gpio: add infallible inherent methods, remove some duplication.
This implements Input and Output using FlexPin, to avoid some code duplication.
2021-12-20 00:55:18 +01:00
Jacob Rosenthal
e7d2c52680 example cleanup 2021-12-16 15:20:56 -07:00
Jacob Rosenthal
1d51f91368 usb_uart_io example equivilent to usb_uart 2021-12-16 14:59:35 -07:00
Jacob Rosenthal
1f2bbe3e4a simplify usb_uart example 2021-12-16 14:59:08 -07:00
bors[bot]
5df16c6793
Merge #544
544: Introduces split on the nRF Uarte r=Dirbaio a=huntc

A new `split` method is introduced such that the Uarte tx and rx can be used from separate tasks. An MPSC is used in an example to illustrate how data may be passed between these tasks.

The approach taken within the `Uarte` struct is to split into tx and rx fields on calling `Uarte::new`. These fields are returned given a call to `Uarte::split`, but otherwise, if that call isn't made, then the API remains as it was before.

Here's a snippet from a new example introduced:

```rust
#[embassy::main]
async fn main(spawner: Spawner, p: Peripherals) {
    // ...

    let uart = uarte::Uarte::new(p.UARTE0, irq, p.P0_08, p.P0_06, NoPin, NoPin, config);
    let (mut tx, rx) = uart.split();

    // ...

    // Spawn a task responsible purely for reading

    unwrap!(spawner.spawn(reader(rx, s)));

    // ...

    // Continue reading in this main task and write
    // back out the buffer we receive from the read
    // task.
    loop {
        if let Some(buf) = r.recv().await {
            info!("writing...");
            unwrap!(tx.write(&buf).await);
        }
    }
}

#[embassy::task]
async fn reader(mut rx: UarteRx<'static, UARTE0>, s: Sender<'static, Noop, [u8; 8], 1>) {
    let mut buf = [0; 8];
    loop {
        info!("reading...");
        unwrap!(rx.read(&mut buf).await);
        unwrap!(s.send(buf).await);
    }
}
```


Co-authored-by: huntc <huntchr@gmail.com>
2021-12-16 07:44:40 +00:00
Jacob Rosenthal
5d19f87acb cleanup example 2021-12-15 12:30:48 -07:00
Jacob Rosenthal
61f12324ff enable USB peripheral for relevant chips 2021-12-15 10:23:19 -07:00
Jacob Rosenthal
79502330de rename to UsbBus 2021-12-15 09:59:56 -07:00