Skip to content

Commit 27fbefc

Browse files
authored
Arduino ci (#5)
* initial arduino-ci * added unit tests (fails for due and zero) ==> Arduino-CI/arduino_ci#252
1 parent 82aa36a commit 27fbefc

File tree

12 files changed

+200
-49
lines changed

12 files changed

+200
-49
lines changed

.arduino-ci.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
compile:
2+
# Choosing to run compilation tests on 2 different Arduino platforms
3+
platforms:
4+
- uno
5+
- leonardo
6+
- due
7+
- zero
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
name: Arduino CI
3+
4+
on: [push, pull_request]
5+
6+
jobs:
7+
arduino_ci:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: Arduino-CI/action@master
13+
# Arduino-CI/[email protected]

FastShiftIn.cpp

+32-21
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
//
22
// FILE: FastShiftIn.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.2.1
4+
// VERSION: 0.2.2
55
// PURPOSE: Fast ShiftIn for 74HC165 register, AVR optimized
66
// DATE: 2013-09-29
77
// URL: https://github.com/RobTillaart/FastShiftIn
88
//
99

1010
#include "FastShiftIn.h"
1111

12+
1213
FastShiftIn::FastShiftIn(const uint8_t datapin, const uint8_t clockpin, const uint8_t bitOrder)
1314
{
1415
_bitorder = bitOrder;
15-
16+
_value = 0;
1617
pinMode(datapin, INPUT);
1718
pinMode(clockpin, OUTPUT);
19+
// https://www.arduino.cc/reference/en/language/functions/advanced-io/shiftin/
20+
digitalWrite(clockpin, LOW); // assume rising pulses from clock
1821

1922
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
2023

@@ -32,7 +35,7 @@ FastShiftIn::FastShiftIn(const uint8_t datapin, const uint8_t clockpin, const ui
3235

3336
#else // reference implementation
3437

35-
// reuse these vars as pin to save some space
38+
// reuse these local vars as pin to save some space
3639
_databit = datapin;
3740
_clockbit = clockpin;
3841

@@ -48,19 +51,18 @@ int FastShiftIn::read()
4851
return readMSBFIRST();
4952
}
5053

51-
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
52-
5354
int FastShiftIn::readLSBFIRST()
5455
{
55-
uint8_t value = 0;
56+
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
57+
uint8_t value = 0;
5658
uint8_t cbmask1 = _clockbit;
5759
uint8_t cbmask2 = ~_clockbit;
58-
uint8_t dbmask = _databit;
60+
uint8_t dbmask = _databit;
5961

6062
for (uint8_t m = 1; m > 0; m <<= 1)
6163
{
6264
uint8_t oldSREG = SREG;
63-
cli();
65+
noInterrupts();
6466
*_clockin |= cbmask1;
6567
if ((*_datain & dbmask) > 0)
6668
{
@@ -71,19 +73,26 @@ int FastShiftIn::readLSBFIRST()
7173
}
7274
_value = value;
7375
return _value;
76+
77+
#else // reference implementation
78+
79+
_value = shiftIn(_databit, _clockbit, LSBFIRST);
80+
return _value;
81+
#endif
7482
}
7583

7684
int FastShiftIn::readMSBFIRST()
7785
{
78-
uint8_t value = 0;
86+
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
87+
uint8_t value = 0;
7988
uint8_t cbmask1 = _clockbit;
8089
uint8_t cbmask2 = ~cbmask1;
81-
uint8_t dbmask = _databit;
90+
uint8_t dbmask = _databit;
8291

8392
for (uint8_t n = 128; n > 0; n >>= 1)
8493
{
8594
uint8_t oldSREG = SREG;
86-
cli();
95+
noInterrupts();
8796
*_clockin |= cbmask1;
8897
if ((*_datain & dbmask) > 0)
8998
{
@@ -94,20 +103,22 @@ int FastShiftIn::readMSBFIRST()
94103
}
95104
_value = value;
96105
return _value;
97-
}
98-
99-
#else // reference implementation - note this has no cli()
106+
107+
#else // reference implementation
100108

101-
int FastShiftIn::readLSBFIRST()
102-
{
103-
return shiftIn(_databit, _clockbit, LSBFIRST);
109+
_value = shiftIn(_databit, _clockbit, MSBFIRST);
110+
return _value;
111+
#endif
104112
}
105113

106-
int FastShiftIn::readMSBFIRST()
114+
bool FastShiftIn::setBitOrder(const uint8_t bitOrder)
107115
{
108-
return shiftIn(_databit, _clockbit, MSBFIRST);
116+
if ((bitOrder == LSBFIRST) || (bitOrder == MSBFIRST))
117+
{
118+
_bitorder = bitOrder;
119+
return true;
120+
};
121+
return false;
109122
}
110123

111-
#endif
112-
113124
// -- END OF FILE --

FastShiftIn.h

+11-6
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,35 @@
22
//
33
// FILE: FastShiftIn.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.2.1
5+
// VERSION: 0.2.2
66
// PURPOSE: Fast ShiftIn for 74HC165 register, AVR optimized
77
// DATE: 2013-09-29
88
// URL: https://github.com/RobTillaart/FastShiftIn
99
//
1010

1111
#include "Arduino.h"
1212

13-
#define FASTSHIFTIN_LIB_VERSION (F("0.2.1"))
13+
#define FASTSHIFTIN_LIB_VERSION (F("0.2.2"))
1414

1515
class FastShiftIn
1616
{
1717
public:
1818
// bitorder = { LSBFIRST, MSBFIRST };
1919
FastShiftIn(const uint8_t datapin, const uint8_t clockpin, const uint8_t bitOrder = LSBFIRST);
20-
int read(void);
20+
21+
int read(void);
22+
int lastRead(void) { return _value; };
23+
24+
bool setBitOrder(const uint8_t bitOrder);
25+
uint8_t getBitOrder(void) { return _bitorder; };
2126

2227
// overrule bitorder (most optimized).
23-
int readLSBFIRST(void);
24-
int readMSBFIRST(void);
28+
int readLSBFIRST(void);
29+
int readMSBFIRST(void);
2530

2631
private:
2732
uint8_t _bitorder;
28-
int _value;
33+
int _value;
2934

3035
uint8_t _databit;
3136
volatile uint8_t *_datain;

README.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2+
[![Arduino CI](https://github.com/RobTillaart/FastShiftIn/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
3+
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/FastShiftIn/blob/master/LICENSE)
4+
[![GitHub release](https://img.shields.io/github/release/RobTillaart/FastShiftIn.svg?maxAge=3600)](https://github.com/RobTillaart/FastShiftIn/releases)
5+
16
# FastShiftIn
27

38
Arduino library for (AVR) optimized shiftIn - e.g. for 74HC165
@@ -25,9 +30,12 @@ It does a comparison and shows how the class is to be used.
2530

2631
The interface exists of the following functions:
2732

28-
- **int read(void);**
29-
- **int readLSBFIRST(void);** most optimized
30-
- **int readMSBFIRST(void);** most optimized
33+
- **int read(void)** reads a new value
34+
- **int lastRead()** returns last value read
35+
- **bool setBitOrder(bitOrder)** set LSBFIRST or MSBFIRST. Returns false for other values.
36+
- **uint8_t getBitOrder(void)** returns LSBFIRST or MSBFIRST
37+
- **int readLSBFIRST(void)** optimized LSB read()
38+
- **int readMSBFIRST(void)** optimized MSB read()
3139

3240
## Notes
3341

examples/fastShiftIn/fastShiftIn.ino

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
//
22
// FILE: fastShiftIn.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.01
4+
// VERSION: 0.1.2
55
// PURPOSE: test sketch
6-
// URL:
7-
//
8-
// Released to the public domain
6+
// URL: https://github.com/RobTillaart/FastShiftIn
97
//
108

119
#include "FastShiftIn.h"
@@ -17,15 +15,15 @@ volatile int x = 0;
1715
void setup()
1816
{
1917
Serial.begin(115200);
20-
Serial.print("example fastShiftIn: ");
18+
Serial.println(__FILE__);
2119
Serial.println(FASTSHIFTIN_LIB_VERSION);
2220

2321
digitalWrite(12, HIGH);
2422
Serial.println("\n 8 bits HIGH\n");
2523

2624
Serial.println("\nPerformance - time in us");
2725
uint32_t start = micros();
28-
for (int i=0; i<1000; i++)
26+
for (int i = 0; i < 1000; i++)
2927
{
3028
x = FSI.read();
3129
}
@@ -34,7 +32,7 @@ void setup()
3432
Serial.println(duration1 * 0.001);
3533

3634
start = micros();
37-
for (int i=0; i<1000; i++)
35+
for (int i = 0; i < 1000; i++)
3836
{
3937
x = FSI.read();
4038
x = FSI.read();
@@ -43,12 +41,12 @@ void setup()
4341
Serial.print("FastShiftIn2: ");
4442
Serial.println(duration2 * 0.001);
4543
Serial.print(" Delta: ");
46-
Serial.println((duration2-duration1)* 0.001);
44+
Serial.println((duration2 - duration1)* 0.001);
4745
Serial.println();
4846

4947

5048
start = micros();
51-
for (int i=0; i<1000; i++)
49+
for (int i = 0; i < 1000; i++)
5250
{
5351
x = shiftIn(12, 13, LSBFIRST);
5452
}
@@ -57,7 +55,7 @@ void setup()
5755
Serial.println(duration1* 0.001);
5856

5957
start = micros();
60-
for (int i=0; i<1000; i++)
58+
for (int i = 0; i < 1000; i++)
6159
{
6260
x = shiftIn(12, 13, LSBFIRST);
6361
x = shiftIn(12, 13, LSBFIRST);
@@ -66,7 +64,7 @@ void setup()
6664
Serial.print("Standard shiftIn2: ");
6765
Serial.println(duration2 * 0.001);
6866
Serial.print(" Delta: ");
69-
Serial.println((duration2-duration1) * 0.001);
67+
Serial.println((duration2 - duration1) * 0.001);
7068
Serial.println();
7169

7270
Serial.println("done...");

examples/fastShiftIn_readLSBFIRST/fastShiftIn_readLSBFIRST.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: fastShiftIn_readLSBFIRST.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.0
4+
// VERSION: 0.1.1
55
// PURPOSE: test sketch
66
// URL: https://github.com/RobTillaart/FastShiftIn
77
//
@@ -15,7 +15,7 @@ volatile int x = 0;
1515
void setup()
1616
{
1717
Serial.begin(115200);
18-
Serial.print("example fastShiftIn: ");
18+
Serial.println(__FILE__);
1919
Serial.println(FASTSHIFTIN_LIB_VERSION);
2020

2121
digitalWrite(12, HIGH);

examples/fastShiftIn_test/fastShiftIn_test.ino

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: fastShiftIn_test.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.0
4+
// VERSION: 0.1.1
55
// PURPOSE: test sketch
66
// URL: https://github.com/RobTillaart/FastShiftIn
77
//
@@ -17,7 +17,7 @@ uint32_t start, duration1, duration2;
1717
void setup()
1818
{
1919
Serial.begin(115200);
20-
Serial.print("example fastShiftIn: ");
20+
Serial.println(__FILE__);
2121
Serial.println(FASTSHIFTIN_LIB_VERSION);
2222

2323
digitalWrite(12, HIGH);
@@ -139,7 +139,7 @@ void test_reference()
139139
Serial.print(" Delta: ");
140140
Serial.println((duration2 - duration1) * 0.001);
141141
Serial.println();
142-
142+
delay(100);
143143
}
144144

145145
void loop()

library.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/FastShiftIn.git"
1717
},
18-
"version":"0.2.1",
18+
"version":"0.2.2",
1919
"frameworks": "arduino",
20-
"platforms": "AVR"
20+
"platforms": "*"
2121
}

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=FastShiftIn
2-
version=0.2.1
2+
version=0.2.2
33
author=Rob Tillaart <[email protected]>
44
maintainer=Rob Tillaart <[email protected]>
55
sentence=Arduino library for (AVR) optimized shiftIn - e.g. for 74HC165

test/.arduino-ci.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
compile:
2+
# Choosing to run compilation tests on 2 different Arduino platforms
3+
platforms:
4+
- uno
5+
- leonardo
6+

0 commit comments

Comments
 (0)