diff --git a/src/app_dio.rs b/src/app_dio.rs index b61ee0f..15a7562 100644 --- a/src/app_dio.rs +++ b/src/app_dio.rs @@ -13,6 +13,21 @@ use usbd_serial::SerialPort; // Size of internal buffers const BUFFER_CAPACITY: usize = 64; +const MAX_PINS: usize = 30; + +type PinO = rp2040_hal::gpio::Pin< + rp2040_hal::gpio::DynPinId, + rp2040_hal::gpio::FunctionSio, + rp2040_hal::gpio::DynPullType, +>; +const PINO_NONE: Option = None; +type PinI = rp2040_hal::gpio::Pin< + rp2040_hal::gpio::DynPinId, + rp2040_hal::gpio::FunctionSio, + rp2040_hal::gpio::DynPullType, +>; +const PINI_NONE: Option = None; + /// Application Digital I/O pub struct AppDio { // Accumulated incoming data buffer @@ -21,6 +36,10 @@ pub struct AppDio { in_buf_size: usize, // Decode buffer decode_buffer: [u8; BUFFER_CAPACITY], + + // rp_pins: rp_pico::Pins, + pins_o: [Option; MAX_PINS], + pins_i: [Option; MAX_PINS], } impl AppDio { @@ -31,9 +50,19 @@ impl AppDio { in_buf: [0u8; 64], in_buf_size: 0, decode_buffer: [0u8; 64], + // rp_pins: rp_pins, + pins_o: [PINO_NONE; MAX_PINS], + pins_i: [PINI_NONE; MAX_PINS], } } + // fn set_pin_as_output(&mut self, pin_num: u32) { + // let pin_num = pin_num as usize; + // if pin_num < MAX_PINS { + // self.pins_o[pin_num] = Some(pin.into_push_pull_output().into_dyn_pin()); + // } + // } + /// Accumulate new data /// fn accumulate_new_data(&mut self, data: &[u8]) { diff --git a/src/main.rs b/src/main.rs index 6db9420..e131ff8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ // uart debug mod uart_debug; +use rp2040_hal::gpio::new_pin; use uart_debug::uart_debug_init; use uart_debug::uart_debug_print; @@ -64,24 +65,6 @@ unsafe fn main() -> ! { let mut watchdog = Watchdog::new(pac.WATCHDOG); let sio = Sio::new(pac.SIO); - // let mut cursor = femtopb::Cursor::new(); - // let rr = mes.encoded_len() - - // let user_factory = NP_Factory::new( - // r#" - // struct({ fields: { - // command: u8({ default: 0 }), - // pin: u8({ default: 0 }), - // value: u8({ default: 0 }), - // }}) - // "#, - // )?; - // // close buffer and get internal bytes - // let user_bytes: Vec = user_buffer.finish().bytes(); - - // let mut slip = serial_line_ip::Encoder::new(); - // let mut totals = slip.encode(INPUT_1, &mut output).unwrap(); - // External high-speed crystal on the pico board is 12Mhz let external_xtal_freq_hz = 12_000_000u32; let clocks = init_clocks_and_plls( @@ -122,6 +105,61 @@ unsafe fn main() -> ! { print_debug_message!(b"Hello World!\r\n"); // -------------------------------------------------------------- + // let pppp: Pin< + // rp2040_hal::gpio::DynPinId, + // rp2040_hal::gpio::FunctionSio, + // rp2040_hal::gpio::DynPullType, + // > = pins + // .led + // .into_push_pull_output() + // .into_pull_type() + // .into_dyn_pin(); + let p2 = pins + .gpio3 + .into_floating_input() + .into_pull_type() + .into_dyn_pin(); + + let did = pins.led.into_push_pull_output().into_dyn_pin().id(); + let pppppp = new_pin(did); + + let mut neerr = pppppp + .try_into_function::() + .ok() + .unwrap(); + + // let pppppppppppp = neerr.into_push_pull_output(); + + neerr.set_high().unwrap(); + + delay.delay_ms(2000u32); + + let pppppp2 = new_pin(did); + + let mut neerr2 = pppppp2 + .try_into_function::() + .ok() + .unwrap(); + + print_debug_message!("Hello World! {}\r\n", neerr2.is_high().unwrap()); + + // let dd = p2.reconfigure(); + + // let mut pins_array_oooo: [Option< + // Pin< + // rp2040_hal::gpio::DynPinId, + // rp2040_hal::gpio::FunctionSio, + // rp2040_hal::gpio::DynPullType, + // >, + // >; 1] = [Some(pppp)]; + + // pins_array_oooo[0].as_mut().unwrap().set_high().unwrap(); + + let pins_array: [Pin< + rp2040_hal::gpio::DynPinId, + rp2040_hal::gpio::FunctionSio, + rp2040_hal::gpio::DynPullType, + >; 1] = [p2]; // // configure LED pin for Pio0. // // let led: Pin<_, FunctionPio0, _> = pins.led.into_function();