|
|
@ -39,6 +39,8 @@
|
|
|
|
#ifndef _FASTIO_DUE_H
|
|
|
|
#ifndef _FASTIO_DUE_H
|
|
|
|
#define _FASTIO_DUE_H
|
|
|
|
#define _FASTIO_DUE_H
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <pins_arduino.h>
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Utility functions
|
|
|
|
* Utility functions
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -64,7 +66,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
// Write to a pin
|
|
|
|
// Write to a pin
|
|
|
|
#define _WRITE_VAR(IO,V) do { \
|
|
|
|
#define _WRITE_VAR(IO,V) do { \
|
|
|
|
volatile Pio* port = g_APinDescription[IO].pPort; \
|
|
|
|
volatile Pio* port = digitalPinToPort(IO); \
|
|
|
|
uint32_t mask = g_APinDescription[IO].ulPin; \
|
|
|
|
uint32_t mask = g_APinDescription[IO].ulPin; \
|
|
|
|
if (V) port->PIO_SODR = mask; \
|
|
|
|
if (V) port->PIO_SODR = mask; \
|
|
|
|
else port->PIO_CODR = mask; \
|
|
|
|
else port->PIO_CODR = mask; \
|
|
|
@ -84,26 +86,19 @@
|
|
|
|
// Set pin as input
|
|
|
|
// Set pin as input
|
|
|
|
#define _SET_INPUT(IO) do{ \
|
|
|
|
#define _SET_INPUT(IO) do{ \
|
|
|
|
pmc_enable_periph_clk(g_APinDescription[IO].ulPeripheralId); \
|
|
|
|
pmc_enable_periph_clk(g_APinDescription[IO].ulPeripheralId); \
|
|
|
|
PIO_Configure(g_APinDescription[IO].pPort, PIO_INPUT, g_APinDescription[IO].ulPin, 0); \
|
|
|
|
PIO_Configure(g_APinDescription[IO].pPort, PIO_INPUT, digitalPinToBitMask(IO), 0); \
|
|
|
|
}while(0)
|
|
|
|
}while(0)
|
|
|
|
|
|
|
|
|
|
|
|
// Set pin as output
|
|
|
|
// Set pin as output
|
|
|
|
#define _SET_OUTPUT(IO) do{ \
|
|
|
|
#define _SET_OUTPUT(IO) do{ \
|
|
|
|
pmc_enable_periph_clk(g_APinDescription[IO].ulPeripheralId); \
|
|
|
|
pmc_enable_periph_clk(g_APinDescription[IO].ulPeripheralId); \
|
|
|
|
PIO_Configure(g_APinDescription[IO].pPort, _READ(IO) ? PIO_OUTPUT_1 : PIO_OUTPUT_0, g_APinDescription[IO].ulPin, g_APinDescription[IO].ulPinConfiguration); \
|
|
|
|
PIO_Configure(g_APinDescription[IO].pPort, _READ(IO) ? PIO_OUTPUT_1 : PIO_OUTPUT_0, digitalPinToBitMask(IO), g_APinDescription[IO].ulPinConfiguration); \
|
|
|
|
g_pinStatus[IO] = (g_pinStatus[IO] & 0xF0) | PIN_STATUS_DIGITAL_OUTPUT;\
|
|
|
|
g_pinStatus[IO] = (g_pinStatus[IO] & 0xF0) | PIN_STATUS_DIGITAL_OUTPUT;\
|
|
|
|
}while(0)
|
|
|
|
}while(0)
|
|
|
|
|
|
|
|
|
|
|
|
// Set pin as input with pullup mode
|
|
|
|
// Set pin as input with pullup mode
|
|
|
|
#define _PULLUP(IO,V) pinMode(IO, (V) ? INPUT_PULLUP : INPUT)
|
|
|
|
#define _PULLUP(IO,V) pinMode(IO, (V) ? INPUT_PULLUP : INPUT)
|
|
|
|
|
|
|
|
|
|
|
|
// Check if pin is an input
|
|
|
|
|
|
|
|
#define _GET_INPUT(IO)
|
|
|
|
|
|
|
|
// Check if pin is an output
|
|
|
|
|
|
|
|
#define _GET_OUTPUT(IO)
|
|
|
|
|
|
|
|
// Check if pin is a timer
|
|
|
|
|
|
|
|
#define _GET_TIMER(IO)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Read a pin (wrapper)
|
|
|
|
// Read a pin (wrapper)
|
|
|
|
#define READ(IO) _READ(IO)
|
|
|
|
#define READ(IO) _READ(IO)
|
|
|
|
|
|
|
|
|
|
|
@ -120,13 +115,16 @@
|
|
|
|
#define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0)
|
|
|
|
#define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0)
|
|
|
|
// Set pin as output (wrapper) - reads the pin and sets the output to that value
|
|
|
|
// Set pin as output (wrapper) - reads the pin and sets the output to that value
|
|
|
|
#define SET_OUTPUT(IO) _SET_OUTPUT(IO)
|
|
|
|
#define SET_OUTPUT(IO) _SET_OUTPUT(IO)
|
|
|
|
// Check if pin is an input (wrapper)
|
|
|
|
|
|
|
|
#define GET_INPUT(IO) _GET_INPUT(IO)
|
|
|
|
|
|
|
|
// Check if pin is an output (wrapper)
|
|
|
|
|
|
|
|
#define GET_OUTPUT(IO) _GET_OUTPUT(IO)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if pin is a timer (wrapper)
|
|
|
|
// Check if pin is an input
|
|
|
|
#define GET_TIMER(IO) _GET_TIMER(IO)
|
|
|
|
#define GET_INPUT(IO) !(digitalPinToPort(IO)->PIO_OSR & digitalPinToBitMask(IO))
|
|
|
|
|
|
|
|
// Check if pin is an output
|
|
|
|
|
|
|
|
#define GET_OUTPUT(IO) !!(digitalPinToPort(IO)->PIO_OSR & digitalPinToBitMask(IO))
|
|
|
|
|
|
|
|
// Check if pin is a timer
|
|
|
|
|
|
|
|
#define GET_TIMER(IO) ( \
|
|
|
|
|
|
|
|
(g_APinDescription[IO].ulPinAttribute & PIN_ATTR_TIMER) == PIN_ATTR_TIMER \
|
|
|
|
|
|
|
|
|| (g_APinDescription[IO].ulPinAttribute & PIN_ATTR_PWM) == PIN_ATTR_PWM \
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// Shorthand
|
|
|
|
// Shorthand
|
|
|
|
#define OUT_WRITE(IO,V) { SET_OUTPUT(IO); WRITE(IO,V); }
|
|
|
|
#define OUT_WRITE(IO,V) { SET_OUTPUT(IO); WRITE(IO,V); }
|
|
|
|