Skip to content

Commit

Permalink
add: configuration for quadax-rift
Browse files Browse the repository at this point in the history
  • Loading branch information
daystram committed Sep 1, 2024
1 parent d4b5def commit 38b7de1
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/keyboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ mod kb_dev;
#[cfg(keyboard = "kb_dev")]
use kb_dev as selected_keyboard;

pub trait KeyboardConfiguration {
#[cfg(keyboard = "quadax_rift")]
mod quadax_rift;
#[cfg(keyboard = "quadax_rift")]
use quadax_rift as selected_keyboard;

#[derive(Default)]
pub struct Configuration {
pub key_matrix: Option<
Expand Down
77 changes: 77 additions & 0 deletions src/keyboard/quadax_rift/layout/default.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#![allow(dead_code)]
use defmt::Format;
use enum_map::enum_map;

use crate::{
key::{
Action::{Control as C, Key as K, LayerModifier as LM, Pass as ___________},
Control, Key, LayerIndex,
},
keyboard::Configurator,
processor::mapper::InputMap,
rotary::Direction,
};

pub const LAYER_COUNT: usize = 3;

#[derive(Clone, Copy, Default, Format, PartialEq, PartialOrd)]
pub enum Layer {
#[default]
Base,
Down,
Up,
}

impl LayerIndex for Layer {}

impl From<Layer> for usize {
fn from(value: Layer) -> usize {
value as usize
}
}

#[rustfmt::skip]
pub fn get_input_map() -> InputMap<{ <super::super::Keyboard as Configurator>::LAYER_COUNT }, { <super::super::Keyboard as Configurator>::KEY_MATRIX_ROW_COUNT }, { <super::super::Keyboard as Configurator>::KEY_MATRIX_COL_COUNT }, <super::super::Keyboard as Configurator>::Layer> {
InputMap::new(
[
[
[K(Key::Escape), K(Key::Keyboard1), K(Key::Keyboard2), K(Key::Keyboard3), K(Key::Keyboard4), K(Key::Keyboard5), ___________, ___________, K(Key::Keyboard6), K(Key::Keyboard7), K(Key::Keyboard8), K(Key::Keyboard9), K(Key::Keyboard0), K(Key::DeleteBackspace)],
[K(Key::Tab), K(Key::Q), K(Key::W), K(Key::E), K(Key::R), K(Key::T), ___________, ___________, K(Key::Y), K(Key::U), K(Key::I), K(Key::O), K(Key::P), K(Key::DeleteForward)],
[K(Key::CapsLock), K(Key::A), K(Key::S), K(Key::D), K(Key::F), K(Key::G), ___________, ___________, K(Key::H), K(Key::J), K(Key::K), K(Key::L), K(Key::Semicolon), K(Key::ReturnEnter)],
[K(Key::LeftShift), K(Key::Z), K(Key::X), K(Key::C), K(Key::V), K(Key::B), ___________, ___________, K(Key::N), K(Key::M), K(Key::Comma), K(Key::Dot), K(Key::ForwardSlash), K(Key::RightShift)],
[___________, K(Key::LeftControl), K(Key::LeftAlt), K(Key::LeftGUI), LM(Layer::Down), K(Key::Space), ___________, ___________, K(Key::Space), LM(Layer::Up), K(Key::RightGUI), K(Key::RightAlt), K(Key::RightControl), ___________],
],
[
[___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________],
[___________, C(Control::RGBAnimationNext), C(Control::RGBSpeedUp), C(Control::RGBBrightnessUp), ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________],
[___________, C(Control::RGBAnimationPrevious), C(Control::RGBSpeedDown), C(Control::RGBBrightnessDown), ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________],
[___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________],
[___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________],
],
[
[___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________],
[___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________],
[___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, K(Key::LeftArrow), K(Key::DownArrow), K(Key::UpArrow), K(Key::RightArrow), ___________],
[___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________],
[___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________, ___________],
],
],
[
enum_map! {
Direction::Clockwise => K(Key::VolumeUp),
Direction::CounterClockwise => K(Key::VolumeDown),
_ => ___________,
},
enum_map! {
Direction::Clockwise => C(Control::RGBBrightnessUp),
Direction::CounterClockwise => C(Control::RGBBrightnessDown),
_ => ___________,
},
enum_map! {
Direction::Clockwise => C(Control::RGBSpeedUp),
Direction::CounterClockwise => C(Control::RGBSpeedDown),
_ => ___________,
},
],
)
}
10 changes: 10 additions & 0 deletions src/keyboard/quadax_rift/layout/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#[cfg(layout = "default")]
mod default;
#[cfg(layout = "default")]
use default as selected_layout;

pub use selected_layout::LAYER_COUNT;

pub use selected_layout::Layer;

pub use selected_layout::get_input_map;
136 changes: 136 additions & 0 deletions src/keyboard/quadax_rift/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
pub mod layout;

use core::cell::RefCell;

use alloc::{boxed::Box, rc::Rc};
use hal::{
fugit::{HertzU32, RateExtU32},
gpio, pac, pio, pwm, uart,
};
use rtic_sync::arbiter::Arbiter;
use ws2812_pio::Ws2812Direct;

use crate::{
heartbeat::HeartbeatLED,
keyboard::{Configuration, Configurator},
matrix::{BasicVerticalSwitchMatrix, SplitSwitchMatrix},
processor::events::rgb::RGBMatrix,
remote::transport::uart::{UartReceiver, UartSender},
rotary::{Mode, RotaryEncoder},
split::SideDetector,
};

const ENABLE_HEARTBEAT_LED: bool = true;
const ENABLE_KEY_MATRIX: bool = true;
const ENABLE_ROTARY_ENCODER: bool = true;
const ENABLE_RGB_MATRIX: bool = true;

pub struct Keyboard {}

impl Configurator for Keyboard {
const KEY_MATRIX_ROW_COUNT: usize = 5;
const KEY_MATRIX_COL_COUNT: usize = 14;

const RGB_MATRIX_LED_COUNT: usize = 67;

fn init(
pins: gpio::Pins,
mut slices: pwm::Slices,
mut pio0: pio::PIO<pac::PIO0>,
sm0: pio::UninitStateMachine<(pac::PIO0, pio::SM0)>,
uart0: pac::UART0,
resets: &mut pac::RESETS,
clock_freq: HertzU32,
) -> (
Configuration,
Option<(Arbiter<Rc<RefCell<UartSender>>>, UartReceiver)>,
) {
#[rustfmt::skip]
let key_matrix_split = if ENABLE_KEY_MATRIX {
Some(SplitSwitchMatrix::new(BasicVerticalSwitchMatrix::new(
[
Box::new(pins.gpio10.into_pull_down_input()),
Box::new(pins.gpio11.into_pull_down_input()),
Box::new(pins.gpio12.into_pull_down_input()),
Box::new(pins.gpio13.into_pull_down_input()),
Box::new(pins.gpio14.into_pull_down_input()),
],
[
Box::new(pins.gpio3.into_push_pull_output()),
Box::new(pins.gpio4.into_push_pull_output()),
Box::new(pins.gpio5.into_push_pull_output()),
Box::new(pins.gpio6.into_push_pull_output()),
Box::new(pins.gpio7.into_push_pull_output()),
Box::new(pins.gpio8.into_push_pull_output()),
Box::new(pins.gpio9.into_push_pull_output()),
],
)))
} else {
None
};

let rotary_encoder = if ENABLE_ROTARY_ENCODER {
Some(RotaryEncoder::new(
Box::new(pins.gpio15.into_pull_up_input()),
Box::new(pins.gpio17.into_pull_up_input()),
Box::new(pins.gpio16.into_push_pull_output()),
Mode::DentHighPrecision,
))
} else {
None
};

let heartbeat_led = if ENABLE_HEARTBEAT_LED {
slices.pwm6.set_ph_correct();
slices.pwm6.enable();
slices.pwm6.channel_b.output_to(
pins.gpio29
.into_push_pull_output_in_state(gpio::PinState::Low),
);
Some(HeartbeatLED::new(Box::new(slices.pwm6.channel_b)))
} else {
None
};

let rgb_matrix = if ENABLE_RGB_MATRIX {
let ws = Ws2812Direct::new(pins.gpio28.into_function(), &mut pio0, sm0, clock_freq);
Some(RGBMatrix::<{ Keyboard::RGB_MATRIX_LED_COUNT }, _>::new(ws))
} else {
None
};

let mut uart_peripheral = uart::UartPeripheral::new(
uart0,
(pins.gpio0.into_function(), pins.gpio1.into_function()),
resets,
)
.enable(
uart::UartConfig::new(
// 115_200.Hz(),
230_400.Hz(),
uart::DataBits::Eight,
None,
uart::StopBits::One,
),
clock_freq,
)
.unwrap();
uart_peripheral.set_fifos(true);
let (uart_reader, uart_writer) = uart_peripheral.split();
let uart_sender = Arbiter::new(Rc::new(RefCell::new(UartSender::new(uart_writer))));
let uart_receiver = UartReceiver::new(uart_reader);

SideDetector::new(Box::new(pins.gpio2.into_pull_down_input())).detect();

(
Configuration {
key_matrix: None,
key_matrix_split,
rotary_encoder,
heartbeat_led,
rgb_matrix,
},
Some((uart_sender, uart_receiver)),
)
}
}

0 comments on commit 38b7de1

Please sign in to comment.