arduino

Fork of arduino by SE HUI PARK

Committer:
gastonfeng
Date:
Mon Apr 15 15:23:54 2019 +0800
Revision:
4:b000674ff8b3
Parent:
3:2f501d4fa486
remove

Who changed what in which revision?

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