File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ // dummy include
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments