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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/**
* @file gpio.c
* Userspace library for GPIO access
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "gpio.h"
#include <stdint.h>
// SVC calls get messed up by GCC's optimization...
#define NOOPTIMIZE __attribute__((optimize(0)))
NOOPTIMIZE
void gpioMode(gpio_pin_t pin, int mode)
{
uint32_t args[2] = { (uint32_t)pin, mode };
__asm volatile("\
mov r0, 0; \
mov r1, 0; \
mov r2, %0; \
svc 1; \
" :: "r" (args));
}
NOOPTIMIZE
void gpioType(gpio_pin_t pin, int type)
{
uint32_t args[2] = { (uint32_t)pin, type };
__asm volatile("\
mov r0, 1; \
mov r1, 0; \
mov r2, %0; \
svc 1; \
" :: "r" (args));
}
NOOPTIMIZE
void gpioPuPd(gpio_pin_t pin, int pupd)
{
uint32_t args[2] = { (uint32_t)pin, pupd };
__asm volatile("\
mov r0, 2; \
mov r1, 0; \
mov r2, %0; \
svc 1; \
" :: "r" (args));
}
NOOPTIMIZE
void gpioSpeed(gpio_pin_t pin, int speed)
{
uint32_t args[2] = { (uint32_t)pin, speed };
__asm volatile("\
mov r0, 3; \
mov r1, 0; \
mov r2, %0; \
svc 1; \
" :: "r" (args));
}
NOOPTIMIZE
void gpioWrite(gpio_pin_t pin, int value)
{
uint32_t args[2] = { (uint32_t)pin, value };
__asm volatile("\
mov r0, 4; \
mov r1, 0; \
mov r2, %0; \
svc 1; \
" :: "r" (args));
}
NOOPTIMIZE
int gpioRead(gpio_pin_t pin)
{
volatile int ret = 0;
uint32_t args[1] = { (uint32_t)pin };
__asm volatile("\
mov r0, 5; \
mov r1, %0; \
mov r2, %1; \
svc 1; \
" :: "r" (&ret), "r" (args));
return ret;
}
|