diff --git a/src/input.rs b/src/input.rs index 31932d4..1f7ed27 100644 --- a/src/input.rs +++ b/src/input.rs @@ -22,8 +22,8 @@ use crate::{ gcc_hid::GcReport, packed_float::{PackedFloat, ToPackedFloatArray}, stick::{ - linearize, notch_remap, StickParams, DEFAULT_CAL_POINTS_X, DEFAULT_CAL_POINTS_Y, - NO_OF_NOTCHES, + linearize, notch_remap, StickParams, DEFAULT_ANGLES, DEFAULT_CAL_POINTS_X, + DEFAULT_CAL_POINTS_Y, NO_OF_NOTCHES, }, ADDR_OFFSET, FLASH_SIZE, }; @@ -34,7 +34,7 @@ static STICK_SIGNAL: Signal = Signal::new() const STICK_HYST_VAL: f32 = 0.3; const FLOAT_ORIGIN: f32 = 127.5; -pub const CONTROLLER_CONFIG_REVISION: u8 = 1; +pub const CONTROLLER_CONFIG_REVISION: u8 = 2; #[derive(Debug, Clone, Format, PackedStruct)] #[packed_struct(endian = "msb")] @@ -102,8 +102,8 @@ impl Default for ControllerConfig { temp_cal_points_ay: *DEFAULT_CAL_POINTS_Y.to_packed_float_array(), temp_cal_points_cx: *DEFAULT_CAL_POINTS_X.to_packed_float_array(), temp_cal_points_cy: *DEFAULT_CAL_POINTS_Y.to_packed_float_array(), - a_angles: [PackedFloat::default(); NO_OF_NOTCHES], - c_angles: [PackedFloat::default(); NO_OF_NOTCHES], + a_angles: *DEFAULT_ANGLES.to_packed_float_array(), + c_angles: *DEFAULT_ANGLES.to_packed_float_array(), } } } @@ -474,6 +474,12 @@ pub async fn input_loop( mut spi_acs: Output<'static, PIN_24>, mut spi_ccs: Output<'static, PIN_23>, ) { + if btn_a.is_low() && btn_x.is_low() && btn_y.is_low() { + info!("Detected reset button press, booting into flash."); + embassy_rp::rom_data::reset_to_usb_boot(0, 0); + loop {} + } + let mut gcc_state = GcReport::default(); // Set the stick states to the center diff --git a/src/stick.rs b/src/stick.rs index 678f355..fc69d5e 100644 --- a/src/stick.rs +++ b/src/stick.rs @@ -14,13 +14,14 @@ use crate::{ const FIT_ORDER: usize = 3; const NUM_COEFFS: usize = FIT_ORDER + 1; pub const NO_OF_NOTCHES: usize = 16; +const NO_OF_ADJ_NOTCHES: usize = 12; pub const NO_OF_CALIBRATION_POINTS: usize = 32; const MAX_ORDER: usize = 20; /// 28 degrees; this is the max angular deflection of the stick. const MAX_STICK_ANGLE: f32 = 0.4886921906; -const NOTCH_STATUS_DEFAULTS: [NotchStatus; NO_OF_NOTCHES] = [ +const DEFAULT_NOTCH_STATUS: [NotchStatus; NO_OF_NOTCHES] = [ NotchStatus::Cardinal, NotchStatus::TertActive, NotchStatus::Secondary, @@ -79,6 +80,34 @@ pub const DEFAULT_CAL_POINTS_Y: [f32; NO_OF_CALIBRATION_POINTS] = [ 0.3000802760,0.3008482317 ]; +pub const DEFAULT_ANGLES: [f32; NO_OF_NOTCHES] = [ + 0., + PI / 8.0, + PI * 2. / 8., + PI * 3. / 8., + PI * 4. / 8., + PI * 5. / 8., + PI * 6. / 8., + PI * 7. / 8., + PI * 8. / 8., + PI * 9. / 8., + PI * 10. / 8., + PI * 11. / 8., + PI * 12. / 8., + PI * 13. / 8., + PI * 14. / 8., + PI * 15. / 8., +]; + +#[rustfmt::skip] +// right notch 1 up right notch 2 up notch 3 up left notch 4 left notch 5 down left notch 6 down notch 7 down right notch 8 +// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 +const CALIBRATION_ORDER: [usize; NO_OF_CALIBRATION_POINTS] = [ 0, 1, 8, 9, 16, 17, 24, 25, 4, 5, 12, 13, 20, 21, 28, 29, 2, 3, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27, 30, 31 ]; + +#[rustfmt::skip] +// up right up left down left down right notch 1 notch 2 notch 3 notch 4 notch 5 notch 6 notch 7 notch 8 +const NOTCH_ADJUSTMENT_ORDER: [usize; NO_OF_ADJ_NOTCHES] = [2, 6, 10, 14, 1, 3, 5, 7, 9, 11, 13, 15]; + #[derive(Clone, Debug, Default, Format)] pub struct StickParams { // these are the linearization coefficients @@ -133,7 +162,7 @@ impl Default for CleanedCalibrationPoints { cleaned_points_y: [0f32; NO_OF_NOTCHES + 1], notch_points_x: [0f32; NO_OF_NOTCHES + 1], notch_points_y: [0f32; NO_OF_NOTCHES + 1], - notch_status: NOTCH_STATUS_DEFAULTS, + notch_status: DEFAULT_NOTCH_STATUS, } } } @@ -238,7 +267,7 @@ impl CleanedCalibrationPoints { // Mark that notch adjustment should be skipped for this out.notch_status[i] = NotchStatus::TertInactive; } else { - out.notch_status[i] = NOTCH_STATUS_DEFAULTS[i]; + out.notch_status[i] = DEFAULT_NOTCH_STATUS[i]; } } @@ -277,7 +306,7 @@ impl LinearizedCalibration { /// /// Outputs: /// linearization fit coefficients for X and Y - pub fn from_points(in_x: &[f64; 17], in_y: &[f64; 17]) -> Self { + pub fn from_calibration_points(in_x: &[f64; 17], in_y: &[f64; 17]) -> Self { let mut fit_points_x = [0f64; 5]; let mut fit_points_y = [0f64; 5];