-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from daystram/feat/configurable-keyboard
Configurable keyboard and layout
- Loading branch information
Showing
16 changed files
with
589 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export KEYBOARD=default | ||
export LAYOUT=default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,6 @@ target/ | |
|
||
# MSVC Windows builds of rustc generate these, which store debugging information | ||
*.pdb | ||
|
||
.envrc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use alloc::boxed::Box; | ||
use embedded_hal::pwm::SetDutyCycle; | ||
use hal::gpio; | ||
|
||
use crate::util; | ||
|
||
const MAX_PWM_POWER: u16 = 0x6000; | ||
|
||
pub struct HeartbeatLED { | ||
pin: Box<dyn SetDutyCycle<Error = gpio::Error>>, | ||
} | ||
|
||
impl HeartbeatLED { | ||
pub fn new(pin: Box<dyn SetDutyCycle<Error = gpio::Error>>) -> Self { | ||
return HeartbeatLED { pin }; | ||
} | ||
|
||
pub async fn cycle(&mut self) { | ||
loop { | ||
util::lerp(&mut self.pin, 0, MAX_PWM_POWER, 200, 10).await; | ||
util::lerp(&mut self.pin, MAX_PWM_POWER, 0, 200, 10).await; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#![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::KeyboardConfiguration, | ||
processor::mapper::InputMap, | ||
rotary::Direction, | ||
}; | ||
|
||
pub const LAYER_COUNT: usize = 2; | ||
|
||
#[derive(Clone, Copy, PartialEq, PartialOrd, Format)] | ||
pub enum Layer { | ||
Base, | ||
Function1, | ||
} | ||
|
||
impl LayerIndex for Layer {} | ||
|
||
impl Into<usize> for Layer { | ||
fn into(self) -> usize { | ||
self as usize | ||
} | ||
} | ||
|
||
impl Default for Layer { | ||
fn default() -> Self { | ||
return Layer::Base; | ||
} | ||
} | ||
|
||
#[rustfmt::skip] | ||
pub fn get_input_map() -> InputMap<{ <super::super::Keyboard as KeyboardConfiguration>::LAYER_COUNT }, { <super::super::Keyboard as KeyboardConfiguration>::KEY_MATRIX_ROW_COUNT }, { <super::super::Keyboard as KeyboardConfiguration>::KEY_MATRIX_COL_COUNT }, <super::super::Keyboard as KeyboardConfiguration>::Layer> { | ||
return InputMap::new( | ||
[ | ||
[ | ||
[K(Key::A), K(Key::B)], | ||
[___________, LM(Layer::Function1)], | ||
], | ||
[ | ||
[K(Key::C), K(Key::D)], | ||
[C(Control::RGBAnimationNext), ___________], | ||
], | ||
], | ||
[ | ||
enum_map! { | ||
Direction::Clockwise => C(Control::RGBBrightnessUp), | ||
Direction::CounterClockwise => C(Control::RGBBrightnessDown), | ||
_ => ___________, | ||
}, | ||
enum_map! { | ||
Direction::Clockwise => C(Control::RGBSpeedUp), | ||
Direction::CounterClockwise => C(Control::RGBSpeedDown), | ||
_ => ___________, | ||
}, | ||
], | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
pub mod layout; | ||
|
||
use alloc::boxed::Box; | ||
use hal::{fugit::HertzU32, gpio, pac, pio, pwm}; | ||
use ws2812_pio::Ws2812Direct; | ||
|
||
use crate::{ | ||
heartbeat::HeartbeatLED, | ||
keyboard::KeyboardConfiguration, | ||
matrix::BasicVerticalSwitchMatrix, | ||
processor::events::rgb::RGBMatrix, | ||
rotary::{Mode, RotaryEncoder}, | ||
}; | ||
|
||
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 KeyboardConfiguration for Keyboard { | ||
const KEY_MATRIX_ROW_COUNT: usize = 2; | ||
const KEY_MATRIX_COL_COUNT: usize = 2; | ||
|
||
const RGB_MATRIX_LED_COUNT: usize = 4; | ||
|
||
fn init( | ||
pins: gpio::Pins, | ||
mut slices: pwm::Slices, | ||
mut pio0: pio::PIO<pac::PIO0>, | ||
sm0: pio::UninitStateMachine<(pac::PIO0, pio::SM0)>, | ||
clock_freq: HertzU32, | ||
) -> ( | ||
Option< | ||
BasicVerticalSwitchMatrix< | ||
{ Self::KEY_MATRIX_ROW_COUNT }, | ||
{ Self::KEY_MATRIX_COL_COUNT }, | ||
>, | ||
>, | ||
Option<RotaryEncoder>, | ||
Option<HeartbeatLED>, | ||
Option< | ||
RGBMatrix< | ||
{ Self::RGB_MATRIX_LED_COUNT }, | ||
Ws2812Direct< | ||
pac::PIO0, | ||
pio::SM0, | ||
gpio::Pin<gpio::bank0::Gpio28, gpio::FunctionPio0, gpio::PullDown>, | ||
>, | ||
>, | ||
>, | ||
) { | ||
#[rustfmt::skip] | ||
let key_matrix = if ENABLE_KEY_MATRIX { | ||
Some(BasicVerticalSwitchMatrix::new( | ||
[ | ||
Box::new(pins.gpio21.into_pull_down_input()), | ||
Box::new(pins.gpio20.into_pull_down_input()), | ||
], | ||
[ | ||
Box::new(pins.gpio0.into_push_pull_output()), | ||
Box::new(pins.gpio1.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 = ws2812_pio::Ws2812Direct::new( | ||
pins.gpio28.into_function(), | ||
&mut pio0, | ||
sm0, | ||
clock_freq, | ||
); | ||
Some(RGBMatrix::<{ Keyboard::RGB_MATRIX_LED_COUNT }, _>::new(ws)) | ||
} else { | ||
None | ||
}; | ||
|
||
(key_matrix, rotary_encoder, heartbeat_led, rgb_matrix) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.