Skip to content

Commit

Permalink
fix: change combo storage key to not conflict with bond info
Browse files Browse the repository at this point in the history
  • Loading branch information
pcasotti committed Dec 6, 2024
1 parent 411ee2c commit ee8fecb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 17 additions & 6 deletions rmk/src/storage/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
mod eeconfig;
pub mod nor_flash;

use crate::{combo::Combo, config::StorageConfig};
use crate::{
combo::{Combo, COMBO_MAX_LENGTH},
config::StorageConfig,
};
use byteorder::{BigEndian, ByteOrder};
use core::fmt::Debug;
use core::ops::Range;
Expand Down Expand Up @@ -124,6 +127,10 @@ pub(crate) fn get_keymap_key<const ROW: usize, const COL: usize, const NUM_LAYER
(0x1000 + layer * COL * ROW + row * COL + col) as u32
}

pub(crate) fn get_combo_key(idx: usize) -> u32 {
(0x3000 + idx) as u32
}

impl Value<'_> for StorageData {
fn serialize_into(&self, buffer: &mut [u8]) -> Result<usize, SerializationError> {
if buffer.len() < 6 {
Expand Down Expand Up @@ -310,7 +317,9 @@ impl StorageData {
panic!("To get storage key for KeymapKey, use `get_keymap_key` instead");
}
StorageData::MacroData(_) => StorageKeys::MacroData as u32,
StorageData::ComboData(_) => StorageKeys::ComboData as u32,
StorageData::ComboData(_) => {
panic!("To get combo key for ComboData, use `get_combo_key` instead");
}
StorageData::ConnectionType(_) => StorageKeys::ConnectionType as u32,
#[cfg(feature = "_nrf_ble")]
StorageData::BondInfo(b) => get_bond_info_key(b.slot_num),
Expand Down Expand Up @@ -341,8 +350,8 @@ pub(crate) struct KeymapKey {

#[derive(Clone, Copy, Debug, Format)]
pub(crate) struct ComboData {
pub(crate) idx: u8,
pub(crate) actions: [KeyAction; 4],
pub(crate) idx: usize,
pub(crate) actions: [KeyAction; COMBO_MAX_LENGTH],
pub(crate) output: KeyAction,
}

Expand Down Expand Up @@ -541,12 +550,13 @@ impl<F: AsyncNorFlash, const ROW: usize, const COL: usize, const NUM_LAYER: usiz
.await
}
FlashOperationMessage::WriteCombo(combo) => {
let key = get_combo_key(combo.idx);
store_item(
&mut self.flash,
self.storage_range.clone(),
&mut storage_cache,
&mut self.buffer,
&(0x2000 + combo.idx as u32),
&key,
&StorageData::ComboData(combo),
)
.await
Expand Down Expand Up @@ -681,12 +691,13 @@ impl<F: AsyncNorFlash, const ROW: usize, const COL: usize, const NUM_LAYER: usiz

pub(crate) async fn read_combos(&mut self, combos: &mut [Combo]) -> Result<(), ()> {
for i in 0..combos.len() {
let key = get_combo_key(i);
let read_data = fetch_item::<u32, StorageData, _>(
&mut self.flash,
self.storage_range.clone(),
&mut NoCache::new(),
&mut self.buffer,
&(0x2000 + i as u32),
&key,
)
.await
.map_err(|e| print_storage_error::<F>(e))?;
Expand Down
2 changes: 1 addition & 1 deletion rmk/src/via/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ impl<'a, const ROW: usize, const COL: usize, const NUM_LAYER: usize>
}
FLASH_CHANNEL
.send(FlashOperationMessage::WriteCombo(ComboData {
idx: combo_idx as u8,
idx: combo_idx,
actions,
output,
}))
Expand Down

0 comments on commit ee8fecb

Please sign in to comment.