Skip to content

Commit

Permalink
Merge pull request #10 from daystram/ci/github-actions
Browse files Browse the repository at this point in the history
GitHub Actions workflow
  • Loading branch information
daystram authored Jul 22, 2024
2 parents b487572 + 37929c2 commit 661014e
Show file tree
Hide file tree
Showing 19 changed files with 157 additions and 99 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: CI

on:
push:

env:
CARGO_TERM_COLOR: always

jobs:
dependencies:
name: Dependencies
runs-on: Ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Cargo fetch
run: cargo fetch --verbose

init-matrix:
name: Initialize Matrix
runs-on: Ubuntu-24.04
needs: [dependencies]
outputs:
combinations: ${{ steps.combinations.outputs.combinations }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get combinations
id: combinations
run: |
echo "combinations=[$(find ./src/keyboard -not -name "mod.rs" -name "*.rs" | awk -F'/' '{sub(/\.rs$/, "", $6); print "{\"keyboard\": \""$4"\", \"layout\": \""$6"\"}"}' ORS="," | sed -e '$ s/,$//')]" >> "$GITHUB_OUTPUT"
build:
name: Build
runs-on: Ubuntu-24.04
needs: [init-matrix]
strategy:
matrix:
combination: ${{ fromJSON(needs.init-matrix.outputs.combinations) }}
env:
KEYBOARD: ${{ matrix.combination.keyboard }}
LAYOUT: ${{ matrix.combination.layout }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Cargo build
run: cargo build --verbose

lint:
name: Lint
runs-on: Ubuntu-24.04
needs: [init-matrix]
strategy:
matrix:
combination: ${{ fromJSON(needs.init-matrix.outputs.combinations) }}
env:
KEYBOARD: ${{ matrix.combination.keyboard }}
LAYOUT: ${{ matrix.combination.layout }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Cargo fmt
run: cargo fmt --all --check --verbose
- name: Cargo clippy
run: cargo clippy --verbose
1 change: 1 addition & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[toolchain]
channel = "nightly-2024-07-18"
targets = ["thumbv6m-none-eabi"]
components = ["rustfmt", "clippy"]
2 changes: 1 addition & 1 deletion src/heartbeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct HeartbeatLED {

impl HeartbeatLED {
pub fn new(pin: Box<dyn SetDutyCycle<Error = gpio::Error>>) -> Self {
return HeartbeatLED { pin };
HeartbeatLED { pin }
}

pub async fn cycle(&mut self) {
Expand Down
20 changes: 8 additions & 12 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use defmt::Format;
use usbd_human_interface_device::page::Keyboard;

#[allow(dead_code)]
#[derive(Clone, Copy, Debug, Format)]
#[derive(Clone, Copy, Debug, Default, Format)]
pub enum Action<L: LayerIndex> {
#[default]
Pass,
None,
Key(Key),
Expand All @@ -23,12 +24,6 @@ impl<L: LayerIndex> From<L> for Action<L> {
}
}

impl<L: LayerIndex> Default for Action<L> {
fn default() -> Self {
Action::Pass
}
}

#[allow(dead_code)]
#[derive(Clone, Copy, Debug, Format, PartialEq)]
pub enum Key {
Expand Down Expand Up @@ -119,9 +114,9 @@ pub enum Key {
VolumeDown,
}

impl Into<Keyboard> for Key {
fn into(self) -> Keyboard {
match self {
impl From<Key> for Keyboard {
fn from(from: Key) -> Keyboard {
match from {
Key::Escape => Keyboard::Escape,
Key::F1 => Keyboard::F1,
Key::F2 => Keyboard::F2,
Expand Down Expand Up @@ -211,7 +206,7 @@ impl Into<Keyboard> for Key {
}
}

#[allow(dead_code)]
#[allow(dead_code, clippy::enum_variant_names)]
#[derive(Clone, Copy, Debug, Format, PartialEq)]
pub enum Control {
RGBAnimationNext,
Expand All @@ -225,8 +220,9 @@ pub enum Control {

pub trait LayerIndex: Copy + Default + PartialEq + PartialOrd + Format + Into<usize> {}

#[derive(Clone, Copy, Debug, Format, PartialEq)]
#[derive(Clone, Copy, Debug, Default, Format, PartialEq)]
pub enum Edge {
#[default]
None,
Rising,
Falling,
Expand Down
19 changes: 7 additions & 12 deletions src/keyboard/default/layout/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,24 @@ use crate::{

pub const LAYER_COUNT: usize = 2;

#[derive(Clone, Copy, PartialEq, PartialOrd, Format)]
#[derive(Clone, Copy, Default, Format, PartialEq, PartialOrd)]
pub enum Layer {
#[default]
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;
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 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(
InputMap::new(
[
[
[K(Key::A), K(Key::B)],
Expand All @@ -59,5 +54,5 @@ pub fn get_input_map() -> InputMap<{ <super::super::Keyboard as KeyboardConfigur
_ => ___________,
},
],
);
)
}
19 changes: 7 additions & 12 deletions src/keyboard/kb_dev/layout/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,25 @@ use crate::{

pub const LAYER_COUNT: usize = 3;

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

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;
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 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(
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::Minus), K(Key::Equal), K(Key::DeleteBackspace), K(Key::DeleteForward)],
Expand Down Expand Up @@ -78,5 +73,5 @@ pub fn get_input_map() -> InputMap<{ <super::super::Keyboard as KeyboardConfigur
_ => ___________,
},
],
);
)
}
2 changes: 1 addition & 1 deletion src/keyboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub trait KeyboardConfiguration {
{ selected_keyboard::Keyboard::KEY_MATRIX_COL_COUNT },
selected_keyboard::layout::Layer,
> {
return selected_keyboard::layout::get_input_map();
selected_keyboard::layout::get_input_map()
}
}

Expand Down
17 changes: 9 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![feature(type_alias_impl_trait)]
#![feature(associated_type_defaults)]
#![feature(trait_alias)]
#![allow(clippy::type_complexity)]
mod heartbeat;
mod key;
mod keyboard;
Expand Down Expand Up @@ -139,7 +140,7 @@ mod kb {

// Configure watchdog, monotonics, and clock - The default is to generate a 125 MHz system clock
let mut watchdog = Watchdog::new(ctx.device.WATCHDOG);
Mono::start(ctx.device.TIMER, &mut ctx.device.RESETS);
Mono::start(ctx.device.TIMER, &ctx.device.RESETS);
let clocks = init_clocks_and_plls(
XOSC_CRYSTAL_FREQ,
ctx.device.XOSC,
Expand Down Expand Up @@ -321,32 +322,32 @@ mod kb {
let mut n: u64 = 0;
while let Ok(mut input) = input_receiver.recv().await {
let process_start_time = Mono::now();
match input_processors
if input_processors
.iter_mut()
.try_for_each(|p| p.process(&mut input))
.is_err()
{
Err(_) => continue,
_ => {}
continue;
}

let mut events =
Vec::<Event<<Keyboard as KeyboardConfiguration>::Layer>>::with_capacity(10);
mapper.map(&input, &mut events);

match events_processors
if events_processors
.iter_mut()
.try_for_each(|p| p.process(&mut events))
.is_err()
{
Err(_) => continue,
_ => {}
continue;
}

keys_sender
.try_send(
events
.into_iter()
.filter_map(|e| match e.action {
Action::Key(k) => Some(k.into()),
Action::Key(k) => Some(k),
_ => None,
})
.collect(),
Expand Down
12 changes: 6 additions & 6 deletions src/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ impl<const ROW_COUNT: usize, const COL_COUNT: usize>
rows: [Box<dyn InputPin<Error = gpio::Error>>; ROW_COUNT],
cols: [Box<dyn OutputPin<Error = gpio::Error>>; COL_COUNT],
) -> Self {
return BasicVerticalSwitchMatrix {
BasicVerticalSwitchMatrix {
rows,
cols,
previous_result: Result::default(),
};
}
}
}

Expand All @@ -74,7 +74,7 @@ impl<const ROW_COUNT: usize, const COL_COUNT: usize> Scanner<ROW_COUNT, COL_COUN
}
result.scan_time_ticks = Mono::now().ticks();
self.previous_result = result;
return result;
result
}
}

Expand All @@ -92,11 +92,11 @@ impl<const ROW_COUNT: usize, const COL_COUNT: usize>
rows: [Box<dyn OutputPin<Error = gpio::Error>>; ROW_COUNT],
cols: [Box<dyn InputPin<Error = gpio::Error>>; COL_COUNT],
) -> Self {
return BasicHorizontalSwitchMatrix {
BasicHorizontalSwitchMatrix {
rows,
cols,
previous_result: Result::default(),
};
}
}
}

Expand All @@ -118,6 +118,6 @@ impl<const ROW_COUNT: usize, const COL_COUNT: usize> Scanner<ROW_COUNT, COL_COUN
halt(1).await;
}
self.previous_result = result;
return result;
result
}
}
4 changes: 2 additions & 2 deletions src/processor/events/none.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ pub struct NoneProcessor {}
#[allow(dead_code)]
impl NoneProcessor {
pub fn new() -> Self {
return NoneProcessor {};
NoneProcessor {}
}
}

impl<L: LayerIndex> EventsProcessor<L> for NoneProcessor {
fn process(&mut self, _: &mut Vec<Event<L>>) -> Result {
return Ok(());
Ok(())
}
}
9 changes: 4 additions & 5 deletions src/processor/events/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@ pub struct KeyReplaceProcessor {
#[allow(dead_code)]
impl KeyReplaceProcessor {
pub fn new(from: Key, to: Key) -> Self {
return KeyReplaceProcessor { from, to };
KeyReplaceProcessor { from, to }
}
}

impl<L: LayerIndex> EventsProcessor<L> for KeyReplaceProcessor {
fn process(&mut self, events: &mut Vec<Event<L>>) -> Result {
events.iter_mut().for_each(|e| match &mut e.action {
Action::Key(k) => {
events.iter_mut().for_each(|e| {
if let Action::Key(k) = &mut e.action {
if *k == self.from {
*k = self.to;
}
}
_ => {}
});
return Ok(());
Ok(())
}
}
Loading

0 comments on commit 661014e

Please sign in to comment.