Skip to content

Commit

Permalink
found a way to do what I want
Browse files Browse the repository at this point in the history
  • Loading branch information
XdoctorwhoZ committed Jul 22, 2024
1 parent 36b6046 commit e1d138f
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 18 deletions.
29 changes: 29 additions & 0 deletions src/app_dio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::SioOutput>,
rp2040_hal::gpio::DynPullType,
>;
const PINO_NONE: Option<PinO> = None;
type PinI = rp2040_hal::gpio::Pin<
rp2040_hal::gpio::DynPinId,
rp2040_hal::gpio::FunctionSio<rp2040_hal::gpio::SioInput>,
rp2040_hal::gpio::DynPullType,
>;
const PINI_NONE: Option<PinI> = None;

/// Application Digital I/O
pub struct AppDio {
// Accumulated incoming data buffer
Expand All @@ -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<PinO>; MAX_PINS],
pins_i: [Option<PinI>; MAX_PINS],
}

impl AppDio {
Expand All @@ -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]) {
Expand Down
74 changes: 56 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<u8> = 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(
Expand Down Expand Up @@ -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::SioOutput>,
// 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::<hal::gpio::FunctionSioOutput>()
.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::<hal::gpio::FunctionSioInput>()
.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::SioOutput>,
// 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::SioInput>,
rp2040_hal::gpio::DynPullType,
>; 1] = [p2];

// // configure LED pin for Pio0.
// // let led: Pin<_, FunctionPio0, _> = pins.led.into_function();
Expand Down

0 comments on commit e1d138f

Please sign in to comment.