-
Notifications
You must be signed in to change notification settings - Fork 0
/
arduino.h
152 lines (124 loc) · 3.64 KB
/
arduino.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Copyright (c) 2015 Wind River Systems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for
* the specific language governing permissions and limitations under the License.
*/
#ifndef _ARDUINO_H_
#define _ARDUINO_H_
#include "zephyr.h"
#include "math.h"
#if defined(CONFIG_STDOUT_CONSOLE)
#include <stdio.h>
#define PRINT printf
#else
#include <misc/printk.h>
#define PRINT printk
#endif
#define DBG_PRINT(...)
typedef unsigned int uint_t;
typedef _Bool BOOL;
#define LOW 0x0
#define HIGH 0x1
#define RISING 0x02
#define FALLING 0x04
#define CHANGE 0x08
#define INPUT 0x00
#define OUTPUT 0x01
#define INPUT_PULLUP 0x02
#define OUTPUT_FAST 0x03
#define INPUT_FAST 0x04
#define MS_PER_SEC 1000
#define US_PER_SEC 10000000
#define DEFAULT 0
#define PWM_FREQUENCY 970
/*
#define true 0x1
#define false 0x0
*/
#define DEFAULT_TASK_PRIORITY 100
BOOL arduino_running;
#define LED_BUILTIN 13
/* Digital I/O */
void pinMode(uint8_t pin, uint8_t mode);
void digitalWrite(register uint8_t pin, register uint8_t value);
int digitalRead(uint_t pin);
/* Analog I/O */
void analogReference(uint8_t type);
uint16_t analogRead(uint8_t pin);
void analogWrite(uint32_t pin, uint32_t value);
/* Advanced I/O */
void tone(uint8_t pin, unsigned int frequency, unsigned long duration); /* XXX: Add duration default of 0 */
void noTone(uint8_t pin);
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value);
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPing, uint8_t bitOrder);
unsigned long pulseIn(uint8_t pin, uint8_t value, unsigned long timeout); /* XXX: Add timeout default of 1000000L */
/* Time */
unsigned long mills(void);
unsigned long micros(void);
void delay(unsigned long ms);
void delayMicroseconds(unsigned int us);
/* Math */
/* #define min(x,y) ((x)<(y)?(x):(y)) */
/* #define max(x,y) ((x)>(y)?(x):(y)) */
#define abs(x) ((x)>0?(x):-(x))
#define constrain(x,a,b) ((x)<(a)?(a):((x)>(b)?(b):(x)))
uint32_t map(uint32_t value, uint32_t fromLow, uint32_t fromHigh, \
uint32_t toLow,uint32_t toHigh);
#define sq(x) ((x)*(x))
/* Random Numbers */
void randomSeed(uint32_t seed);
long random(long min, long max); /* XXX: add min default of 0 */
/* Bits and Bytes */
#define lowByte(x) ((uint8_t) ((x) & 0xff))
#define highByte(x) ((uint8_t) ((x) >> 8))
#define bitRead(x,n) (((x) >> (n)) & 0x01)
#define bitWrite(x,n,b) (b ? bitSet(x,n) : bitClear(x,n))
#define bitClear(x,n) ((x) &= ~(1UL << (n)))
#define bitSet(x,n) ((x) |= (1UL << (bit)))
#define bit(n) (1UL << (b))
#define IO0 0
#define IO1 1
#define IO2 2
#define IO3 3
#define IO4 4
#define IO5 5
#define IO6 6
#define IO7 7
#define IO8 8
#define IO9 9
#define IO10 10
#define IO11 11
#define IO12 12
#define IO13 13
#define IO14 14
#define IO15 15
#define IO16 16
#define IO17 17
#define IO18 18
#define IO19 19
#define A0 14
#define A1 15
#define A2 16
#define A3 17
#define A4 18
#define A5 19
/* External Interrupts */
void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode);
void detachInterrupt(uint32_t pin);
/* Interrupts */
void interrupts(void);
void noInterrupts(void);
extern void arduino(void);
extern void main(void);
extern void setup(void);
extern void loop(void);
#endif /* _ARDUINO_H_ */