11#![ no_std]
22#![ no_main]
3+ #[ cfg( feature = "rp2040" ) ]
34teleprobe_meta:: target!( b"rpi-pico" ) ;
5+ #[ cfg( feature = "rp235xb" ) ]
6+ teleprobe_meta:: target!( b"pimoroni-pico-plus-2" ) ;
47
58use defmt:: * ;
69use embassy_executor:: Spawner ;
7- use embassy_rp:: adc:: { Adc , Channel , Config , InterruptHandler , Sample } ;
10+ use embassy_rp:: adc:: Sample ;
11+ use embassy_rp:: adc:: { Adc , Channel , Config , InterruptHandler } ;
812use embassy_rp:: bind_interrupts;
9- use embassy_rp:: gpio:: { Level , Output , Pull } ;
13+ use embassy_rp:: gpio:: Pull ;
14+ use embassy_rp:: gpio:: { Level , Output } ;
1015use { defmt_rtt as _, panic_probe as _} ;
1116
1217bind_interrupts ! ( struct Irqs {
@@ -20,52 +25,57 @@ async fn main(_spawner: Spawner) {
2025 let _wifi_off = Output :: new ( p. PIN_25 , Level :: High ) ;
2126 let mut adc = Adc :: new ( p. ADC , Irqs , Config :: default ( ) ) ;
2227
28+ #[ cfg( any( feature = "rp2040" , feature = "rp235xa" ) ) ]
29+ let ( mut a, mut b, mut c, mut d) = ( p. PIN_26 , p. PIN_27 , p. PIN_28 , p. PIN_29 ) ;
30+ #[ cfg( feature = "rp235xb" ) ]
31+ let ( mut a, mut b, mut c, mut d) = ( p. PIN_44 , p. PIN_45 , p. PIN_46 , p. PIN_47 ) ;
32+
2333 {
2434 {
25- let mut p = Channel :: new_pin ( & mut p . PIN_26 , Pull :: Down ) ;
35+ let mut p = Channel :: new_pin ( & mut a , Pull :: Down ) ;
2636 defmt:: assert!( adc. blocking_read( & mut p) . unwrap( ) < 0b01_0000_0000 ) ;
2737 defmt:: assert!( adc. read( & mut p) . await . unwrap( ) < 0b01_0000_0000 ) ;
2838 }
2939 {
30- let mut p = Channel :: new_pin ( & mut p . PIN_26 , Pull :: Up ) ;
40+ let mut p = Channel :: new_pin ( & mut a , Pull :: Up ) ;
3141 defmt:: assert!( adc. blocking_read( & mut p) . unwrap( ) > 0b11_0000_0000 ) ;
3242 defmt:: assert!( adc. read( & mut p) . await . unwrap( ) > 0b11_0000_0000 ) ;
3343 }
3444 }
3545 // not bothering with async reads from now on
3646 {
3747 {
38- let mut p = Channel :: new_pin ( & mut p . PIN_27 , Pull :: Down ) ;
48+ let mut p = Channel :: new_pin ( & mut b , Pull :: Down ) ;
3949 defmt:: assert!( adc. blocking_read( & mut p) . unwrap( ) < 0b01_0000_0000 ) ;
4050 }
4151 {
42- let mut p = Channel :: new_pin ( & mut p . PIN_27 , Pull :: Up ) ;
52+ let mut p = Channel :: new_pin ( & mut b , Pull :: Up ) ;
4353 defmt:: assert!( adc. blocking_read( & mut p) . unwrap( ) > 0b11_0000_0000 ) ;
4454 }
4555 }
4656 {
4757 {
48- let mut p = Channel :: new_pin ( & mut p . PIN_28 , Pull :: Down ) ;
58+ let mut p = Channel :: new_pin ( & mut c , Pull :: Down ) ;
4959 defmt:: assert!( adc. blocking_read( & mut p) . unwrap( ) < 0b01_0000_0000 ) ;
5060 }
5161 {
52- let mut p = Channel :: new_pin ( & mut p . PIN_28 , Pull :: Up ) ;
62+ let mut p = Channel :: new_pin ( & mut c , Pull :: Up ) ;
5363 defmt:: assert!( adc. blocking_read( & mut p) . unwrap( ) > 0b11_0000_0000 ) ;
5464 }
5565 }
5666 {
5767 // gp29 is connected to vsys through a 200k/100k divider,
5868 // adding pulls should change the value
5969 let low = {
60- let mut p = Channel :: new_pin ( & mut p . PIN_29 , Pull :: Down ) ;
70+ let mut p = Channel :: new_pin ( & mut d , Pull :: Down ) ;
6171 adc. blocking_read ( & mut p) . unwrap ( )
6272 } ;
6373 let none = {
64- let mut p = Channel :: new_pin ( & mut p . PIN_29 , Pull :: None ) ;
74+ let mut p = Channel :: new_pin ( & mut d , Pull :: None ) ;
6575 adc. blocking_read ( & mut p) . unwrap ( )
6676 } ;
6777 let up = {
68- let mut p = Channel :: new_pin ( & mut p . PIN_29 , Pull :: Up ) ;
78+ let mut p = Channel :: new_pin ( & mut d , Pull :: Up ) ;
6979 adc. blocking_read ( & mut p) . unwrap ( )
7080 } ;
7181 defmt:: assert!( low < none) ;
@@ -89,29 +99,14 @@ async fn main(_spawner: Spawner) {
8999 let mut low = [ 0u16 ; 16 ] ;
90100 let mut none = [ 0u8 ; 16 ] ;
91101 let mut up = [ Sample :: default ( ) ; 16 ] ;
92- adc. read_many (
93- & mut Channel :: new_pin ( & mut p. PIN_29 , Pull :: Down ) ,
94- & mut low,
95- 1 ,
96- & mut p. DMA_CH0 ,
97- )
98- . await
99- . unwrap ( ) ;
100- adc. read_many (
101- & mut Channel :: new_pin ( & mut p. PIN_29 , Pull :: None ) ,
102- & mut none,
103- 1 ,
104- & mut p. DMA_CH0 ,
105- )
106- . await
107- . unwrap ( ) ;
108- adc. read_many_raw (
109- & mut Channel :: new_pin ( & mut p. PIN_29 , Pull :: Up ) ,
110- & mut up,
111- 1 ,
112- & mut p. DMA_CH0 ,
113- )
114- . await ;
102+ adc. read_many ( & mut Channel :: new_pin ( & mut d, Pull :: Down ) , & mut low, 1 , & mut p. DMA_CH0 )
103+ . await
104+ . unwrap ( ) ;
105+ adc. read_many ( & mut Channel :: new_pin ( & mut d, Pull :: None ) , & mut none, 1 , & mut p. DMA_CH0 )
106+ . await
107+ . unwrap ( ) ;
108+ adc. read_many_raw ( & mut Channel :: new_pin ( & mut d, Pull :: Up ) , & mut up, 1 , & mut p. DMA_CH0 )
109+ . await ;
115110 defmt:: assert!( low. iter( ) . zip( none. iter( ) ) . all( |( l, n) | * l >> 4 < * n as u16 ) ) ;
116111 defmt:: assert!( up. iter( ) . all( |s| s. good( ) ) ) ;
117112 defmt:: assert!( none. iter( ) . zip( up. iter( ) ) . all( |( n, u) | ( * n as u16 ) < u. value( ) ) ) ;
@@ -133,7 +128,7 @@ async fn main(_spawner: Spawner) {
133128 {
134129 let mut multi = [ 0u16 ; 2 ] ;
135130 let mut channels = [
136- Channel :: new_pin ( & mut p . PIN_26 , Pull :: Up ) ,
131+ Channel :: new_pin ( & mut a , Pull :: Up ) ,
137132 Channel :: new_temp_sensor ( & mut p. ADC_TEMP_SENSOR ) ,
138133 ] ;
139134 adc. read_many_multichannel ( & mut channels, & mut multi, 1 , & mut p. DMA_CH0 )
0 commit comments