Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

147 lines
3.8KB

  1. /*
  2. wiring.h - Partial implementation of the Wiring API for the ATmega8.
  3. Part of Arduino - http://www.arduino.cc/
  4. Copyright (c) 2005-2006 David A. Mellis
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General
  14. Public License along with this library; if not, write to the
  15. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  16. Boston, MA 02111-1307 USA
  17. $Id: wiring.h 387 2008-03-08 21:30:00Z mellis $
  18. */
  19. #ifndef Wiring_h
  20. #define Wiring_h
  21. //#include <avr/io.h>
  22. #include <stdint.h>
  23. #include <stdlib.h>
  24. #include "binary.h"
  25. #include "core_id.h"
  26. #include "core_pins.h"
  27. #ifdef __cplusplus
  28. extern "C"{
  29. #endif
  30. #ifdef PI
  31. #undef PI
  32. #endif
  33. #define PI 3.1415926535897932384626433832795
  34. #define HALF_PI 1.5707963267948966192313216916398
  35. #define TWO_PI 6.283185307179586476925286766559
  36. #define DEG_TO_RAD 0.017453292519943295769236907684886
  37. #define RAD_TO_DEG 57.295779513082320876798154814105
  38. #ifndef M_PI
  39. #define M_PI 3.1415926535897932384626433832795
  40. #endif
  41. #ifndef M_SQRT2
  42. #define M_SQRT2 1.4142135623730950488016887
  43. #endif
  44. #define SERIAL 0
  45. #define DISPLAY 1
  46. // undefine stdlib's abs if encountered
  47. #ifdef abs
  48. #undef abs
  49. #endif
  50. #if __cplusplus >= 201103L && defined(__STRICT_ANSI__)
  51. #define typeof(a) decltype(a)
  52. #endif
  53. #define min(a, b) ({ \
  54. typeof(a) _a = (a); \
  55. typeof(b) _b = (b); \
  56. (_a < _b) ? _a : _b; \
  57. })
  58. #define max(a, b) ({ \
  59. typeof(a) _a = (a); \
  60. typeof(b) _b = (b); \
  61. (_a > _b) ? _a : _b; \
  62. })
  63. #define abs(x) ({ \
  64. typeof(x) _x = (x); \
  65. (_x > 0) ? _x : -_x; \
  66. })
  67. #define constrain(amt, low, high) ({ \
  68. typeof(amt) _amt = (amt); \
  69. typeof(low) _low = (low); \
  70. typeof(high) _high = (high); \
  71. (_amt < _low) ? _low : ((_amt > _high) ? _high : _amt); \
  72. })
  73. #define round(x) ({ \
  74. typeof(x) _x = (x); \
  75. (_x>=0) ? (long)(_x+0.5) : (long)(_x-0.5); \
  76. })
  77. #define radians(deg) ((deg)*DEG_TO_RAD)
  78. #define degrees(rad) ((rad)*RAD_TO_DEG)
  79. #define sq(x) ({ \
  80. typeof(x) _x = (x); \
  81. _x * _x; \
  82. })
  83. #define sei() __enable_irq()
  84. #define cli() __disable_irq()
  85. #define interrupts() __enable_irq()
  86. #define noInterrupts() __disable_irq()
  87. #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
  88. #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
  89. #define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
  90. #define lowByte(w) ((uint8_t)((w) & 0xFF))
  91. #define highByte(w) ((uint8_t)((w) >> 8))
  92. #define bitRead(value, bit) (((value) >> (bit)) & 0x01)
  93. #define bitSet(value, bit) ((value) |= (1UL << (bit)))
  94. #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
  95. #define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet((value), (bit)) : bitClear((value), (bit)))
  96. typedef unsigned int word;
  97. #define bit(b) (1UL << (b))
  98. typedef uint8_t byte;
  99. uint32_t pulseIn(uint8_t pin, uint8_t state, uint32_t timeout);
  100. void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val);
  101. //void tone(uint8_t pin, uint16_t frequency, uint32_t duration);
  102. //void noTone(uint8_t pin);
  103. //void attachInterrupt(uint8_t, void (*)(void), uint8_t mode);
  104. //void detachInterrupt(uint8_t);
  105. void setup(void);
  106. void loop(void);
  107. #ifdef __cplusplus
  108. } // extern "C"
  109. #endif
  110. // fix C++ boolean issue
  111. // https://github.com/arduino/Arduino/pull/2151
  112. #ifdef __cplusplus
  113. typedef bool boolean;
  114. #else
  115. typedef uint8_t boolean;
  116. #define false 0
  117. #define true (!false)
  118. #endif
  119. #endif