forked from MCUdude/MCUdude_corefiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wiring_extras.cpp
76 lines (56 loc) · 1.37 KB
/
wiring_extras.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
64
65
66
67
68
69
70
71
72
73
74
75
76
/* wiring_extras.c
|| @author Brett Hagman <[email protected]>
|| @url http://wiring.org.co/
|| @contribution Hernando Barragan <[email protected]>
||
|| Modified by MCUdude to work with MegaCore
||
*/
#include "Arduino.h"
#include "wiring_extras.h"
/*************************************************************
* Port functions
*************************************************************/
void _portMode(uint8_t port, uint8_t mode)
{
volatile uint8_t *moderegister;
moderegister = portModeRegister(port);
if(moderegister == NULL)
return;
uint8_t oldSREG = SREG;
cli();
if(mode == OUTPUT)
*moderegister = 0xff;
else if(mode == INPUT_PULLUP)
{
*moderegister = 0x00;
volatile uint8_t *portregister = portOutputRegister(port);
*portregister = 0xff;
}
else // INPUT
*moderegister = 0x00;
SREG = oldSREG;
}
uint8_t _portRead(uint8_t port)
{
volatile uint8_t *inputregister;
inputregister = portInputRegister(port);
if(inputregister == NULL)
return 0;
uint8_t oldSREG = SREG;
cli();
uint8_t portValue = *inputregister;
SREG = oldSREG;
return portValue;
}
void _portWrite(uint8_t port, uint8_t val)
{
volatile uint8_t *portregister;
portregister = portOutputRegister(port);
if(portregister == NULL)
return;
uint8_t oldSREG = SREG;
cli();
*portregister = val;
SREG = oldSREG;
}