Skip to content

Commit

Permalink
v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdralph committed Jul 9, 2020
1 parent dafa2d7 commit 6042c4d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions ArduinoShrink.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// dummy include
52 changes: 52 additions & 0 deletions wiring_digital.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// (c) Ralph Doncaster 2020
// thanks to Bill W for inspiration
// github.com/WestfW/Duino-hacks/blob/master/fastdigitalIO/fastdigitalIO.h
// 20200709 v0.1.0 release

#define ARDUINO_MAIN
#include <Arduino.h>

typedef volatile uint8_t* ioreg_p;

inline ioreg_p pin_to_port(uint8_t pin)
{
return (ioreg_p) port_to_output_PGM[digital_pin_to_port_PGM[pin]];
}

inline ioreg_p pin_to_ddr(uint8_t pin)
{
return pin_to_port(pin) - 1;
}

inline ioreg_p pin_to_pinreg(uint8_t pin)
{
return pin_to_port(pin) - 2;
}

inline uint8_t pin_to_bit(uint8_t pin)
{
return digital_pin_to_bit_mask_PGM[pin];
}

void pinMode(uint8_t pin, uint8_t mode)
{
if (mode == OUTPUT)
*pin_to_ddr(pin) |= (pin_to_bit(pin));
else {
*pin_to_ddr(pin) &= ~(pin_to_bit(pin));
if (mode == INPUT_PULLUP) *pin_to_port(pin) |= (pin_to_bit(pin));
}
}

void digitalWrite(uint8_t pin, uint8_t val)
{
if (val == LOW)
*pin_to_port(pin) &= ~(pin_to_bit(pin));
else // HIGH
*pin_to_port(pin) |= (pin_to_bit(pin));
}

int digitalRead(uint8_t pin)
{
return (*pin_to_pinreg(pin) & pin_to_bit(pin)) ? HIGH : LOW;
}

0 comments on commit 6042c4d

Please sign in to comment.