Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
XdoctorwhoZ committed Jul 20, 2024
1 parent 73cd6ff commit c33448f
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 20 deletions.
18 changes: 12 additions & 6 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@
runner = "elf2uf2-rs -d"

rustflags = [
"-C", "linker=flip-link",
"-C", "link-arg=--nmagic",
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=-Tdefmt.x",
"-C",
"linker=flip-link",
"-C",
"link-arg=--nmagic",
"-C",
"link-arg=-Tlink.x",
"-C",
"link-arg=-Tdefmt.x",

# Code-size optimizations.
# trap unreachable can save a lot of space, but requires nightly compiler.
# uncomment the next line if you wish to enable it
# "-Z", "trap-unreachable=no",
"-C", "inline-threshold=5",
"-C", "no-vectorize-loops",
"-C",
"inline-threshold=5",
"-C",
"no-vectorize-loops",
]

[build]
Expand Down
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ panic-probe = { version = "0.3", features = ["print-defmt"] }

# We're using a Pico by default on this template
rp-pico = "0.9"

# panic-halt = "0.2.0"
# but you can use any BSP. Uncomment this to use the pro_micro_rp2040 BSP instead
# sparkfun-pro-micro-rp2040 = "0.8"

Expand All @@ -35,6 +35,8 @@ irq = "0.2.3"
femtopb = "0.4.5"
serial-line-ip = "0.5.0"

fugit = "0.3.7"

[build-dependencies]
femtopb-build = "0.4.5"

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ cargo install --locked elf2uf2-rs
cargo run --release
```

------------------------






Expand Down
69 changes: 56 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ use embedded_hal::digital::{InputPin, OutputPin};
use femtopb::Message;
use panic_probe as _;

use rp2040_hal::pio::PIOExt;

use fugit::RateExtU32;
use rp2040_hal::{
pio::PIOExt,
uart::{DataBits, StopBits, UartConfig, UartPeripheral},
};
// USB Device support
use usb_device::{class_prelude::*, prelude::*};

Expand Down Expand Up @@ -44,6 +47,19 @@ mod api_dio;

use serial_line_ip;

fn setup_debug_uart(pins: &mut rp_pico::Pins) {
// let ppp: Pin<_, FunctionPio0, _> = pins.gpio0.into_function();
// Set up UART on GP0 and GP1 (Pico pins 1 and 2)
// let pins = (pins.gpio0.into_function(), pins.gpio1.into_function());
// // Need to perform clock init before using UART or it will freeze.
// let uart = UartPeripheral::new(peripherals.UART0, pins, &mut peripherals.RESETS)
// .enable(
// UartConfig::new(9600.Hz(), DataBits::Eight, None, StopBits::One),
// clocks.peripheral_clock.freq(),
// )
// .unwrap();
}

#[entry]
fn main() -> ! {
info!("Program start");
Expand Down Expand Up @@ -94,13 +110,25 @@ fn main() -> ! {
let timer = hal::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks);
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());

let pins = bsp::Pins::new(
let pins: rp_pico::Pins = bsp::Pins::new(
pac.IO_BANK0,
pac.PADS_BANK0,
sio.gpio_bank0,
&mut pac.RESETS,
);

// Set up UART on GP0 and GP1 (Pico pins 1 and 2)
let pins = (pins.gpio0.into_function(), pins.gpio1.into_function());
// Need to perform clock init before using UART or it will freeze.
let uart = UartPeripheral::new(pac.UART0, pins, &mut pac.RESETS)
.enable(
UartConfig::new(9600.Hz(), DataBits::Eight, None, StopBits::One),
clocks.peripheral_clock.freq(),
)
.unwrap();

uart.write_full_blocking(b"Hello World!\r\n");

// // configure LED pin for Pio0.
// // let led: Pin<_, FunctionPio0, _> = pins.led.into_function();
// let p0: Pin<_, FunctionPio0, _> = pins.gpio0.into_function();
Expand All @@ -111,7 +139,7 @@ fn main() -> ! {
// let mut piiii = pins.led.into_inout();

// Use GPIO 28 as an InOutPin
let mut pin = pins.led.into_push_pull_output().into_dyn_pin();
// let mut pin = pins.led.into_push_pull_output().into_dyn_pin();

// pin.
// let _ = pin.set_low();
Expand Down Expand Up @@ -199,19 +227,23 @@ fn main() -> ! {

// cmd_buf[cmd_buf_size..count].clone_from_slice(&buf);

{
let (left, right) = cmd_buf.split_at_mut(cmd_buf_size);
right.clone_from_slice(&buf[..count]);
cmd_buf_size += count;
}
let mut message = String::<512>::new();
writeln!(&mut message, "Received {} bytes", count).unwrap();
uart.write_full_blocking(message.as_bytes());

// {
// let (left, right) = cmd_buf.split_at_mut(cmd_buf_size);
// right.clone_from_slice(&buf[..count]);
// cmd_buf_size += count;
// }

// cmd_buf_size += count;

for i in 0..count {
pin.set_high().unwrap();
delay.delay_ms(250);
pin.set_low().unwrap();
delay.delay_ms(250);
// pin.set_high().unwrap();
// delay.delay_ms(250);
// pin.set_low().unwrap();
// delay.delay_ms(250);
}

// // Convert to upper case
Expand All @@ -235,4 +267,15 @@ fn main() -> ! {
}
}

// use core::panic::PanicInfo;
// use core::sync::atomic::{self, Ordering};

// #[inline(never)]
// #[panic_handler]
// fn panic(_info: &PanicInfo) -> ! {
// loop {
// atomic::compiler_fence(Ordering::SeqCst);
// }
// }

// End of file

0 comments on commit c33448f

Please sign in to comment.