Commit Graph

60 Commits

Author SHA1 Message Date
Dario Nieuwenhuis
a0487380da Replace futures::future::poll_fn -> core::future::poll_fn. 2022-09-22 16:42:49 +02:00
huntc
30641d0564 Avoid context switch and wait for stop
Should be more efficient given the sub 100 cycles to wait.
2022-08-31 08:47:44 +10:00
huntc
dcd8c62169 Permits the future to be cancelled
Includes documentation
2022-08-30 20:56:56 +10:00
huntc
c0b7fd910e Additional doco 2022-08-30 09:49:04 +10:00
huntc
9a873d1dbf Ensure that the sampling is stopped
Ensures that nRF saadc sampling is stopped and is awaited prior to exiting the two sampling methods. Not doing so causes a potential power drain and the potential for dropped buffer writes when having finished continuous sampling.
2022-08-26 14:40:20 +10:00
Dario Nieuwenhuis
21072bee48 split embassy-util into embassy-futures, embassy-sync. 2022-08-22 22:18:13 +02:00
Dario Nieuwenhuis
a0f1b0ee01 Split embassy crate into embassy-executor, embassy-util. 2022-07-29 23:40:36 +02:00
Dario Nieuwenhuis
709df0dc1d nrf: replace PhantomData usages with PeripheralRef. 2022-07-23 15:13:47 +02:00
Dario Nieuwenhuis
4901c34d9c Rename Unborrowed -> PeripheralRef, Unborrow -> Peripheral 2022-07-23 14:00:19 +02:00
Dario Nieuwenhuis
be6408e202 Rename unsafe_impl_unborrow to impl_unborrow 2022-07-23 01:33:22 +02:00
Grant Miller
65a82d02d1 WIP: Make unborrow safe to use 2022-07-23 01:33:22 +02:00
Dario Nieuwenhuis
424f6ffadb nrf/saadc: add type-erased AnyInput. 2022-07-21 16:42:46 +02:00
Dario Nieuwenhuis
a8703b7598 Run rustfmt. 2022-06-12 22:22:31 +02:00
Dario Nieuwenhuis
5085100df2 Add embassy-cortex-m crate.
- Move Interrupt and InterruptExecutor from `embassy` to `embassy-cortex-m`.
- Move Unborrow from `embassy` to `embassy-hal-common` (nothing in `embassy` requires it anymore)
- Move PeripheralMutex from `embassy-hal-common` to `embassy-cortex-m`.
2022-06-12 21:45:38 +02:00
alexmoon
9c6d49961b Add saadc::VddhDiv5Input 2022-04-08 13:41:21 -04: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
huntc
d4179ee2e4 Some documentation corrections and expansion 2021-11-22 12:26:11 +11:00
Jacob Rosenthal
18d94a7d01 nrf: saadc do not reexport pac enums
Closes #415
2021-11-20 18:07:20 -07:00
Dario Nieuwenhuis
c995a97f20 nrf91: support running in both S and NS mode. 2021-10-26 17:40:07 +02:00
Jacob Rosenthal
32850bba79 nrf: saadc dummy pin for vdd sampling 2021-10-24 09:41:51 -07:00
huntc
3f31774674 Formatting 2021-10-18 12:29:31 +11:00
huntc
8dcc41c7f0 Optimises the buffer passing for nRF SAADC
The buffer will always have been filled and we never explicitly stop the task outside of this code. Thus, we can assume the number of bytes in the slice.
2021-10-18 12:23:13 +11:00
huntc
a94d44a689 Comments corrected 2021-10-18 11:45:23 +11:00
huntc
6dc0ed53ff Renamed sample rate to what it actually is 2021-10-18 11:42:30 +11:00
huntc
93407ed5e2 Remove unneeded stop 2021-10-18 11:31:06 +11:00
huntc
c7e426655d Ensure the compiler doesn't reorder things before calling the sampler 2021-10-18 11:28:43 +11:00
huntc
785030df96 Use types to strengthen the buffer dimensioning 2021-10-18 10:26:11 +11:00
huntc
0c317a64f6 As suggested, use the const param to declare the internal sample for one channel only 2021-10-18 10:26:11 +11:00
huntc
cb56f52b99 Removed the Mode enum and factored out into two functions so that we can assert channel limits 2021-10-18 10:26:11 +11:00
huntc
a020b1a404 Combine intenset calls 2021-10-18 10:26:11 +11:00
huntc
b6cacb98db Compact expression 2021-10-18 10:26:11 +11:00
huntc
e37a10ae99 Hangover - should have set this to internal for a previous PR 2021-10-18 10:26:11 +11:00
huntc
3be274dc2a We must allow the run handler to mutate state
The handler may well need to close over and mutate state
2021-10-18 10:26:11 +11:00
huntc
34e9e85819 We can kick start the internal timer outside of the main loop 2021-10-18 10:26:11 +11:00
huntc
16b6c78332 Removed debugging logs 2021-10-18 10:26:11 +11:00
huntc
103a3305e2 Implements continuous sampling for the nRF SAADC
Implements continuous sampling for the nRF SAADC and also renames `OneShot` to `Saadc`. The one-shot behaviour is retained with the `sample` method and a new `run_sampler` method is provided for efficiently (i.e. zero copying) sampler processing. A double buffer is used for continuously sampling, which wlll be swapped once sampling has taken place.

A sample frequency is provided and will set the internal timer of the SAADC when there is just the one channel being sampled. Otherwise, PPI will be used to hook up the TIMER peripheral to drive the sampling task.
2021-10-18 10:26:11 +11:00
Dario Nieuwenhuis
c675fb1036 nrf/saadc: make InputChannel private. 2021-10-13 22:13:30 +02:00
Dario Nieuwenhuis
d8c3365d6a nrf/saadc: make Input trait sealed. 2021-10-13 22:13:26 +02:00
Dario Nieuwenhuis
0d709fa5c8 nrf/saadc: require unborrow for Input.
This allows using borrowed pins in ChannelConfig.
2021-10-13 22:06:09 +02:00
Dario Nieuwenhuis
14c3260d88 nrf/saadc: move chip-specific mappings to chips/ 2021-10-11 01:36:31 +02:00
Dario Nieuwenhuis
668364da9c nrf/saadc: nrf52805 only has 2 channels 2021-10-11 00:55:31 +02:00
huntc
8c9e50b378 Conflates the negative and positive types as they are the same, and renames pin to input as they can be more than pins 2021-10-11 09:38:35 +11:00
huntc
b043778f75 Removed the NotConnected as it isn't used. 2021-10-11 09:08:58 +11:00
huntc
25d6a2cd13 No use case understood for NotConnected, so hiding it for now 2021-10-11 08:56:53 +11:00
huntc
617a976e96 No need for unwrap 2021-10-11 08:54:24 +11:00
huntc
5f5470a320 Need to borrow the pins for the lifetime of the config, and subsequently the one shot. 2021-10-11 08:52:45 +11:00
huntc
cef6158c31 Extend SAADC one shot support
One-shot mode now permits the sampling of differential pins, and the sampling of multiple pins simultaneously.

A new ChannelConfig structure has been introduced so that multiple channels can be configured individually. Further, the `sample` method now accepts a buffer into which samples are written.

Along the way, I've reset some default configuration to align with Nordic's settings in their nrfx saadc driver. Specifically, the channel gain defaults to 6 (from 4) and the time defaults to 10us (from 20us).
2021-10-09 11:25:18 +11:00
Dario Nieuwenhuis
0e05ba688d nrf/saadc: remove Sample trait. 2021-10-07 02:10:22 +02:00
Dario Nieuwenhuis
ead987245d embassy: Refactor module structure to remove kitchen-sink util. 2021-09-11 02:35:35 +02:00