Skip to content

Commit

Permalink
add precommit, fix clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
hathach committed Jul 18, 2024
1 parent 3b1934e commit 1da3889
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 71 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/githubci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]

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
Expand All @@ -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 }}
Expand Down
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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]
7 changes: 2 additions & 5 deletions Adafruit_FRAM_SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -378,5 +377,3 @@ bool Adafruit_FRAM_SPI::exit_low_power_mode(void) {

return spi_dev->write(&cmd, 1);
}


16 changes: 8 additions & 8 deletions Adafruit_FRAM_SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/*!
Expand Down
67 changes: 37 additions & 30 deletions examples/FRAMInfo/FRAMInfo.ino
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
#include <SPI.h>
#include "Adafruit_FRAM_SPI.h"
#include <SPI.h>

/* 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;
}
Expand All @@ -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))
Expand All @@ -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) {}
44 changes: 25 additions & 19 deletions examples/MB85RS64V/MB85RS64V.ino
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
#include <SPI.h>
#include "Adafruit_FRAM_SPI.h"
#include <SPI.h>

/* 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);
Expand All @@ -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) {}

0 comments on commit 1da3889

Please sign in to comment.