Skip to content

Commit 8252052

Browse files
authored
Merge pull request #847 from HaoboGu/feat/rynk-pr1-protocol
Rename rmk_protocol to rynk, add basic rynk protocol, remove postcard-rpc
2 parents 0b94501 + b424542 commit 8252052

51 files changed

Lines changed: 875 additions & 1356 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

rmk-config/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(crate) mod storage;
2626
///
2727
/// These define the maximum values any firmware may use for protocol
2828
/// Vec capacities (`COMBO_SIZE`, `MORSE_SIZE`, etc.). The host tool compiles
29-
/// against these as upper bounds. Any firmware with `rmk_protocol` enabled
29+
/// against these as upper bounds. Any firmware with `rynk` enabled
3030
/// must satisfy `value <= ceiling` at compile time.
3131
///
3232
/// Constant names mirror the generated constants with a `MAX_` prefix:
@@ -249,6 +249,11 @@ pub(crate) struct RmkConstantsConfig {
249249
/// Smaller values reduce firmware RAM usage but require more round-trips.
250250
#[serde_inline_default(64)]
251251
pub protocol_macro_chunk_size: usize,
252+
/// Optional override for the Rynk RX/TX buffer size (bytes). When `None`,
253+
/// the build emits `RYNK_BUFFER_SIZE = RYNK_MIN_BUFFER_SIZE`. The const
254+
/// assertion in `rmk/src/host/rynk` rejects user values below the floor.
255+
#[serde(default)]
256+
pub rynk_buffer_size: Option<usize>,
252257
}
253258

254259
fn check_combo_max_num<'de, D>(deserializer: D) -> Result<usize, D::Error>
@@ -316,6 +321,7 @@ impl Default for RmkConstantsConfig {
316321
split_central_sleep_timeout_seconds: 0,
317322
protocol_max_bulk_size: 8,
318323
protocol_macro_chunk_size: 64,
324+
rynk_buffer_size: None,
319325
}
320326
}
321327
}

rmk-config/src/resolved/build_constants.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ pub struct BuildConstants {
4848
pub split_central_sleep_timeout_seconds: u32,
4949
pub protocol_max_bulk_size: usize,
5050
pub protocol_macro_chunk_size: usize,
51+
/// Optional override for the Rynk RX/TX buffer size (bytes). `None`
52+
/// instructs `rmk-types/build.rs` to fall back to `RYNK_MIN_BUFFER_SIZE`.
53+
pub rynk_buffer_size: Option<usize>,
5154
pub events: Vec<EventChannel>,
5255
pub passkey: Option<Passkey>,
5356
}
@@ -173,6 +176,7 @@ impl crate::KeyboardTomlConfig {
173176
split_central_sleep_timeout_seconds: rmk.split_central_sleep_timeout_seconds,
174177
protocol_max_bulk_size: rmk.protocol_max_bulk_size,
175178
protocol_macro_chunk_size: rmk.protocol_macro_chunk_size,
179+
rynk_buffer_size: rmk.rynk_buffer_size,
176180
events,
177181
passkey,
178182
})

rmk-types/Cargo.toml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ defmt = { version = "1.0", optional = true }
1414

1515
serde = { version = "1", default-features = false, features = ["derive"] }
1616
postcard = { version = "1", features = ["experimental-derive"] }
17-
postcard-schema = { version = "0.2", default-features = false, features = ["derive", "heapless-v0_9"], optional = true }
18-
postcard-rpc = { version = "0.12", default-features = false, optional = true }
1917
heapless = { version = "0.9", default-features = false, features = ["serde"] }
2018
strum = { version = "0.28", default-features = false, features = ["derive"] }
2119

@@ -34,14 +32,14 @@ defmt = [
3432
]
3533
# Feature for proc-macro code generation only, not included in firmware
3634
_codegen = []
37-
# Feature for RMK native protocol schema/endpoint support
38-
rmk_protocol = ["dep:postcard-rpc", "dep:postcard-schema"]
35+
# Feature for RMK native (rynk) protocol support
36+
rynk = []
3937
# Bulk transfer endpoints for MCUs with sufficient RAM.
4038
# Enables multi-element bulk keymap/combo/morse endpoints and BULK_SIZE constant.
41-
bulk = ["rmk_protocol"]
39+
bulk = ["rynk"]
4240
# Host tool: uses protocol ceiling values for Vec capacities.
4341
# Enables all optional endpoint groups so the host can talk to any firmware.
44-
host = ["rmk_protocol", "bulk", "_ble", "split"]
42+
host = ["rynk", "bulk", "_ble", "split"]
4543
# Build-time only features: forwarded from rmk to control constant generation in build.rs.
4644
# Also used as `#[cfg(feature = "...")]` guards for protocol endpoint/topic gating.
4745
_ble = []

rmk-types/build.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ fn generate_constants(bc: &BuildConstants) -> String {
150150
bc.protocol_macro_chunk_size
151151
));
152152
// Compile-time check: firmware Vec sizes must not exceed protocol ceilings.
153-
// Only enforce when the rmk_protocol feature is active.
154-
if env::var("CARGO_FEATURE_RMK_PROTOCOL").is_ok() {
153+
// Only enforce when the rynk feature is active.
154+
if env::var("CARGO_FEATURE_RYNK").is_ok() {
155155
lines.push("const _: () = assert!(COMBO_SIZE <= MAX_COMBO_SIZE, \"firmware COMBO_SIZE exceeds protocol ceiling MAX_COMBO_SIZE\");".to_string());
156156
lines.push("const _: () = assert!(MORSE_SIZE <= MAX_MORSE_SIZE, \"firmware MORSE_SIZE exceeds protocol ceiling MAX_MORSE_SIZE\");".to_string());
157157
lines.push("const _: () = assert!(MACRO_DATA_SIZE <= MAX_MACRO_DATA_SIZE, \"firmware MACRO_DATA_SIZE exceeds protocol ceiling MAX_MACRO_DATA_SIZE\");".to_string());
@@ -164,6 +164,25 @@ fn generate_constants(bc: &BuildConstants) -> String {
164164
}
165165
}
166166

167+
// Rynk RX/TX buffer size. Only emitted when the `rynk` feature is on
168+
// so the constant doesn't leak into non-Rynk builds. `None` falls back
169+
// to `RYNK_MIN_BUFFER_SIZE`, which is the compile-time lower bound;
170+
// the `rmk/src/host/rynk/mod.rs` const-assert rejects values below it.
171+
if env::var("CARGO_FEATURE_RYNK").is_ok() {
172+
match bc.rynk_buffer_size {
173+
Some(n) => {
174+
lines.push(format!("pub const RYNK_BUFFER_SIZE: usize = {n};"));
175+
}
176+
None => {
177+
lines.push(
178+
"pub const RYNK_BUFFER_SIZE: usize = \
179+
crate::protocol::rynk::RYNK_MIN_BUFFER_SIZE;"
180+
.to_string(),
181+
);
182+
}
183+
}
184+
}
185+
167186
// Event channels
168187
for ev in &bc.events {
169188
let upper = ev.name.to_uppercase();

rmk-types/src/action/encoder.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! Rotary encoder actions.
22
33
use postcard::experimental::max_size::MaxSize;
4-
#[cfg(feature = "rmk_protocol")]
5-
use postcard_schema::Schema;
64
use serde::{Deserialize, Serialize};
75

86
use super::KeyAction;
@@ -12,7 +10,6 @@ use super::KeyAction;
1210
/// Both fields default to `KeyAction::No` (no action).
1311
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, MaxSize)]
1412
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
15-
#[cfg_attr(feature = "rmk_protocol", derive(Schema))]
1613
pub struct EncoderAction {
1714
/// Action triggered when the encoder is rotated clockwise.
1815
pub clockwise: KeyAction,

rmk-types/src/action/key_action.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! Composite key actions stored in the keymap.
22
33
use postcard::experimental::max_size::MaxSize;
4-
#[cfg(feature = "rmk_protocol")]
5-
use postcard_schema::Schema;
64
use serde::{Deserialize, Serialize};
75

86
use super::Action;
@@ -12,7 +10,6 @@ use crate::morse::MorseProfile;
1210
/// It can be a single action like triggering a key, or a composite keyboard action like tap/hold
1311
#[derive(Debug, Copy, Clone, Eq, Serialize, Deserialize, MaxSize)]
1412
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
15-
#[cfg_attr(feature = "rmk_protocol", derive(Schema))]
1613
#[non_exhaustive]
1714
pub enum KeyAction {
1815
/// No action

rmk-types/src/action/keyboard.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
//! Keyboard control actions.
22
33
use postcard::experimental::max_size::MaxSize;
4-
#[cfg(feature = "rmk_protocol")]
5-
use postcard_schema::Schema;
64
use serde::{Deserialize, Serialize};
75

86
/// Actions for controlling the keyboard or changing the keyboard's state, for example, enable/disable a particular function
97
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, MaxSize)]
108
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
11-
#[cfg_attr(feature = "rmk_protocol", derive(Schema))]
129
#[cfg_attr(feature = "_codegen", derive(strum::VariantNames))]
1310
#[non_exhaustive]
1411
pub enum KeyboardAction {

rmk-types/src/action/light.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
//! Light control actions.
22
33
use postcard::experimental::max_size::MaxSize;
4-
#[cfg(feature = "rmk_protocol")]
5-
use postcard_schema::Schema;
64
use serde::{Deserialize, Serialize};
75

86
/// Actions for controlling lights
97
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, MaxSize)]
108
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
11-
#[cfg_attr(feature = "rmk_protocol", derive(Schema))]
129
#[cfg_attr(feature = "_codegen", derive(strum::VariantNames))]
1310
#[non_exhaustive]
1411
pub enum LightAction {

rmk-types/src/action/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ pub use key_action::KeyAction;
2222
pub use keyboard::KeyboardAction;
2323
pub use light::LightAction;
2424
use postcard::experimental::max_size::MaxSize;
25-
#[cfg(feature = "rmk_protocol")]
26-
use postcard_schema::Schema;
2725
use serde::{Deserialize, Serialize};
2826

2927
use crate::keycode::{KeyCode, SpecialKey};
@@ -34,7 +32,6 @@ use crate::steno::StenoKey;
3432
/// A single basic action that a keyboard can execute.
3533
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, MaxSize)]
3634
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
37-
#[cfg_attr(feature = "rmk_protocol", derive(Schema))]
3835
#[non_exhaustive]
3936
pub enum Action {
4037
/// Default action, no action.

rmk-types/src/battery.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
//! Battery status types.
22
33
use postcard::experimental::max_size::MaxSize;
4-
#[cfg(feature = "rmk_protocol")]
5-
use postcard_schema::Schema;
64
use serde::{Deserialize, Serialize};
75

86
/// Charge state of the battery.
97
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, MaxSize)]
10-
#[cfg_attr(feature = "rmk_protocol", derive(Schema))]
118
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
129
pub enum ChargeState {
1310
Charging,
@@ -28,7 +25,6 @@ impl From<bool> for ChargeState {
2825

2926
/// Battery status used for both status queries and event notifications.
3027
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, MaxSize)]
31-
#[cfg_attr(feature = "rmk_protocol", derive(Schema))]
3228
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
3329
pub enum BatteryStatus {
3430
Unavailable,

0 commit comments

Comments
 (0)