diff options
| author | huntc <[email protected]> | 2021-10-17 07:02:17 +1100 |
|---|---|---|
| committer | huntc <[email protected]> | 2021-10-18 10:26:11 +1100 |
| commit | 0c317a64f6f0f845dd2ca3323c9579fda09be410 (patch) | |
| tree | 9aefe079b80467001737f389ddfd47c72a1eacf4 | |
| parent | cb56f52b9952bea266fdcad3a539b6097ddf5079 (diff) | |
As suggested, use the const param to declare the internal sample for one channel only
| -rw-r--r-- | embassy-nrf/src/saadc.rs | 54 |
1 files changed, 24 insertions, 30 deletions
diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index af45a8033..6e0bcc167 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs | |||
| @@ -240,36 +240,6 @@ impl<'d, const N: usize> Saadc<'d, N> { | |||
| 240 | /// Continuous sampling with double buffers. The sample buffers generally | 240 | /// Continuous sampling with double buffers. The sample buffers generally |
| 241 | /// should be a multiple of the number of channels configured. | 241 | /// should be a multiple of the number of channels configured. |
| 242 | /// | 242 | /// |
| 243 | /// The internal clock is to be used with a sample rate expressed as a divisor of | ||
| 244 | /// 16MHz, ranging from 80..2047. For example, 1600 represnts a sample rate of 10KHz | ||
| 245 | /// given 16_000_000 / 10_000_000 = 1600. | ||
| 246 | /// | ||
| 247 | /// A sampler closure is provided that receives the buffer of samples, noting | ||
| 248 | /// that the size of this buffer can be less than the original buffer's size. | ||
| 249 | /// A command is return from the closure that indicates whether the sampling | ||
| 250 | /// should continue or stop. | ||
| 251 | pub async fn run_timer_sampler<S, const N0: usize>( | ||
| 252 | &mut self, | ||
| 253 | bufs: &mut [[i16; N0]; 2], | ||
| 254 | sample_rate: u16, | ||
| 255 | sampler: S, | ||
| 256 | ) where | ||
| 257 | S: FnMut(&[i16]) -> SamplerState, | ||
| 258 | { | ||
| 259 | assert!( | ||
| 260 | N == 1, | ||
| 261 | "The internal timer can only be used with one channel" | ||
| 262 | ); | ||
| 263 | assert!( | ||
| 264 | N0 % N == 0, | ||
| 265 | "The buffer size must be a multiple of the number of channels" | ||
| 266 | ); | ||
| 267 | self.run_sampler(bufs, Some(sample_rate), sampler).await; | ||
| 268 | } | ||
| 269 | |||
| 270 | /// Continuous sampling with double buffers. The sample buffers generally | ||
| 271 | /// should be a multiple of the number of channels configured. | ||
| 272 | /// | ||
| 273 | /// A task-driven approach to driving TASK_SAMPLE is expected. With a task | 243 | /// A task-driven approach to driving TASK_SAMPLE is expected. With a task |
| 274 | /// driven approach, multiple channels can be used. | 244 | /// driven approach, multiple channels can be used. |
| 275 | /// | 245 | /// |
| @@ -387,6 +357,30 @@ impl<'d, const N: usize> Saadc<'d, N> { | |||
| 387 | } | 357 | } |
| 388 | } | 358 | } |
| 389 | 359 | ||
| 360 | impl<'d> Saadc<'d, 1> { | ||
| 361 | /// Continuous sampling on a single channel with double buffers. The sample | ||
| 362 | /// buffers generally should be a multiple of the number of channels configured. | ||
| 363 | /// | ||
| 364 | /// The internal clock is to be used with a sample rate expressed as a divisor of | ||
| 365 | /// 16MHz, ranging from 80..2047. For example, 1600 represnts a sample rate of 10KHz | ||
| 366 | /// given 16_000_000 / 10_000_000 = 1600. | ||
| 367 | /// | ||
| 368 | /// A sampler closure is provided that receives the buffer of samples, noting | ||
| 369 | /// that the size of this buffer can be less than the original buffer's size. | ||
| 370 | /// A command is return from the closure that indicates whether the sampling | ||
| 371 | /// should continue or stop. | ||
| 372 | pub async fn run_timer_sampler<S, const N0: usize>( | ||
| 373 | &mut self, | ||
| 374 | bufs: &mut [[i16; N0]; 2], | ||
| 375 | sample_rate: u16, | ||
| 376 | sampler: S, | ||
| 377 | ) where | ||
| 378 | S: FnMut(&[i16]) -> SamplerState, | ||
| 379 | { | ||
| 380 | self.run_sampler(bufs, Some(sample_rate), sampler).await; | ||
| 381 | } | ||
| 382 | } | ||
| 383 | |||
| 390 | impl<'d, const N: usize> Drop for Saadc<'d, N> { | 384 | impl<'d, const N: usize> Drop for Saadc<'d, N> { |
| 391 | fn drop(&mut self) { | 385 | fn drop(&mut self) { |
| 392 | let r = Self::regs(); | 386 | let r = Self::regs(); |
