Skip to content

Mock for SD #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/arduino_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: Arduino CI

on: [push, pull_request]

jobs:
arduino_ci:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: Arduino-CI/[email protected]
15 changes: 15 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: test-clang-format

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: DoozyX/[email protected]
with:
source: './'
extensions: 'c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx,ino'
clangFormatVersion: 9
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ Gemfile.lock
.bundle
vendor
*.cpp.bin*
.vscode
58 changes: 30 additions & 28 deletions examples/CardInfo/CardInfo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@

This example shows how use the utility libraries on which the'
SD library is based in order to get info about your SD card.
Very useful for testing a card when you're not sure whether its working or not.
Pin numbers reflect the default SPI pins for Uno and Nano models
The circuit:
SD card attached to SPI bus as follows:
Very useful for testing a card when you're not sure whether its working or
not. Pin numbers reflect the default SPI pins for Uno and Nano models The
circuit: SD card attached to SPI bus as follows:
** SDO - pin 11 on Arduino Uno/Duemilanove/Diecimila
** SDI - pin 12 on Arduino Uno/Duemilanove/Diecimila
** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
** CS - depends on your SD card shield or module.
Pin 10 used here for consistency with other Arduino examples
Pin 10 used here for consistency with other Arduino examples

created 28 Mar 2011
by Limor Fried
modified 24 July 2020
by Tom Igoe
*/
// include the SD library:
#include <SPI.h>
#include <SD.h>
#include <SPI.h>

// set up variables using the SD utility library functions:
Sd2Card card;
Expand All @@ -42,7 +41,6 @@ void setup() {
; // wait for serial port to connect. Needed for native USB port only
}


Serial.print("\nInitializing SD card...");

// we'll use the initialization code from the utility libraries
Expand All @@ -51,8 +49,10 @@ void setup() {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card inserted?");
Serial.println("* is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
while (1);
Serial.println(
"* did you change the chipSelect pin to match your shield or module?");
while (1)
;
} else {
Serial.println("Wiring is correct and a card is present.");
}
Expand All @@ -61,23 +61,26 @@ void setup() {
Serial.println();
Serial.print("Card type: ");
switch (card.type()) {
case SD_CARD_TYPE_SD1:
Serial.println("SD1");
break;
case SD_CARD_TYPE_SD2:
Serial.println("SD2");
break;
case SD_CARD_TYPE_SDHC:
Serial.println("SDHC");
break;
default:
Serial.println("Unknown");
case SD_CARD_TYPE_SD1:
Serial.println("SD1");
break;
case SD_CARD_TYPE_SD2:
Serial.println("SD2");
break;
case SD_CARD_TYPE_SDHC:
Serial.println("SDHC");
break;
default:
Serial.println("Unknown");
}

// Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
// Now we will try to open the 'volume'/'partition' - it should be FAT16 or
// FAT32
if (!volume.init(card)) {
Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
while (1);
Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've "
"formatted the card");
while (1)
;
}

Serial.print("Clusters: ");
Expand All @@ -94,9 +97,9 @@ void setup() {
Serial.print("Volume type is: FAT");
Serial.println(volume.fatType(), DEC);

volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
volumesize *= volume.clusterCount(); // we'll have a lot of clusters
volumesize /= 2; // SD card blocks are always 512 bytes (2 blocks are 1KB)
volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
volumesize *= volume.clusterCount(); // we'll have a lot of clusters
volumesize /= 2; // SD card blocks are always 512 bytes (2 blocks are 1KB)
Serial.print("Volume size (Kb): ");
Serial.println(volumesize);
Serial.print("Volume size (Mb): ");
Expand All @@ -113,5 +116,4 @@ void setup() {
root.close();
}

void loop(void) {
}
void loop(void) {}
16 changes: 10 additions & 6 deletions examples/Datalogger/Datalogger.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
** SDI - pin 12
** CLK - pin 13
** CS - depends on your SD card shield or module.
Pin 10 used here for consistency with other Arduino examples
Pin 10 used here for consistency with other Arduino examples
(for MKRZero SD: SDCARD_SS_PIN)

created 24 Nov 2010
Expand All @@ -23,26 +23,30 @@

*/

#include <SPI.h>
#include <SD.h>
#include <SPI.h>

const int chipSelect = 10;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// wait for Serial Monitor to connect. Needed for native USB port boards only:
while (!Serial);
while (!Serial)
;

Serial.print("Initializing SD card...");

if (!SD.begin(chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("1. is a card inserted?");
Serial.println("2. is your wiring correct?");
Serial.println("3. did you change the chipSelect pin to match your shield or module?");
Serial.println("Note: press reset or reopen this serial monitor after fixing your issue!");
while (true);
Serial.println(
"3. did you change the chipSelect pin to match your shield or module?");
Serial.println("Note: press reset or reopen this serial monitor after "
"fixing your issue!");
while (true)
;
}

Serial.println("initialization done.");
Expand Down
17 changes: 10 additions & 7 deletions examples/DumpFile/DumpFile.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
** SDI - pin 12
** CLK - pin 13
** CS - depends on your SD card shield or module.
Pin 10 used here for consistency with other Arduino examples
Pin 10 used here for consistency with other Arduino examples
(for MKRZero SD: SDCARD_SS_PIN)

created 22 December 2010
Expand All @@ -29,17 +29,21 @@ void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// wait for Serial Monitor to connect. Needed for native USB port boards only:
while (!Serial);
while (!Serial)
;

Serial.print("Initializing SD card...");

if (!SD.begin(chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("1. is a card inserted?");
Serial.println("2. is your wiring correct?");
Serial.println("3. did you change the chipSelect pin to match your shield or module?");
Serial.println("Note: press reset or reopen this serial monitor after fixing your issue!");
while (true);
Serial.println(
"3. did you change the chipSelect pin to match your shield or module?");
Serial.println("Note: press reset or reopen this serial monitor after "
"fixing your issue!");
while (true)
;
}

Serial.println("initialization done.");
Expand All @@ -61,5 +65,4 @@ void setup() {
}
}

void loop() {
}
void loop() {}
8 changes: 5 additions & 3 deletions examples/Files/Files.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
** SDI - pin 12
** CLK - pin 13
** CS - depends on your SD card shield or module.
Pin 10 used here for consistency with other Arduino examples
Pin 10 used here for consistency with other Arduino examples
(for MKRZero SD: SDCARD_SS_PIN)

created Nov 2010
Expand All @@ -28,13 +28,15 @@ void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// wait for Serial Monitor to connect. Needed for native USB port boards only:
while (!Serial);
while (!Serial)
;

Serial.print("Initializing SD card...");

if (!SD.begin(chipSelect)) {
Serial.println("initialization failed!");
while (1);
while (1)
;
}
Serial.println("initialization done.");

Expand Down
15 changes: 10 additions & 5 deletions examples/NonBlockingWrite/NonBlockingWrite.ino
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,21 @@ void setup() {
pinMode(LED_BUILTIN, OUTPUT);

// wait for Serial Monitor to connect. Needed for native USB port boards only:
while (!Serial);
while (!Serial)
;

Serial.print("Initializing SD card...");

if (!SD.begin(chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("1. is a card inserted?");
Serial.println("2. is your wiring correct?");
Serial.println("3. did you change the chipSelect pin to match your shield or module?");
Serial.println("Note: press reset or reopen this serial monitor after fixing your issue!");
while (true);
Serial.println(
"3. did you change the chipSelect pin to match your shield or module?");
Serial.println("Note: press reset or reopen this serial monitor after "
"fixing your issue!");
while (true)
;
}

Serial.println("initialization done.");
Expand All @@ -79,7 +83,8 @@ void setup() {
if (!myFile) {
Serial.print("error opening ");
Serial.println(filename);
while (true);
while (true)
;
}

// add some new lines to start
Expand Down
12 changes: 8 additions & 4 deletions examples/ReadWrite/ReadWrite.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,21 @@ void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// wait for Serial Monitor to connect. Needed for native USB port boards only:
while (!Serial);
while (!Serial)
;

Serial.print("Initializing SD card...");

if (!SD.begin(chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("1. is a card inserted?");
Serial.println("2. is your wiring correct?");
Serial.println("3. did you change the chipSelect pin to match your shield or module?");
Serial.println("Note: press reset or reopen this serial monitor after fixing your issue!");
while (true);
Serial.println(
"3. did you change the chipSelect pin to match your shield or module?");
Serial.println("Note: press reset or reopen this serial monitor after "
"fixing your issue!");
while (true)
;
}

Serial.println("initialization done.");
Expand Down
22 changes: 13 additions & 9 deletions examples/listfiles/listfiles.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
** SDI - pin 12
** CLK - pin 13
** CS - depends on your SD card shield or module.
Pin 10 used here for consistency with other Arduino examples
Pin 10 used here for consistency with other Arduino examples
(for MKRZero SD: SDCARD_SS_PIN)

created Nov 2010
Expand All @@ -22,7 +22,7 @@
by Scott Fitzgerald
modified 24 July 2020
by Tom Igoe

This example code is in the public domain.

*/
Expand All @@ -32,20 +32,24 @@ const int chipSelect = 10;
File root;

void setup() {
// Open serial communications and wait for port to open:
// Open serial communications and wait for port to open:
Serial.begin(9600);
// wait for Serial Monitor to connect. Needed for native USB port boards only:
while (!Serial);
while (!Serial)
;

Serial.print("Initializing SD card...");

if (!SD.begin(chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("1. is a card inserted?");
Serial.println("2. is your wiring correct?");
Serial.println("3. did you change the chipSelect pin to match your shield or module?");
Serial.println("Note: press reset or reopen this serial monitor after fixing your issue!");
while (true);
Serial.println(
"3. did you change the chipSelect pin to match your shield or module?");
Serial.println("Note: press reset or reopen this serial monitor after "
"fixing your issue!");
while (true)
;
}

Serial.println("initialization done.");
Expand All @@ -64,8 +68,8 @@ void loop() {
void printDirectory(File dir, int numTabs) {
while (true) {

File entry = dir.openNextFile();
if (! entry) {
File entry = dir.openNextFile();
if (!entry) {
// no more files
break;
}
Expand Down
Loading