Arduino Libraries
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
util
fast_io.hpp
Go to the documentation of this file.
1
// Author: Mario S. Könz <mskoenz@gmx.net>
2
// Date: 30.03.2013 12:55:28 CET
3
// File: fast_io.hpp
4
5
/* This program is free software. It comes without any warranty, to
6
* the extent permitted by applicable law. You can redistribute it
7
* and/or modify it under the terms of the Do What The Fuck You Want
8
* To Public License, Version 2, as published by Sam Hocevar. See
9
* http://www.wtfpl.net/ or COPYING for more details. */
10
11
#ifndef __FAST_IO_HEADER
12
#define __FAST_IO_HEADER
13
14
#include <Arduino.h>
15
16
namespace
detail {
17
inline
void
old_digital_write(
int
const
p
,
bool
const
state) {
18
digitalWrite
(p, state);
// calls the arduino function for pins bigger than 13
19
}
20
21
inline
bool
old_digital_read(
int
const
p
) {
22
return
digitalRead
(p);
// calls the arduino function for pins bigger than 13
23
}
24
template
<
int
p>
25
struct
dw {
26
inline
static
void
write(
bool
const
state) {
27
if
(state) {
28
if
(
p
>= 0 and
p
<= 7)
29
PORTD |= (1<<
p
);
30
else
if
(
p
>= 8 and
p
<= 13)
31
PORTB |= (1<<(
p
-8*int(
p
/8)));
//*int(p/8) is only there to get rid of the error "negative shift"
32
else
33
old_digital_write(
p
, HIGH);
34
}
35
else
{
36
if
(
p
>= 0 and
p
<= 7)
37
PORTD &= ~(1<<
p
);
38
else
if
(
p
>= 8 and
p
<= 13)
39
PORTB &= ~(1<<(
p
-8*int(
p
/8)));
//see comment above
40
else
41
old_digital_write(
p
, LOW);
42
}
43
}
44
};
45
46
template
<
int
p>
47
struct
dr {
48
inline
static
bool
read() {
49
if
(
p
>= 0 and
p
<= 7)
50
return
(PIND >>
p
) & 1;
51
else
if
(
p
>= 8 and
p
<= 13)
52
return
(PINB >> (
p
-8*
int
(
p
/8))) & 1;
//*int(p/8) is only there to get rid of the error "negative shift"
53
else
54
return
old_digital_read(
p
);
55
}
56
};
57
}
//end namespace detail
58
59
#define digitalWrite(x, y) detail::dw<x>::write(y)
60
#define digitalRead(x) detail::dr<x>::read()
61
62
#endif //__FAST_IO_HEADER
digitalRead
#define digitalRead(x)
Definition:
fast_io.hpp:60
digitalWrite
#define digitalWrite(x, y)
Definition:
fast_io.hpp:59
key::p
Generated on Wed Oct 8 2014 19:44:56 for Arduino Libraries by
1.8.6