Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: DISCO-L072CZ-LRWAN1_LoRa_PingPong DISCO-L072CZ-LRWAN1_LoRa_PingPong DISCO-L072CZ-LRWAN1_LoRa_PingPong DISCO-L072CZ-LRWAN1_LoRa_USB_Rx ... more
Fork of SX1276Lib by
Revision 69:d440a5b04708, committed 2017-07-21
- Comitter:
- Helmut Tschemernjak
- Date:
- Fri Jul 21 17:09:05 2017 +0200
- Parent:
- 68:66251038a897
- Child:
- 70:1d496aae2819
- Commit message:
- Added more support for Arduino D21
Added mode (push/pull) for InterruptIn
Added proper SPI support for Arduino
Changed in this revision
| sx1276/arduino-mbed.cpp | Show annotated file Show diff for this revision Revisions of this file |
| sx1276/arduino-mbed.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/sx1276/arduino-mbed.cpp Wed Jul 19 09:36:56 2017 +0200
+++ b/sx1276/arduino-mbed.cpp Fri Jul 21 17:09:05 2017 +0200
@@ -179,7 +179,7 @@
if (func) {
_func = func;
intPtrTable[_gpioPin].context = this;
- attachInterrupt(digitalPinToInterrupt(_gpioPin), intPtrTable[_gpioPin].func, RISING);
+ attachInterrupt(MYdigitalPinToInterrupt(_gpioPin), intPtrTable[_gpioPin].func, RISING);
} else {
_func = InterruptIn::donothing;
intPtrTable[_gpioPin].context = NULL;
@@ -192,7 +192,7 @@
if (func) {
_func = func;
intPtrTable[_gpioPin].context = this;
- attachInterrupt(digitalPinToInterrupt(_gpioPin), intPtrTable[_gpioPin].func, FALLING);
+ attachInterrupt(MYdigitalPinToInterrupt(_gpioPin), intPtrTable[_gpioPin].func, FALLING);
} else {
_func = InterruptIn::donothing;
intPtrTable[_gpioPin].context = NULL;
--- a/sx1276/arduino-mbed.h Wed Jul 19 09:36:56 2017 +0200
+++ b/sx1276/arduino-mbed.h Fri Jul 21 17:09:05 2017 +0200
@@ -22,6 +22,14 @@
#define NC -1
#define wait_ms delay
+
+#if ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606
+ #define MYdigitalPinToInterrupt(x) digitalPinToInterrupt(x)
+#else
+ #define MYdigitalPinToInterrupt(x) (x)
+#endif
+
+
enum PinMode {
PullUp = 1,
PullDown = 2,
@@ -125,8 +133,10 @@
_hz = 1000000;
_mode = SPI_MODE0;
_spi->beginTransaction(SPISettings(_hz, MSBFIRST, _mode));
+ }
+ ~XSPI() {
_spi->endTransaction();
- }
+ };
void format(int bits, int mode = 0) {
if (mode == 0)
@@ -140,19 +150,17 @@
else
_mode = SPI_MODE0;
_bits = bits;
+ _spi->endTransaction();
_spi->beginTransaction(SPISettings(_hz, MSBFIRST, _mode));
- _spi->endTransaction();
}
void frequency(int hz) {
_hz = hz;
+ _spi->endTransaction();
_spi->beginTransaction(SPISettings(_hz, MSBFIRST, _mode));
- _spi->endTransaction();
}
int write(int value) {
- _spi->beginTransaction(SPISettings(_hz, MSBFIRST, _mode));
int ret = _spi->transfer(value);
- _spi->endTransaction();
return ret;
}
@@ -176,7 +184,7 @@
}
~InterruptIn() {
- detachInterrupt(digitalPinToInterrupt(_gpioPin));
+ detachInterrupt(MYdigitalPinToInterrupt(_gpioPin));
};
static void _irq_handler(InterruptIn *id) {
@@ -188,6 +196,16 @@
void fall(Callback<void()> func);
+ void mode(PinMode pull) {
+ switch(pull) {
+ case PullUp:
+ pinMode(_gpioPin, INPUT_PULLUP);
+ break;
+ case PullDown:
+ pinMode(_gpioPin, INPUT_PULLDOWN);
+ break;
+ }
+ }
private:
int _gpioPin;
Callback<void()> _func;

