Skip to content

Commit

Permalink
Actually blinks... I think I need to create my own hal for my board...
Browse files Browse the repository at this point in the history
  • Loading branch information
bentwire committed Oct 17, 2023
1 parent a413d69 commit 4098a4c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 84 deletions.
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ defmt-rtt = "0.4"
panic-probe = { version = "0.3", features = ["print-defmt"] }

# We're using a Pico by default on this template
# rp-pico = { version = "0.8.0", features = ["rt", "rtic-monotonic"] }
rp-pico = { version = "0.8.0", features = ["rt"] }

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

# If you're not going to use a Board Support Package you'll need these:
rp2040-hal = { version="0.9.0", features=["rt", "critical-section-impl", "rtic-monotonic"] }
# rp2040-boot2 = "0.2"
#rp2040-boot2 = "0.3"

[[bin]]
name = "old"
path = "src/old.rs"

# cargo build/run
[profile.dev]
Expand Down
36 changes: 18 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod app {

use embedded_hal::digital::v2::OutputPin;
use fugit::{ExtU64, Instant};
use rp2040_hal::{
use rp_pico::hal::{
self,
clocks::init_clocks_and_plls,
gpio, i2c,
Expand Down Expand Up @@ -105,28 +105,28 @@ mod app {
&mut resets,
);

let i2c0_pins = (
// UART TX (characters sent from RP2040) on pin 1 (GPIO0)
pins.gpio0.into_function::<gpio::FunctionI2C>(),
// UART RX (characters received by RP2040) on pin 2 (GPIO1)
pins.gpio1.into_function::<gpio::FunctionI2C>(),
);
// let i2c0_pins = (
// // UART TX (characters sent from RP2040) on pin 1 (GPIO0)
// pins.gpio0.into_function::<gpio::FunctionI2C>(),
// // UART RX (characters received by RP2040) on pin 2 (GPIO1)
// pins.gpio1.into_function::<gpio::FunctionI2C>(),
// );

let i2c0 = i2c::I2C::i2c0(
c.device.I2C0,
i2c0_pins.0,
i2c0_pins.1,
fugit::RateExtU32::Hz(100000_u32),
&mut resets,
rp2040_hal::Clock::freq(&clocks.system_clock),
);
// let i2c0 = i2c::I2C::i2c0(
// c.device.I2C0,
// i2c0_pins.0,
// i2c0_pins.1,
// fugit::RateExtU32::Hz(100000_u32),
// &mut resets,
// rp2040_hal::Clock::freq(&clocks.system_clock),
// );

let mut pd = usb_pd::sink::Sink::new(fusb302b::Fusb302b::new(i2c0), &crate::callback);
// let mut pd = usb_pd::sink::Sink::new(fusb302b::Fusb302b::new(i2c0), &crate::callback);

pd.init();
// pd.init();

let mut led = pins.gpio11.into_push_pull_output();
led.set_low().unwrap();
led.set_high().unwrap();

let mut timer = rp2040_hal::Timer::new(c.device.TIMER, &mut resets, &clocks);
let alarm = timer.alarm_0().unwrap();
Expand Down
71 changes: 7 additions & 64 deletions src/old.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ use usb_pd::{
sink::Sink,
};

/// The linker will place this boot block at the start of our program image. We
/// need this to help the ROM bootloader get our code up and running.
// #[no_mangle]
// #[used]
// pub static BOOT2_FIRMWARE: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;

#[entry]
fn main() -> ! {
info!("Program start");
Expand All @@ -54,7 +60,7 @@ fn main() -> ! {

let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());

let pins = bsp::Pins::new(
let pins = gpio::Pins::new(
pac.IO_BANK0,
pac.PADS_BANK0,
sio.gpio_bank0,
Expand All @@ -68,77 +74,14 @@ fn main() -> ! {
// LED to one of the GPIO pins, and reference that pin here.
let mut led_pin = pins.gpio11.into_push_pull_output();

let i2c0_pins = (
// UART TX (characters sent from RP2040) on pin 1 (GPIO0)
pins.gpio0.into_mode::<gpio::FunctionI2C>(),
// UART RX (characters received by RP2040) on pin 2 (GPIO1)
pins.gpio1.into_mode::<gpio::FunctionI2C>(),
);

let i2c0 = i2c::I2C::i2c0(
pac.I2C0,
i2c0_pins.0,
i2c0_pins.1,
100000_u32.Hz(),
&mut pac.RESETS,
clocks.system_clock.freq(),
);

let mut fusb302b = Fusb302b::new(i2c0);
//let mut pd = { Sink::new(Fusb302b::new(i2c0), &callback) };

//pd.init();

loop {
info!("on!");
led_pin.set_high().unwrap();
delay.delay_ms(500);
info!("off!");
led_pin.set_low().unwrap();
delay.delay_ms(500);

fusb302b::registers::Control0
}
}

fn callback(event: Event) -> Option<Response> {
match event {
Event::SourceCapabilitiesChanged(caps) => {
info!("Capabilities changed: {}", caps.len());

// Take maximum voltage
let (index, supply) = caps
.iter()
.enumerate()
.filter_map(|(i, cap)| {
if let PowerDataObject::FixedSupply(supply) = cap {
debug!(
"supply @ {}: {}mV {}mA",
i,
supply.voltage() * 50,
supply.max_current() * 10
);
Some((i, supply))
} else {
None
}
})
.max_by(|(_, x), (_, y)| x.voltage().cmp(&y.voltage()))
.unwrap();

info!("requesting supply {:?}@{}", supply, index);

return Some(Response::RequestPower {
index,
current: supply.max_current() * 10,
});
}
Event::PowerReady => info!("power ready"),
Event::ProtocolChanged => info!("protocol changed"),
Event::PowerAccepted => info!("power accepted"),
Event::PowerRejected => info!("power rejected"),
}

None
}
// End of file

0 comments on commit 4098a4c

Please sign in to comment.