Fix Pull Up/Down and test

This commit is contained in:
2025-05-26 14:37:13 +02:00
parent c9ab0bc885
commit 18233ec722
3 changed files with 35 additions and 19 deletions

View File

@@ -4,8 +4,9 @@
use core::{arch::asm, panic::PanicInfo};
use gpio::{gpio_high, gpio_low, set_gpio_state};
use gpio::{gpio_get_state, gpio_high, gpio_low, gpio_pull_up, set_gpio_state};
use timer::{delay_nops, sleep};
use uart::print;
mod gpio;
mod timer;
@@ -29,18 +30,20 @@ pub unsafe extern "C" fn _start() {
#[no_mangle]
extern "C" fn main() {
uart::configure_uart();
unsafe {
// Set ACT Led to Outout
let _ = set_gpio_state(29, gpio::GPIOState::Output);
// Set ACT Led to Outout
let _ = set_gpio_state(21, gpio::GPIOState::Output);
// Set GPIO Pins to UART
let _ = set_gpio_state(14, gpio::GPIOState::Alternative0);
let _ = set_gpio_state(15, gpio::GPIOState::Alternative0);
}
// Set GPIO Pins to UART
let _ = set_gpio_state(14, gpio::GPIOState::Alternative0);
let _ = set_gpio_state(15, gpio::GPIOState::Alternative0);
// Set GPIO 21 to Input
let _ = set_gpio_state(21, gpio::GPIOState::Input);
gpio_pull_up(21);
// Delay so clock speed can stabilize
delay_nops(50000);
uart::print("Hello World!\n");
uart::print("Hello World!\r\n");
sleep(500_000);
@@ -49,6 +52,18 @@ extern "C" fn main() {
sleep(500_000); // 0.5s
let _ = gpio_low(29);
sleep(500_000) // 0.5s
sleep(500_000); // 0.5s
print_gpio_state();
}
}
fn print_gpio_state() {
let state = gpio_get_state(21);
let ascii_byte = b'0' + state;
let data = [ascii_byte];
let s = str::from_utf8(&data).unwrap();
print(s);
print("\r\n");
}