Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

119 lines
3.3KB

  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. #define PI 3.1415926535897932384626433832795
  31. #define HALF_PI 1.5707963267948966192313216916398
  32. #define TWO_PI 6.283185307179586476925286766559
  33. #define DEG_TO_RAD 0.017453292519943295769236907684886
  34. #define RAD_TO_DEG 57.295779513082320876798154814105
  35. #ifndef M_PI
  36. #define M_PI 3.1415926535897932384626433832795
  37. #endif
  38. #ifndef M_SQRT2
  39. #define M_SQRT2 1.4142135623730950488016887
  40. #endif
  41. #define SERIAL 0
  42. #define DISPLAY 1
  43. // undefine stdlib's abs if encountered
  44. #ifdef abs
  45. #undef abs
  46. #endif
  47. #define min(a,b) ((a)<(b)?(a):(b))
  48. #define max(a,b) ((a)>(b)?(a):(b))
  49. #define abs(x) ((x)>0?(x):-(x))
  50. #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
  51. #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
  52. #define radians(deg) ((deg)*DEG_TO_RAD)
  53. #define degrees(rad) ((rad)*RAD_TO_DEG)
  54. #define sq(x) ((x)*(x))
  55. #define sei() __enable_irq()
  56. #define cli() __disable_irq()
  57. #define interrupts() __enable_irq()
  58. #define noInterrupts() __disable_irq()
  59. #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
  60. #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
  61. #define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
  62. #define lowByte(w) ((uint8_t)((w) & 0xFF))
  63. #define highByte(w) ((uint8_t)((w) >> 8))
  64. #define bitRead(value, bit) (((value) >> (bit)) & 0x01)
  65. #define bitSet(value, bit) ((value) |= (1UL << (bit)))
  66. #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
  67. #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
  68. typedef unsigned int word;
  69. #define bit(b) (1UL << (b))
  70. typedef uint8_t byte;
  71. uint32_t pulseIn(uint8_t pin, uint8_t state, uint32_t timeout);
  72. void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val);
  73. //void tone(uint8_t pin, uint16_t frequency, uint32_t duration);
  74. //void noTone(uint8_t pin);
  75. //void attachInterrupt(uint8_t, void (*)(void), uint8_t mode);
  76. //void detachInterrupt(uint8_t);
  77. void setup(void);
  78. void loop(void);
  79. #ifdef __cplusplus
  80. } // extern "C"
  81. #endif
  82. // fix C++ boolean issue
  83. // https://github.com/arduino/Arduino/pull/2151
  84. #ifdef __cplusplus
  85. typedef bool boolean;
  86. #else
  87. typedef uint8_t boolean;
  88. #define false 0
  89. #define true (!false)
  90. #endif
  91. #endif