2424#include < stdint.h>
2525#include < stdlib.h>
2626#include < string.h>
27- // Wacky deprecated AVR compatibility functions
28- #include " stdlib_noniso.h"
29-
27+ #include " stdlib_noniso.h" // Wacky deprecated AVR compatibility functions
3028#include " api/ArduinoAPI.h"
29+ #include " api/itoa.h" // ARM toolchain doesn't provide itoa etc, provide them
3130#include < pins_arduino.h>
32-
33-
34- // Required for the port*Register macros
35- #include " hardware/gpio.h"
36-
31+ #include " hardware/gpio.h" // Required for the port*Register macros
3732#include " debug_internal.h"
3833
3934// Try and make the best of the old Arduino abs() macro. When in C++, use
4439#endif // abs
4540#ifdef __cplusplus
4641using std::abs;
42+ using std::round;
4743#else
48- #define abs (x ) ((x)>0 ?(x):-(x))
44+ #define abs (x ) ({ __typeof__ (x) _x = (x); _x >= 0 ? _x : -_x; })
45+ #define round (x ) ({ __typeof__ (x) _x = (x); _x >= 0 ? (long )(_x + 0.5 ) : (long )(_x - 0.5 ); })
4946#endif
5047
5148#ifdef __cplusplus
@@ -61,10 +58,6 @@ extern "C" {
6158void interrupts();
6259void noInterrupts ();
6360
64- // GPIO change/value interrupts
65- void attachInterrupt (pin_size_t pin, voidFuncPtr callback, PinStatus mode);
66- void detachInterrupt (pin_size_t pin);
67-
6861// AVR compatibility macros...naughty and accesses the HW directly
6962#define digitalPinToPort (pin ) (0 )
7063#define digitalPinToBitMask (pin ) (1UL << (pin))
@@ -75,28 +68,14 @@ void detachInterrupt(pin_size_t pin);
7568#define portInputRegister (port ) ((volatile uint32_t *) sio_hw->gpio_in)
7669#define portModeRegister (port ) ((volatile uint32_t *) sio_hw->gpio_oe)
7770
78- // IO config
79- void pinMode (pin_size_t pinNumber, PinMode pinMode);
80-
81- // SIO (GPIO)
82- void digitalWrite (pin_size_t pinNumber, PinStatus status);
83- PinStatus digitalRead (pin_size_t pinNumber);
84-
85- // ADC
86- int analogRead (pin_size_t pinNumber);
71+ // ADC RP2040-specific calls
8772float analogReadTemp (); // Returns core temp in Centigrade
8873
89- // PWM
90- void analogWrite (pin_size_t pinNumber, int value);
74+ // PWM RP2040-specific calls
9175void analogWriteFreq (uint32_t freq);
9276void analogWriteRange (uint32_t range);
9377void analogWriteResolution (int res);
9478
95- // Timing
96- void delay (unsigned long );
97- void delayMicroseconds (unsigned int us);
98- unsigned long millis ();
99-
10079#ifdef __cplusplus
10180} // extern "C"
10281#endif
@@ -127,8 +106,4 @@ constexpr uint32_t __bitset(const int (&a)[N], size_t i = 0U) {
127106}
128107#endif
129108
130-
131- // ARM toolchain doesn't provide itoa etc, provide them
132- #include " api/itoa.h"
133-
134109#endif // Arduino_h
0 commit comments