diff --git a/.github/workflows/build esp.yml b/.github/workflows/build esp.yml index 2c92e266..553d48f7 100644 --- a/.github/workflows/build esp.yml +++ b/.github/workflows/build esp.yml @@ -21,8 +21,17 @@ env: CARGO_TERM_COLOR: always jobs: - build_esp32c3_ble: + build_esp: runs-on: ubuntu-22.04 + strategy: + matrix: + chip: + - esp32c3 + - esp32c6 + - esp32s3 + example_type: + - use_rust + - use_config steps: - uses: cargo-bins/cargo-binstall@main - uses: actions/checkout@v3 @@ -30,101 +39,8 @@ jobs: run: cargo binstall ldproxy espup -y - name: Install esp toolchain run: espup install - - name: Build esp32c3_ble - working-directory: ./examples/use_rust/esp32c3_ble - run: | - cargo +esp build --release - cargo clean - build_esp32c3_ble_with_config: - runs-on: ubuntu-22.04 - steps: - - uses: cargo-bins/cargo-binstall@main - - uses: actions/checkout@v3 - - name: Install ldproxy and espup - run: cargo binstall ldproxy espup -y - - name: Install esp toolchain - run: espup install - - name: Build esp32c3_ble with config - working-directory: ./examples/use_config/esp32c3_ble - run: | - cargo +esp build --release - cargo clean - build_esp32c6_ble: - runs-on: ubuntu-22.04 - steps: - - uses: cargo-bins/cargo-binstall@main - - uses: actions/checkout@v3 - - name: Install ldproxy and espup - run: cargo binstall ldproxy espup -y - - name: Install esp toolchain - run: espup install - - name: Build esp32c6_ble - working-directory: ./examples/use_rust/esp32c6_ble - run: | - cargo +esp build --release - cargo clean - build_esp32c6_ble_with_config: - runs-on: ubuntu-22.04 - steps: - - uses: cargo-bins/cargo-binstall@main - - uses: actions/checkout@v3 - - name: Install ldproxy and espup - run: cargo binstall ldproxy espup -y - - name: Install esp toolchain - run: espup install - - name: Build esp32c6_ble with config - working-directory: ./examples/use_config/esp32c6_ble - run: | - cargo +esp build --release - cargo clean - - build_esp32s3_ble: - runs-on: ubuntu-22.04 - steps: - - uses: cargo-bins/cargo-binstall@main - - uses: actions/checkout@v3 - - uses: actions/cache@v3 - id: cache-cargo - with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - ./examples/use_rust/esp32s3_ble/target/ - ./examples/use_rust/esp32s3_ble/.embuild/ - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: Install ldproxy and espup - run: cargo binstall ldproxy espup -y - - name: Install esp toolchain - run: espup install - - name: Build esp32s3_ble - working-directory: ./examples/use_rust/esp32s3_ble - run: | - cargo +esp build --release - cargo clean - build_esp32s3_ble_with_config: - runs-on: ubuntu-22.04 - steps: - - uses: cargo-bins/cargo-binstall@main - - uses: actions/checkout@v3 - - uses: actions/cache@v3 - id: cache-cargo - with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - ./examples/use_rust/esp32s3_ble/target/ - ./examples/use_rust/esp32s3_ble/.embuild/ - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: Install ldproxy and espup - run: cargo binstall ldproxy espup -y - - name: Install esp toolchain - run: espup install - - name: Build esp32s3_ble with config - working-directory: ./examples/use_config/esp32s3_ble + - name: Build + working-directory: ./examples/${{ matrix.example_type }}/${{ matrix.chip }}_ble run: | cargo +esp build --release cargo clean diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2e1ce5df..d73694ae 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,281 +19,41 @@ concurrency: env: CARGO_TERM_COLOR: always - # By default, RUSTFLAGS with “-D warnings” turns warnings into errors. - RUSTFLAGS: jobs: - determine-runner: + build_examples: runs-on: ubuntu-latest - outputs: - runner: ${{ steps.set-runner.outputs.use-runner }} - steps: - - name: Determine which runner to use - id: set-runner - uses: jimmygchen/runner-fallback-action@v1 - with: - primary-runner: "self-hosted" - fallback-runner: "ubuntu-latest" - github-token: ${{ vars.RMK_GITHUB_TOKEN }} - - build_rmk: - needs: determine-runner - runs-on: ${{ fromJson(needs.determine-runner.outputs.runner) }} + strategy: + matrix: + example: + - nrf52832_ble + - nrf52840_ble + - nrf52840_ble_split + - rp2040 + - rp2040_split + - rp2040_direct_pin + - stm32f1 + - stm32f4 + - stm32h7 + example_type: + - use_rust + - use_config steps: - uses: actions/setup-python@v5 with: - python-version: '3.11' - - uses: actions-rust-lang/setup-rust-toolchain@v1 - - name: Install cargo-make - run: cargo install cargo-make + python-version: "3.11" + - uses: cargo-bins/cargo-binstall@main - uses: actions/checkout@v3 - - name: Build rmk - working-directory: ./rmk - run: cargo build --release - build_rp2040: - needs: determine-runner - runs-on: ${{ fromJson(needs.determine-runner.outputs.runner) }} - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - uses: actions-rust-lang/setup-rust-toolchain@v1 - name: Install cargo-make - run: cargo install cargo-make - - uses: actions/checkout@v3 + run: cargo binstall cargo-make - name: Install target - run: rustup target add thumbv6m-none-eabi + run: rustup target add thumbv6m-none-eabi thumbv7em-none-eabihf thumbv7m-none-eabi - name: Build rp2040 - working-directory: ./examples/use_rust/rp2040 - run: cargo make uf2 --release - build_rp2040_with_config: - needs: determine-runner - runs-on: ${{ fromJson(needs.determine-runner.outputs.runner) }} - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - uses: actions-rust-lang/setup-rust-toolchain@v1 - - name: Install cargo-make - run: cargo install cargo-make - - uses: actions/checkout@v3 - - name: Install target - run: rustup target add thumbv6m-none-eabi - - name: Build rp2040 with config - working-directory: ./examples/use_config/rp2040 - run: cargo make uf2 --release - build_stm32h7: - needs: determine-runner - runs-on: ${{ fromJson(needs.determine-runner.outputs.runner) }} - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - uses: actions-rust-lang/setup-rust-toolchain@v1 - - name: Install cargo-make - run: cargo install cargo-make - - uses: actions/checkout@v3 - - name: Install target - run: rustup target add thumbv7em-none-eabihf - - name: Build stm32h7 - working-directory: ./examples/use_rust/stm32h7 - run: cargo make uf2 --release - build_stm32h7_with_config: - needs: determine-runner - runs-on: ${{ fromJson(needs.determine-runner.outputs.runner) }} - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - uses: actions-rust-lang/setup-rust-toolchain@v1 - - name: Install cargo-make - run: cargo install cargo-make - - uses: actions/checkout@v3 - - name: Install target - run: rustup target add thumbv7em-none-eabihf - - name: Build stm32h7 with config - working-directory: ./examples/use_config/stm32h7 - run: cargo make uf2 --release - build_stm32f1: - needs: determine-runner - runs-on: ${{ fromJson(needs.determine-runner.outputs.runner) }} - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - uses: actions-rust-lang/setup-rust-toolchain@v1 - - name: Install cargo-make - run: cargo install cargo-make - - uses: actions/checkout@v3 - - name: Install target - run: rustup target add thumbv7m-none-eabi - - name: Build stm32f1 - working-directory: ./examples/use_rust/stm32f1 - run: cargo make uf2 --release - build_stm32f1_with_config: - needs: determine-runner - runs-on: ${{ fromJson(needs.determine-runner.outputs.runner) }} - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - uses: actions-rust-lang/setup-rust-toolchain@v1 - - name: Install cargo-make - run: cargo install cargo-make - - uses: actions/checkout@v3 - - name: Install target - run: rustup target add thumbv7m-none-eabi - - name: Build stm32f1 with config - working-directory: ./examples/use_config/stm32f1 - run: cargo make uf2 --release - build_stm32f4: - needs: determine-runner - runs-on: ${{ fromJson(needs.determine-runner.outputs.runner) }} - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - uses: actions-rust-lang/setup-rust-toolchain@v1 - - name: Install cargo-make - run: cargo install cargo-make - - uses: actions/checkout@v3 - - name: Install target - run: rustup target add thumbv7em-none-eabihf - - name: Build stm32f4 - working-directory: ./examples/use_rust/stm32f4 - run: cargo make uf2 --release - build_stm32f4_with_config: - needs: determine-runner - runs-on: ${{ fromJson(needs.determine-runner.outputs.runner) }} - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - uses: actions-rust-lang/setup-rust-toolchain@v1 - - name: Install cargo-make - run: cargo install cargo-make - - uses: actions/checkout@v3 - - name: Install target - run: rustup target add thumbv7em-none-eabihf - - name: Build stm32f4 with config - working-directory: ./examples/use_config/stm32f4 - run: cargo make uf2 --release - build_nrf52840_ble: - needs: determine-runner - runs-on: ${{ fromJson(needs.determine-runner.outputs.runner) }} - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - uses: actions-rust-lang/setup-rust-toolchain@v1 - - name: Install cargo-make - run: cargo install cargo-make - - uses: actions/checkout@v3 - - name: Install target - run: rustup target add thumbv7em-none-eabihf - - name: Build nrf52840_ble - working-directory: ./examples/use_rust/nrf52840_ble - run: cargo make uf2 --release - build_nrf52832_ble: - needs: determine-runner - runs-on: ${{ fromJson(needs.determine-runner.outputs.runner) }} - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - uses: actions-rust-lang/setup-rust-toolchain@v1 - - name: Install cargo-make - run: cargo install cargo-make - - uses: actions/checkout@v3 - - name: Install target - run: rustup target add thumbv7em-none-eabihf - - name: Build nrf52832_ble - working-directory: ./examples/use_rust/nrf52832_ble - run: cargo make uf2 --release - build_nrf52832_ble_with_config: - needs: determine-runner - runs-on: ${{ fromJson(needs.determine-runner.outputs.runner) }} - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - uses: actions-rust-lang/setup-rust-toolchain@v1 - - name: Install cargo-make - run: cargo install cargo-make - - uses: actions/checkout@v3 - - name: Install target - run: rustup target add thumbv7em-none-eabihf - - name: Build nrf52832_ble with config - working-directory: ./examples/use_config/nrf52832_ble - run: cargo make uf2 --release - build_rp2040_split: - needs: determine-runner - runs-on: ${{ fromJson(needs.determine-runner.outputs.runner) }} - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - uses: actions-rust-lang/setup-rust-toolchain@v1 - - name: Install cargo-make - run: cargo install cargo-make - - uses: actions/checkout@v3 - - name: Install target - run: rustup target add thumbv6m-none-eabi - - name: Build rp2040 split - working-directory: ./examples/use_rust/rp2040_split - run: cargo make uf2 --release - build_rp2040_split_with_config: - needs: determine-runner - runs-on: ${{ fromJson(needs.determine-runner.outputs.runner) }} - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - uses: actions-rust-lang/setup-rust-toolchain@v1 - - name: Install cargo-make - run: cargo install cargo-make - - uses: actions/checkout@v3 - - name: Install target - run: rustup target add thumbv6m-none-eabi - - name: Build rp2040 split with config - working-directory: ./examples/use_config/rp2040_split - run: cargo make uf2 --release - build_nrf52840: - needs: determine-runner - runs-on: ${{ fromJson(needs.determine-runner.outputs.runner) }} - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - uses: actions-rust-lang/setup-rust-toolchain@v1 - - name: Install cargo-make - run: cargo install cargo-make - - uses: actions/checkout@v3 - - name: Install target - run: rustup target add thumbv7em-none-eabihf - - name: Build nrf52840 split - working-directory: ./examples/use_rust/nrf52840_ble_split - run: cargo make uf2 --release - build_nrf52840_split_with_config: - needs: determine-runner - runs-on: ${{ fromJson(needs.determine-runner.outputs.runner) }} - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - uses: actions-rust-lang/setup-rust-toolchain@v1 - - name: Install cargo-make - run: cargo install cargo-make - - uses: actions/checkout@v3 - - name: Install target - run: rustup target add thumbv7em-none-eabihf - - name: Build nrf52840 split with config - working-directory: ./examples/use_config/nrf52840_ble_split + working-directory: ./examples/${{ matrix.example_type }}/${{ matrix.example }} run: cargo make uf2 --release binary-size: # Copied from sequential-storage: https://github.com/tweedegolf/sequential-storage/blob/master/.github/workflows/ci.yaml - needs: determine-runner - runs-on: ${{ fromJson(needs.determine-runner.outputs.runner) }} + runs-on: ubuntu-latest permissions: actions: read pull-requests: write @@ -310,7 +70,7 @@ jobs: ./example/target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Install flip-link - run: cargo install flip-link + run: cargo install flip-link --force - run: rustup target add thumbv7em-none-eabihf - run: rustup component add rust-src llvm-tools - if: steps.cache-cargo.outputs.cache-hit != 'true' @@ -318,7 +78,7 @@ jobs: - name: Check out the repo with the full git history uses: actions/checkout@v3 with: - fetch-depth: '0' + fetch-depth: "0" - name: Build new binary working-directory: ./examples/use_config/nrf52840_ble run: | @@ -354,4 +114,4 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, body: `## PR build size\n \`\`\`\n${{ join(steps.new-size.outputs.*, '\n') }}\n\`\`\`\n ### Diff\n\`\`\`\n${{ steps.bloaty-comparison.outputs.bloaty-output-encoded }}\`\`\`\n` - }) + }) diff --git a/.github/workflows/user_build.yml b/.github/workflows/user_build.yml new file mode 100644 index 00000000..50536529 --- /dev/null +++ b/.github/workflows/user_build.yml @@ -0,0 +1,120 @@ +name: Build firmware according to user config file + +on: + workflow_call: + inputs: + keyboard_toml_path: + description: "Path to the keyboard.toml" + default: "keyboard.toml" + required: false + type: string + vial_json_path: + description: "Path to the vial.json" + default: "vial.json" + required: false + type: string + +jobs: + get_chip_name: + runs-on: ubuntu-latest + outputs: + chip_name: ${{ steps.capture.outputs.chip_name }} + steps: + - uses: cargo-bins/cargo-binstall@main + - uses: actions/checkout@v3 + - name: Install rmkit + run: cargo binstall rmkit -y + - name: Get chip name + id: capture + run: | + # Run rmkit command to get the chip name + OUTPUT=$(rmkit get-chip --keyboard-toml-path ${{ inputs.keyboard_toml_path }}) + + # Print the output to confirm + echo "Command output: $OUTPUT" + + # Save the output as a GitHub Actions output variable + echo "chip_name=$OUTPUT" >> $GITHUB_OUTPUT + + build: + runs-on: ubuntu-latest + needs: get_chip_name + if: needs.get_chip_name.outputs.chip_name != 'esp32c3' && needs.get_chip_name.outputs.chip_name != 'esp32s3' && needs.get_chip_name.outputs.chip_name != 'esp32c6' + steps: + - uses: cargo-bins/cargo-binstall@main + - name: Install rmkit and cargo-make + run: cargo binstall cargo-make rmkit -y + - uses: actions/checkout@v3 + - name: Install libssl + run: wget http://nz2.archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb && sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb + - name: Create firmware project + working-directory: . + run: rmkit create --keyboard-toml-path ${{ inputs.keyboard_toml_path }} --vial-json-path ${{ inputs.vial_json_path }} --target-dir rmk + - name: Build firmware + working-directory: ./rmk + run: cargo make uf2 --release + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: firmware_uf2 + path: rmk/*.uf2 + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: firmware_hex + path: rmk/*.hex + build_esp: + runs-on: ubuntu-latest + needs: get_chip_name + if: needs.get_chip_name.outputs.chip_name == 'esp32c3' || needs.get_chip_name.outputs.chip_name == 'esp32s3' || needs.get_chip_name.outputs.chip_name == 'esp32c6' + steps: + - uses: cargo-bins/cargo-binstall@main + - name: Install rmkit and espflash + run: cargo binstall rmkit espflash -y + - uses: actions/checkout@v3 + - name: Install libssl + run: wget http://nz2.archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb && sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb + - name: Prepare esp environment + run: | + cargo binstall ldproxy espup -y + espup install + - name: Create firmware project + working-directory: . + run: rmkit create --keyboard-toml-path ${{ inputs.keyboard_toml_path }} --vial-json-path ${{ inputs.vial_json_path }} --target-dir rmk + - name: Build firmware for esp32 + working-directory: ./rmk + run: cargo +esp build --release + - name: Get target arch + id: arch + run: | + if [ "${{ needs.get_chip_name.outputs.chip_name }}" == "esp32c3" ]; then + ARCH="riscv32imc-esp-espidf" + elif [ "${{ needs.get_chip_name.outputs.chip_name }}" == "esp32s3" ]; then + ARCH="riscv32imac-esp-espidf" + elif [ "${{ needs.get_chip_name.outputs.chip_name }}" == "esp32c6" ]; then + ARCH="xtensa-esp32s3-espidf" + else + ARCH="" + fi + # Save the arch as a GitHub Actions output variable + echo "arch=$ARCH" >> $GITHUB_OUTPUT + - name: Get project name + id: project_name + run: | + # Run rmkit command to get the chip name + OUTPUT=$(rmkit get-project-name --keyboard-toml-path ${{ inputs.keyboard_toml_path }}) + + # Print the output to confirm + echo "Command output: $OUTPUT" + + # Save the output as a GitHub Actions output variable + echo "project_name=$OUTPUT" >> $GITHUB_OUTPUT + - name: convert firmware to bin + working-directory: ./rmk + run: espflash save-image --chip ${{ needs.get_chip_name.outputs.chip_name }} target/${{ steps.arch.outputs.arch }}/release/${{ steps.project_name.outputs.project_name }} ./rmk.bin + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: firmware_bin + path: rmk/*.bin + diff --git a/docs/src/user_guide/2-1_cloud_compilation.md b/docs/src/user_guide/2-1_cloud_compilation.md index 4e0bd1ee..60cf94f7 100644 --- a/docs/src/user_guide/2-1_cloud_compilation.md +++ b/docs/src/user_guide/2-1_cloud_compilation.md @@ -4,7 +4,7 @@ RMK provides a [project-template](https://github.com/HaoboGu/rmk-project-templat ## Steps -1. To get started, click `Use this template` button and choose `Create a new repository`: +1. To get started, open [project-template](https://github.com/HaoboGu/rmk-project-template), click `Use this template` button and choose `Create a new repository`: ![use_template](../images/use_template.png) diff --git a/rmk-macro/src/config/mod.rs b/rmk-macro/src/config/mod.rs index 4be0dc62..6e7a6a8d 100644 --- a/rmk-macro/src/config/mod.rs +++ b/rmk-macro/src/config/mod.rs @@ -56,6 +56,7 @@ pub enum MatrixType { direct_pin, } +#[allow(unused)] #[derive(Clone, Debug, Default, Deserialize)] pub struct MatrixConfig { #[serde(default)] @@ -65,6 +66,8 @@ pub struct MatrixConfig { pub direct_pins: Option>>, #[serde(default = "default_true")] pub direct_pin_low_active: bool, + #[serde(default = "default_false")] + pub row2col: bool, } /// Config for storage @@ -200,10 +203,14 @@ pub struct SerialConfig { #[derive(Clone, Debug, Deserialize)] pub struct DurationMillis(#[serde(deserialize_with = "parse_duration_millis")] pub u64); -fn default_true() -> bool { +const fn default_true() -> bool { true } +const fn default_false() -> bool { + false +} + fn parse_duration_millis<'de, D: de::Deserializer<'de>>(deserializer: D) -> Result { let input: String = de::Deserialize::deserialize(deserializer)?; let num = input.trim_end_matches(|c: char| !c.is_numeric()); diff --git a/rmk-macro/src/keyboard.rs b/rmk-macro/src/keyboard.rs index 8e79918a..7f431376 100644 --- a/rmk-macro/src/keyboard.rs +++ b/rmk-macro/src/keyboard.rs @@ -40,6 +40,12 @@ pub(crate) fn parse_keyboard_mod(item_mod: ItemMod) -> TokenStream2 { Err(e) => return e, }; + if let Some(m) = toml_config.clone().matrix { + if m.row2col { + eprintln!("row2col is enabled, please ensure that you have updated your Cargo.toml, disabled default features(col2row is enabled as default feature)"); + } + } + let keyboard_config = match KeyboardConfig::new(toml_config) { Ok(c) => c, Err(e) => return e, diff --git a/rmk-macro/src/keyboard_config.rs b/rmk-macro/src/keyboard_config.rs index 1861f7ae..70c40309 100644 --- a/rmk-macro/src/keyboard_config.rs +++ b/rmk-macro/src/keyboard_config.rs @@ -186,7 +186,7 @@ impl KeyboardConfig { /// /// The chip model can be either configured to a board or a microcontroller chip. pub(crate) fn get_chip_model(config: &KeyboardTomlConfig) -> Result { - if config.keyboard.board.is_none() ^ config.keyboard.board.is_none() { + if config.keyboard.board.is_none() == config.keyboard.chip.is_none() { let message = format!( "Either \"board\" or \"chip\" should be set in keyboard.toml, but not both" ); diff --git a/rmk/Cargo.toml b/rmk/Cargo.toml index e5bb24e7..00b70340 100644 --- a/rmk/Cargo.toml +++ b/rmk/Cargo.toml @@ -40,7 +40,7 @@ num_enum = { version = "0.7", default-features = false } bitfield-struct = "0.9" byteorder = { version = "1", default-features = false } futures = { version = "0.3", default-features = false } -sequential-storage = { version = "3.0.0", features = ["defmt-03"] } +sequential-storage = { version = "3.0.1", git = "https://github.com/tweedegolf/sequential-storage", features = ["defmt-03"] } serde = { version = "1", default-features = false, features = ["derive"] } postcard = { version = "1", features = ["experimental-derive", "use-defmt"] } diff --git a/rmk/src/storage/mod.rs b/rmk/src/storage/mod.rs index f2c2b9ef..1e45975c 100644 --- a/rmk/src/storage/mod.rs +++ b/rmk/src/storage/mod.rs @@ -12,7 +12,7 @@ use embedded_storage::nor_flash::NorFlash; use embedded_storage_async::nor_flash::NorFlash as AsyncNorFlash; use sequential_storage::{ cache::NoCache, - map::{fetch_item, store_item, SerializationError, Value}, + map::{fetch_all_items, fetch_item, store_item, SerializationError, Value}, Error as SSError, }; #[cfg(feature = "_nrf_ble")] @@ -380,7 +380,6 @@ impl Result<(), ()> { - for (layer, layer_data) in keymap.iter_mut().enumerate() { - for (row, row_data) in layer_data.iter_mut().enumerate() { - for (col, value) in row_data.iter_mut().enumerate() { - let key = get_keymap_key::(row, col, layer); - let item = match fetch_item::( - &mut self.flash, - self.storage_range.clone(), - &mut NoCache::new(), - &mut self.buffer, - &key, - ) - .await - { - Ok(Some(StorageData::KeymapKey(k))) => k.action, - Ok(None) => { - error!("Got none when reading keymap from storage at (layer,col,row)=({},{},{})", layer, col, row); - return Err(()); - } - Err(e) => { - print_storage_error::(e); - error!( - "Load keymap key from storage error: (layer,col,row)=({},{},{})", - layer, col, row - ); - return Err(()); - } - _ => { - error!( - "Load keymap key from storage error: (layer,col,row)=({},{},{})", - layer, col, row - ); - return Err(()); - } - }; - *value = item; + let mut storage_cache = NoCache::new(); + if let Ok(mut key_iterator) = fetch_all_items::( + &mut self.flash, + self.storage_range.clone(), + &mut storage_cache, + &mut self.buffer, + ) + .await + { + // Iterator the storage, read all keymap keys + while let Ok(Some((_key, item))) = key_iterator + .next::(&mut self.buffer) + .await + { + match item { + StorageData::KeymapKey(key) => { + assert!(key.layer < NUM_LAYER); + assert!(key.row < ROW); + assert!(key.col < COL); + keymap[key.layer][key.row][key.col] = key.action; + } + _ => continue, } } - } + }; + Ok(()) }