8000 add "blinky" function to the arty-board with bio by samchin · Pull Request #663 · betrusted-io/xous-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add "blinky" function to the arty-board with bio #663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: baremetal
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions baremetal/src/arty_rgb.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use utralib::{Field, Register};

pub const RGB_NUMREGS: usize = 1;
pub const HW_RGB_BASE: usize = 0xf0000000;
pub const OUT: Register = Register::new(0, 0xfff);
pub const OUT_OUT: Field = Field::new(12, 0, OUT);
pub const LD0: Field = Field::new(3, 0, OUT);
pub const LD1: Field = Field::new(3, 3, OUT);
pub const LD2: Field = Field::new(3, 6, OUT);
pub const LD3: Field = Field::new(3, 9, OUT);
6 changes: 4 additions & 2 deletions baremetal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern crate alloc;
// contains runtime setup
mod asm;

pub mod arty_rgb;
mod platform;
mod repl;
use alloc::collections::VecDeque;
Expand Down Expand Up @@ -44,7 +45,7 @@ pub fn uart_irq_handler() {
pub unsafe extern "C" fn rust_entry() -> ! {
// turn on a green LED to indicate boot
let mut rgb = CSR::new(utra::rgb::HW_RGB_BASE as *mut u32);
rgb.wfo(utra::rgb::OUT_OUT, 0x002);
rgb.wfo(arty_rgb::LD3, 0b010);

crate::platform::early_init();
crate::println!("\n~~Baremetal up!~~\n");
Expand Down Expand Up @@ -76,7 +77,8 @@ pub unsafe extern "C" fn rust_entry() -> ! {
// Animate the LED flashing to indicate repl loop is running
delay(1);
count += 1;
rgb.wfo(utra::rgb::OUT_OUT, ((count / 500) as u32) << 6);

rgb.rmwf(arty_rgb::LD3, (count / 500) as u32);
}
}

Expand Down
80 changes: 76 additions & 4 deletions baremetal/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use alloc::vec::Vec;
use utralib::*;
use xous_bio_bdma::*;

use crate::arty_rgb;

pub struct Repl {
cmdline: String,
do_cmd: bool,
Expand Down Expand Up @@ -49,7 +51,7 @@ impl Repl {
match cmd.as_str() {
"mon" => {
let bio_ss = BioSharedState::new();
let mut rgb = CSR::new(utra::rgb::HW_RGB_BASE as *mut u32);
let mut rgb = CSR::new(arty_rgb::HW_RGB_BASE as *mut u32);
let mut count = 0;
let mut quit = false;
const TICKS_PER_PRINT: usize = 5;
Expand All @@ -65,7 +67,7 @@ impl Repl {
bio_ss.bio.r(utra::bio_bdma::SFR_DBG2),
bio_ss.bio.r(utra::bio_bdma::SFR_DBG3)
);
rgb.wfo(utra::rgb::OUT_OUT, (count / TICKS_PER_PRINT) as u32);
rgb.wfo(arty_rgb::OUT_OUT, (count / TICKS_PER_PRINT) as u32);
}
crate::platform::delay(TICK_MS);
count += 1;
Expand All @@ -85,9 +87,79 @@ impl Repl {
}
crate::println!("");
}

"blinky" => {
if args.len() != 2 {
crate::println!("Usage: blinky <LED_NAME> <RGB_HEX_VALUE>");
crate::println!("Example: blinky LD2 ff0000");
crate::println!("Available LEDs: LD0, LD1, LD2");
self.do_cmd = false;
self.cmdline.clear();
return;
}

let ld_name = &args[0];
let hex_code = &args[1];

let target_led_field = match ld_name.as_str() {
"LD0" => arty_rgb::LD0,
"LD1" => arty_rgb::LD1,
"LD2" => arty_rgb::LD2,
_ => {
crate::println!("Invalid LED name: {}. Use LD0, LD1, LD2.", ld_name);
self.cmdline.clear();
self.do_cmd = false;
return;
}
};

let color_val = if hex_code.starts_with("0x") {
u32::from_str_radix(&hex_code[2..], 16)
} else {
u32::from_str_radix(hex_code, 16)
};

match color_val {
Ok(color) => {
// convert 24-bit RRGGBB into 3-bit BGR
let r_msb = color & 0x800000;
let g_msb = color & 0x008000;
let b_msb = color & 0x000080;
let bgr_val = (b_msb >> 6) | (g_msb >> 13) | (r_msb >> 23);

let mut rgb = CSR::new(arty_rgb::HW_RGB_BASE as *mut u32);

rgb.rmwf(target_led_field, bgr_val);

crate::println!(
"Set {} to BGR value 0b{:03b} (from hex {}).",
ld_name,
bgr_val,
hex_code
);
}
Err(_) => {
crate::println!("Invalid hex color value: {}", hex_code);
}
}
}
"help" => {
crate::println!("Available commands:");
crate::println!(" help - Shows this help message.");
crate::println!(" echo [ARGS] - Prints the arguments to the console.");
crate::println!(
" mon - Monitors the program counters of the BIO cores."
);
crate::println!(" blinky <LD> <RGB_HEX> - Sets an LED to a color.");
crate::println!(" LD: LD0, LD1, or LD2");
crate::println!(" RGB_HEX: e.g., ff0000 (red), 00ff00 (green), 0000ff (blue)");
}

"" => {}

_ => {
crate::println!("Command not recognized: {}", cmd);
crate::println!("Commands include: echo, mon");
crate::println!("Command not recognized: '{}'", cmd);
crate::println!("Type 'help' for a list of commands.");
}
}

Expand Down
0