From 1da3889a88a59ac8b53b59b4d751d186b9ed13dd Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 18 Jul 2024 15:44:29 +0700 Subject: [PATCH] add precommit, fix clang format --- .github/workflows/githubci.yml | 20 +++++----- .pre-commit-config.yaml | 10 +++++ Adafruit_FRAM_SPI.cpp | 7 +--- Adafruit_FRAM_SPI.h | 16 ++++---- examples/FRAMInfo/FRAMInfo.ino | 67 ++++++++++++++++++-------------- examples/MB85RS64V/MB85RS64V.ino | 44 ++++++++++++--------- 6 files changed, 93 insertions(+), 71 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml index 18129ba..5eca00e 100644 --- a/.github/workflows/githubci.yml +++ b/.github/workflows/githubci.yml @@ -3,15 +3,20 @@ name: Arduino Library CI on: [pull_request, push, repository_dispatch] jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run pre-commit + uses: pre-commit/action@v3.0.1 + build: runs-on: ubuntu-latest - steps: - - uses: actions/setup-python@v4 - with: - python-version: '3.x' - - uses: actions/checkout@v3 - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - uses: actions/checkout@v4 with: repository: adafruit/ci-arduino path: ci @@ -22,9 +27,6 @@ jobs: - name: test platforms run: python3 ci/build_platform.py main_platforms - - name: clang - run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r . - - name: doxygen env: GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..966e884 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,10 @@ +# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# +# SPDX-License-Identifier: Unlicense + +repos: +- repo: https://github.com/pre-commit/mirrors-clang-format + rev: v15.0.7 + hooks: + - id: clang-format + types_or: [c++, c, header] diff --git a/Adafruit_FRAM_SPI.cpp b/Adafruit_FRAM_SPI.cpp index 4622fc2..6c514c9 100644 --- a/Adafruit_FRAM_SPI.cpp +++ b/Adafruit_FRAM_SPI.cpp @@ -358,7 +358,6 @@ bool Adafruit_FRAM_SPI::enter_low_power_mode(void) { return spi_dev->write(&cmd, 1); } - /*! * @brief exits the FRAM's low power sleep mode * @return true if successful @@ -367,8 +366,8 @@ bool Adafruit_FRAM_SPI::enter_low_power_mode(void) { bool Adafruit_FRAM_SPI::exit_low_power_mode(void) { uint8_t cmd; - // Returning to an normal operation from the SLEEP mode is carried out after tREC (Max 400 μs) - // time from the falling edge of CS + // Returning to an normal operation from the SLEEP mode is carried out after + // tREC (Max 400 μs) time from the falling edge of CS spi_dev->beginTransactionWithAssertingCS(); delayMicroseconds(300); // It is possible to return CS to H level before tREC time. However, it @@ -378,5 +377,3 @@ bool Adafruit_FRAM_SPI::exit_low_power_mode(void) { return spi_dev->write(&cmd, 1); } - - diff --git a/Adafruit_FRAM_SPI.h b/Adafruit_FRAM_SPI.h index 214adae..548c1e0 100644 --- a/Adafruit_FRAM_SPI.h +++ b/Adafruit_FRAM_SPI.h @@ -28,14 +28,14 @@ /** Operation Codes **/ typedef enum opcodes_e { - OPCODE_WREN = 0b0110, /* Write Enable Latch */ - OPCODE_WRDI = 0b0100, /* Reset Write Enable Latch */ - OPCODE_RDSR = 0b0101, /* Read Status Register */ - OPCODE_WRSR = 0b0001, /* Write Status Register */ - OPCODE_READ = 0b0011, /* Read Memory */ - OPCODE_WRITE = 0b0010, /* Write Memory */ - OPCODE_RDID = 0b10011111, /* Read Device ID */ - OPCODE_SLEEP = 0b10111001 /* Sleep Mode */ // added by FUEL4EP + OPCODE_WREN = 0b0110, /* Write Enable Latch */ + OPCODE_WRDI = 0b0100, /* Reset Write Enable Latch */ + OPCODE_RDSR = 0b0101, /* Read Status Register */ + OPCODE_WRSR = 0b0001, /* Write Status Register */ + OPCODE_READ = 0b0011, /* Read Memory */ + OPCODE_WRITE = 0b0010, /* Write Memory */ + OPCODE_RDID = 0b10011111, /* Read Device ID */ + OPCODE_SLEEP = 0b10111001 /* Sleep Mode by FUEL4EP */ } opcodes_t; /*! diff --git a/examples/FRAMInfo/FRAMInfo.ino b/examples/FRAMInfo/FRAMInfo.ino index f354f0d..978fcba 100644 --- a/examples/FRAMInfo/FRAMInfo.ino +++ b/examples/FRAMInfo/FRAMInfo.ino @@ -1,36 +1,38 @@ -#include #include "Adafruit_FRAM_SPI.h" +#include -/* Example code to interrogate Adafruit SPI FRAM breakout for address size and storage capacity */ +/* Example code to interrogate Adafruit SPI FRAM breakout for address size and + * storage capacity */ /* NOTE: This sketch will overwrite data already on the FRAM breakout */ uint8_t FRAM_CS = 10; -Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_CS); // use hardware SPI +Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_CS); // use hardware SPI uint8_t FRAM_SCK = 13; uint8_t FRAM_MISO = 12; uint8_t FRAM_MOSI = 11; -//Or use software SPI, any pins! -//Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_SCK, FRAM_MISO, FRAM_MOSI, FRAM_CS); +// Or use software SPI, any pins! +// Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_SCK, FRAM_MISO, FRAM_MOSI, +// FRAM_CS); -uint8_t addrSizeInBytes = 2; //Default to address size of two bytes -uint32_t memSize; +uint8_t addrSizeInBytes = 2; // Default to address size of two bytes +uint32_t memSize; int32_t readBack(uint32_t addr, int32_t data) { int32_t check = !data; int32_t wrapCheck, backup; - fram.read(addr, (uint8_t*)&backup, sizeof(int32_t)); + fram.read(addr, (uint8_t *)&backup, sizeof(int32_t)); fram.writeEnable(true); - fram.write(addr, (uint8_t*)&data, sizeof(int32_t)); + fram.write(addr, (uint8_t *)&data, sizeof(int32_t)); fram.writeEnable(false); - fram.read(addr, (uint8_t*)&check, sizeof(int32_t)); - fram.read(0, (uint8_t*)&wrapCheck, sizeof(int32_t)); + fram.read(addr, (uint8_t *)&check, sizeof(int32_t)); + fram.read(0, (uint8_t *)&wrapCheck, sizeof(int32_t)); fram.writeEnable(true); - fram.write(addr, (uint8_t*)&backup, sizeof(int32_t)); + fram.write(addr, (uint8_t *)&backup, sizeof(int32_t)); fram.writeEnable(false); // Check for warparound, address 0 will work anyway - if (wrapCheck==check) + if (wrapCheck == check) check = 0; return check; } @@ -42,17 +44,18 @@ bool testAddrSize(uint8_t addrSize) { return false; } - void setup(void) { Serial.begin(9600); - while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens - + while (!Serial) + delay(10); // will pause Zero, Leonardo, etc until serial console opens + if (fram.begin(addrSizeInBytes)) { Serial.println("Found SPI FRAM"); } else { Serial.println("No SPI FRAM found ... check your connections\r\n"); - while (1); + while (1) + ; } if (testAddrSize(2)) @@ -62,28 +65,32 @@ void setup(void) { else if (testAddrSize(4)) addrSizeInBytes = 4; else { - Serial.println("SPI FRAM can not be read/written with any address size\r\n"); - while (1); + Serial.println( + "SPI FRAM can not be read/written with any address size\r\n"); + while (1) + ; } - + memSize = 0; while (readBack(memSize, memSize) == memSize) { memSize += 256; - //Serial.print("Block: #"); Serial.println(memSize/256); + // Serial.print("Block: #"); Serial.println(memSize/256); } - + Serial.print("SPI FRAM address size is "); Serial.print(addrSizeInBytes); Serial.println(" bytes."); Serial.println("SPI FRAM capacity appears to be.."); - Serial.print(memSize); Serial.println(" bytes"); - Serial.print(memSize/0x400); Serial.println(" kilobytes"); - Serial.print((memSize*8)/0x400); Serial.println(" kilobits"); - if (memSize >= (0x100000/8)) { - Serial.print((memSize*8)/0x100000); Serial.println(" megabits"); + Serial.print(memSize); + Serial.println(" bytes"); + Serial.print(memSize / 0x400); + Serial.println(" kilobytes"); + Serial.print((memSize * 8) / 0x400); + Serial.println(" kilobits"); + if (memSize >= (0x100000 / 8)) { + Serial.print((memSize * 8) / 0x100000); + Serial.println(" megabits"); } } -void loop(void) { - -} +void loop(void) {} diff --git a/examples/MB85RS64V/MB85RS64V.ino b/examples/MB85RS64V/MB85RS64V.ino index 038513a..f9103a5 100644 --- a/examples/MB85RS64V/MB85RS64V.ino +++ b/examples/MB85RS64V/MB85RS64V.ino @@ -1,37 +1,42 @@ -#include #include "Adafruit_FRAM_SPI.h" +#include /* Example code for the Adafruit SPI FRAM breakout */ uint8_t FRAM_CS = 10; -//Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_CS); // use hardware SPI +// Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_CS); // use hardware SPI -uint8_t FRAM_SCK= 13; +uint8_t FRAM_SCK = 13; uint8_t FRAM_MISO = 12; uint8_t FRAM_MOSI = 11; -//Or use software SPI, any pins! -Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_SCK, FRAM_MISO, FRAM_MOSI, FRAM_CS); +// Or use software SPI, any pins! +Adafruit_FRAM_SPI fram = + Adafruit_FRAM_SPI(FRAM_SCK, FRAM_MISO, FRAM_MOSI, FRAM_CS); -uint16_t addr = 0; +uint16_t addr = 0; void setup(void) { Serial.begin(9600); - while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens - + while (!Serial) + delay(10); // will pause Zero, Leonardo, etc until serial console opens + if (fram.begin()) { Serial.println("Found SPI FRAM"); } else { Serial.println("No SPI FRAM found ... check your connections\r\n"); - while (1); + while (1) + ; } - + // Read the first byte uint8_t test = fram.read8(0x0); - Serial.print("Restarted "); Serial.print(test); Serial.println(" times"); + Serial.print("Restarted "); + Serial.print(test); + Serial.println(" times"); // Test write ++ fram.writeEnable(true); - fram.write8(0x0, test+1); + fram.write8(0x0, test + 1); fram.writeEnable(false); fram.writeEnable(true); @@ -43,15 +48,16 @@ void setup(void) { for (uint16_t a = 0; a < 8192; a++) { value = fram.read8(a); if ((a % 32) == 0) { - Serial.print("\n 0x"); Serial.print(a, HEX); Serial.print(": "); + Serial.print("\n 0x"); + Serial.print(a, HEX); + Serial.print(": "); } - Serial.print("0x"); - if (value < 0x1) + Serial.print("0x"); + if (value < 0x1) Serial.print('0'); - Serial.print(value, HEX); Serial.print(" "); + Serial.print(value, HEX); + Serial.print(" "); } } -void loop(void) { - -} +void loop(void) {}