|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#ifdef __cplusplus |
| 4 | +#include <cstdint> |
| 5 | +#include <cstddef> |
| 6 | +#include <stdlib.h> |
| 7 | +#else |
| 8 | +#include <stdint.h> |
| 9 | +#include <stddef.h> |
| 10 | +#include <stdlib.h> |
| 11 | +#endif |
| 12 | +#include <zephyr/drivers/gpio.h> |
| 13 | + |
| 14 | +#include "api/HardwareSerial.h" |
| 15 | +#include "arduino_types.h" |
| 16 | + |
| 17 | +#define lowByte(w) ((uint8_t) ((w) & 0xff)) |
| 18 | +#define highByte(w) ((uint8_t) ((w) >> 8)) |
| 19 | + |
| 20 | +#define bit(b) BIT(b) |
| 21 | +#define bitRead(value, bit) FIELD_GET(BIT(bit), value) |
| 22 | +#define bitSet(value, bit) ((value) |= BIT(bit)) |
| 23 | +#define bitClear(value, bit) ((value) &= ~BIT(bit)) |
| 24 | +#define bitToggle(value, bit) ((value) ^= BIT(bit)) |
| 25 | +#define bitWrite(value, bit, bitvalue) WRITE_BIT(value, bit, bitvalue) |
| 26 | + |
| 27 | + |
| 28 | +#ifdef __cplusplus |
| 29 | +extern "C" { |
| 30 | +#endif |
| 31 | + |
| 32 | +typedef gpio_port_pins_t pin_size_t; |
| 33 | + |
| 34 | +typedef void (*voidFuncPtr)(void); |
| 35 | +typedef void (*voidFuncPtrParam)(void*); |
| 36 | + |
| 37 | +void yield(void); |
| 38 | + |
| 39 | +void init(void); |
| 40 | +void initVariant(void); |
| 41 | + |
| 42 | +int main() __attribute__((weak)); |
| 43 | + |
| 44 | +void pinMode(pin_size_t pinNumber, PinMode pinMode); |
| 45 | +void digitalWrite(pin_size_t pinNumber, PinStatus status); |
| 46 | +PinStatus digitalRead(pin_size_t pinNumber); |
| 47 | +int analogRead(pin_size_t pinNumber); |
| 48 | +void analogReference(uint8_t mode); |
| 49 | +void analogWrite(pin_size_t pinNumber, int value); |
| 50 | + |
| 51 | +unsigned long millis(void); |
| 52 | +unsigned long micros(void); |
| 53 | +void delay(unsigned long); |
| 54 | +void delayMicroseconds(unsigned int us); |
| 55 | +unsigned long pulseIn(pin_size_t pin, uint8_t state, unsigned long timeout); |
| 56 | +unsigned long pulseInLong(pin_size_t pin, uint8_t state, unsigned long timeout); |
| 57 | + |
| 58 | +void shiftOut(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder, uint8_t val); |
| 59 | +uint8_t shiftIn(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder); |
| 60 | + |
| 61 | +void attachInterrupt(pin_size_t interruptNumber, voidFuncPtr callback, PinStatus mode); |
| 62 | +void attachInterruptParam(pin_size_t interruptNumber, voidFuncPtrParam callback, PinStatus mode, void* param); |
| 63 | +void detachInterrupt(pin_size_t interruptNumber); |
| 64 | + |
| 65 | +void setup(void); |
| 66 | +void loop(void); |
| 67 | + |
| 68 | +#ifdef __cplusplus |
| 69 | +} // extern "C" |
| 70 | +#endif |
| 71 | + |
| 72 | +unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); |
| 73 | +unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); |
| 74 | + |
| 75 | +void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); |
| 76 | +void noTone(uint8_t _pin); |
| 77 | + |
| 78 | +// WMath prototypes |
| 79 | +long random(long); |
| 80 | +long random(long, long); |
| 81 | +void randomSeed(unsigned long); |
| 82 | + |
| 83 | + |
| 84 | +extern "C" { |
| 85 | + int32_t map_i32(int32_t x, int32_t in_min, int32_t in_max, int32_t out_min, int32_t out_max); |
| 86 | + uint16_t makeWord_w(uint16_t w); |
| 87 | + uint16_t makeWord_hl(uint8_t h, uint8_t l); |
| 88 | +} |
| 89 | + |
| 90 | +inline long map(long x, long in_min, long in_max, long out_min, long out_max) |
| 91 | +{ |
| 92 | + return map_i32(x, in_min, in_max, out_min, out_max); |
| 93 | +} |
| 94 | + |
| 95 | +inline uint16_t makeWord(uint16_t w) { |
| 96 | + return makeWord_w(w); |
| 97 | +} |
| 98 | + |
| 99 | +inline uint16_t makeWord(uint8_t h, uint8_t l) { |
| 100 | + return makeWord_hl(h, l); |
| 101 | +} |
| 102 | + |
| 103 | +#define word(...) makeWord(__VA_ARGS__) |
| 104 | + |
| 105 | +#ifdef __cplusplus |
| 106 | + template<class T, class L> |
| 107 | + auto min(const T& a, const L& b) -> decltype((b < a) ? b : a) |
| 108 | + { |
| 109 | + return (b < a) ? b : a; |
| 110 | + } |
| 111 | + |
| 112 | + template<class T, class L> |
| 113 | + auto max(const T& a, const L& b) -> decltype((b < a) ? b : a) |
| 114 | + { |
| 115 | + return (a < b) ? b : a; |
| 116 | + } |
| 117 | +#else |
| 118 | +#ifndef min |
| 119 | +#define min(a,b) \ |
| 120 | + ({ __typeof__ (a) _a = (a); \ |
| 121 | + __typeof__ (b) _b = (b); \ |
| 122 | + _a < _b ? _a : _b; }) |
| 123 | +#endif |
| 124 | +#ifndef max |
| 125 | +#define max(a,b) \ |
| 126 | + ({ __typeof__ (a) _a = (a); \ |
| 127 | + __typeof__ (b) _b = (b); \ |
| 128 | + _a > _b ? _a : _b; }) |
| 129 | +#endif |
| 130 | +#endif |
0 commit comments