finish firmware & add build script
This commit is contained in:
parent
66e589bc26
commit
f227ded675
6 changed files with 131 additions and 92 deletions
39
Cargo.lock
generated
39
Cargo.lock
generated
|
@ -127,15 +127,6 @@ dependencies = [
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crc-any"
|
|
||||||
version = "2.4.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "774646b687f63643eb0f4bf13dc263cb581c8c9e57973b6ddf78bda3994d88df"
|
|
||||||
dependencies = [
|
|
||||||
"debug-helper",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "critical-section"
|
name = "critical-section"
|
||||||
version = "1.1.1"
|
version = "1.1.1"
|
||||||
|
@ -148,12 +139,6 @@ version = "0.2.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
|
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "debug-helper"
|
|
||||||
version = "0.3.13"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f578e8e2c440e7297e008bb5486a3a8a194775224bbc23729b0dbdfaeebf162e"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "defmt"
|
name = "defmt"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
|
@ -623,29 +608,6 @@ version = "0.6.29"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
|
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rp-pico"
|
|
||||||
version = "0.7.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "aab28f6f4e19cec2d61b64cdd685e69794b81c579fd3b765579c46018fe616d0"
|
|
||||||
dependencies = [
|
|
||||||
"cortex-m",
|
|
||||||
"cortex-m-rt",
|
|
||||||
"fugit",
|
|
||||||
"rp2040-boot2",
|
|
||||||
"rp2040-hal",
|
|
||||||
"usb-device",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rp2040-boot2"
|
|
||||||
version = "0.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3c773ec49b836077aa144b58dc7654a243e1eecdb6cf0d25361ae7c7600fabd8"
|
|
||||||
dependencies = [
|
|
||||||
"crc-any",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rp2040-hal"
|
name = "rp2040-hal"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
|
@ -713,7 +675,6 @@ dependencies = [
|
||||||
"panic-probe",
|
"panic-probe",
|
||||||
"pio",
|
"pio",
|
||||||
"pio-proc",
|
"pio-proc",
|
||||||
"rp-pico",
|
|
||||||
"rp2040-hal",
|
"rp2040-hal",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ defmt-rtt = "0.4.0"
|
||||||
panic-probe = { version = "0.3.0", features = ["print-defmt"] }
|
panic-probe = { version = "0.3.0", features = ["print-defmt"] }
|
||||||
|
|
||||||
# We're using a Pico by default on this template
|
# We're using a Pico by default on this template
|
||||||
rp-pico = "0.7.0"
|
|
||||||
rp2040-hal = { version="0.8", features=["rt", "critical-section-impl"] }
|
rp2040-hal = { version="0.8", features=["rt", "critical-section-impl"] }
|
||||||
|
|
||||||
pio-proc = "0.2"
|
pio-proc = "0.2"
|
||||||
|
|
3
build.sh
Executable file
3
build.sh
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
(cargo build --target thumbv6m-none-eabi --release && elf2uf2-rs target/thumbv6m-none-eabi/release/rustgcc) || echo "Build failed."
|
153
src/gccstate.rs
153
src/gccstate.rs
|
@ -1,5 +1,11 @@
|
||||||
use embedded_hal::digital::v2::InputPin;
|
use embedded_hal::digital::v2::InputPin;
|
||||||
use rp2040_hal::gpio::{bank0::*, Pin, PinId, PullUp, PullUpInput};
|
use rp2040_hal::gpio::{bank0::*, Pin, PullUpInput};
|
||||||
|
|
||||||
|
const MOD1_POS_VAL: u8 = 186; // 127 + 69 (max walk is 69)
|
||||||
|
const MOD1_NEG_VAL: u8 = 68; // 127 - 69
|
||||||
|
|
||||||
|
const MOD2_POS_VAL: u8 = 159;
|
||||||
|
const MOD2_NEG_VAL: u8 = 95;
|
||||||
|
|
||||||
macro_rules! determine_stick_state {
|
macro_rules! determine_stick_state {
|
||||||
($previous_state:ident, $current_state:ident, $button:ident) => {
|
($previous_state:ident, $current_state:ident, $button:ident) => {
|
||||||
|
@ -16,20 +22,54 @@ macro_rules! determine_stick_state {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! get_current_positive_val {
|
||||||
|
($pin_state:ident, $pin_axis:ident, $modifier_state:ident) => {
|
||||||
|
match $pin_state.$pin_axis {
|
||||||
|
true => match $modifier_state {
|
||||||
|
ModifierState::MOD1 => MOD1_POS_VAL,
|
||||||
|
ModifierState::MOD2 => MOD2_POS_VAL,
|
||||||
|
ModifierState::NONE => 255,
|
||||||
|
},
|
||||||
|
false => 127,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! get_current_negative_val {
|
||||||
|
($pin_state:ident, $pin_axis:ident, $modifier_state:ident) => {
|
||||||
|
match $pin_state.$pin_axis {
|
||||||
|
true => match $modifier_state {
|
||||||
|
ModifierState::MOD1 => MOD1_NEG_VAL,
|
||||||
|
ModifierState::MOD2 => MOD2_NEG_VAL,
|
||||||
|
ModifierState::NONE => 0,
|
||||||
|
},
|
||||||
|
false => 127,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! get_current_axis_val {
|
||||||
|
($pin_state:ident, $pos_axis:ident, $neg_axis:ident, $modifier_state:ident) => {
|
||||||
|
match $pin_state.$neg_axis {
|
||||||
|
true => get_current_negative_val!($pin_state, $neg_axis, $modifier_state),
|
||||||
|
false => get_current_positive_val!($pin_state, $pos_axis, $modifier_state),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! determine_positive_stick_axis {
|
macro_rules! determine_positive_stick_axis {
|
||||||
($stick_state:ident, $modifier_state:ident, $gccstate:ident, $pin_state:ident, $axis:ident, $neg_axis:ident) => {
|
($stick_state:ident, $modifier_state:ident, $gccstate:ident, $pin_state:ident, $axis:ident, $neg_axis:ident) => {
|
||||||
match $stick_state {
|
match $stick_state {
|
||||||
StickButtonState::PRESSED => {
|
StickButtonState::PRESSED => {
|
||||||
$gccstate.$axis = match $modifier_state {
|
$gccstate.$axis = match $modifier_state {
|
||||||
ModifierState::MOD1 => 159, // 127 + 32
|
ModifierState::MOD1 => MOD1_POS_VAL,
|
||||||
ModifierState::MOD2 => 191, // 127 + 64
|
ModifierState::MOD2 => MOD2_POS_VAL,
|
||||||
ModifierState::NONE => 255, // 127 + 128
|
ModifierState::NONE => 255,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StickButtonState::RELEASED => match $pin_state.$neg_axis {
|
StickButtonState::RELEASED => {
|
||||||
true => {}
|
$gccstate.$axis = get_current_negative_val!($pin_state, $neg_axis, $modifier_state)
|
||||||
false => $gccstate.$axis = 127,
|
}
|
||||||
},
|
|
||||||
StickButtonState::UNCHANGED => {}
|
StickButtonState::UNCHANGED => {}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -40,15 +80,14 @@ macro_rules! determine_negative_stick_axis {
|
||||||
match $stick_state {
|
match $stick_state {
|
||||||
StickButtonState::PRESSED => {
|
StickButtonState::PRESSED => {
|
||||||
$gccstate.$axis = match $modifier_state {
|
$gccstate.$axis = match $modifier_state {
|
||||||
ModifierState::MOD1 => 95, // 127 - 32
|
ModifierState::MOD1 => MOD1_NEG_VAL,
|
||||||
ModifierState::MOD2 => 63, // 127 - 64
|
ModifierState::MOD2 => MOD2_NEG_VAL,
|
||||||
ModifierState::NONE => 0, // 127 - 128
|
ModifierState::NONE => 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StickButtonState::RELEASED => match $pin_state.$pos_axis {
|
StickButtonState::RELEASED => {
|
||||||
true => {}
|
$gccstate.$axis = get_current_positive_val!($pin_state, $pos_axis, $modifier_state)
|
||||||
false => $gccstate.$axis = 127,
|
}
|
||||||
},
|
|
||||||
StickButtonState::UNCHANGED => {}
|
StickButtonState::UNCHANGED => {}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -120,8 +159,8 @@ impl From<GccState> for [u8; 8] {
|
||||||
response[3] = value.lsticky;
|
response[3] = value.lsticky;
|
||||||
response[4] = value.rstickx;
|
response[4] = value.rstickx;
|
||||||
response[5] = value.rsticky;
|
response[5] = value.rsticky;
|
||||||
response[6] = value.l as u8 * 127;
|
response[6] = value.l as u8 * 255;
|
||||||
response[7] = value.r as u8 * 127;
|
response[7] = value.r as u8 * 255;
|
||||||
|
|
||||||
response
|
response
|
||||||
}
|
}
|
||||||
|
@ -298,10 +337,10 @@ pub fn pinstate_to_gccstate(
|
||||||
gccstate.a = current_pin_state.a;
|
gccstate.a = current_pin_state.a;
|
||||||
gccstate.b = current_pin_state.b;
|
gccstate.b = current_pin_state.b;
|
||||||
gccstate.x = current_pin_state.x;
|
gccstate.x = current_pin_state.x;
|
||||||
gccstate.y = current_pin_state.y;
|
gccstate.y = current_pin_state.y || current_pin_state.zr;
|
||||||
gccstate.l = current_pin_state.l;
|
gccstate.l = current_pin_state.l || current_pin_state.zr;
|
||||||
gccstate.r = current_pin_state.r || current_pin_state.ddown;
|
gccstate.r = current_pin_state.r || current_pin_state.ddown || current_pin_state.zl;
|
||||||
gccstate.z = current_pin_state.zl || current_pin_state.zr || current_pin_state.dleft;
|
gccstate.z = current_pin_state.zl;
|
||||||
|
|
||||||
let stick_to_dpad = current_pin_state.q || current_pin_state.e;
|
let stick_to_dpad = current_pin_state.q || current_pin_state.e;
|
||||||
|
|
||||||
|
@ -315,18 +354,52 @@ pub fn pinstate_to_gccstate(
|
||||||
gccstate.dright = current_pin_state.right;
|
gccstate.dright = current_pin_state.right;
|
||||||
|
|
||||||
return gccstate;
|
return gccstate;
|
||||||
|
} else {
|
||||||
|
gccstate.dup = false;
|
||||||
|
gccstate.ddown = false;
|
||||||
|
gccstate.dleft = false;
|
||||||
|
gccstate.dright = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MOD1 = soft modifier, makes stick go half length
|
// MOD1 = soft modifier, makes stick go half length
|
||||||
// MOD2 = hard modifier, makes stick go quarter length
|
// MOD2 = hard modifier, makes stick go quarter length
|
||||||
let modifier_state = match current_pin_state.shift || current_pin_state.dup {
|
let modifier_state = match current_pin_state.shift {
|
||||||
true => ModifierState::MOD1,
|
true => ModifierState::MOD1,
|
||||||
false => match current_pin_state.ddown {
|
false => match current_pin_state.dup {
|
||||||
true => ModifierState::MOD2,
|
true => ModifierState::MOD2,
|
||||||
false => ModifierState::NONE,
|
false => ModifierState::NONE,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// turnaround up tilt angles
|
||||||
|
match determine_stick_state!(previous_pin_state, current_pin_state, dleft) {
|
||||||
|
StickButtonState::PRESSED | StickButtonState::UNCHANGED => {
|
||||||
|
if current_pin_state.dleft {
|
||||||
|
gccstate.rsticky = 255;
|
||||||
|
gccstate.rstickx = 53;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StickButtonState::RELEASED => {
|
||||||
|
gccstate.rsticky = get_current_axis_val!(current_pin_state, cup, cdown, modifier_state);
|
||||||
|
gccstate.rstickx =
|
||||||
|
get_current_axis_val!(current_pin_state, cleft, cright, modifier_state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match determine_stick_state!(previous_pin_state, current_pin_state, dright) {
|
||||||
|
StickButtonState::PRESSED | StickButtonState::UNCHANGED => {
|
||||||
|
if current_pin_state.dright {
|
||||||
|
gccstate.rsticky = 255;
|
||||||
|
gccstate.rstickx = 201;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StickButtonState::RELEASED => {
|
||||||
|
gccstate.rsticky = get_current_axis_val!(current_pin_state, cup, cdown, modifier_state);
|
||||||
|
gccstate.rstickx =
|
||||||
|
get_current_axis_val!(current_pin_state, cleft, cright, modifier_state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// determine down / up presses for stick buttons
|
// determine down / up presses for stick buttons
|
||||||
let lstick_up_state = determine_stick_state!(previous_pin_state, current_pin_state, up);
|
let lstick_up_state = determine_stick_state!(previous_pin_state, current_pin_state, up);
|
||||||
let lstick_down_state = determine_stick_state!(previous_pin_state, current_pin_state, down);
|
let lstick_down_state = determine_stick_state!(previous_pin_state, current_pin_state, down);
|
||||||
|
@ -406,27 +479,33 @@ pub fn pinstate_to_gccstate(
|
||||||
cright
|
cright
|
||||||
);
|
);
|
||||||
|
|
||||||
// clamp lstickx if lsticky is 0 or 255 for uptilt and downtilt angles
|
// clamp lstickx if lsticky is 0 or 255, so that if we hit A,
|
||||||
|
// we get an up or down attack instead of left or right
|
||||||
|
// comment this if you want ftilt/-smash angles instead
|
||||||
if gccstate.lsticky <= 1 || gccstate.lsticky >= 254 {
|
if gccstate.lsticky <= 1 || gccstate.lsticky >= 254 {
|
||||||
gccstate.lstickx = gccstate.lstickx.max(53).min(201);
|
gccstate.lstickx = gccstate.lstickx.max(18).min(236);
|
||||||
} else {
|
} else {
|
||||||
gccstate.lstickx = match gccstate.lstickx {
|
gccstate.lstickx = match gccstate.lstickx {
|
||||||
201 => 255,
|
236 => 255,
|
||||||
53 => 0,
|
18 => 0,
|
||||||
_ => gccstate.lstickx,
|
_ => gccstate.lstickx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// do the same for cstick
|
// C-stick logic, however this is kinda useless since the game won't
|
||||||
if gccstate.rsticky <= 1 || gccstate.rsticky >= 254 {
|
// let you do turnaround up/down tilt like this
|
||||||
gccstate.rstickx = gccstate.rstickx.max(53).min(201);
|
//
|
||||||
} else {
|
// so for C-stick it's usually better to just keep the angles the defaults,
|
||||||
gccstate.rstickx = match gccstate.rstickx {
|
// in order to easily perform angled f-tilt's / smashes
|
||||||
201 => 255,
|
// if gccstate.rsticky <= 1 || gccstate.rsticky >= 254 {
|
||||||
53 => 0,
|
// gccstate.rstickx = gccstate.rstickx.max(18).min(236);
|
||||||
_ => gccstate.rstickx,
|
// } else {
|
||||||
}
|
// gccstate.rstickx = match gccstate.rstickx {
|
||||||
}
|
// 201 => 255,
|
||||||
|
// 53 => 0,
|
||||||
|
// _ => gccstate.rstickx,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
gccstate
|
gccstate
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,16 @@
|
||||||
use cortex_m::delay::Delay;
|
use cortex_m::delay::Delay;
|
||||||
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
|
||||||
use rp2040_hal::gpio::{bank0::BankPinId, PinId};
|
use rp2040_hal::{
|
||||||
use rp_pico::{
|
gpio::{bank0::BankPinId, PinId},
|
||||||
hal::{
|
pac::{PIO0, RESETS},
|
||||||
pio::{
|
pio::{
|
||||||
InstalledProgram, Rx, StateMachine, StateMachineIndex, Stopped, Tx, UninitStateMachine,
|
InstalledProgram, PIOBuilder, Rx, StateMachine, StateMachineIndex, Stopped, Tx,
|
||||||
PIO,
|
UninitStateMachine, PIO,
|
||||||
},
|
},
|
||||||
prelude::_rphal_pio_PIOExt,
|
prelude::_rphal_pio_PIOExt,
|
||||||
},
|
|
||||||
pac::{PIO0, RESETS},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
gccstate::GccState,
|
|
||||||
input::CURRENT_STATE,
|
input::CURRENT_STATE,
|
||||||
pio::{to_pio_response, PioResponse},
|
pio::{to_pio_response, PioResponse},
|
||||||
};
|
};
|
||||||
|
@ -59,10 +56,10 @@ where
|
||||||
PE: _rphal_pio_PIOExt,
|
PE: _rphal_pio_PIOExt,
|
||||||
SM: StateMachineIndex,
|
SM: StateMachineIndex,
|
||||||
{
|
{
|
||||||
let (sm, rx, tx) = rp_pico::hal::pio::PIOBuilder::from_program(installed)
|
let (sm, rx, tx) = PIOBuilder::from_program(installed)
|
||||||
.set_pins(pin_id, 1)
|
.set_pins(pin_id, 1)
|
||||||
.in_shift_direction(rp_pico::hal::pio::ShiftDirection::Left)
|
.in_shift_direction(rp2040_hal::pio::ShiftDirection::Left)
|
||||||
.out_shift_direction(rp_pico::hal::pio::ShiftDirection::Right)
|
.out_shift_direction(rp2040_hal::pio::ShiftDirection::Right)
|
||||||
.pull_threshold(32)
|
.pull_threshold(32)
|
||||||
.push_threshold(8)
|
.push_threshold(8)
|
||||||
.clock_divisor_fixed_point(5, 0)
|
.clock_divisor_fixed_point(5, 0)
|
||||||
|
|
|
@ -81,7 +81,7 @@ fn main() -> ! {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
datatransfer(
|
datatransfer(
|
||||||
pins.gpio28.into_pull_up_input(),
|
pins.gpio24.into_pull_up_input(),
|
||||||
pac.PIO0,
|
pac.PIO0,
|
||||||
&mut pac.RESETS,
|
&mut pac.RESETS,
|
||||||
delay,
|
delay,
|
||||||
|
|
Loading…
Reference in a new issue