re-worked GPIO implementation
This commit is contained in:
@ -14,7 +14,7 @@ use zynq7000_hal::{
|
||||
BootMode,
|
||||
clocks::Clocks,
|
||||
gic::{GicConfigurator, GicInterruptHelper, Interrupt},
|
||||
gpio::{Mio7, MioPin, MioPins, Output, PinState},
|
||||
gpio::{Output, PinState, mio},
|
||||
gtc::Gtc,
|
||||
time::Hertz,
|
||||
uart::{ClkConfigRaw, TxAsync, Uart, UartConfig, on_interrupt_tx},
|
||||
@ -52,18 +52,16 @@ async fn main(spawner: Spawner) -> ! {
|
||||
let gtc = Gtc::new(dp.gtc, clocks.arm_clocks());
|
||||
zynq7000_embassy::init(clocks.arm_clocks(), gtc);
|
||||
|
||||
let mio_pins = MioPins::new(dp.gpio);
|
||||
let mio_pins = mio::Pins::new(dp.gpio);
|
||||
|
||||
// Set up the UART, we are logging with it.
|
||||
let uart_clk_config = ClkConfigRaw::new_autocalc_with_error(clocks.io_clocks(), 115200)
|
||||
.unwrap()
|
||||
.0;
|
||||
let uart_tx = mio_pins.mio48.into_uart();
|
||||
let uart_rx = mio_pins.mio49.into_uart();
|
||||
let mut uart = Uart::new_with_mio(
|
||||
dp.uart_1,
|
||||
UartConfig::new_with_clk_config(uart_clk_config),
|
||||
(uart_tx, uart_rx),
|
||||
(mio_pins.mio48, mio_pins.mio49),
|
||||
)
|
||||
.unwrap();
|
||||
uart.write_all(b"-- Zynq 7000 Logging example --\n\r")
|
||||
@ -77,7 +75,7 @@ async fn main(spawner: Spawner) -> ! {
|
||||
let boot_mode = BootMode::new();
|
||||
info!("Boot mode: {:?}", boot_mode);
|
||||
|
||||
let led = mio_pins.mio7.into_output(PinState::Low);
|
||||
let led = Output::new_for_mio(mio_pins.mio7, PinState::Low);
|
||||
spawner.spawn(led_task(led)).unwrap();
|
||||
let mut log_buf: [u8; 2048] = [0; 2048];
|
||||
let frame_queue = zynq7000_hal::log::rb::get_frame_queue();
|
||||
@ -89,7 +87,7 @@ async fn main(spawner: Spawner) -> ! {
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn led_task(mut mio_led: MioPin<Mio7, Output>) {
|
||||
async fn led_task(mut mio_led: Output) {
|
||||
let mut ticker = Ticker::every(Duration::from_millis(1000));
|
||||
loop {
|
||||
mio_led.toggle().unwrap();
|
||||
|
@ -19,7 +19,7 @@ use zynq7000_hal::{
|
||||
BootMode,
|
||||
clocks::Clocks,
|
||||
gic::{GicConfigurator, GicInterruptHelper, Interrupt},
|
||||
gpio::{MioPins, PinState},
|
||||
gpio::{Output, PinState, mio},
|
||||
gtc::Gtc,
|
||||
time::Hertz,
|
||||
uart::{ClkConfigRaw, Uart, UartConfig},
|
||||
@ -54,7 +54,7 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
unsafe {
|
||||
gic.enable_interrupts();
|
||||
}
|
||||
let mio_pins = MioPins::new(dp.gpio);
|
||||
let mio_pins = mio::Pins::new(dp.gpio);
|
||||
|
||||
// Set up global timer counter and embassy time driver.
|
||||
let gtc = Gtc::new(dp.gtc, clocks.arm_clocks());
|
||||
@ -71,12 +71,10 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
let uart_clk_config = ClkConfigRaw::new_autocalc_with_error(clocks.io_clocks(), 115200)
|
||||
.unwrap()
|
||||
.0;
|
||||
let uart_tx = mio_pins.mio48.into_uart();
|
||||
let uart_rx = mio_pins.mio49.into_uart();
|
||||
let mut uart = Uart::new_with_mio(
|
||||
dp.uart_1,
|
||||
UartConfig::new_with_clk_config(uart_clk_config),
|
||||
(uart_tx, uart_rx),
|
||||
(mio_pins.mio48, mio_pins.mio49),
|
||||
)
|
||||
.unwrap();
|
||||
uart.write_all(b"-- Zynq 7000 Embassy Hello World --\n\r")
|
||||
@ -94,7 +92,7 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Boot mode: {:?}", boot_mode);
|
||||
|
||||
let mut ticker = Ticker::every(Duration::from_millis(1000));
|
||||
let mut led = mio_pins.mio7.into_output(PinState::Low);
|
||||
let mut led = Output::new_for_mio(mio_pins.mio7, PinState::Low);
|
||||
let mut current_duty = 0;
|
||||
loop {
|
||||
led.toggle().unwrap();
|
||||
|
@ -12,7 +12,7 @@ use zynq7000_hal::{
|
||||
BootMode,
|
||||
clocks::Clocks,
|
||||
gic::{GicConfigurator, GicInterruptHelper, Interrupt},
|
||||
gpio::{MioPins, PinState},
|
||||
gpio::{Output, PinState, mio},
|
||||
gtc::Gtc,
|
||||
time::Hertz,
|
||||
uart::{ClkConfigRaw, Uart, UartConfig},
|
||||
@ -48,7 +48,7 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
unsafe {
|
||||
gic.enable_interrupts();
|
||||
}
|
||||
let mio_pins = MioPins::new(dp.gpio);
|
||||
let mio_pins = mio::Pins::new(dp.gpio);
|
||||
|
||||
// Set up global timer counter and embassy time driver.
|
||||
let gtc = Gtc::new(dp.gtc, clocks.arm_clocks());
|
||||
@ -58,12 +58,10 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
let uart_clk_config = ClkConfigRaw::new_autocalc_with_error(clocks.io_clocks(), 115200)
|
||||
.unwrap()
|
||||
.0;
|
||||
let uart_tx = mio_pins.mio48.into_uart();
|
||||
let uart_rx = mio_pins.mio49.into_uart();
|
||||
let mut uart = Uart::new_with_mio(
|
||||
dp.uart_1,
|
||||
UartConfig::new_with_clk_config(uart_clk_config),
|
||||
(uart_tx, uart_rx),
|
||||
(mio_pins.mio48, mio_pins.mio49),
|
||||
)
|
||||
.unwrap();
|
||||
uart.write_all(b"-- Zynq 7000 Embassy Hello World --\n\r")
|
||||
@ -81,7 +79,7 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Boot mode: {:?}", boot_mode);
|
||||
|
||||
let mut ticker = Ticker::every(Duration::from_millis(1000));
|
||||
let mut led = mio_pins.mio7.into_output(PinState::Low);
|
||||
let mut led = Output::new_for_mio(mio_pins.mio7, PinState::Low);
|
||||
loop {
|
||||
info!("Hello, world!");
|
||||
led.toggle().unwrap();
|
||||
|
@ -10,7 +10,7 @@ use log::{error, info};
|
||||
use zynq7000_hal::{
|
||||
clocks::Clocks,
|
||||
gic::{GicConfigurator, GicInterruptHelper, Interrupt},
|
||||
gpio::{MioPins, PinState},
|
||||
gpio::{Output, PinState, mio},
|
||||
gtc::Gtc,
|
||||
prelude::*,
|
||||
time::Hertz,
|
||||
@ -58,13 +58,11 @@ pub fn main() -> ! {
|
||||
gtc.enable();
|
||||
|
||||
// This structure holds all MIO pins.
|
||||
let mio_pins = MioPins::new(dp.gpio);
|
||||
let uart_tx = mio_pins.mio48.into_uart();
|
||||
let uart_rx = mio_pins.mio49.into_uart();
|
||||
let mio_pins = mio::Pins::new(dp.gpio);
|
||||
let mut uart = Uart::new_with_mio(
|
||||
dp.uart_1,
|
||||
UartConfig::new_with_clk_config(uart_clk_config),
|
||||
(uart_tx, uart_rx),
|
||||
(mio_pins.mio48, mio_pins.mio49),
|
||||
)
|
||||
.unwrap();
|
||||
uart.write_all(b"-- Zynq 7000 GTC Ticks example --\n\r")
|
||||
@ -78,7 +76,7 @@ pub fn main() -> ! {
|
||||
)
|
||||
};
|
||||
|
||||
let mut led = mio_pins.mio7.into_output(PinState::Low);
|
||||
let mut led = Output::new_for_mio(mio_pins.mio7, PinState::Low);
|
||||
loop {
|
||||
info!(
|
||||
"MS_TICKS: {}",
|
||||
|
@ -11,7 +11,7 @@ use zynq7000_hal::{
|
||||
BootMode,
|
||||
clocks::Clocks,
|
||||
gic::{GicConfigurator, GicInterruptHelper, Interrupt},
|
||||
gpio::{MioPins, PinState},
|
||||
gpio::{Output, PinState, mio},
|
||||
gtc::Gtc,
|
||||
prelude::*,
|
||||
time::Hertz,
|
||||
@ -57,14 +57,12 @@ pub fn main() -> ! {
|
||||
gtc.enable_auto_increment();
|
||||
gtc.enable_interrupt();
|
||||
gtc.enable();
|
||||
let mio_pins = MioPins::new(dp.gpio);
|
||||
let uart_tx = mio_pins.mio48.into_uart();
|
||||
let uart_rx = mio_pins.mio49.into_uart();
|
||||
let mio_pins = mio::Pins::new(dp.gpio);
|
||||
|
||||
let mut uart = Uart::new_with_mio(
|
||||
dp.uart_1,
|
||||
UartConfig::new_with_clk_config(uart_clk_config),
|
||||
(uart_tx, uart_rx),
|
||||
(mio_pins.mio48, mio_pins.mio49),
|
||||
)
|
||||
.unwrap();
|
||||
uart.write_all(b"-- Zynq 7000 Logging example --\n\r")
|
||||
@ -81,7 +79,7 @@ pub fn main() -> ! {
|
||||
let boot_mode = BootMode::new();
|
||||
info!("Boot mode: {:?}", boot_mode);
|
||||
|
||||
let mut led = mio_pins.mio7.into_output(PinState::Low);
|
||||
let mut led = Output::new_for_mio(mio_pins.mio7, PinState::Low);
|
||||
loop {
|
||||
let gtc = gtc.read_timer();
|
||||
info!("Hello, world!");
|
||||
|
@ -6,7 +6,7 @@ use core::panic::PanicInfo;
|
||||
use cortex_ar::asm::nop;
|
||||
use embedded_hal::digital::StatefulOutputPin;
|
||||
use zynq7000::PsPeripherals;
|
||||
use zynq7000_hal::gpio::{MioPins, PinState};
|
||||
use zynq7000_hal::gpio::{Output, PinState, mio};
|
||||
use zynq7000_rt as _;
|
||||
|
||||
/// One user LED is MIO7
|
||||
@ -45,8 +45,8 @@ pub fn main() -> ! {
|
||||
}
|
||||
Lib::Hal => {
|
||||
let dp = PsPeripherals::take().unwrap();
|
||||
let mio_pins = MioPins::new(dp.gpio);
|
||||
let mut led = mio_pins.mio7.into_output(PinState::High);
|
||||
let mio_pins = mio::Pins::new(dp.gpio);
|
||||
let mut led = Output::new_for_mio(mio_pins.mio7, PinState::High);
|
||||
loop {
|
||||
led.toggle().unwrap();
|
||||
for _ in 0..5_000_000 {
|
||||
|
@ -11,7 +11,7 @@ keywords = ["no-std", "arm", "cortex-a", "amd", "zynq7000"]
|
||||
categories = ["embedded", "no-std", "hardware-support"]
|
||||
|
||||
[dependencies]
|
||||
cortex-ar = { git = "https://github.com/us-irs/cortex-ar.git", branch = "cortex-a-addition", features = ["critical-section-single-core"] }
|
||||
cortex-ar = { git = "https://github.com/rust-embedded/cortex-ar", branch = "main", features = ["critical-section-single-core"] }
|
||||
zynq7000-rt = { path = "../../zynq7000-rt" }
|
||||
zynq7000 = { path = "../../zynq7000" }
|
||||
zynq7000-hal = { path = "../../zynq7000-hal" }
|
||||
|
@ -22,7 +22,7 @@ use zynq7000_hal::{
|
||||
clocks::Clocks,
|
||||
configure_level_shifter,
|
||||
gic::{GicConfigurator, GicInterruptHelper, Interrupt},
|
||||
gpio::{EmioPin, GpioPins, PinState},
|
||||
gpio::{GpioPins, Output, PinState},
|
||||
gtc::Gtc,
|
||||
i2c,
|
||||
time::Hertz,
|
||||
@ -73,12 +73,10 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
let uart_clk_config = uart::ClkConfigRaw::new_autocalc_with_error(clocks.io_clocks(), 115200)
|
||||
.unwrap()
|
||||
.0;
|
||||
let uart_tx = gpio_pins.mio.mio48.into_uart();
|
||||
let uart_rx = gpio_pins.mio.mio49.into_uart();
|
||||
let mut uart = uart::Uart::new_with_mio(
|
||||
dp.uart_1,
|
||||
uart::UartConfig::new_with_clk_config(uart_clk_config),
|
||||
(uart_tx, uart_rx),
|
||||
(gpio_pins.mio.mio48, gpio_pins.mio.mio49),
|
||||
)
|
||||
.unwrap();
|
||||
uart.write_all(b"-- Zynq 7000 Zedboard I2C L3GD20H example --\n\r")
|
||||
@ -95,45 +93,48 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
let boot_mode = BootMode::new();
|
||||
info!("Boot mode: {:?}", boot_mode);
|
||||
|
||||
let sck_pin = gpio_pins.mio.mio12.into_i2c();
|
||||
let sda_pin = gpio_pins.mio.mio13.into_i2c();
|
||||
let pin_sel = match I2C_ADDR_SEL {
|
||||
I2cAddr::Sa0Low => PinState::Low,
|
||||
I2cAddr::Sa0High => PinState::High,
|
||||
};
|
||||
let _sa0_pin = gpio_pins.mio.mio11.into_output(pin_sel);
|
||||
let _sa0_pin = Output::new_for_mio(gpio_pins.mio.mio11, pin_sel);
|
||||
// The CS pin must be pulled high.
|
||||
let _cs_pin = gpio_pins.mio.mio10.into_output(PinState::High);
|
||||
let _cs_pin = Output::new_for_mio(gpio_pins.mio.mio10, PinState::High);
|
||||
|
||||
let clk_config = i2c::calculate_divisors(
|
||||
clocks.arm_clocks().cpu_1x_clk(),
|
||||
i2c::I2cSpeed::Normal100kHz,
|
||||
)
|
||||
.unwrap();
|
||||
let i2c = i2c::I2c::new_with_mio(dp.i2c_1, clk_config, (sck_pin, sda_pin)).unwrap();
|
||||
let i2c = i2c::I2c::new_with_mio(
|
||||
dp.i2c_1,
|
||||
clk_config,
|
||||
(gpio_pins.mio.mio12, gpio_pins.mio.mio13),
|
||||
)
|
||||
.unwrap();
|
||||
let mut l3gd20 = l3gd20::i2c::L3gd20::new(i2c, l3gd20::i2c::I2cAddr::Sa0Low).unwrap();
|
||||
let who_am_i = l3gd20.who_am_i().unwrap();
|
||||
info!("L3GD20 WHO_AM_I: 0x{:02X}", who_am_i);
|
||||
|
||||
let mut delay = Delay;
|
||||
let mut ticker = Ticker::every(Duration::from_millis(400));
|
||||
let mut mio_led = gpio_pins.mio.mio7.into_output(PinState::Low);
|
||||
let mut mio_led = Output::new_for_mio(gpio_pins.mio.mio7, PinState::Low);
|
||||
|
||||
let mut emio_leds: [EmioPin; 8] = [
|
||||
gpio_pins.emio.take(0).unwrap(),
|
||||
gpio_pins.emio.take(1).unwrap(),
|
||||
gpio_pins.emio.take(2).unwrap(),
|
||||
gpio_pins.emio.take(3).unwrap(),
|
||||
gpio_pins.emio.take(4).unwrap(),
|
||||
gpio_pins.emio.take(5).unwrap(),
|
||||
gpio_pins.emio.take(6).unwrap(),
|
||||
gpio_pins.emio.take(7).unwrap(),
|
||||
let mut emio_leds: [Output; 8] = [
|
||||
Output::new_for_emio(gpio_pins.emio.take(0).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(1).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(2).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(3).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(4).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(5).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(6).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(7).unwrap(), PinState::Low),
|
||||
];
|
||||
for (idx, led) in emio_leds.iter_mut().enumerate() {
|
||||
if idx % 2 == 0 {
|
||||
led.into_output(PinState::High);
|
||||
led.set_high();
|
||||
} else {
|
||||
led.into_output(PinState::Low);
|
||||
led.set_low();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ use zynq7000_hal::{
|
||||
clocks::Clocks,
|
||||
configure_level_shifter,
|
||||
gic::{GicConfigurator, GicInterruptHelper, Interrupt},
|
||||
gpio::{DynMioPin, EmioPin, GpioPins, PinState},
|
||||
gpio::{GpioPins, Output, PinState},
|
||||
gtc::Gtc,
|
||||
spi::{self, SpiAsync, SpiId, SpiWithHwCs, SpiWithHwCsAsync, on_interrupt},
|
||||
time::Hertz,
|
||||
@ -82,12 +82,10 @@ async fn main(spawner: Spawner) -> ! {
|
||||
let uart_clk_config = uart::ClkConfigRaw::new_autocalc_with_error(clocks.io_clocks(), 115200)
|
||||
.unwrap()
|
||||
.0;
|
||||
let uart_tx = gpio_pins.mio.mio48.into_uart();
|
||||
let uart_rx = gpio_pins.mio.mio49.into_uart();
|
||||
let mut uart = uart::Uart::new_with_mio(
|
||||
dp.uart_1,
|
||||
uart::UartConfig::new_with_clk_config(uart_clk_config),
|
||||
(uart_tx, uart_rx),
|
||||
(gpio_pins.mio.mio48, gpio_pins.mio.mio49),
|
||||
)
|
||||
.unwrap();
|
||||
uart.write_all(b"-- Zynq 7000 Zedboard SPI L3GD20H example --\n\r")
|
||||
@ -106,10 +104,6 @@ async fn main(spawner: Spawner) -> ! {
|
||||
spi_ref_clk_div
|
||||
);
|
||||
}
|
||||
let sck_pin = gpio_pins.mio.mio12.into_spi();
|
||||
let mosi_pin = gpio_pins.mio.mio10.into_spi();
|
||||
let miso_pin = gpio_pins.mio.mio11.into_spi();
|
||||
let ss_pin = gpio_pins.mio.mio13.into_spi();
|
||||
|
||||
let mut spi = spi::Spi::new_one_hw_cs(
|
||||
dp.spi_1,
|
||||
@ -121,8 +115,12 @@ async fn main(spawner: Spawner) -> ! {
|
||||
embedded_hal::spi::MODE_3,
|
||||
spi::SlaveSelectConfig::AutoWithAutoStart,
|
||||
),
|
||||
(sck_pin, mosi_pin, miso_pin),
|
||||
ss_pin,
|
||||
(
|
||||
gpio_pins.mio.mio12,
|
||||
gpio_pins.mio.mio10,
|
||||
gpio_pins.mio.mio11,
|
||||
),
|
||||
gpio_pins.mio.mio13,
|
||||
)
|
||||
.unwrap();
|
||||
let mod_id = spi.regs().read_mod_id();
|
||||
@ -138,24 +136,25 @@ async fn main(spawner: Spawner) -> ! {
|
||||
.build(),
|
||||
);
|
||||
|
||||
let mio_led = gpio_pins.mio.mio7.into_output(PinState::Low).downgrade();
|
||||
let mut emio_leds: [EmioPin; 8] = [
|
||||
gpio_pins.emio.take(0).unwrap(),
|
||||
gpio_pins.emio.take(1).unwrap(),
|
||||
gpio_pins.emio.take(2).unwrap(),
|
||||
gpio_pins.emio.take(3).unwrap(),
|
||||
gpio_pins.emio.take(4).unwrap(),
|
||||
gpio_pins.emio.take(5).unwrap(),
|
||||
gpio_pins.emio.take(6).unwrap(),
|
||||
gpio_pins.emio.take(7).unwrap(),
|
||||
let mio_led = Output::new_for_mio(gpio_pins.mio.mio7, PinState::Low);
|
||||
let mut emio_leds: [Output; 8] = [
|
||||
Output::new_for_emio(gpio_pins.emio.take(0).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(1).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(2).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(3).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(4).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(5).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(6).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(7).unwrap(), PinState::Low),
|
||||
];
|
||||
for (idx, led) in emio_leds.iter_mut().enumerate() {
|
||||
if idx % 2 == 0 {
|
||||
led.into_output(PinState::High);
|
||||
led.set_high();
|
||||
} else {
|
||||
led.into_output(PinState::Low);
|
||||
led.set_low();
|
||||
}
|
||||
}
|
||||
|
||||
spawner.spawn(logger_task(uart)).unwrap();
|
||||
if BLOCKING {
|
||||
blocking_application(mio_led, emio_leds, spi).await;
|
||||
@ -178,8 +177,8 @@ pub async fn logger_task(uart: uart::Uart) {
|
||||
}
|
||||
|
||||
pub async fn blocking_application(
|
||||
mut mio_led: DynMioPin,
|
||||
mut emio_leds: [EmioPin; 8],
|
||||
mut mio_led: Output,
|
||||
mut emio_leds: [Output; 8],
|
||||
spi: spi::Spi,
|
||||
) -> ! {
|
||||
let mut delay = Delay;
|
||||
@ -207,8 +206,8 @@ pub async fn blocking_application(
|
||||
}
|
||||
|
||||
pub async fn non_blocking_application(
|
||||
mut mio_led: DynMioPin,
|
||||
mut emio_leds: [EmioPin; 8],
|
||||
mut mio_led: Output,
|
||||
mut emio_leds: [Output; 8],
|
||||
spi: spi::Spi,
|
||||
) -> ! {
|
||||
let mut delay = Delay;
|
||||
|
@ -17,7 +17,7 @@ use zynq7000_hal::{
|
||||
clocks::Clocks,
|
||||
configure_level_shifter,
|
||||
gic::{GicConfigurator, GicInterruptHelper, Interrupt},
|
||||
gpio::{EmioPin, GpioPins, PinState},
|
||||
gpio::{GpioPins, Output, PinState},
|
||||
gtc::Gtc,
|
||||
uart::{ClkConfigRaw, Uart, UartConfig},
|
||||
};
|
||||
@ -50,13 +50,13 @@ pub enum UartSel {
|
||||
}
|
||||
|
||||
pub struct UartMultiplexer {
|
||||
sel_pins: [EmioPin; 3],
|
||||
sel_pins: [Output; 3],
|
||||
}
|
||||
|
||||
impl UartMultiplexer {
|
||||
pub fn new(mut sel_pins: [EmioPin; 3]) -> Self {
|
||||
pub fn new(mut sel_pins: [Output; 3]) -> Self {
|
||||
for pin in sel_pins.iter_mut() {
|
||||
pin.into_output(PinState::Low);
|
||||
pin.set_low();
|
||||
}
|
||||
Self { sel_pins }
|
||||
}
|
||||
@ -65,34 +65,34 @@ impl UartMultiplexer {
|
||||
// TODO: A pin group switcher would be nice to do this in one go.
|
||||
match sel {
|
||||
UartSel::Uart0 => {
|
||||
self.sel_pins[2].set_low().unwrap();
|
||||
self.sel_pins[1].set_low().unwrap();
|
||||
self.sel_pins[0].set_low().unwrap();
|
||||
self.sel_pins[2].set_low();
|
||||
self.sel_pins[1].set_low();
|
||||
self.sel_pins[0].set_low();
|
||||
}
|
||||
UartSel::Uartlite => {
|
||||
self.sel_pins[2].set_low().unwrap();
|
||||
self.sel_pins[1].set_low().unwrap();
|
||||
self.sel_pins[0].set_high().unwrap();
|
||||
self.sel_pins[2].set_low();
|
||||
self.sel_pins[1].set_low();
|
||||
self.sel_pins[0].set_high();
|
||||
}
|
||||
UartSel::Uart16550 => {
|
||||
self.sel_pins[2].set_low().unwrap();
|
||||
self.sel_pins[1].set_high().unwrap();
|
||||
self.sel_pins[0].set_low().unwrap();
|
||||
self.sel_pins[2].set_low();
|
||||
self.sel_pins[1].set_high();
|
||||
self.sel_pins[0].set_low();
|
||||
}
|
||||
UartSel::Uart0ToUartlite => {
|
||||
self.sel_pins[2].set_low().unwrap();
|
||||
self.sel_pins[1].set_high().unwrap();
|
||||
self.sel_pins[0].set_high().unwrap();
|
||||
self.sel_pins[2].set_low();
|
||||
self.sel_pins[1].set_high();
|
||||
self.sel_pins[0].set_high();
|
||||
}
|
||||
UartSel::Uart0ToUart16550 => {
|
||||
self.sel_pins[2].set_high().unwrap();
|
||||
self.sel_pins[1].set_low().unwrap();
|
||||
self.sel_pins[0].set_low().unwrap();
|
||||
self.sel_pins[2].set_high();
|
||||
self.sel_pins[1].set_low();
|
||||
self.sel_pins[0].set_low();
|
||||
}
|
||||
UartSel::UartliteToUart16550 => {
|
||||
self.sel_pins[2].set_high().unwrap();
|
||||
self.sel_pins[1].set_low().unwrap();
|
||||
self.sel_pins[0].set_high().unwrap();
|
||||
self.sel_pins[2].set_high();
|
||||
self.sel_pins[1].set_low();
|
||||
self.sel_pins[0].set_high();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -123,12 +123,10 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
let uart_clk_config = ClkConfigRaw::new_autocalc_with_error(clocks.io_clocks(), 115200)
|
||||
.unwrap()
|
||||
.0;
|
||||
let uart_tx = gpio_pins.mio.mio48.into_uart();
|
||||
let uart_rx = gpio_pins.mio.mio49.into_uart();
|
||||
let mut log_uart = Uart::new_with_mio(
|
||||
dp.uart_1,
|
||||
UartConfig::new_with_clk_config(uart_clk_config),
|
||||
(uart_tx, uart_rx),
|
||||
(gpio_pins.mio.mio48, gpio_pins.mio.mio49),
|
||||
)
|
||||
.unwrap();
|
||||
log_uart.write_all(INIT_STRING.as_bytes()).unwrap();
|
||||
@ -163,26 +161,23 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Boot mode: {:?}", boot_mode);
|
||||
|
||||
let mut ticker = Ticker::every(Duration::from_millis(1000));
|
||||
let mut mio_led = gpio_pins.mio.mio7.into_output(PinState::Low);
|
||||
|
||||
let mut emio_leds: [EmioPin; 8] = [
|
||||
gpio_pins.emio.take(0).unwrap(),
|
||||
gpio_pins.emio.take(1).unwrap(),
|
||||
gpio_pins.emio.take(2).unwrap(),
|
||||
gpio_pins.emio.take(3).unwrap(),
|
||||
gpio_pins.emio.take(4).unwrap(),
|
||||
gpio_pins.emio.take(5).unwrap(),
|
||||
gpio_pins.emio.take(6).unwrap(),
|
||||
gpio_pins.emio.take(7).unwrap(),
|
||||
let mut mio_led = Output::new_for_mio(gpio_pins.mio.mio7, PinState::Low);
|
||||
let mut emio_leds: [Output; 8] = [
|
||||
Output::new_for_emio(gpio_pins.emio.take(0).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(1).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(2).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(3).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(4).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(5).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(6).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(7).unwrap(), PinState::Low),
|
||||
];
|
||||
for led in emio_leds.iter_mut() {
|
||||
led.into_output(PinState::Low);
|
||||
}
|
||||
|
||||
let mut uart_mux = UartMultiplexer::new([
|
||||
gpio_pins.emio.take(8).unwrap(),
|
||||
gpio_pins.emio.take(9).unwrap(),
|
||||
gpio_pins.emio.take(10).unwrap(),
|
||||
Output::new_for_emio(gpio_pins.emio.take(8).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(9).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(10).unwrap(), PinState::Low),
|
||||
]);
|
||||
let mut current_sel = UartSel::Uart0;
|
||||
uart_mux.select(current_sel);
|
||||
|
@ -43,7 +43,7 @@ use zynq7000_hal::{
|
||||
clocks::Clocks,
|
||||
configure_level_shifter,
|
||||
gic::{GicConfigurator, GicInterruptHelper, Interrupt},
|
||||
gpio::{EmioPin, GpioPins, Mio7, MioPin, Output, PinState},
|
||||
gpio::{GpioPins, Output, PinState},
|
||||
gtc::Gtc,
|
||||
time::Hertz,
|
||||
uart::{ClkConfigRaw, Uart, UartConfig},
|
||||
@ -114,13 +114,13 @@ pub enum UartSel {
|
||||
}
|
||||
|
||||
pub struct UartMultiplexer {
|
||||
sel_pins: [EmioPin; 3],
|
||||
sel_pins: [Output; 3],
|
||||
}
|
||||
|
||||
impl UartMultiplexer {
|
||||
pub fn new(mut sel_pins: [EmioPin; 3]) -> Self {
|
||||
pub fn new(mut sel_pins: [Output; 3]) -> Self {
|
||||
for pin in sel_pins.iter_mut() {
|
||||
pin.into_output(PinState::Low);
|
||||
pin.set_low();
|
||||
}
|
||||
Self { sel_pins }
|
||||
}
|
||||
@ -129,38 +129,39 @@ impl UartMultiplexer {
|
||||
// TODO: A pin group switcher would be nice to do this in one go.
|
||||
match sel {
|
||||
UartSel::Uart0 => {
|
||||
self.sel_pins[2].set_low().unwrap();
|
||||
self.sel_pins[1].set_low().unwrap();
|
||||
self.sel_pins[0].set_low().unwrap();
|
||||
self.sel_pins[2].set_low();
|
||||
self.sel_pins[1].set_low();
|
||||
self.sel_pins[0].set_low();
|
||||
}
|
||||
UartSel::Uartlite => {
|
||||
self.sel_pins[2].set_low().unwrap();
|
||||
self.sel_pins[1].set_low().unwrap();
|
||||
self.sel_pins[0].set_high().unwrap();
|
||||
self.sel_pins[2].set_low();
|
||||
self.sel_pins[1].set_low();
|
||||
self.sel_pins[0].set_high();
|
||||
}
|
||||
UartSel::Uart16550 => {
|
||||
self.sel_pins[2].set_low().unwrap();
|
||||
self.sel_pins[1].set_high().unwrap();
|
||||
self.sel_pins[0].set_low().unwrap();
|
||||
self.sel_pins[2].set_low();
|
||||
self.sel_pins[1].set_high();
|
||||
self.sel_pins[0].set_low();
|
||||
}
|
||||
UartSel::Uart0ToUartlite => {
|
||||
self.sel_pins[2].set_low().unwrap();
|
||||
self.sel_pins[1].set_high().unwrap();
|
||||
self.sel_pins[0].set_high().unwrap();
|
||||
self.sel_pins[2].set_low();
|
||||
self.sel_pins[1].set_high();
|
||||
self.sel_pins[0].set_high();
|
||||
}
|
||||
UartSel::Uart0ToUart16550 => {
|
||||
self.sel_pins[2].set_high().unwrap();
|
||||
self.sel_pins[1].set_low().unwrap();
|
||||
self.sel_pins[0].set_low().unwrap();
|
||||
self.sel_pins[2].set_high();
|
||||
self.sel_pins[1].set_low();
|
||||
self.sel_pins[0].set_low();
|
||||
}
|
||||
UartSel::UartliteToUart16550 => {
|
||||
self.sel_pins[2].set_high().unwrap();
|
||||
self.sel_pins[1].set_low().unwrap();
|
||||
self.sel_pins[0].set_high().unwrap();
|
||||
self.sel_pins[2].set_high();
|
||||
self.sel_pins[1].set_low();
|
||||
self.sel_pins[0].set_high();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
#[unsafe(export_name = "main")]
|
||||
async fn main(spawner: Spawner) -> ! {
|
||||
@ -192,12 +193,10 @@ async fn main(spawner: Spawner) -> ! {
|
||||
let uart_clk_config = ClkConfigRaw::new_autocalc_with_error(clocks.io_clocks(), 115200)
|
||||
.unwrap()
|
||||
.0;
|
||||
let uart_tx = gpio_pins.mio.mio48.into_uart();
|
||||
let uart_rx = gpio_pins.mio.mio49.into_uart();
|
||||
let mut log_uart = Uart::new_with_mio(
|
||||
dp.uart_1,
|
||||
UartConfig::new_with_clk_config(uart_clk_config),
|
||||
(uart_tx, uart_rx),
|
||||
(gpio_pins.mio.mio48, gpio_pins.mio.mio49),
|
||||
)
|
||||
.unwrap();
|
||||
log_uart.write_all(INIT_STRING.as_bytes()).unwrap();
|
||||
@ -222,9 +221,9 @@ async fn main(spawner: Spawner) -> ! {
|
||||
|
||||
// Set up UART multiplexing before creating and configuring the UARTs.
|
||||
let mut uart_mux = UartMultiplexer::new([
|
||||
gpio_pins.emio.take(8).unwrap(),
|
||||
gpio_pins.emio.take(9).unwrap(),
|
||||
gpio_pins.emio.take(10).unwrap(),
|
||||
Output::new_for_emio(gpio_pins.emio.take(8).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(9).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(10).unwrap(), PinState::Low),
|
||||
]);
|
||||
match UART_MODE {
|
||||
UartMode::Uart0ToUartlite => uart_mux.select(UartSel::Uart0ToUartlite),
|
||||
@ -254,21 +253,17 @@ async fn main(spawner: Spawner) -> ! {
|
||||
let boot_mode = BootMode::new();
|
||||
info!("Boot mode: {:?}", boot_mode);
|
||||
|
||||
let mio_led = gpio_pins.mio.mio7.into_output(PinState::Low);
|
||||
|
||||
let mut emio_leds: [EmioPin; 8] = [
|
||||
gpio_pins.emio.take(0).unwrap(),
|
||||
gpio_pins.emio.take(1).unwrap(),
|
||||
gpio_pins.emio.take(2).unwrap(),
|
||||
gpio_pins.emio.take(3).unwrap(),
|
||||
gpio_pins.emio.take(4).unwrap(),
|
||||
gpio_pins.emio.take(5).unwrap(),
|
||||
gpio_pins.emio.take(6).unwrap(),
|
||||
gpio_pins.emio.take(7).unwrap(),
|
||||
let mio_led = Output::new_for_mio(gpio_pins.mio.mio7, PinState::Low);
|
||||
let emio_leds: [Output; 8] = [
|
||||
Output::new_for_emio(gpio_pins.emio.take(0).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(1).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(2).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(3).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(4).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(5).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(6).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(7).unwrap(), PinState::Low),
|
||||
];
|
||||
for led in emio_leds.iter_mut() {
|
||||
led.into_output(PinState::Low);
|
||||
}
|
||||
|
||||
let (uart_0_tx, mut uart_0_rx) = uart_0.split();
|
||||
let (uartlite_tx, _uartlite_rx) = uartlite.split();
|
||||
@ -353,7 +348,7 @@ fn build_print_string(prefix: &str, base_str: &str) -> alloc::string::String {
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn led_task(mut mio_led: MioPin<Mio7, Output>, mut emio_leds: [EmioPin; 8]) {
|
||||
async fn led_task(mut mio_led: Output, mut emio_leds: [Output; 8]) {
|
||||
let mut ticker = Ticker::every(Duration::from_millis(1000));
|
||||
let mut led_idx = 0;
|
||||
loop {
|
||||
|
@ -14,7 +14,7 @@ use zynq7000_hal::{
|
||||
clocks::Clocks,
|
||||
configure_level_shifter,
|
||||
gic::{GicConfigurator, GicInterruptHelper, Interrupt},
|
||||
gpio::{EmioPin, GpioPins, PinState},
|
||||
gpio::{GpioPins, Output, PinState},
|
||||
gtc::Gtc,
|
||||
uart::{ClkConfigRaw, Uart, UartConfig},
|
||||
};
|
||||
@ -59,12 +59,10 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
let uart_clk_config = ClkConfigRaw::new_autocalc_with_error(clocks.io_clocks(), 115200)
|
||||
.unwrap()
|
||||
.0;
|
||||
let uart_tx = gpio_pins.mio.mio48.into_uart();
|
||||
let uart_rx = gpio_pins.mio.mio49.into_uart();
|
||||
let mut uart = Uart::new_with_mio(
|
||||
dp.uart_1,
|
||||
UartConfig::new_with_clk_config(uart_clk_config),
|
||||
(uart_tx, uart_rx),
|
||||
(gpio_pins.mio.mio48, gpio_pins.mio.mio49),
|
||||
)
|
||||
.unwrap();
|
||||
uart.write_all(INIT_STRING.as_bytes()).unwrap();
|
||||
@ -81,21 +79,18 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Boot mode: {:?}", boot_mode);
|
||||
|
||||
let mut ticker = Ticker::every(Duration::from_millis(200));
|
||||
let mut mio_led = gpio_pins.mio.mio7.into_output(PinState::Low);
|
||||
|
||||
let mut emio_leds: [EmioPin; 8] = [
|
||||
gpio_pins.emio.take(0).unwrap(),
|
||||
gpio_pins.emio.take(1).unwrap(),
|
||||
gpio_pins.emio.take(2).unwrap(),
|
||||
gpio_pins.emio.take(3).unwrap(),
|
||||
gpio_pins.emio.take(4).unwrap(),
|
||||
gpio_pins.emio.take(5).unwrap(),
|
||||
gpio_pins.emio.take(6).unwrap(),
|
||||
gpio_pins.emio.take(7).unwrap(),
|
||||
let mut mio_led = Output::new_for_mio(gpio_pins.mio.mio7, PinState::Low);
|
||||
let mut emio_leds: [Output; 8] = [
|
||||
Output::new_for_emio(gpio_pins.emio.take(0).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(1).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(2).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(3).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(4).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(5).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(6).unwrap(), PinState::Low),
|
||||
Output::new_for_emio(gpio_pins.emio.take(7).unwrap(), PinState::Low),
|
||||
];
|
||||
for led in emio_leds.iter_mut() {
|
||||
led.into_output(PinState::Low);
|
||||
}
|
||||
loop {
|
||||
mio_led.toggle().unwrap();
|
||||
|
||||
|
Reference in New Issue
Block a user