|
| 1 | +/* |
| 2 | +Copyright (c) 2020 SparkFun Electronics |
| 3 | +
|
| 4 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | +of this software and associated documentation files (the "Software"), to deal |
| 6 | +in the Software without restriction, including without limitation the rights |
| 7 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | +copies of the Software, and to permit persons to whom the Software is |
| 9 | +furnished to do so, subject to the following conditions: |
| 10 | +
|
| 11 | +The above copyright notice and this permission notice shall be included in all |
| 12 | +copies or substantial portions of the Software. |
| 13 | +
|
| 14 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 | +SOFTWARE. |
| 21 | +*/ |
| 22 | + |
| 23 | +#ifndef _ARDUINO_MBED_BRIDGE_CORE_EXTEND_COMMON_H_ |
| 24 | +#define _ARDUINO_MBED_BRIDGE_CORE_EXTEND_COMMON_H_ |
| 25 | + |
| 26 | +#include "mbed.h" |
| 27 | + |
| 28 | +#define PinMode Arduino_PinMode // note: this changes the Arduino API for mbed compatibility - use Arduino_PinMode where PinMode was specified in the Arduino API |
| 29 | +#include "core-api/api/Common.h" |
| 30 | +#undef PinMode |
| 31 | + |
| 32 | +void indexPinMode(pin_size_t index, Arduino_PinMode pinMode); |
| 33 | +void pinMode(PinName pinName, Arduino_PinMode pinMode); |
| 34 | + |
| 35 | +void indexDigitalWrite(pin_size_t index, PinStatus val); |
| 36 | +void digitalWrite(PinName pinName, PinStatus val); |
| 37 | + |
| 38 | +PinStatus indexDigitalRead(pin_size_t index); |
| 39 | +PinStatus digitalRead(PinName pinName); |
| 40 | + |
| 41 | +int indexAnalogRead(pin_size_t index); |
| 42 | +int analogRead(PinName pinName); |
| 43 | + |
| 44 | +void indexAnalogWriteDAC(pin_size_t index, int val); |
| 45 | +void analogWriteDAC(PinName pinName, int val); |
| 46 | +void analogWriteDAC(pin_size_t pinNumber, int val); |
| 47 | + |
| 48 | +void indexAnalogWrite(pin_size_t index, int val); |
| 49 | +void analogWrite(PinName pinName, int val); |
| 50 | + |
| 51 | +void indexShiftOut(pin_size_t data_index, pin_size_t clock_index, BitOrder bitOrder, uint8_t val); |
| 52 | +void shiftOut(PinName dataPinName, PinName clockPinName, BitOrder bitOrder, uint8_t val); |
| 53 | + |
| 54 | +pin_size_t indexShiftIn(pin_size_t data_index, pin_size_t clock_index, BitOrder bitOrder); |
| 55 | +pin_size_t shiftIn(PinName dataPinName, PinName clockPinName, BitOrder bitOrder); |
| 56 | + |
| 57 | +void indexAttachInterrupt(pin_size_t index, voidFuncPtr callback, PinStatus mode); |
| 58 | +void attachInterrupt(PinName pinName, voidFuncPtr callback, PinStatus mode); |
| 59 | + |
| 60 | +void indexAttachInterruptParam(pin_size_t index, voidFuncPtrParam callback, PinStatus mode, void* param); |
| 61 | +void attachInterruptParam(PinName pinName, voidFuncPtrParam callback, PinStatus mode, void* param); |
| 62 | + |
| 63 | +void indexDetachInterrupt(pin_size_t index); |
| 64 | +void detachInterrupt(PinName pinName); |
| 65 | + |
| 66 | +#ifdef __cplusplus |
| 67 | + |
| 68 | +void indexTone(pin_size_t index, unsigned int frequency, unsigned long duration = 0); |
| 69 | +unsigned long indexPulseIn(pin_size_t index, uint8_t state, unsigned long timeout = 1000000L); |
| 70 | +unsigned long pulseIn(PinName pinName, uint8_t state, unsigned long timeout = 1000000L); |
| 71 | +unsigned long indexPulseInLong(pin_size_t index, uint8_t state, unsigned long timeout = 1000000L); |
| 72 | +unsigned long pulseInLong(PinName pinName, uint8_t state, unsigned long timeout = 1000000L); |
| 73 | + |
| 74 | +#if DEVICE_INTERRUPTIN |
| 75 | + |
| 76 | +namespace arduino { |
| 77 | + |
| 78 | +class InterruptInParam : public mbed::InterruptIn { |
| 79 | +private: |
| 80 | +protected: |
| 81 | +public: |
| 82 | + /** Create an InterruptIn connected to the specified pin |
| 83 | + * |
| 84 | + * @param pin InterruptIn pin to connect to |
| 85 | + */ |
| 86 | + InterruptInParam(PinName pin); |
| 87 | + |
| 88 | + /** Create an InterruptIn connected to the specified pin, |
| 89 | + * and the pin configured to the specified mode. |
| 90 | + * |
| 91 | + * @param pin InterruptIn pin to connect to |
| 92 | + * @param mode Desired Pin mode configuration. |
| 93 | + * (Valid values could be PullNone, PullDown, PullUp and PullDefault. |
| 94 | + * See PinNames.h for your target for definitions) |
| 95 | + * |
| 96 | + */ |
| 97 | + InterruptInParam(PinName pin, PinMode mode); |
| 98 | + |
| 99 | + virtual ~InterruptInParam(); |
| 100 | + |
| 101 | + /** Attach a function to call when a rising edge occurs on the input |
| 102 | + * |
| 103 | + * @param func A pointer to a void function with argument, or 0 to set as none |
| 104 | + */ |
| 105 | + void rise(Callback<void(void*)> func, void* param); |
| 106 | + |
| 107 | + /** Attach a function to call when a rising edge occurs on the input |
| 108 | + * |
| 109 | + * @param func A pointer to a void function, or 0 to set as none |
| 110 | + */ |
| 111 | + void rise(Callback<void()> func); // shadows InterruptIn::rise |
| 112 | + |
| 113 | + /** Attach a function to call when a falling edge occurs on the input |
| 114 | + * |
| 115 | + * @param func A pointer to a void function with argument, or 0 to set as none |
| 116 | + */ |
| 117 | + void fall(Callback<void(void*)> func, void* param); |
| 118 | + |
| 119 | + /** Attach a function to call when a falling edge occurs on the input |
| 120 | + * |
| 121 | + * @param func A pointer to a void function, or 0 to set as none |
| 122 | + */ |
| 123 | + void fall(Callback<void()> func); // shadows InterruptIn::fall |
| 124 | + |
| 125 | + static void _irq_handler(uint32_t id, gpio_irq_event event); |
| 126 | + |
| 127 | +protected: |
| 128 | + Callback<void(void*)> _rise; // shadows InterruptIn::_rise |
| 129 | + Callback<void(void*)> _fall; // shadows InterruptIn::_fall |
| 130 | + |
| 131 | + void* _rise_param = nullptr; |
| 132 | + void* _fall_param = nullptr; |
| 133 | + |
| 134 | + void irq_init(PinName pin); // shadows InterruptIn::irq_init |
| 135 | +}; |
| 136 | + |
| 137 | +} // namespace arduio |
| 138 | + |
| 139 | +#endif //DEVICE_INTERRUPTIN |
| 140 | + |
| 141 | +#endif // __cplusplus |
| 142 | + |
| 143 | +#endif // _ARDUINO_MBED_BRIDGE_CORE_EXTEND_COMMON_H_ |
0 commit comments