From 73e40ace0ea400186a85db85ca4a5015a61c9b55 Mon Sep 17 00:00:00 2001 From: Etienne Wodey Date: Wed, 24 Apr 2024 16:01:44 +0200 Subject: [PATCH] Add and apply pre-commit config (basic fixers, rustfmt) --- .gitignore | 2 +- .pre-commit-config.yaml | 19 +++++ LICENSE | 1 - README.md | 14 ++-- flake.nix | 16 ++--- flash.py | 2 +- itm-cargo-lock.patch | 98 +++++++++++++------------- openocd/main.cfg | 2 +- openocd/openocd.cfg | 2 +- openocd/stm32h7x-itm_fix.cfg | 2 +- openocd/stm32h7x_dual_bank-itm_fix.cfg | 2 +- 11 files changed, 89 insertions(+), 71 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.gitignore b/.gitignore index e464bf2..795f63c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ target/ **/build **/__pycache__ itm.fifo -result \ No newline at end of file +result diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..f8fd7f1 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,19 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: mixed-line-ending + - id: check-merge-conflict + - id: check-toml + - id: check-yaml + - id: check-added-large-files + - id: end-of-file-fixer + - id: trailing-whitespace + - id: no-commit-to-branch + args: [--branch, master] + - repo: https://github.com/doublify/pre-commit-rust + rev: v1.0 + hooks: + - id: fmt + entry: cargo +stable fmt + name: format rust sources diff --git a/LICENSE b/LICENSE index 0cdc7c9..5f875f4 100644 --- a/LICENSE +++ b/LICENSE @@ -11,4 +11,3 @@ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - diff --git a/README.md b/README.md index 10c30cf..420d7f7 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ MQTT-controlled 4-channel DDS signal generator using Urukul, Humpback and STM32 ## Nix commands -Humpback-DDS firmware is packaged using the [Nix](https://nixos.org) Flakes system. Install Nix 2.4+ and enable flakes by adding ``experimental-features = nix-command flakes`` to ``nix.conf`` (e.g. ``~/.config/nix/nix.conf``). +Humpback-DDS firmware is packaged using the [Nix](https://nixos.org) Flakes system. Install Nix 2.4+ and enable flakes by adding ``experimental-features = nix-command flakes`` to ``nix.conf`` (e.g. ``~/.config/nix/nix.conf``). Once you have Flakes enabled, you can use ``nix build`` to build the firmware. @@ -55,8 +55,8 @@ Parameters: ```shell openocd-flash-customised 192.168.1.200/24 AC:6F:7A:DE:D6:C8 192.168.1.125 "Urukul" ``` -The device will be named `Urukul`. -It has `192.168.1.200` as IPv4 Address, inside a `/24` network, with `AC:6F:7A:DE:D6:C8` as MAC address. +The device will be named `Urukul`. +It has `192.168.1.200` as IPv4 Address, inside a `/24` network, with `AC:6F:7A:DE:D6:C8` as MAC address. It will connect to a MQTT broker at `192.168.1.125:1883`. @@ -84,7 +84,7 @@ For example, to publish a local MQTT broker, with the topic of `Foo/Bar` and `Ba ```shell mosquitto_pub -h localhost -t Foo/Bar -m "Baz" ``` -Note that MQTT topics are case-sensitive. +Note that MQTT topics are case-sensitive. Alternatively, the following nix command provided by the shell simplify the syntax. ```shell publish-mqtt @@ -95,8 +95,8 @@ publish-mqtt Foo/Bar "baz" ``` ## List of Commands -All currently supported commands are listed below. -**Note: The following table only lists the subtopic. To make a full topic, add `Urukul/Control/` in front of all subtopics.** +All currently supported commands are listed below. +**Note: The following table only lists the subtopic. To make a full topic, add `Urukul/Control/` in front of all subtopics.** ### Example: Full topic of Reset command ```shell Urukul/Control/Reset @@ -178,7 +178,7 @@ This sets the attenuation of the channel 0 attenuator to be 20 dB. ```shell publish-mqtt Urukul/Control/Clock/Source "OSC" ``` - This sets the clock source of Urukul to be the internal oscillator. + This sets the clock source of Urukul to be the internal oscillator. (Note: The internal oscillator should have a frequency of 100MHz, though this command does not setup the clock frequency.) 3. Clock Frequency Division diff --git a/flake.nix b/flake.nix index 76e6475..a47a7c8 100644 --- a/flake.nix +++ b/flake.nix @@ -56,13 +56,13 @@ openOCDFlashCustomised = pkgs.writeShellScriptBin "openocd-flash-customised" '' python3 flash.py $@ openocd -f openocd/openocd.cfg \ - -c "init - reset init - halt - stm32h7x mass_erase 1 - flash write_image erase target/thumbv7em-none-eabihf/release/humpback-dds - flash write_image flash_config.bin 0x081e0000 bin - reset run + -c "init + reset init + halt + stm32h7x mass_erase 1 + flash write_image erase target/thumbv7em-none-eabihf/release/humpback-dds + flash write_image flash_config.bin 0x081e0000 bin + reset run shutdown" ''; @@ -71,7 +71,7 @@ version = "0.0.0"; src = self; - cargoLock = { + cargoLock = { lockFile = ./Cargo.lock; outputHashes = { "SaiTLS-0.1.0" = "sha256-T3hyASQGZAXGLKfOB3mh33VrvRlYSMc1CJdX4XvDFrQ="; diff --git a/flash.py b/flash.py index 8067b8d..9990f49 100644 --- a/flash.py +++ b/flash.py @@ -46,4 +46,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/itm-cargo-lock.patch b/itm-cargo-lock.patch index 9aaaba9..a773545 100644 --- a/itm-cargo-lock.patch +++ b/itm-cargo-lock.patch @@ -16,7 +16,7 @@ index d18dbe7..c19483d 100644 - "memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "gimli", ] - + [[package]] -name = "ansi_term" -version = "0.10.2" @@ -24,7 +24,7 @@ index d18dbe7..c19483d 100644 +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567b077b825e468cc974f0020d4082ee6e03132512f207ef1a02fd5d00d1f32d" - + [[package]] -name = "atty" -version = "0.2.3" @@ -39,7 +39,7 @@ index d18dbe7..c19483d 100644 - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr", ] - + [[package]] -name = "backtrace" -version = "0.3.4" @@ -57,7 +57,7 @@ index d18dbe7..c19483d 100644 - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi", ] - + [[package]] -name = "backtrace-sys" -version = "0.1.16" @@ -72,7 +72,7 @@ index d18dbe7..c19483d 100644 + "libc", + "winapi", ] - + [[package]] -name = "bitflags" -version = "0.7.0" @@ -80,7 +80,7 @@ index d18dbe7..c19483d 100644 +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" - + [[package]] -name = "bitflags" -version = "1.0.1" @@ -96,7 +96,7 @@ index d18dbe7..c19483d 100644 + "object", + "rustc-demangle", +] - + [[package]] -name = "cc" -version = "1.0.3" @@ -104,14 +104,14 @@ index d18dbe7..c19483d 100644 +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" - + [[package]] name = "cfg-if" -version = "0.1.2" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - + [[package]] name = "chrono" -version = "0.4.0" @@ -125,7 +125,7 @@ index d18dbe7..c19483d 100644 + "num-traits", + "time", ] - + [[package]] name = "clap" -version = "2.29.0" @@ -157,7 +157,7 @@ index d18dbe7..c19483d 100644 + "unicode-width", + "vec_map", ] - + [[package]] name = "env_logger" version = "0.4.3" @@ -169,7 +169,7 @@ index d18dbe7..c19483d 100644 + "log 0.3.9", + "regex", ] - + [[package]] name = "failure" -version = "0.1.1" @@ -182,7 +182,7 @@ index d18dbe7..c19483d 100644 + "backtrace", + "failure_derive", ] - + [[package]] name = "failure_derive" -version = "0.1.1" @@ -198,7 +198,7 @@ index d18dbe7..c19483d 100644 + "syn", + "synstructure", ] - + [[package]] -name = "fuchsia-zircon" -version = "0.2.1" @@ -209,7 +209,7 @@ index d18dbe7..c19483d 100644 - "fuchsia-zircon-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - + [[package]] -name = "fuchsia-zircon-sys" -version = "0.2.0" @@ -220,7 +220,7 @@ index d18dbe7..c19483d 100644 - "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", -] +checksum = "bcc8e0c9bce37868955864dbecd2b1ab2bdf967e6f28066d65aaac620444b65c" - + [[package]] -name = "itm" -version = "0.3.0" @@ -238,7 +238,7 @@ index d18dbe7..c19483d 100644 - "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] - + [[package]] -name = "kernel32-sys" -version = "0.2.2" @@ -256,21 +256,21 @@ index d18dbe7..c19483d 100644 + "log 0.3.9", + "tempdir", ] - + [[package]] name = "lazy_static" -version = "1.0.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - + [[package]] name = "libc" -version = "0.2.34" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" - + [[package]] name = "log" -version = "0.3.8" @@ -280,7 +280,7 @@ index d18dbe7..c19483d 100644 +dependencies = [ + "log 0.4.8", +] - + [[package]] -name = "memchr" -version = "2.0.1" @@ -292,7 +292,7 @@ index d18dbe7..c19483d 100644 - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if", ] - + [[package]] -name = "num" -version = "0.1.41" @@ -312,7 +312,7 @@ index d18dbe7..c19483d 100644 - "num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "adler32", ] - + [[package]] name = "num-integer" -version = "0.1.35" @@ -324,7 +324,7 @@ index d18dbe7..c19483d 100644 + "autocfg", + "num-traits", ] - + [[package]] -name = "num-iter" -version = "0.1.34" @@ -337,7 +337,7 @@ index d18dbe7..c19483d 100644 - "num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg", ] - + [[package]] -name = "num-traits" -version = "0.1.41" @@ -354,7 +354,7 @@ index d18dbe7..c19483d 100644 +dependencies = [ + "unicode-xid", +] - + [[package]] name = "quote" -version = "0.3.15" @@ -364,7 +364,7 @@ index d18dbe7..c19483d 100644 +dependencies = [ + "proc-macro2", +] - + [[package]] name = "rand" -version = "0.3.18" @@ -380,7 +380,7 @@ index d18dbe7..c19483d 100644 + "rdrand", + "winapi", ] - + [[package]] -name = "redox_syscall" -version = "0.1.32" @@ -391,7 +391,7 @@ index d18dbe7..c19483d 100644 +dependencies = [ + "rand_core 0.4.2", +] - + [[package]] -name = "redox_termios" -version = "0.1.1" @@ -409,7 +409,7 @@ index d18dbe7..c19483d 100644 - "redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1", ] - + [[package]] name = "regex" -version = "0.2.3" @@ -428,7 +428,7 @@ index d18dbe7..c19483d 100644 + "thread_local", + "utf8-ranges", ] - + [[package]] name = "regex-syntax" -version = "0.4.1" @@ -438,7 +438,7 @@ index d18dbe7..c19483d 100644 +dependencies = [ + "ucd-util", +] - + [[package]] -name = "rustc-demangle" -version = "0.1.5" @@ -449,7 +449,7 @@ index d18dbe7..c19483d 100644 +dependencies = [ + "winapi", +] - + [[package]] -name = "strsim" -version = "0.6.0" @@ -457,7 +457,7 @@ index d18dbe7..c19483d 100644 +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" - + [[package]] -name = "syn" -version = "0.11.11" @@ -470,7 +470,7 @@ index d18dbe7..c19483d 100644 - "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", -] +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - + [[package]] -name = "synom" -version = "0.11.3" @@ -484,7 +484,7 @@ index d18dbe7..c19483d 100644 + "quote", + "unicode-xid", ] - + [[package]] name = "synstructure" -version = "0.6.1" @@ -499,7 +499,7 @@ index d18dbe7..c19483d 100644 + "syn", + "unicode-xid", ] - + [[package]] name = "tempdir" -version = "0.3.5" @@ -521,7 +521,7 @@ index d18dbe7..c19483d 100644 + "rand", + "remove_dir_all", ] - + [[package]] name = "textwrap" -version = "0.9.0" @@ -532,7 +532,7 @@ index d18dbe7..c19483d 100644 - "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width", ] - + [[package]] name = "thread_local" -version = "0.3.5" @@ -544,7 +544,7 @@ index d18dbe7..c19483d 100644 - "unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static", ] - + [[package]] name = "time" -version = "0.1.38" @@ -559,7 +559,7 @@ index d18dbe7..c19483d 100644 + "libc", + "winapi", ] - + [[package]] -name = "unicode-width" -version = "0.1.4" @@ -567,7 +567,7 @@ index d18dbe7..c19483d 100644 +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c85f514e095d348c279b1e5cd76795082cf15bd59b93207832abe0b1d8fed236" - + [[package]] -name = "unicode-xid" -version = "0.0.4" @@ -575,7 +575,7 @@ index d18dbe7..c19483d 100644 +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" - + [[package]] -name = "unreachable" -version = "1.0.0" @@ -586,21 +586,21 @@ index d18dbe7..c19483d 100644 - "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", -] +checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" - + [[package]] name = "utf8-ranges" -version = "1.0.0" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ae116fef2b7fea257ed6440d3cfcff7f190865f170cdad00bb6465bf18ecba" - + [[package]] name = "vec_map" -version = "0.8.0" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - + [[package]] -name = "void" -version = "1.0.2" @@ -612,7 +612,7 @@ index d18dbe7..c19483d 100644 + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] - + [[package]] -name = "winapi" -version = "0.2.8" @@ -620,7 +620,7 @@ index d18dbe7..c19483d 100644 +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - + [[package]] -name = "winapi-build" -version = "0.1.1" @@ -687,7 +687,7 @@ index 455623a..a002c83 100644 @@ -128,13 +128,13 @@ fn run() -> Result<(), failure::Error> { // Unreachable. } - + -fn open_read(matches: &ArgMatches) -> Result, io::Error> { +fn open_read(matches: &ArgMatches) -> Result, io::Error> { let path = matches.value_of("file"); diff --git a/openocd/main.cfg b/openocd/main.cfg index 10f62c1..d1252c4 100644 --- a/openocd/main.cfg +++ b/openocd/main.cfg @@ -3,4 +3,4 @@ reset init halt flash write_image erase target/thumbv7em-none-eabihf/release/humpback-dds reset run -shutdown \ No newline at end of file +shutdown diff --git a/openocd/openocd.cfg b/openocd/openocd.cfg index ac8961a..6a8c11a 100644 --- a/openocd/openocd.cfg +++ b/openocd/openocd.cfg @@ -1,4 +1,4 @@ source [find interface/stlink.cfg] transport select hla_swd source [find openocd/stm32h7x_dual_bank-itm_fix.cfg] -reset_config srst_only \ No newline at end of file +reset_config srst_only diff --git a/openocd/stm32h7x-itm_fix.cfg b/openocd/stm32h7x-itm_fix.cfg index 8e79357..3fb8074 100644 --- a/openocd/stm32h7x-itm_fix.cfg +++ b/openocd/stm32h7x-itm_fix.cfg @@ -277,4 +277,4 @@ if {[set $_CHIPNAME.USE_CTI]} { $_CHIPNAME.$cti write INACK 0x01 $_CHIPNAME.$cti write INACK 0x00 } -} \ No newline at end of file +} diff --git a/openocd/stm32h7x_dual_bank-itm_fix.cfg b/openocd/stm32h7x_dual_bank-itm_fix.cfg index 83ef85c..ca2c0d5 100644 --- a/openocd/stm32h7x_dual_bank-itm_fix.cfg +++ b/openocd/stm32h7x_dual_bank-itm_fix.cfg @@ -3,4 +3,4 @@ # STM32H7xxxI 2Mo have a dual bank flash. set DUAL_BANK 1 -source [find openocd/stm32h7x-itm_fix.cfg] \ No newline at end of file +source [find openocd/stm32h7x-itm_fix.cfg]