forked from NaxdyOrg/NaxGCC-FW
get to a working state with multicore
This commit is contained in:
parent
6ba86985d5
commit
eacb979c61
5 changed files with 67 additions and 27 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -167,6 +167,12 @@ dependencies = [
|
|||
"void",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "format_no_std"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2d8ca877c98f19024674b6959301d81d3708c417823fa050692b45b54d74fe7d"
|
||||
|
||||
[[package]]
|
||||
name = "frunk"
|
||||
version = "0.4.2"
|
||||
|
@ -264,6 +270,7 @@ dependencies = [
|
|||
"defmt",
|
||||
"defmt-rtt",
|
||||
"embedded-hal",
|
||||
"format_no_std",
|
||||
"fugit",
|
||||
"packed_struct",
|
||||
"panic-halt",
|
||||
|
|
|
@ -20,6 +20,7 @@ rp2040-boot2 = "0.3.0"
|
|||
fugit = "0.3.7"
|
||||
packed_struct = { version = "0.10.1", default_features = false }
|
||||
panic-halt = "0.2.0"
|
||||
format_no_std = "1.0.2"
|
||||
|
||||
# cargo build/run
|
||||
[profile.dev]
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use core::default::Default;
|
||||
|
||||
use defmt::{error, info, unwrap, Debug2Format};
|
||||
use defmt::{error, info, unwrap, Debug2Format, Format};
|
||||
use embedded_hal::timer::CountDown as _;
|
||||
use fugit::ExtU32;
|
||||
use packed_struct::{derive::PackedStruct, PackedStruct};
|
||||
use rp2040_flash::flash::flash_unique_id;
|
||||
use rp2040_hal::timer::CountDown;
|
||||
use usb_device::{
|
||||
bus::{UsbBus, UsbBusAllocator},
|
||||
|
@ -20,7 +21,7 @@ use usbd_human_interface_device::{
|
|||
UsbHidError,
|
||||
};
|
||||
|
||||
use crate::input::GCC_STATE;
|
||||
use crate::{input::GCC_STATE, CORE_LOCK, LOCKED};
|
||||
|
||||
#[rustfmt::skip]
|
||||
pub const GCC_REPORT_DESCRIPTOR: &[u8] = &[
|
||||
|
@ -79,7 +80,7 @@ pub const GCC_REPORT_DESCRIPTOR: &[u8] = &[
|
|||
0xC0, // End Collection
|
||||
];
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, PackedStruct)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, PackedStruct, Format)]
|
||||
#[packed_struct(bit_numbering = "lsb0", size_bytes = "1")]
|
||||
pub struct Buttons1 {
|
||||
#[packed_field(bits = "0")]
|
||||
|
@ -100,7 +101,7 @@ pub struct Buttons1 {
|
|||
pub dpad_up: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, PackedStruct)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, PackedStruct, Format)]
|
||||
#[packed_struct(bit_numbering = "lsb0", size_bytes = "1")]
|
||||
pub struct Buttons2 {
|
||||
#[packed_field(bits = "0")]
|
||||
|
@ -115,7 +116,7 @@ pub struct Buttons2 {
|
|||
pub blank1: u8,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, PackedStruct)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, PackedStruct, Format)]
|
||||
#[packed_struct(bit_numbering = "msb0", size_bytes = "8")]
|
||||
pub struct GcReport {
|
||||
#[packed_field(bits = "0..=7")]
|
||||
|
@ -248,17 +249,35 @@ pub fn usb_transfer_loop<'a, T: UsbBus>(
|
|||
usb_bus: UsbBusAllocator<T>,
|
||||
mut poll_timer: CountDown<'a>,
|
||||
) -> ! {
|
||||
info!("Got to this point");
|
||||
// let mut serial_buffer = [0u8; 64];
|
||||
|
||||
// let serial = unsafe {
|
||||
// let mut id = [0u8; 8];
|
||||
|
||||
// flash_unique_id(&mut id, true);
|
||||
|
||||
// let s = format_no_std::show(
|
||||
// &mut serial_buffer,
|
||||
// format_args!(
|
||||
// "{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}",
|
||||
// id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7]
|
||||
// ),
|
||||
// )
|
||||
// .unwrap();
|
||||
|
||||
// info!("Detected flash with unique serial number {}", s);
|
||||
|
||||
// s
|
||||
// };
|
||||
|
||||
let mut gcc = UsbHidClassBuilder::new()
|
||||
.add_device(GcConfig::default())
|
||||
.build(&usb_bus);
|
||||
|
||||
info!("Got the gc");
|
||||
|
||||
let mut usb_dev = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x057e, 0x0337))
|
||||
.manufacturer("Naxdy")
|
||||
.product("NaxGCC")
|
||||
.serial_number("fleeb") // TODO: Get this from the flash unique id
|
||||
.serial_number("flarn")
|
||||
.device_class(0)
|
||||
.device_protocol(0)
|
||||
.device_sub_class(0)
|
||||
|
@ -272,6 +291,10 @@ pub fn usb_transfer_loop<'a, T: UsbBus>(
|
|||
info!("Got here");
|
||||
|
||||
loop {
|
||||
if unsafe { LOCKED } {
|
||||
continue;
|
||||
}
|
||||
|
||||
if poll_timer.wait().is_ok() {
|
||||
match gcc.device().write_report(&(unsafe { GCC_STATE })) {
|
||||
Err(UsbHidError::WouldBlock) => {}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use embedded_hal::digital::{v2::InputPin, v2::IoPin};
|
||||
use rp2040_hal::gpio::{FunctionSpi, Pin, PinId, PullDown};
|
||||
use defmt::info;
|
||||
use embedded_hal::digital::v2::InputPin;
|
||||
|
||||
use crate::gcc_hid::{Buttons1, Buttons2, GcReport};
|
||||
|
||||
|
@ -83,6 +83,8 @@ pub fn input_loop<
|
|||
>(
|
||||
basic_inputs: BasicInputs<A, B, X, Y, Dl, Dr, Dd, Du, S, Z, R, L>,
|
||||
) -> ! {
|
||||
info!("Input loop started.");
|
||||
|
||||
let update_gcc_state = || unsafe {
|
||||
// simple booleans
|
||||
assign_pins!(GCC_STATE, basic_inputs, {
|
||||
|
|
39
src/main.rs
39
src/main.rs
|
@ -12,16 +12,17 @@ mod flash_mem;
|
|||
mod gcc_hid;
|
||||
mod input;
|
||||
|
||||
use cortex_m::interrupt::Mutex;
|
||||
use defmt::{error, info};
|
||||
use gcc_hid::GcConfig;
|
||||
|
||||
use fugit::{ExtU32, RateExtU32};
|
||||
|
||||
// Ensure we halt the program on panic (if we don't mention this crate it won't
|
||||
// be linked)
|
||||
use defmt_rtt as _;
|
||||
use panic_halt as _;
|
||||
use panic_probe as _;
|
||||
|
||||
use rp2040_flash::flash::flash_unique_id;
|
||||
// Alias for our HAL crate
|
||||
use rp2040_hal as hal;
|
||||
|
||||
|
@ -29,23 +30,19 @@ use rp2040_hal as hal;
|
|||
// register access
|
||||
use hal::{
|
||||
gpio::FunctionSpi,
|
||||
multicore::{Multicore, Stack},
|
||||
multicore::{self, Multicore, Stack},
|
||||
pac, Spi,
|
||||
};
|
||||
|
||||
// Some traits we need
|
||||
use embedded_hal::{
|
||||
blocking::spi::Transfer,
|
||||
blocking::{delay::DelayMs, spi::Transfer},
|
||||
digital::v2::OutputPin,
|
||||
spi::{FullDuplex, MODE_0},
|
||||
spi::MODE_0,
|
||||
timer::CountDown,
|
||||
};
|
||||
|
||||
use usb_device::{
|
||||
bus::UsbBusAllocator,
|
||||
device::{UsbDeviceBuilder, UsbVidPid},
|
||||
};
|
||||
use usbd_human_interface_device::usb_class::UsbHidClassBuilder;
|
||||
use usb_device::bus::UsbBusAllocator;
|
||||
|
||||
use crate::{
|
||||
flash_mem::{read_from_flash, write_to_flash},
|
||||
|
@ -55,6 +52,10 @@ use crate::{
|
|||
|
||||
static mut CORE1_STACK: Stack<4096> = Stack::new();
|
||||
|
||||
pub static mut LOCKED: bool = false;
|
||||
|
||||
pub static CORE_LOCK: Mutex<()> = Mutex::new(());
|
||||
|
||||
/// 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.
|
||||
/// Note: This boot block is not necessary when using a rp-hal based BSP
|
||||
|
@ -95,7 +96,7 @@ fn main() -> ! {
|
|||
.ok()
|
||||
.unwrap();
|
||||
|
||||
let timer = rp2040_hal::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks);
|
||||
let mut timer = rp2040_hal::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks);
|
||||
|
||||
// The single-cycle I/O block controls our GPIO pins
|
||||
let mut sio = hal::Sio::new(pac.SIO);
|
||||
|
@ -118,9 +119,6 @@ fn main() -> ! {
|
|||
));
|
||||
|
||||
unsafe {
|
||||
let some_byte: u8 = 0xAB;
|
||||
info!("Byte to be written is {:02X}", some_byte);
|
||||
write_to_flash(some_byte);
|
||||
let r = read_from_flash();
|
||||
info!("Byte read from flash is {:02X}", r);
|
||||
}
|
||||
|
@ -143,8 +141,8 @@ fn main() -> ! {
|
|||
let mut ccs = pins.gpio23.into_push_pull_output();
|
||||
let mut acs = pins.gpio24.into_push_pull_output();
|
||||
|
||||
ccs.set_low();
|
||||
acs.set_low();
|
||||
ccs.set_high().unwrap();
|
||||
acs.set_high().unwrap();
|
||||
|
||||
let spi_device = pac.SPI0;
|
||||
|
||||
|
@ -176,6 +174,15 @@ fn main() -> ! {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe {
|
||||
LOCKED = true;
|
||||
timer.delay_ms(100);
|
||||
let some_byte: u8 = 0xAB;
|
||||
info!("Byte to be written is {:02X}", some_byte);
|
||||
write_to_flash(some_byte);
|
||||
LOCKED = false;
|
||||
}
|
||||
|
||||
input_loop(BasicInputs {
|
||||
button_a: pins.gpio17.into_pull_up_input(),
|
||||
button_b: pins.gpio16.into_pull_up_input(),
|
||||
|
|
Loading…
Reference in a new issue