base.cpp
1021 Bytes
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
/*
* Copyright (C) 2015 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
* details.
*/
/**
* @ingroup sys_arduino
* @{
*
* @file
* @brief Implementation of Arduino core functionality
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/
extern "C" {
#include "xtimer.h"
#include "periph/gpio.h"
}
#include "arduino.hpp"
void pinMode(int pin, int mode)
{
gpio_mode_t m = GPIO_OUT;
if (mode == INPUT) {
m = GPIO_IN;
}
else if (mode == INPUT_PULLUP) {
m = GPIO_IN_PU;
}
gpio_init(arduino_pinmap[pin], m);
}
void digitalWrite(int pin, int state)
{
gpio_write(arduino_pinmap[pin], state);
}
int digitalRead(int pin)
{
if (gpio_read(arduino_pinmap[pin])) {
return HIGH;
}
else {
return LOW;
}
}
void delay(unsigned long msec)
{
xtimer_usleep(1000 * msec);
}