mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
commit
aad14c2cca
5 changed files with 47 additions and 25 deletions
|
|
@ -17,7 +17,7 @@ impl<'a> ShellCmdApi<'a> for Touch {
|
||||||
fn process(&mut self, args: String, env: &mut super::CommonEnv) -> Result<Option<String>, xous::Error> {
|
fn process(&mut self, args: String, env: &mut super::CommonEnv) -> Result<Option<String>, xous::Error> {
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
let mut ret = String::new();
|
let mut ret = String::new();
|
||||||
let helpstring = "ws2812 [rainbow [<duration>]] [length <pixels>] [hexcolor <#rrggbb>]";
|
let helpstring = "touch [pin] [monitor] [wait-touch] [wait-release] [touch-release]";
|
||||||
|
|
||||||
let mut tokens = args.split(' ');
|
let mut tokens = args.split(' ');
|
||||||
|
|
||||||
|
|
@ -34,7 +34,7 @@ impl<'a> ShellCmdApi<'a> for Touch {
|
||||||
let mut captouch = bio_lib::captouch::Captouch::new(self.pin, None).unwrap();
|
let mut captouch = bio_lib::captouch::Captouch::new(self.pin, None).unwrap();
|
||||||
captouch.calibrate(None).unwrap();
|
captouch.calibrate(None).unwrap();
|
||||||
loop {
|
loop {
|
||||||
log::info!("{:?}, {}", captouch.is_touched(), captouch.raw_status());
|
log::info!("{}", captouch.raw_status());
|
||||||
env.ticktimer.sleep_ms(100).ok();
|
env.ticktimer.sleep_ms(100).ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,8 @@ impl<'a> ShellCmdApi<'a> for Ws2812 {
|
||||||
fn process(&mut self, args: String, env: &mut super::CommonEnv) -> Result<Option<String>, xous::Error> {
|
fn process(&mut self, args: String, env: &mut super::CommonEnv) -> Result<Option<String>, xous::Error> {
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
let mut ret = String::new();
|
let mut ret = String::new();
|
||||||
let helpstring = "ws2812 [rainbow [<duration>]] [length <pixels>] [hexcolor <#rrggbb>]";
|
let helpstring =
|
||||||
|
"ws2812 [rainbow [<duration>]] [touch [<duration>]] [length <pixels>] [hexcolor <#rrggbb>]";
|
||||||
|
|
||||||
let mut tokens = args.split(' ');
|
let mut tokens = args.split(' ');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -893,13 +893,14 @@ impl Repl {
|
||||||
let iox = Iox::new(utra::iox::HW_IOX_BASE as *mut u32);
|
let iox = Iox::new(utra::iox::HW_IOX_BASE as *mut u32);
|
||||||
let (power_port, power_pin) = bao1x_hal::board::setup_trng_power_pin(&iox);
|
let (power_port, power_pin) = bao1x_hal::board::setup_trng_power_pin(&iox);
|
||||||
let bio_input = bao1x_hal::board::setup_trng_input_pin(&iox);
|
let bio_input = bao1x_hal::board::setup_trng_input_pin(&iox);
|
||||||
|
let bio_mask = bao1x_api::bio::port_and_pin_to_bio_bit(bio_input.0, bio_input.1).unwrap();
|
||||||
// turn on the system
|
// turn on the system
|
||||||
iox.set_gpio_pin_value(power_port, power_pin, IoxValue::High);
|
iox.set_gpio_pin_value(power_port, power_pin, IoxValue::High);
|
||||||
|
|
||||||
let mut bio_ss = BioSharedState::new();
|
let mut bio_ss = BioSharedState::new();
|
||||||
bio_ss.init();
|
bio_ss.init();
|
||||||
crate::println!("bio_input: {}", bio_input);
|
crate::println!("bio_input: {}", bio_mask.value());
|
||||||
crate::avtrng::setup(&mut bio_ss, bio_input);
|
crate::avtrng::setup(&mut bio_ss, bio_mask.value());
|
||||||
|
|
||||||
crate::println!("====AVSTART====");
|
crate::println!("====AVSTART====");
|
||||||
const BUFLEN: usize = 256;
|
const BUFLEN: usize = 256;
|
||||||
|
|
|
||||||
|
|
@ -249,26 +249,41 @@ bio_code!(
|
||||||
CAPTOUCH_SENSE_START,
|
CAPTOUCH_SENSE_START,
|
||||||
CAPTOUCH_SENSE_END,
|
CAPTOUCH_SENSE_END,
|
||||||
|
|
||||||
"mv t0, x19", // Load pin mask into register t0.
|
"mv x5, x19", // Load pin mask into register x5.
|
||||||
"mv x26, t0", // Set GPIO mask to our pin.
|
"mv x26, x5", // Set GPIO mask to our pin.
|
||||||
"10:", // start of sensor loop
|
"10:", // start of sensor loop
|
||||||
"mv x24, t0", // Configure pin as an OUTPUT.
|
"mv x24, x5", // Configure pin as an OUTPUT.
|
||||||
"mv x23, x0", // Drive pin LOW.
|
"mv x23, x0", // Drive pin LOW.
|
||||||
|
|
||||||
"li t3, 0x200",
|
"li x6, 0x100",
|
||||||
"20:", // wait loop for "low" settling
|
"20:", // wait loop for "low" settling - this can be made much shorter if needed
|
||||||
"addi t3, t3, -1",
|
// as it is, the sampling rate is about 236kHz, which is already quite high
|
||||||
"bne t3, x0, 20b",
|
"addi x6, x6, -1",
|
||||||
|
"bne x6, x0, 20b",
|
||||||
|
|
||||||
"mv s0, x31", // remember aclk time
|
"mv x7, x31", // remember aclk time
|
||||||
"mv x25, t0", // make it an input
|
"mv x25, x5", // make it an input
|
||||||
// now, the pull-up on the pin will slowly charge the capacitance on the pin. We wait
|
// now, the pull-up on the pin will slowly charge the capacitance on the pin. We wait
|
||||||
// for the rising edge to be detected and that is our captouch interval
|
// for the rising edge to be detected and that is our captouch interval
|
||||||
"mv x20, x0", // wait for quantum: based on EXTCLK rising edge on the configured pin
|
"mv x20, x0", // wait for quantum: based on EXTCLK rising edge on the configured pin
|
||||||
|
|
||||||
"mv s1, x31", // remember aclk time
|
"mv x8, x31", // remember aclk time
|
||||||
"sub t2, s1, s0",
|
|
||||||
"mv x19, t2", // report the delta-t
|
// mask out core ID
|
||||||
|
"li x10, 0x3FFFFFFF", // x10 is re-used in roll-over computation below
|
||||||
|
"and x7, x7, x10",
|
||||||
|
"and x8, x8, x10",
|
||||||
|
|
||||||
|
// handle roll-over case: x7 is greater than x8 in the case of roll-over
|
||||||
|
"bgtu x7, x8, 30f",
|
||||||
|
"sub x9, x8, x7", // total cycles is x8 - x7
|
||||||
|
"j 40f",
|
||||||
|
"30:", // roll-over path
|
||||||
|
"sub x10, x10, x7", // x10 now contains cycles from max versus start
|
||||||
|
"add x9, x10, x8", // total cycles is x10 + x8 (masked)
|
||||||
|
|
||||||
|
"40:",
|
||||||
|
"mv x19, x9", // report the delta-t
|
||||||
// the line below keeps us from blocking on the FIFO being full - we steal our own entry
|
// the line below keeps us from blocking on the FIFO being full - we steal our own entry
|
||||||
// and cause the host to read the stale value in the FIFO.
|
// and cause the host to read the stale value in the FIFO.
|
||||||
"mv x0, x19", // drain the FIFO entry - host will read the "stale" empty entry
|
"mv x0, x19", // drain the FIFO entry - host will read the "stale" empty entry
|
||||||
|
|
|
||||||
|
|
@ -171,7 +171,7 @@ bio_code!(ws2812b_kernel, WS2812B_START, WS2812B_END,
|
||||||
// LEDs will go onto the stack
|
// LEDs will go onto the stack
|
||||||
"li x9, 0x1000000", // bit 24 mask
|
"li x9, 0x1000000", // bit 24 mask
|
||||||
"li sp, 0x800", // start of the LED buffer
|
"li sp, 0x800", // start of the LED buffer
|
||||||
"10:",
|
"10:",
|
||||||
// read a 24-bit color number from FIFO1
|
// read a 24-bit color number from FIFO1
|
||||||
"mv x8, x17",
|
"mv x8, x17",
|
||||||
"sw x8, 0(sp)",
|
"sw x8, 0(sp)",
|
||||||
|
|
@ -181,19 +181,24 @@ bio_code!(ws2812b_kernel, WS2812B_START, WS2812B_END,
|
||||||
"j 10b", // go back and get more data
|
"j 10b", // go back and get more data
|
||||||
|
|
||||||
// -- sending loop --
|
// -- sending loop --
|
||||||
"20:",
|
"20:",
|
||||||
"li x8, 0x800", // x8 now has the starting address of the data we're going to send
|
"li x8, 0x800", // x8 now has the starting address of the data we're going to send
|
||||||
// x9 is the bit 24 mask used by the above loop
|
// x9 is the bit 24 mask used by the above loop
|
||||||
"li x12, 0x800000", // bit 23 mask
|
"li x12, 0x800000", // bit 23 mask
|
||||||
// loop setup done
|
// loop setup done
|
||||||
"30:",
|
"30:",
|
||||||
"li x11, 24", // number of bits to shift through
|
"li x11, 24", // number of bits to shift through
|
||||||
"lw x10, 0(x8)", // fetch the word to send
|
"lw x10, 0(x8)", // fetch the word to send
|
||||||
// "mv x18, x10", // debug by looping back -----------
|
// "mv x18, x10", // debug by looping back -----------
|
||||||
"31:",
|
"31:",
|
||||||
"and x13, x12, x10", // the bit we're contemplating is at bit 23 position, extract it into x13
|
"and x13, x12, x10", // the bit we're contemplating is at bit 23 position, extract it into x13
|
||||||
"bne x13, x0, 40f", // if 1, go to 40f, where the 1 routine is
|
"bne x13, x0, 40f", // if 1, go to 40f, where the 1 routine is
|
||||||
|
|
||||||
|
"mv x20, x0", // snap to quantum before doing the send routine - this improves timing uniformity of high pulses
|
||||||
|
// at the expense of T1L time being a little out of spec, but this is better-tolerated than T0H time being variable.
|
||||||
|
// this quantum snap has to be introduced here because snap quantum to output makes the ws2812 driver not
|
||||||
|
// composable with other BIO applications
|
||||||
|
|
||||||
// zero routine
|
// zero routine
|
||||||
// 2 hi
|
// 2 hi
|
||||||
"mv x22, x4", // sets to 1
|
"mv x22, x4", // sets to 1
|
||||||
|
|
@ -214,7 +219,7 @@ bio_code!(ws2812b_kernel, WS2812B_START, WS2812B_END,
|
||||||
"j 50f", // jump to the loop end check
|
"j 50f", // jump to the loop end check
|
||||||
|
|
||||||
// one routine
|
// one routine
|
||||||
"40:",
|
"40:",
|
||||||
// 7 hi
|
// 7 hi
|
||||||
"mv x22, x4", // sets to 1
|
"mv x22, x4", // sets to 1
|
||||||
"mv x20, x0", // wait for quantum
|
"mv x20, x0", // wait for quantum
|
||||||
|
|
@ -232,16 +237,16 @@ bio_code!(ws2812b_kernel, WS2812B_START, WS2812B_END,
|
||||||
"addi x11, x11, -1", // decrement the pixel bit counter
|
"addi x11, x11, -1", // decrement the pixel bit counter
|
||||||
"mv x20, x0",
|
"mv x20, x0",
|
||||||
|
|
||||||
"50:", // shift and do the next pixel value
|
"50:", // shift and do the next pixel value
|
||||||
"bne x11, x0, 31b", // go back for more in the loop
|
"bne x11, x0, 31b", // go back for more in the loop
|
||||||
|
|
||||||
"60:", // check if we've exhausted all the LED values
|
"60:", // check if we've exhausted all the LED values
|
||||||
"addi x8, x8, 4",
|
"addi x8, x8, 4",
|
||||||
"bge sp, x8, 30b", // see if we've hit the value of current sp
|
"bge sp, x8, 30b", // see if we've hit the value of current sp
|
||||||
"li sp, 0x800", // reset the stack pointer for a fresh fetch
|
"li sp, 0x800", // reset the stack pointer for a fresh fetch
|
||||||
// wait to reset the chain
|
// wait to reset the chain
|
||||||
"li x14, 2000", // delay wait time to reset the chain per spec
|
"li x14, 2000", // delay wait time to reset the chain per spec
|
||||||
"70:",
|
"70:",
|
||||||
"addi x14, x14, -1",
|
"addi x14, x14, -1",
|
||||||
"mv x20, x0",
|
"mv x20, x0",
|
||||||
"bne x14, x0, 70b",
|
"bne x14, x0, 70b",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue