-
Notifications
You must be signed in to change notification settings - Fork 13
/
io_impl.h
73 lines (63 loc) · 2.12 KB
/
io_impl.h
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
/* This file is part of ukbdc.
*
* ukbdc is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* ukbdc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ukbdc; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
#include <avr/io.h>
#include <stdbool.h>
static inline bool IO_get_internal(uint8_t pin)
{
return (*PINS[pin].pinx & PINS[pin].mask) ? true : false;
}
static inline void IO_set_internal(uint8_t pin, bool val)
{
if (val)
*PINS[pin].portx |= PINS[pin].mask;
else
*PINS[pin].portx &= ~PINS[pin].mask;
}
static inline void IO_config_internal(uint8_t pin, bool dir)
{
if (dir == OUTPUT)
*PINS[pin].ddrx |= PINS[pin].mask;
else
*PINS[pin].ddrx &= ~PINS[pin].mask;
}
#if defined(PLATFORM_ikea) || defined(PLATFORM_alpha) || defined(PLATFORM_gh60) || defined(PLATFORM_gh60b) || defined(PLATFORM_ghpad)
static inline bool IO_get_external(__attribute__((unused)) uint8_t pin)
{
return false;
}
#endif
#if defined(PLATFORM_ikea) || defined(PLATFORM_gh60) || defined(PLATFORM_gh60b) || defined(PLATFORM_ghpad)
static inline void IO_set_external(__attribute__((unused)) uint8_t pin, __attribute__((unused)) bool val)
{
}
#elif defined(PLATFORM_alpha)
void IO_set_external(uint8_t pin, bool val)
{
static uint16_t hc_state = 0;
if (val)
hc_state |= 0x0001 << (pin & 0x7f);
else
hc_state &= ~(0x0001 << (pin & 0x7f));
HC595_set_outputs(hc_state);
}
#endif
#if defined(PLATFORM_alpha) || defined(PLATFORM_ikea) || defined(PLATFORM_gh60) || defined(PLATFORM_gh60b) || defined(PLATFORM_ghpad)
static inline void IO_config_external(__attribute__((unused)) uint8_t pin, __attribute__((unused)) bool dir)
{
}
#endif