Skip to content

Commit

Permalink
mark some enums as non-exhaustive, u8 repr, explicit discriminants
Browse files Browse the repository at this point in the history
  • Loading branch information
Univa committed Apr 3, 2024
1 parent f02e391 commit eb32fc7
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 84 deletions.
8 changes: 5 additions & 3 deletions rumcake/src/hw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub static BATTERY_LEVEL_STATE: State<u8> = State::new(
/// Possible settings used to determine how the firmware will choose the destination for HID
/// reports.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum OutputMode {
Usb,
Bluetooth,
Expand Down Expand Up @@ -99,23 +100,24 @@ pub(crate) static BLUETOOTH_CONNECTED_STATE_LISTENER: Signal<RawMutex, ()> = Sig
pub(crate) static HARDWARE_COMMAND_CHANNEL: Channel<RawMutex, HardwareCommand, 2> = Channel::new();

#[derive(Debug, Clone, Copy)]
#[non_exhaustive]
/// An enumeration of possible commands that will be processed by the bluetooth task.
pub enum HardwareCommand {
/// Switch between USB and Bluetooth operation.
///
/// This will **NOT** disconnect your keyboard from your host device. It
/// will simply determine which device the HID reports get sent to.
ToggleOutput,
ToggleOutput = 0,
/// Switch to USB operation.
///
/// If your keyboard is connected to a bluetooth device, this will **NOT** disconnect your
/// keyboard from it. It will simply output the HID reports to the connected USB device.
OutputUSB,
OutputUSB = 1,
/// Switch to bluetooth operation.
///
/// If your keyboard is connected to a USB device, this will **NOT** disconnect your keyboard
/// from it. It will simply output the HID reports to the connected bluetooth device.
OutputBluetooth,
OutputBluetooth = 2,
}

#[rumcake_macros::task]
Expand Down
17 changes: 10 additions & 7 deletions rumcake/src/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,37 +216,40 @@ pub fn setup_analog_keyboard_matrix<S: MatrixSampler, const CS: usize, const RS:
///
/// These can be used in your keyboard layout, defined in [`KeyboardLayout::get_layout`]
#[derive(Debug, Clone, Copy)]
#[non_exhaustive]
#[repr(u8)]
pub enum Keycode {
/// Custom keycode, which can be used to run custom code. You can use
/// [`KeyboardLayout::on_custom_keycode`] to handle it.
Custom(u8),
Custom(u8) = 0,

/// Hardware keycode, which can be any variant in [`crate::hw::HardwareCommand`]
Hardware(crate::hw::HardwareCommand),
Hardware(crate::hw::HardwareCommand) = 1,

#[cfg(feature = "media-keycodes")]
/// Media keycode, which can be any variant in [`usbd_human_interface_device::page::Consumer`]
Media(usbd_human_interface_device::page::Consumer),
Media(usbd_human_interface_device::page::Consumer) = 2,

#[cfg(feature = "simple-backlight")]
/// Keycode used to control a simple backlight system, which can be any variant in
/// [`crate::lighting::simple_backlight::SimpleBacklightCommand`]
SimpleBacklight(crate::lighting::simple_backlight::SimpleBacklightCommand),
SimpleBacklight(crate::lighting::simple_backlight::SimpleBacklightCommand) = 3,

#[cfg(feature = "simple-backlight-matrix")]
/// Keycode used to control a simple backlight matrix system, which can be any variant in
/// [`crate::lighting::simple_backlight_matrix::SimpleBacklightMatrixCommand`]
SimpleBacklightMatrix(crate::lighting::simple_backlight_matrix::SimpleBacklightMatrixCommand),
SimpleBacklightMatrix(crate::lighting::simple_backlight_matrix::SimpleBacklightMatrixCommand) =
4,

#[cfg(feature = "rgb-backlight-matrix")]
/// Keycode used to control an RGB backlight matrix system, which can be any variant in
/// [`crate::lighting::rgb_backlight_matrix::RGBBacklightMatrixCommand`]
RGBBacklightMatrix(crate::lighting::rgb_backlight_matrix::RGBBacklightMatrixCommand),
RGBBacklightMatrix(crate::lighting::rgb_backlight_matrix::RGBBacklightMatrixCommand) = 5,

#[cfg(feature = "underglow")]
/// Underglow keycode, which can be any variant in
/// [`crate::lighting::underglow::UnderglowCommand`]
Underglow(crate::lighting::underglow::UnderglowCommand),
Underglow(crate::lighting::underglow::UnderglowCommand) = 6,
}

pub struct PollableMatrix<T> {
Expand Down
42 changes: 22 additions & 20 deletions rumcake/src/lighting/rgb_backlight_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,28 +188,30 @@ impl Default for RGBBacklightMatrixConfig {
}

#[derive(Serialize, Deserialize, Debug, Clone, Copy, MaxSize)]
#[non_exhaustive]
#[repr(u8)]
pub enum RGBBacklightMatrixCommand {
Toggle,
TurnOn,
TurnOff,
NextEffect,
PrevEffect,
SetEffect(RGBBacklightMatrixEffect),
SetHue(u8),
IncreaseHue(u8),
DecreaseHue(u8),
SetSaturation(u8),
IncreaseSaturation(u8),
DecreaseSaturation(u8),
SetValue(u8),
IncreaseValue(u8),
DecreaseValue(u8),
SetSpeed(u8),
IncreaseSpeed(u8),
DecreaseSpeed(u8),
Toggle = 0,
TurnOn = 1,
TurnOff = 2,
NextEffect = 3,
PrevEffect = 4,
SetEffect(RGBBacklightMatrixEffect) = 5,
SetHue(u8) = 6,
IncreaseHue(u8) = 7,
DecreaseHue(u8) = 8,
SetSaturation(u8) = 9,
IncreaseSaturation(u8) = 10,
DecreaseSaturation(u8) = 11,
SetValue(u8) = 12,
IncreaseValue(u8) = 13,
DecreaseValue(u8) = 14,
SetSpeed(u8) = 15,
IncreaseSpeed(u8) = 16,
DecreaseSpeed(u8) = 17,
#[cfg(feature = "storage")]
SaveConfig,
ResetTime, // normally used internally for syncing LEDs for split keyboards
SaveConfig = 18,
ResetTime = 19, // normally used internally for syncing LEDs for split keyboards
}

#[generate_items_from_enum_variants("const {variant_shouty_snake_case}_ENABLED: bool = true")]
Expand Down
30 changes: 16 additions & 14 deletions rumcake/src/lighting/simple_backlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,24 @@ impl Default for SimpleBacklightConfig {
}

#[derive(Serialize, Deserialize, Debug, Clone, Copy, MaxSize)]
#[non_exhaustive]
#[repr(u8)]
pub enum SimpleBacklightCommand {
Toggle,
TurnOn,
TurnOff,
NextEffect,
PrevEffect,
SetEffect(SimpleBacklightEffect),
SetValue(u8),
IncreaseValue(u8),
DecreaseValue(u8),
SetSpeed(u8),
IncreaseSpeed(u8),
DecreaseSpeed(u8),
Toggle = 0,
TurnOn = 1,
TurnOff = 2,
NextEffect = 3,
PrevEffect = 4,
SetEffect(SimpleBacklightEffect) = 5,
SetValue(u8) = 6,
IncreaseValue(u8) = 7,
DecreaseValue(u8) = 8,
SetSpeed(u8) = 9,
IncreaseSpeed(u8) = 10,
DecreaseSpeed(u8) = 11,
#[cfg(feature = "storage")]
SaveConfig,
ResetTime, // normally used internally for syncing LEDs for split keyboards
SaveConfig = 12,
ResetTime = 13, // normally used internally for syncing LEDs for split keyboards
}

#[generate_items_from_enum_variants("const {variant_shouty_snake_case}_ENABLED: bool = true")]
Expand Down
30 changes: 16 additions & 14 deletions rumcake/src/lighting/simple_backlight_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,24 @@ impl Default for SimpleBacklightMatrixConfig {
}

#[derive(Serialize, Deserialize, Debug, Clone, Copy, MaxSize)]
#[non_exhaustive]
#[repr(u8)]
pub enum SimpleBacklightMatrixCommand {
Toggle,
TurnOn,
TurnOff,
NextEffect,
PrevEffect,
SetEffect(SimpleBacklightMatrixEffect),
SetValue(u8),
IncreaseValue(u8),
DecreaseValue(u8),
SetSpeed(u8),
IncreaseSpeed(u8),
DecreaseSpeed(u8),
Toggle = 0,
TurnOn = 1,
TurnOff = 2,
NextEffect = 3,
PrevEffect = 4,
SetEffect(SimpleBacklightMatrixEffect) = 5,
SetValue(u8) = 6,
IncreaseValue(u8) = 7,
DecreaseValue(u8) = 8,
SetSpeed(u8) = 9,
IncreaseSpeed(u8) = 10,
DecreaseSpeed(u8) = 11,
#[cfg(feature = "storage")]
SaveConfig,
ResetTime, // normally used internally for syncing LEDs for split keyboards
SaveConfig = 12,
ResetTime = 13, // normally used internally for syncing LEDs for split keyboards
}

#[generate_items_from_enum_variants("const {variant_shouty_snake_case}_ENABLED: bool = true")]
Expand Down
42 changes: 22 additions & 20 deletions rumcake/src/lighting/underglow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,28 +180,30 @@ impl Default for UnderglowConfig {
}

#[derive(Serialize, Deserialize, Debug, Clone, Copy, MaxSize)]
#[non_exhaustive]
#[repr(u8)]
pub enum UnderglowCommand {
Toggle,
TurnOn,
TurnOff,
NextEffect,
PrevEffect,
SetEffect(UnderglowEffect),
SetHue(u8),
IncreaseHue(u8),
DecreaseHue(u8),
SetSaturation(u8),
IncreaseSaturation(u8),
DecreaseSaturation(u8),
SetValue(u8),
IncreaseValue(u8),
DecreaseValue(u8),
SetSpeed(u8),
IncreaseSpeed(u8),
DecreaseSpeed(u8),
Toggle = 0,
TurnOn = 1,
TurnOff = 2,
NextEffect = 3,
PrevEffect = 4,
SetEffect(UnderglowEffect) = 5,
SetHue(u8) = 6,
IncreaseHue(u8) = 7,
DecreaseHue(u8) = 8,
SetSaturation(u8) = 9,
IncreaseSaturation(u8) = 10,
DecreaseSaturation(u8) = 11,
SetValue(u8) = 12,
IncreaseValue(u8) = 13,
DecreaseValue(u8) = 14,
SetSpeed(u8) = 15,
IncreaseSpeed(u8) = 16,
DecreaseSpeed(u8) = 17,
#[cfg(feature = "storage")]
SaveConfig,
ResetTime, // normally used internally for syncing LEDs for split keyboards
SaveConfig = 18,
ResetTime = 19, // normally used internally for syncing LEDs for split keyboards
}

#[generate_items_from_enum_variants("const {variant_shouty_snake_case}_ENABLED: bool = true")]
Expand Down
16 changes: 10 additions & 6 deletions rumcake/src/split/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ pub mod central;
#[cfg(feature = "split-peripheral")]
pub mod peripheral;

#[derive(Serialize, Deserialize, Debug, Clone, Copy, MaxSize)]
/// Possible messages that can be sent to a central device.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, MaxSize)]
#[repr(u8)]
pub enum MessageToCentral {
/// Key press in the form of (row, col).
KeyPress(u8, u8),
Expand Down Expand Up @@ -44,29 +45,32 @@ impl TryFrom<MessageToCentral> for Event {
}
}

#[derive(Serialize, Deserialize, Debug, Clone, Copy, MaxSize)]
/// Possible messages that can be sent to a peripheral device.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, MaxSize)]
#[non_exhaustive]
#[repr(u8)]
pub enum MessageToPeripheral {
#[cfg(feature = "simple-backlight")]
/// A [`SimpleBacklightCommand`](crate::lighting::simple_backlight::SimpleBacklightCommand) to
/// be processed by the peripheral's simple backlight animator.
SimpleBacklight(crate::lighting::simple_backlight::SimpleBacklightCommand),
SimpleBacklight(crate::lighting::simple_backlight::SimpleBacklightCommand) = 3,

#[cfg(feature = "simple-backlight-matrix")]
/// A
/// [`SimpleBacklightMatrixCommand`](crate::lighting::simple_backlight_matrix::SimpleBacklightMatrixCommand)
/// to be processed by the peripheral's simple backlight matrix animator.
SimpleBacklightMatrix(crate::lighting::simple_backlight_matrix::SimpleBacklightMatrixCommand),
SimpleBacklightMatrix(crate::lighting::simple_backlight_matrix::SimpleBacklightMatrixCommand) =
4,

#[cfg(feature = "rgb-backlight-matrix")]
/// A
/// [`RGBBacklightMatrixCommand`](crate::lighting::rgb_backlight_matrix::RGBBacklightMatrixCommand)
/// to be processed by the peripheral's RGB backlight matrix animator.
RGBBacklightMatrix(crate::lighting::rgb_backlight_matrix::RGBBacklightMatrixCommand),
RGBBacklightMatrix(crate::lighting::rgb_backlight_matrix::RGBBacklightMatrixCommand) = 5,

#[cfg(feature = "underglow")]
/// An [`UnderglowCommand`](crate::lighting::underglow::UnderglowCommand) to be processed by the peripheral's backlight animator.
Underglow(crate::lighting::underglow::UnderglowCommand),
Underglow(crate::lighting::underglow::UnderglowCommand) = 6,
}

/// Size of buffer used when sending messages to a peripheral device
Expand Down

0 comments on commit eb32fc7

Please sign in to comment.