Linux: Add support for RFM69 (#823)

This commit is contained in:
Marcelo Aquino
2017-04-19 22:40:21 +02:00
committed by Henrik Ekblad
parent 4c31e22d6f
commit 66ff5b2880
5 changed files with 44 additions and 16 deletions
+1 -1
View File
@@ -292,7 +292,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
// RAM ROUTING TABLE
#if defined(MY_RAM_ROUTING_TABLE_FEATURE) && defined(MY_REPEATER_FEATURE)
// activate feature based on architecture
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_SAMD) || defined(LINUX_ARCH_RASPBERRYPI) || defined(__linux__)
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_SAMD) || defined(__linux__)
#define MY_RAM_ROUTING_TABLE_ENABLED
#elif defined(ARDUINO_ARCH_AVR)
#if defined(__avr_atmega1280__) || defined(__avr_atmega1284__) || defined(__avr_atmega2560__)
Vendored
+32 -9
View File
@@ -24,7 +24,7 @@ Building options:
--extra-cxxflags=<CXXFLAGS> Extra C++ flags passed to C++ compilation. []
--extra-ldflags=<LDFLAGS> Extra C flags passed to linking. []
--c_compiler=<CC> C compiler. [arm-linux-gnueabihf-gcc][gcc]
--cxx_compiler=<CXX> C++ compiler [arm-linux-gnueabihf-g++][g++]
--cxx_compiler=<CXX> C++ compiler. [arm-linux-gnueabihf-g++][g++]
--build-dir=<DIR> Compiler directory to store object files. [build]
--bin-dir=<DIR> Compiler directory to store binary files. [bin]
--arduino-lib-dir=<DIR> Arduino library directory.
@@ -61,10 +61,10 @@ MySensors options:
MQTT publish topic prefix.
--my-mqtt-subscribe-topic-prefix=<PREFIX>
MQTT subscribe topic prefix.
--my-transport=[none|nrf24|rs485|rfm95]
--my-transport=[none|nrf24|rs485|rfm95|rfm69]
Set the transport to be used to communicate with other nodes.
[nrf24]
--my-rf24-channel=<0-125> RF channel for the sensor net, 0-125. [76]
--my-rf24-channel=<0-125> RF channel for the sensor net. [76]
--my-rf24-pa-level=[RF24_PA_MAX|RF24_PA_LOW]
RF24 PA level. [RF24_PA_MAX]
--my-rf24-ce-pin=<PIN> Pin number to use for rf24 Chip-Enable.
@@ -76,8 +76,12 @@ MySensors options:
personalized with the same AES key
--my-rx-message-buffer-size=<SIZE>
Buffer size for incoming messages when using rf24 interrupts. [20]
--my-rf69-irq-pin=<PIN> Pin number connected to RFM69 IRQ pin.
--my-rs485-serial-port=<PORT>
--my-rfm69-frequency=[315|433|868|915]
RFM69 Module Frequency. [868]
--my-is-rfm69hw Enable high-powered rfm69hw.
--my-rfm69-irq-pin=<PIN> Pin number connected to RFM69 IRQ pin.
--my-rfm69-cs-pin=<PIN> Pin number to use for RFM69 Chip-Select.
--my-rs485-serial-port=<PORT>
RS485 serial port. You must provide a port.
--my-rs485-baudrate=<BAUD> RS485 baudrate. [9600]
--my-rs485-de-pin=<PIN> Pin number connected to RS485 driver enable pin.
@@ -400,9 +404,28 @@ for opt do
--my-rx-message-buffer-size=*)
CPPFLAGS="-DMY_RX_MESSAGE_BUFFER_SIZE=${optarg} $CPPFLAGS"
;;
--my-rf69-irq-pin=*)
CPPFLAGS="-DMY_RF69_IRQ_PIN=${optarg} $CPPFLAGS"
;;
--my-rfm69-frequency=*)
if [[ ${optarg} == "315" ]]; then
CPPFLAGS="-DMY_RFM69_FREQUENCY=RFM69_315MHZ $CPPFLAGS"
elif [[ ${optarg} == "433" ]]; then
CPPFLAGS="-DMY_RFM69_FREQUENCY=RFM69_433MHZ $CPPFLAGS"
elif [[ ${optarg} == "868" ]]; then
CPPFLAGS="-DMY_RFM69_FREQUENCY=RFM69_868MHZ $CPPFLAGS"
elif [[ ${optarg} == "915" ]]; then
CPPFLAGS="-DMY_RFM69_FREQUENCY=RFM69_915MHZ $CPPFLAGS"
else
echo "[WARNING] Illegal value for --my-rfm69-frequency=${optarg}, ignored"
fi
;;
--my-is-rfm69hw*)
CPPFLAGS="-DMY_IS_RFM69HW $CPPFLAGS"
;;
--my-rfm69-irq-pin=*)
CPPFLAGS="-DMY_RFM69_IRQ_PIN=${optarg} $CPPFLAGS"
;;
--my-rfm69-cs-pin=*)
CPPFLAGS="-DMY_RFM69_CS_PIN=${optarg} $CPPFLAGS"
;;
--my-rs485-serial-port=*)
CPPFLAGS="-DMY_RS485_HWSERIAL=\\\"${optarg}\\\" $CPPFLAGS"
;;
@@ -527,7 +550,7 @@ if [[ ${transport_type} == "none" ]]; then
elif [[ ${transport_type} == "nrf24" ]]; then
CPPFLAGS="-DMY_RADIO_NRF24 $CPPFLAGS"
elif [[ ${transport_type} == "rfm69" ]]; then
CPPFLAGS="-DMY_RADIO_RFM69 $CPPFLAGS"
CPPFLAGS="-DMY_RADIO_RFM69 -DMY_RFM69_NEW_DRIVER $CPPFLAGS"
elif [[ ${transport_type} == "rs485" ]]; then
CPPFLAGS="-DMY_RS485 $CPPFLAGS"
elif [[ ${transport_type} == "rfm95" ]]; then
+2
View File
@@ -33,6 +33,7 @@
#define SPI_CLOCK_BASE 16000000 // 16Mhz
#define SPI_CLOCK_DIV1 1
#define SPI_CLOCK_DIV2 2
#define SPI_CLOCK_DIV4 4
#define SPI_CLOCK_DIV8 8
@@ -40,6 +41,7 @@
#define SPI_CLOCK_DIV32 32
#define SPI_CLOCK_DIV64 64
#define SPI_CLOCK_DIV128 128
#define SPI_CLOCK_DIV256 256
// SPI Data mode
#define SPI_MODE0 SPI_MODE_0
+6 -5
View File
@@ -52,7 +52,7 @@ uint8_t _SPCR; //!< _SPCR
uint8_t _SPSR; //!< _SPSR
#endif
#ifdef LINUX_ARCH_RASPBERRYPI
#ifdef LINUX_SPI_BCM
// SPI RX and TX buffers (max packet len + 1 byte for the command)
uint8_t spi_rxbuff[RFM69_MAX_PACKET_LEN + 1];
uint8_t spi_txbuff[RFM69_MAX_PACKET_LEN + 1];
@@ -115,7 +115,7 @@ LOCAL uint8_t RFM69_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, uint8_
RFM69_prepareSPITransaction();
RFM69_csn(LOW);
#ifdef LINUX_ARCH_RASPBERRYPI
#ifdef LINUX_SPI_BCM
uint8_t * prx = spi_rxbuff;
uint8_t * ptx = spi_txbuff;
uint8_t size = len + 1; // Add register value to transmit buffer
@@ -274,7 +274,7 @@ LOCAL void RFM69_interruptHandler(void)
RFM69_prepareSPITransaction();
RFM69_csn(LOW);
#ifdef LINUX_ARCH_RASPBERRYPI
#ifdef LINUX_SPI_BCM
char data[RFM69_MAX_PACKET_LEN + 1]; // max packet len + 1 byte for the command
data[0] = RFM69_REG_FIFO & RFM69_READ_REGISTER;
@@ -357,7 +357,8 @@ LOCAL uint8_t RFM69_recv(uint8_t* buf, const uint8_t maxBufSize)
// atomic
noInterrupts();
const uint8_t payloadLen = min(RFM69.currentPacket.payloadLen, maxBufSize);
const uint8_t payloadLen = RFM69.currentPacket.payloadLen < maxBufSize?
RFM69.currentPacket.payloadLen : maxBufSize;
const uint8_t sender = RFM69.currentPacket.header.sender;
const rfm69_sequenceNumber_t sequenceNumber = RFM69.currentPacket.header.sequenceNumber;
const uint8_t controlFlags = RFM69.currentPacket.header.controlFlags;
@@ -734,7 +735,7 @@ LOCAL int16_t RFM69_getReceivingRSSI(void)
LOCAL bool RFM69_setTxPowerPercent(uint8_t newPowerPercent)
{
newPowerPercent = min(newPowerPercent, 100); // limit
newPowerPercent = min(newPowerPercent, (uint8_t)100); // limit
const rfm69_powerlevel_t newPowerLevel = static_cast<rfm69_powerlevel_t>
(RFM69_MIN_POWER_LEVEL_DBM + (RFM69_MAX_POWER_LEVEL_DBM
- RFM69_MIN_POWER_LEVEL_DBM) * (newPowerPercent / 100.0f));
+3 -1
View File
@@ -105,6 +105,8 @@ void transportSetTargetRSSI(int16_t targetSignalStrength)
{
#if !defined(MY_GATEWAY_FEATURE) && !defined(MY_RFM69_ATC_MODE_DISABLED)
RFM69_ATCmode(true, targetSignalStrength);
#else
(void)targetSignalStrength;
#endif
}
@@ -203,7 +205,7 @@ bool transportSanityCheck(void)
uint8_t transportReceive(void* data)
{
// save payload length
const uint8_t dataLen = min(MAX_MESSAGE_LENGTH,_radio.DATALEN);
const uint8_t dataLen = _radio.DATALEN < MAX_MESSAGE_LENGTH? _radio.DATALEN : MAX_MESSAGE_LENGTH;
(void)memcpy((void*)data, (void*)_radio.DATA, dataLen);
// Send ack back if this message wasn't a broadcast
if (_radio.ACKRequested()) {