Skip to content

Commit

Permalink
Fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jannic committed Jan 3, 2024
1 parent af24c28 commit 68809ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions rp2040-hal/examples/adc_fifo_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ use rp2040_hal::Clock;
// UART related types
use hal::uart::{DataBits, StopBits, UartConfig};

// ADC related types
use hal::adc::AdcPin;
use hal::Adc;

// A shorter alias for the Peripheral Access Crate, which provides low-level
// register access
use hal::pac;
Expand Down Expand Up @@ -108,13 +112,13 @@ fn main() -> ! {
let dma = pac.DMA.split(&mut pac.RESETS);

// Enable ADC
let mut adc = hal::Adc::new(pac.ADC, &mut pac.RESETS);
let mut adc = Adc::new(pac.ADC, &mut pac.RESETS);

// Enable the temperature sense channel
let mut temperature_sensor = adc.take_temp_sensor().unwrap();

// Configure GPIO26 as an ADC input
let mut adc_pin_0 = hal::adc::AdcPin::new(pins.gpio26.into_floating_input()).unwrap();
let adc_pin_0 = AdcPin::new(pins.gpio26.into_floating_input()).unwrap();

// we'll capture 1000 samples in total (500 per channel)
// NOTE: when calling `shift_8bit` below, the type here must be changed from `u16` to `u8`
Expand All @@ -130,7 +134,7 @@ fn main() -> ! {
// sample the temperature sensor first
.set_channel(&mut temperature_sensor)
// then alternate between GPIO26 and the temperature sensor
.round_robin((&mut adc_pin_0, &mut temperature_sensor))
.round_robin((&adc_pin_0, &temperature_sensor))
// Uncomment this line to produce 8-bit samples, instead of 12 bit (lower bits are discarded)
//.shift_8bit()
// Enable DMA transfers for the FIFO
Expand Down
4 changes: 2 additions & 2 deletions rp2040-hal/examples/adc_fifo_poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn main() -> ! {
let mut temperature_sensor = adc.take_temp_sensor().unwrap();

// Configure GPIO26 as an ADC input
let mut adc_pin_0 = hal::adc::AdcPin::new(pins.gpio26.into_floating_input()).unwrap();
let adc_pin_0 = hal::adc::AdcPin::new(pins.gpio26.into_floating_input()).unwrap();

// Configure free-running mode:
let mut adc_fifo = adc
Expand All @@ -121,7 +121,7 @@ fn main() -> ! {
// sample the temperature sensor first
.set_channel(&mut temperature_sensor)
// then alternate between GPIO26 and the temperature sensor
.round_robin((&mut adc_pin_0, &mut temperature_sensor))
.round_robin((&adc_pin_0, &temperature_sensor))
// Uncomment this line to produce 8-bit samples, instead of 12 bit (lower bits are discarded)
//.shift_8bit()
// start sampling
Expand Down

0 comments on commit 68809ee

Please sign in to comment.