MySensors Library & Examples
2.3.2-62-ge298769
hal
transport
PJON
driver
interfaces
RPI
PJON_RPI_Interface.h
1
2
/* PJON RaspeberryPi Interface
3
_____________________________________________________________________________
4
5
Copyright 2018 Giovanni Blu Mitolo
[email protected]
6
7
Licensed under the Apache License, Version 2.0 (the "License");
8
you may not use this file except in compliance with the License.
9
You may obtain a copy of the License at
10
11
http://www.apache.org/licenses/LICENSE-2.0
12
13
Unless required by applicable law or agreed to in writing, software
14
distributed under the License is distributed on an "AS IS" BASIS,
15
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
See the License for the specific language governing permissions and
17
limitations under the License. */
18
19
#pragma once
20
21
#if defined(RPI)
22
#include <cinttypes>
23
#include <cstdlib>
24
#include <cstring>
25
#include <wiringPi.h>
26
#include <wiringSerial.h>
27
28
/* Generic constants ---------------------------------------------------- */
29
30
#ifndef A0
31
#define A0 0
32
#endif
33
34
#ifndef LED_BUILTIN
35
#define LED_BUILTIN -1
36
#endif
37
38
/* Fallback to WiringPi core functions ---------------------------------- */
39
40
#if !defined(PJON_ANALOG_READ)
41
#define PJON_ANALOG_READ(P) analogRead(P)
42
#endif
43
44
#if !defined(PJON_IO_WRITE)
45
#define PJON_IO_WRITE digitalWrite
46
#endif
47
48
#if !defined(PJON_IO_READ)
49
#define PJON_IO_READ digitalRead
50
#endif
51
52
#if !defined(PJON_IO_MODE)
53
#define PJON_IO_MODE pinMode
54
#endif
55
56
#if !defined(PJON_IO_PULL_DOWN)
57
#define PJON_IO_PULL_DOWN(P) { \
58
PJON_IO_MODE(P, INPUT); \
59
pullUpDnControl(P, PUD_DOWN); \
60
}
61
#endif
62
63
/* Random ----------------------------------------------------------------- */
64
65
#ifndef PJON_RANDOM
66
#define PJON_RANDOM(randMax) (int)((1.0 + randMax) * rand() / ( RAND_MAX + 1.0 ) )
67
/* Scale rand()'s return value against RAND_MAX using doubles instead of
68
a pure modulus to have a more distributed result */
69
#endif
70
71
#ifndef PJON_RANDOM_SEED
72
#define PJON_RANDOM_SEED srand
73
#endif
74
75
/* Serial ----------------------------------------------------------------- */
76
77
#ifndef PJON_SERIAL_TYPE
78
#define PJON_SERIAL_TYPE int16_t
79
#endif
80
81
#ifndef PJON_SERIAL_AVAILABLE
82
#define PJON_SERIAL_AVAILABLE(S) serialDataAvail(S)
83
#endif
84
85
#ifndef PJON_SERIAL_WRITE
86
#define PJON_SERIAL_WRITE(S, C) write(S, &C, 1)
87
#endif
88
89
#ifndef PJON_SERIAL_READ
90
#define PJON_SERIAL_READ(S) serialGetchar(S)
91
#endif
92
93
#ifndef PJON_SERIAL_FLUSH
94
#define PJON_SERIAL_FLUSH(S) serialFlush(S)
95
#endif
96
97
/* Timing offset in microseconds between expected and real serial
98
byte transmission: */
99
100
#ifndef TS_FLUSH_OFFSET
101
#define TS_FLUSH_OFFSET 152
102
#endif
103
104
/* Timing ----------------------------------------------------------------- */
105
106
#ifndef PJON_DELAY
107
#define PJON_DELAY delay
108
#endif
109
110
#ifndef PJON_DELAY_MICROSECONDS
111
#define PJON_DELAY_MICROSECONDS delayMicroseconds
112
#endif
113
114
#ifndef PJON_MICROS
115
#define PJON_MICROS micros
116
#endif
117
118
#ifndef PJON_MILLIS
119
#define PJON_MILLIS millis
120
#endif
121
#endif
Copyright (C) 2013-2019 Sensnology AB. Generated by
doxygen
1.8.17