Teensy 4.1 core updated for C++20
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vor 9 Jahren
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #ifndef WProgram_h
  2. #define WProgram_h
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <math.h>
  6. // some libraries and sketches depend on this
  7. // AVR stuff, assuming Arduino.h or WProgram.h
  8. // automatically includes it...
  9. #include <avr/pgmspace.h>
  10. #include <avr/interrupt.h>
  11. #include "avr_functions.h"
  12. #include "wiring.h"
  13. #include "HardwareSerial.h"
  14. #define DMAMEM __attribute__ ((section(".dmabuffers"), used))
  15. #define FASTRUN __attribute__ ((section(".fastrun"), noinline, noclone ))
  16. #ifdef __cplusplus
  17. #include "avr_emulation.h"
  18. #include "usb_serial.h"
  19. #include "usb_seremu.h"
  20. #include "usb_keyboard.h"
  21. #include "usb_mouse.h"
  22. #include "usb_joystick.h"
  23. #include "usb_midi.h"
  24. #include "usb_rawhid.h"
  25. #include "usb_flightsim.h"
  26. #include "usb_mtp.h"
  27. #include "usb_audio.h"
  28. #include "usb_touch.h"
  29. #include "usb_undef.h" // do not allow usb_desc.h stuff to leak to user programs
  30. #include "WCharacter.h"
  31. #include "WString.h"
  32. #include "elapsedMillis.h"
  33. #include "IntervalTimer.h"
  34. uint16_t makeWord(uint16_t w);
  35. uint16_t makeWord(byte h, byte l);
  36. #define word(...) makeWord(__VA_ARGS__)
  37. unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
  38. void tone(uint8_t pin, uint16_t frequency, uint32_t duration = 0);
  39. void noTone(uint8_t pin);
  40. // WMath prototypes
  41. int32_t random(void);
  42. uint32_t random(uint32_t howbig);
  43. int32_t random(int32_t howsmall, int32_t howbig);
  44. void randomSeed(uint32_t newseed);
  45. void srandom(uint32_t newseed);
  46. #include <type_traits>
  47. // when the input number is an integer type, do all math as 32 bit signed long
  48. template <class T, class A, class B, class C, class D>
  49. T map(T _x, A _in_min, B _in_max, C _out_min, D _out_max, typename std::enable_if<std::is_integral<T>::value >::type* = 0)
  50. {
  51. long x = _x, in_min = _in_min, in_max = _in_max, out_min = _out_min, out_max = _out_max;
  52. // Arduino's traditional algorithm
  53. //return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
  54. // st42's suggestion: https://github.com/arduino/Arduino/issues/2466#issuecomment-69873889
  55. if ((in_max - in_min) > (out_max - out_min)) {
  56. return (x - in_min) * (out_max - out_min+1) / (in_max - in_min+1) + out_min;
  57. } else {
  58. return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
  59. }
  60. }
  61. // when the input is a float or double, do all math using the input's type
  62. template <class T, class A, class B, class C, class D>
  63. T map(T x, A in_min, B in_max, C out_min, D out_max, typename std::enable_if<std::is_floating_point<T>::value >::type* = 0)
  64. {
  65. return (x - (T)in_min) * ((T)out_max - (T)out_min) / ((T)in_max - (T)in_min) + (T)out_min;
  66. }
  67. #include "pins_arduino.h"
  68. #endif // __cplusplus
  69. // Fast memcpy
  70. #if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)
  71. #ifdef __cplusplus
  72. extern "C" {
  73. extern void *memcpy (void *dst, const void *src, size_t count);
  74. }
  75. #else
  76. extern void *memcpy (void *dst, const void *src, size_t count);
  77. #endif
  78. #endif
  79. #endif // WProgram_h