Skip to content

Commit 6042c4d

Browse files
committed
v0.1.0
1 parent dafa2d7 commit 6042c4d

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

ArduinoShrink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// dummy include

wiring_digital.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// (c) Ralph Doncaster 2020
2+
// thanks to Bill W for inspiration
3+
// github.com/WestfW/Duino-hacks/blob/master/fastdigitalIO/fastdigitalIO.h
4+
// 20200709 v0.1.0 release
5+
6+
#define ARDUINO_MAIN
7+
#include <Arduino.h>
8+
9+
typedef volatile uint8_t* ioreg_p;
10+
11+
inline ioreg_p pin_to_port(uint8_t pin)
12+
{
13+
return (ioreg_p) port_to_output_PGM[digital_pin_to_port_PGM[pin]];
14+
}
15+
16+
inline ioreg_p pin_to_ddr(uint8_t pin)
17+
{
18+
return pin_to_port(pin) - 1;
19+
}
20+
21+
inline ioreg_p pin_to_pinreg(uint8_t pin)
22+
{
23+
return pin_to_port(pin) - 2;
24+
}
25+
26+
inline uint8_t pin_to_bit(uint8_t pin)
27+
{
28+
return digital_pin_to_bit_mask_PGM[pin];
29+
}
30+
31+
void pinMode(uint8_t pin, uint8_t mode)
32+
{
33+
if (mode == OUTPUT)
34+
*pin_to_ddr(pin) |= (pin_to_bit(pin));
35+
else {
36+
*pin_to_ddr(pin) &= ~(pin_to_bit(pin));
37+
if (mode == INPUT_PULLUP) *pin_to_port(pin) |= (pin_to_bit(pin));
38+
}
39+
}
40+
41+
void digitalWrite(uint8_t pin, uint8_t val)
42+
{
43+
if (val == LOW)
44+
*pin_to_port(pin) &= ~(pin_to_bit(pin));
45+
else // HIGH
46+
*pin_to_port(pin) |= (pin_to_bit(pin));
47+
}
48+
49+
int digitalRead(uint8_t pin)
50+
{
51+
return (*pin_to_pinreg(pin) & pin_to_bit(pin)) ? HIGH : LOW;
52+
}

0 commit comments

Comments
 (0)