PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 satır
5.0KB

  1. // ArduinoCompat/wirish.h
  2. #ifndef _wirish_h
  3. #define _wirish_h
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <stdint.h>
  8. #include <stm32f4xx_rng.h>
  9. #define PROGMEM
  10. #define memcpy_P memcpy
  11. typedef enum WiringPinMode {
  12. OUTPUT, /**< Basic digital output: when the pin is HIGH, the
  13. voltage is held at +3.3v (Vcc) and when it is LOW, it
  14. is pulled down to ground. */
  15. OUTPUT_OPEN_DRAIN, /**< In open drain mode, the pin indicates
  16. "low" by accepting current flow to ground
  17. and "high" by providing increased
  18. impedance. An example use would be to
  19. connect a pin to a bus line (which is pulled
  20. up to a positive voltage by a separate
  21. supply through a large resistor). When the
  22. pin is high, not much current flows through
  23. to ground and the line stays at positive
  24. voltage; when the pin is low, the bus
  25. "drains" to ground with a small amount of
  26. current constantly flowing through the large
  27. resistor from the external supply. In this
  28. mode, no current is ever actually sourced
  29. from the pin. */
  30. INPUT, /**< Basic digital input. The pin voltage is sampled; when
  31. it is closer to 3.3v (Vcc) the pin status is high, and
  32. when it is closer to 0v (ground) it is low. If no
  33. external circuit is pulling the pin voltage to high or
  34. low, it will tend to randomly oscillate and be very
  35. sensitive to noise (e.g., a breath of air across the pin
  36. might cause the state to flip). */
  37. INPUT_ANALOG, /**< This is a special mode for when the pin will be
  38. used for analog (not digital) reads. Enables ADC
  39. conversion to be performed on the voltage at the
  40. pin. */
  41. INPUT_PULLUP, /**< The state of the pin in this mode is reported
  42. the same way as with INPUT, but the pin voltage
  43. is gently "pulled up" towards +3.3v. This means
  44. the state will be high unless an external device
  45. is specifically pulling the pin down to ground,
  46. in which case the "gentle" pull up will not
  47. affect the state of the input. */
  48. INPUT_PULLDOWN, /**< The state of the pin in this mode is reported
  49. the same way as with INPUT, but the pin voltage
  50. is gently "pulled down" towards 0v. This means
  51. the state will be low unless an external device
  52. is specifically pulling the pin up to 3.3v, in
  53. which case the "gentle" pull down will not
  54. affect the state of the input. */
  55. INPUT_FLOATING, /**< Synonym for INPUT. */
  56. PWM, /**< This is a special mode for when the pin will be used for
  57. PWM output (a special case of digital output). */
  58. PWM_OPEN_DRAIN, /**< Like PWM, except that instead of alternating
  59. cycles of LOW and HIGH, the voltage on the pin
  60. consists of alternating cycles of LOW and
  61. floating (disconnected). */
  62. } WiringPinMode;
  63. extern void pinMode(uint8_t pin, WiringPinMode mode);
  64. extern uint32_t millis();
  65. extern void delay(uint32_t millis);
  66. extern void attachInterrupt(uint8_t, void (*)(void), int mode);
  67. extern void digitalWrite(uint8_t pin, uint8_t val);
  68. extern uint8_t digitalRead(uint8_t pin);
  69. //extern long random(long to);
  70. //extern long random(long from, long to);
  71. #define HIGH 0x1
  72. #define LOW 0x0
  73. #define LSBFIRST 0
  74. #define MSBFIRST 1
  75. #define CHANGE 1
  76. #define FALLING 2
  77. #define RISING 3
  78. // Equivalent to HardwareSerial in Arduino
  79. class SerialUSBClass
  80. {
  81. public:
  82. #define DEC 10
  83. #define HEX 16
  84. #define OCT 8
  85. #define BIN 2
  86. // TODO: move these from being inlined
  87. void begin(int baud) {}
  88. size_t println(const char* s)
  89. {
  90. print(s);
  91. printf("\n");
  92. return 0;
  93. }
  94. size_t print(const char* s)
  95. {
  96. printf(s);
  97. return 0;
  98. }
  99. size_t print(unsigned int n, int base = DEC)
  100. {
  101. if (base == DEC)
  102. printf("%d", n);
  103. else if (base == HEX)
  104. printf("%02x", n);
  105. else if (base == OCT)
  106. printf("%o", n);
  107. // TODO: BIN
  108. return 0;
  109. }
  110. size_t print(char ch)
  111. {
  112. printf("%c", ch);
  113. return 0;
  114. }
  115. size_t println(char ch)
  116. {
  117. printf("%c\n", ch);
  118. return 0;
  119. }
  120. size_t print(unsigned char ch, int base = DEC)
  121. {
  122. return print((unsigned int)ch, base);
  123. }
  124. size_t println(unsigned char ch, int base = DEC)
  125. {
  126. print((unsigned int)ch, base);
  127. printf("\n");
  128. return 0;
  129. }
  130. };
  131. // Global instance of the Serial output
  132. extern SerialUSBClass SerialUSB;
  133. #endif