Skip to content

Commit 5decd2c

Browse files
committed
shiftin/shiftout
1 parent 15bace7 commit 5decd2c

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

Diff for: cores/esp32/wiring_shift.c

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
wiring_shift.c - shiftOut() function
3+
Part of Arduino - http://www.arduino.cc/
4+
5+
Copyright (c) 2005-2006 David A. Mellis
6+
7+
Note: file renamed with a core_esp8266_ prefix to simplify linker
8+
script rules for moving code into irom0_text section.
9+
10+
This library is free software; you can redistribute it and/or
11+
modify it under the terms of the GNU Lesser General Public
12+
License as published by the Free Software Foundation; either
13+
version 2.1 of the License, or (at your option) any later version.
14+
15+
This library is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18+
Lesser General Public License for more details.
19+
20+
You should have received a copy of the GNU Lesser General
21+
Public License along with this library; if not, write to the
22+
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23+
Boston, MA 02111-1307 USA
24+
25+
$Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
26+
*/
27+
28+
#include "wiring_private.h"
29+
30+
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) {
31+
uint8_t value = 0;
32+
uint8_t i;
33+
34+
for(i = 0; i < 8; ++i) {
35+
digitalWrite(clockPin, HIGH);
36+
if(bitOrder == LSBFIRST)
37+
value |= digitalRead(dataPin) << i;
38+
else
39+
value |= digitalRead(dataPin) << (7 - i);
40+
digitalWrite(clockPin, LOW);
41+
}
42+
return value;
43+
}
44+
45+
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) {
46+
uint8_t i;
47+
48+
for(i = 0; i < 8; i++) {
49+
if(bitOrder == LSBFIRST)
50+
digitalWrite(dataPin, !!(val & (1 << i)));
51+
else
52+
digitalWrite(dataPin, !!(val & (1 << (7 - i))));
53+
54+
digitalWrite(clockPin, HIGH);
55+
digitalWrite(clockPin, LOW);
56+
}
57+
}

0 commit comments

Comments
 (0)