Fork of the espurna firmware for `mhsw` switches
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.

65 lines
1.9 KiB

  1. /*
  2. RFM69Wrap
  3. RFM69 by Felix Ruso (http://LowPowerLab.com/contact) wrapper for ESP8266
  4. Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. #include <RFM69.h>
  18. #include <RFM69_ATC.h>
  19. #include <SPI.h>
  20. class RFM69Wrap: public RFM69_ATC {
  21. public:
  22. RFM69Wrap(uint8_t slaveSelectPin=RF69_SPI_CS, uint8_t interruptPin=RF69_IRQ_PIN, bool isRFM69HW=false, uint8_t interruptNum=0):
  23. RFM69_ATC(slaveSelectPin, interruptPin, isRFM69HW, interruptNum) {};
  24. protected:
  25. // overriding SPI_CLOCK for ESP8266
  26. void select() {
  27. noInterrupts();
  28. #if defined (SPCR) && defined (SPSR)
  29. // save current SPI settings
  30. _SPCR = SPCR;
  31. _SPSR = SPSR;
  32. #endif
  33. // set RFM69 SPI settings
  34. SPI.setDataMode(SPI_MODE0);
  35. SPI.setBitOrder(MSBFIRST);
  36. #if defined(__arm__)
  37. SPI.setClockDivider(SPI_CLOCK_DIV16);
  38. #elif defined(ARDUINO_ARCH_ESP8266)
  39. SPI.setClockDivider(SPI_CLOCK_DIV2); // speeding it up for the ESP8266
  40. #else
  41. SPI.setClockDivider(SPI_CLOCK_DIV4);
  42. #endif
  43. digitalWrite(_slaveSelectPin, LOW);
  44. }
  45. };