-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathFastDigitalWrite.cpp
66 lines (53 loc) · 1.62 KB
/
FastDigitalWrite.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// FastDigitalWrite.cpp
// Library C++ code
// ----------------------------------
// Developed with embedXcode
// http://embedXcode.weebly.com
//
// Project SPI_23LC1024
//
// Created by Rei VILO, Jul 08, 2013
//
//
// Copyright © Rei VILO, 2013
// Licence CC = BY NC SA
//
// See FastDigitalWrite.h and ReadMe.txt for references
//
// Library header
#include "FastDigitalWrite.h"
// Macros
#define portOutputRegister(x) (regtype)portBASERegister(x)
#define cbi_macro(reg, mask) GPIOPinWrite(reg, mask, 0)
#define sbi_macro(reg, mask) GPIOPinWrite(reg, mask, mask)
#define pulse_high_macro(reg, bitmask) { sbi_macro(reg, bitmask); cbi_macro(reg, bitmask); }
#define pulse_low_macro(reg, bitmask) { cbi_macro(reg, bitmask); sbi_macro(reg, bitmask); }
// Code
fastDigitalOutputPin::fastDigitalOutputPin(uint8_t pinChipSelect)
{
_port = portOutputRegister(digitalPinToPort(pinChipSelect));
_bit = digitalPinToBitMask(pinChipSelect);
pinMode(pinChipSelect, OUTPUT);
}
void fastDigitalOutputPin::setHIGH()
{
sbi_macro(_port, _bit); // HIGH
}
void fastDigitalOutputPin::setLOW()
{
cbi_macro(_port, _bit); // LOW
}
void fastDigitalOutputPin::set(uint8_t value)
{
if (value>0) setHIGH();
else setLOW();
}
void fastDigitalOutputPin::pulseHIGH()
{
pulse_high_macro(_port, _bit); // HIGH then LOW
}
void fastDigitalOutputPin::pulseLOW()
{
pulse_low_macro(_port, _bit); // LOW then HIGH
}