arduino

Fork of arduino by SE HUI PARK

Committer:
gastonfeng
Date:
Tue Oct 23 16:04:36 2018 +0800
Revision:
1:4e1b6bfbac98
Parent:
0:3b83fc30bbdf
pin

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aluqard 0:3b83fc30bbdf 1 #ifndef _ARDUINO_H_
aluqard 0:3b83fc30bbdf 2 #define _ARDUINO_H_
aluqard 0:3b83fc30bbdf 3
aluqard 0:3b83fc30bbdf 4 #include "mbed.h"
aluqard 0:3b83fc30bbdf 5 #include "math.h"
aluqard 0:3b83fc30bbdf 6 // Macros
gastonfeng 1:4e1b6bfbac98 7 //add by gastonfeng begin
gastonfeng 1:4e1b6bfbac98 8 typedef enum WiringPinMode
gastonfeng 1:4e1b6bfbac98 9 {
gastonfeng 1:4e1b6bfbac98 10 OUTPUT, /**< Basic digital output: when the pin is HIGH, the
gastonfeng 1:4e1b6bfbac98 11 voltage is held at +3.3v (Vcc) and when it is LOW, it
gastonfeng 1:4e1b6bfbac98 12 is pulled down to ground. */
gastonfeng 1:4e1b6bfbac98 13
gastonfeng 1:4e1b6bfbac98 14 OUTPUT_OPEN_DRAIN, /**< In open drain mode, the pin indicates
gastonfeng 1:4e1b6bfbac98 15 "low" by accepting current flow to ground
gastonfeng 1:4e1b6bfbac98 16 and "high" by providing increased
gastonfeng 1:4e1b6bfbac98 17 impedance. An example use would be to
gastonfeng 1:4e1b6bfbac98 18 connect a pin to a bus line (which is pulled
gastonfeng 1:4e1b6bfbac98 19 up to a positive voltage by a separate
gastonfeng 1:4e1b6bfbac98 20 supply through a large resistor). When the
gastonfeng 1:4e1b6bfbac98 21 pin is high, not much current flows through
gastonfeng 1:4e1b6bfbac98 22 to ground and the line stays at positive
gastonfeng 1:4e1b6bfbac98 23 voltage; when the pin is low, the bus
gastonfeng 1:4e1b6bfbac98 24 "drains" to ground with a small amount of
gastonfeng 1:4e1b6bfbac98 25 current constantly flowing through the large
gastonfeng 1:4e1b6bfbac98 26 resistor from the external supply. In this
gastonfeng 1:4e1b6bfbac98 27 mode, no current is ever actually sourced
gastonfeng 1:4e1b6bfbac98 28 from the pin. */
gastonfeng 1:4e1b6bfbac98 29
gastonfeng 1:4e1b6bfbac98 30 INPUT, /**< Basic digital input. The pin voltage is sampled; when
gastonfeng 1:4e1b6bfbac98 31 it is closer to 3.3v (Vcc) the pin status is high, and
gastonfeng 1:4e1b6bfbac98 32 when it is closer to 0v (ground) it is low. If no
gastonfeng 1:4e1b6bfbac98 33 external circuit is pulling the pin voltage to high or
gastonfeng 1:4e1b6bfbac98 34 low, it will tend to randomly oscillate and be very
gastonfeng 1:4e1b6bfbac98 35 sensitive to noise (e.g., a breath of air across the pin
gastonfeng 1:4e1b6bfbac98 36 might cause the state to flip). */
gastonfeng 1:4e1b6bfbac98 37
gastonfeng 1:4e1b6bfbac98 38 INPUT_ANALOG, /**< This is a special mode for when the pin will be
gastonfeng 1:4e1b6bfbac98 39 used for analog (not digital) reads. Enables ADC
gastonfeng 1:4e1b6bfbac98 40 conversion to be performed on the voltage at the
gastonfeng 1:4e1b6bfbac98 41 pin. */
gastonfeng 1:4e1b6bfbac98 42
gastonfeng 1:4e1b6bfbac98 43 INPUT_PULLUP, /**< The state of the pin in this mode is reported
gastonfeng 1:4e1b6bfbac98 44 the same way as with INPUT, but the pin voltage
gastonfeng 1:4e1b6bfbac98 45 is gently "pulled up" towards +3.3v. This means
gastonfeng 1:4e1b6bfbac98 46 the state will be high unless an external device
gastonfeng 1:4e1b6bfbac98 47 is specifically pulling the pin down to ground,
gastonfeng 1:4e1b6bfbac98 48 in which case the "gentle" pull up will not
gastonfeng 1:4e1b6bfbac98 49 affect the state of the input. */
gastonfeng 1:4e1b6bfbac98 50
gastonfeng 1:4e1b6bfbac98 51 INPUT_PULLDOWN, /**< The state of the pin in this mode is reported
gastonfeng 1:4e1b6bfbac98 52 the same way as with INPUT, but the pin voltage
gastonfeng 1:4e1b6bfbac98 53 is gently "pulled down" towards 0v. This means
gastonfeng 1:4e1b6bfbac98 54 the state will be low unless an external device
gastonfeng 1:4e1b6bfbac98 55 is specifically pulling the pin up to 3.3v, in
gastonfeng 1:4e1b6bfbac98 56 which case the "gentle" pull down will not
gastonfeng 1:4e1b6bfbac98 57 affect the state of the input. */
gastonfeng 1:4e1b6bfbac98 58
gastonfeng 1:4e1b6bfbac98 59 INPUT_FLOATING, /**< Synonym for INPUT. */
gastonfeng 1:4e1b6bfbac98 60
gastonfeng 1:4e1b6bfbac98 61 PWM, /**< This is a special mode for when the pin will be used for
gastonfeng 1:4e1b6bfbac98 62 PWM output (a special case of digital output). */
gastonfeng 1:4e1b6bfbac98 63
gastonfeng 1:4e1b6bfbac98 64 PWM_OPEN_DRAIN, /**< Like PWM, except that instead of alternating
gastonfeng 1:4e1b6bfbac98 65 cycles of LOW and HIGH, the voltage on the pin
gastonfeng 1:4e1b6bfbac98 66 consists of alternating cycles of LOW and
gastonfeng 1:4e1b6bfbac98 67 floating (disconnected). */
gastonfeng 1:4e1b6bfbac98 68 } WiringPinMode;
gastonfeng 1:4e1b6bfbac98 69
gastonfeng 1:4e1b6bfbac98 70 // Roger Clark. Added _BV macro for AVR compatibility. As requested by @sweetlilmre and @stevestrong
gastonfeng 1:4e1b6bfbac98 71 #ifndef _BV
gastonfeng 1:4e1b6bfbac98 72 #define _BV(bit) (1 << (bit))
gastonfeng 1:4e1b6bfbac98 73 #endif
gastonfeng 1:4e1b6bfbac98 74 #define HIGH 1
gastonfeng 1:4e1b6bfbac98 75 #define LOW 0
gastonfeng 1:4e1b6bfbac98 76 #define digitalRead(x) x
gastonfeng 1:4e1b6bfbac98 77 #define digitalWrite(a, b) a->write(b)
gastonfeng 1:4e1b6bfbac98 78 void *pinMode(PinName pin, uint8_t f);
gastonfeng 1:4e1b6bfbac98 79 //gastonfeng end
gastonfeng 1:4e1b6bfbac98 80
aluqard 0:3b83fc30bbdf 81 #define PI 3.1415926535897932384626433832795
aluqard 0:3b83fc30bbdf 82 #define HALF_PI 1.5707963267948966192313216916398
aluqard 0:3b83fc30bbdf 83 #define TWO_PI 6.283185307179586476925286766559
aluqard 0:3b83fc30bbdf 84 #define DEG_TO_RAD 0.017453292519943295769236907684886
aluqard 0:3b83fc30bbdf 85 #define RAD_TO_DEG 57.295779513082320876798154814105
aluqard 0:3b83fc30bbdf 86
aluqard 0:3b83fc30bbdf 87 #define radians(deg) ((deg)*DEG_TO_RAD)
aluqard 0:3b83fc30bbdf 88 #define degrees(rad) ((rad)*RAD_TO_DEG)
aluqard 0:3b83fc30bbdf 89 #define sq(x) ((x)*(x))
aluqard 0:3b83fc30bbdf 90
aluqard 0:3b83fc30bbdf 91 #define pgm_read_word(x) (*(const short int*)x)
aluqard 0:3b83fc30bbdf 92 #define pgm_read_dword_near(x) (*(const int*)x)
aluqard 0:3b83fc30bbdf 93 #define pgm_read_word_near(x) (*(const unsigned int*)x)
aluqard 0:3b83fc30bbdf 94 #define pgm_read_int_near(x) (*(const int*)x)
aluqard 0:3b83fc30bbdf 95 #define pgm_read_int(x) (*(const int*)x)
aluqard 0:3b83fc30bbdf 96 #define pgm_read_byte(x) (*(const char*)x)
aluqard 0:3b83fc30bbdf 97 #define pgm_read_byte_near(x) (*(const char*)x)
aluqard 0:3b83fc30bbdf 98 #define PROGMEM const
aluqard 0:3b83fc30bbdf 99 #define char(x) ((char)x)
aluqard 0:3b83fc30bbdf 100 #define byte(x) ((byte)x)
aluqard 0:3b83fc30bbdf 101 #define int(x) ((int)x)
aluqard 0:3b83fc30bbdf 102 #define word(x) ((word)x)
aluqard 0:3b83fc30bbdf 103 #define long(x) ((long)x)
aluqard 0:3b83fc30bbdf 104 #define float(x) ((float)x)
aluqard 0:3b83fc30bbdf 105
aluqard 0:3b83fc30bbdf 106 #define in_range(c, lo, up) ((uint8_t)c >= lo && (uint8_t)c <= up)
aluqard 0:3b83fc30bbdf 107 #define isprint(c) in_range(c, 0x20, 0x7f)
aluqard 0:3b83fc30bbdf 108 #define isdigit(c) in_range(c, '0', '9')
aluqard 0:3b83fc30bbdf 109 #define isxdigit(c) (isdigit(c) || in_range(c, 'a', 'f') || in_range(c, 'A', 'F'))
aluqard 0:3b83fc30bbdf 110 #define islower(c) in_range(c, 'a', 'z')
aluqard 0:3b83fc30bbdf 111 #define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v')
aluqard 0:3b83fc30bbdf 112
aluqard 0:3b83fc30bbdf 113 /** Macro for delay()
aluqard 0:3b83fc30bbdf 114 *
aluqard 0:3b83fc30bbdf 115 * @param void
aluqard 0:3b83fc30bbdf 116 */
aluqard 0:3b83fc30bbdf 117 #define delay(x) (wait_ms(x))
aluqard 0:3b83fc30bbdf 118 /** Macro for delayMicroseconds()
aluqard 0:3b83fc30bbdf 119 *
aluqard 0:3b83fc30bbdf 120 * @param void
aluqard 0:3b83fc30bbdf 121 */
aluqard 0:3b83fc30bbdf 122 #define delayMicroseconds(x) (wait_us(x))
aluqard 0:3b83fc30bbdf 123
aluqard 0:3b83fc30bbdf 124 /** Macro for min()
aluqard 0:3b83fc30bbdf 125 *
aluqard 0:3b83fc30bbdf 126 * @param any
aluqard 0:3b83fc30bbdf 127 */
aluqard 0:3b83fc30bbdf 128 #define min(a,b) ((a)<(b)?(a):(b))
aluqard 0:3b83fc30bbdf 129 /** Macro for max()
aluqard 0:3b83fc30bbdf 130 *
aluqard 0:3b83fc30bbdf 131 * @param any
aluqard 0:3b83fc30bbdf 132 */
aluqard 0:3b83fc30bbdf 133 #define max(a,b) ((a)>(b)?(a):(b))
aluqard 0:3b83fc30bbdf 134 /** Macro for abs()
aluqard 0:3b83fc30bbdf 135 *
aluqard 0:3b83fc30bbdf 136 * @param any
aluqard 0:3b83fc30bbdf 137 */
aluqard 0:3b83fc30bbdf 138 #define abs(x) ((x)>0?(x):(x*-1))
aluqard 0:3b83fc30bbdf 139
aluqard 0:3b83fc30bbdf 140 /** Macro for randomSeed()
aluqard 0:3b83fc30bbdf 141 *
aluqard 0:3b83fc30bbdf 142 * @param int
aluqard 0:3b83fc30bbdf 143 */
aluqard 0:3b83fc30bbdf 144 #define randomSeed(x) srand(x)
aluqard 0:3b83fc30bbdf 145
aluqard 0:3b83fc30bbdf 146 #define bitRead(value, bit) (((value) >> (bit)) & 0x01)
aluqard 0:3b83fc30bbdf 147 #define bitSet(value, bit) ((value) |= (1UL << (bit)))
aluqard 0:3b83fc30bbdf 148 #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
aluqard 0:3b83fc30bbdf 149 #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
aluqard 0:3b83fc30bbdf 150
aluqard 0:3b83fc30bbdf 151 // typedefs
aluqard 0:3b83fc30bbdf 152
aluqard 0:3b83fc30bbdf 153 typedef unsigned char prog_uchar;
aluqard 0:3b83fc30bbdf 154 typedef unsigned char prog_uint8_t;
aluqard 0:3b83fc30bbdf 155 typedef unsigned int prog_uint16_t;
aluqard 0:3b83fc30bbdf 156 typedef unsigned int prog_uint32_t;
aluqard 0:3b83fc30bbdf 157 typedef unsigned char byte;
aluqard 0:3b83fc30bbdf 158 typedef bool boolean;
aluqard 0:3b83fc30bbdf 159 typedef unsigned char prog_uchar;
aluqard 0:3b83fc30bbdf 160 typedef signed char prog_char;
aluqard 0:3b83fc30bbdf 161 typedef signed long int word;
aluqard 0:3b83fc30bbdf 162
aluqard 0:3b83fc30bbdf 163 // function prototypes
aluqard 0:3b83fc30bbdf 164
aluqard 0:3b83fc30bbdf 165 void timer_start(void);
aluqard 0:3b83fc30bbdf 166 long millis(void);
aluqard 0:3b83fc30bbdf 167 long micros(void);
aluqard 0:3b83fc30bbdf 168 byte lowByte(short int low);
aluqard 0:3b83fc30bbdf 169 byte highByte(short int high);
aluqard 0:3b83fc30bbdf 170
aluqard 0:3b83fc30bbdf 171 int random(int number);
aluqard 0:3b83fc30bbdf 172 int random(int numberone, int numbertwo);
aluqard 0:3b83fc30bbdf 173 #endif