Fix variable names, minor updates (#1071)

This commit is contained in:
tekka
2018-02-19 13:26:14 +01:00
committed by GitHub
parent a0af38a0d8
commit 345d6d7d11
7 changed files with 83 additions and 128 deletions
+20 -17
View File
@@ -6,7 +6,7 @@
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2017 Sensnology AB
* Copyright (C) 2013-2018 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
@@ -36,9 +36,10 @@ LOCAL uint8_t RF24_NODE_ADDRESS = RF24_BROADCAST_ADDRESS;
LOCAL RF24_receiveCallbackType RF24_receiveCallback = NULL;
#endif
#ifdef LINUX_SPI_BCM
uint8_t spi_rxbuff[32+1] ; //SPI receive buffer (payload max 32 bytes)
uint8_t spi_txbuff[32+1] ; //SPI transmit buffer (payload max 32 bytes + 1 byte for the command)
#if defined(LINUX_SPI_BCM)
uint8_t RF24_spi_rxbuff[32+1] ; //SPI receive buffer (payload max 32 bytes)
uint8_t RF24_spi_txbuff[32+1]
; //SPI transmit buffer (payload max 32 bytes + 1 byte for the command)
#endif
LOCAL void RF24_csn(const bool level)
@@ -51,21 +52,22 @@ LOCAL void RF24_ce(const bool level)
hwDigitalWrite(MY_RF24_CE_PIN, level);
}
LOCAL uint8_t RF24_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, uint8_t len,
LOCAL uint8_t RF24_spiMultiByteTransfer(const uint8_t cmd, uint8_t *buf, uint8_t len,
const bool readMode)
{
uint8_t status;
uint8_t* current = buf;
uint8_t *current = buf;
#if !defined(MY_SOFTSPI) && defined(SPI_HAS_TRANSACTION)
RF24_SPI.beginTransaction(SPISettings(MY_RF24_SPI_SPEED, RF24_SPI_DATA_ORDER,
RF24_SPI_DATA_MODE));
#endif
RF24_csn(LOW);
// timing
delayMicroseconds(10);
#ifdef LINUX_SPI_BCM
uint8_t * prx = spi_rxbuff;
uint8_t * ptx = spi_txbuff;
uint8_t *prx = RF24_spi_rxbuff;
uint8_t *ptx = RF24_spi_txbuff;
uint8_t size = len + 1; // Add register value to transmit buffer
*ptx++ = cmd;
@@ -76,7 +78,7 @@ LOCAL uint8_t RF24_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, uint8_t
*ptx++ = *current++;
}
}
RF24_SPI.transfernb( (char *) spi_txbuff, (char *) spi_rxbuff, size);
RF24_SPI.transfernb( (char *) RF24_spi_txbuff, (char *) RF24_spi_rxbuff, size);
if (readMode) {
if (size == 2) {
status = *++prx; // result is 2nd byte of receive buffer
@@ -103,6 +105,7 @@ LOCAL uint8_t RF24_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, uint8_t
}
}
#endif
RF24_csn(HIGH);
#if !defined(MY_SOFTSPI) && defined(SPI_HAS_TRANSACTION)
RF24_SPI.endTransaction();
@@ -198,7 +201,7 @@ LOCAL void RF24_setRFConfiguration(const uint8_t configuration)
RF24_writeByteRegister(RF24_REG_NRF_CONFIG, configuration);
}
LOCAL void RF24_setPipeAddress(const uint8_t pipe, uint8_t* address, const uint8_t addressWidth)
LOCAL void RF24_setPipeAddress(const uint8_t pipe, uint8_t *address, const uint8_t addressWidth)
{
RF24_writeMultiByteRegister(pipe, address, addressWidth);
}
@@ -283,7 +286,7 @@ LOCAL void RF24_standBy(void)
}
LOCAL bool RF24_sendMessage(const uint8_t recipient, const void* buf, const uint8_t len,
LOCAL bool RF24_sendMessage(const uint8_t recipient, const void *buf, const uint8_t len,
const bool noACK)
{
uint8_t RF24_status;
@@ -296,7 +299,7 @@ LOCAL bool RF24_sendMessage(const uint8_t recipient, const void* buf, const uint
// AutoACK is disabled on the broadcasting pipe - NO_ACK prevents resending
RF24_spiMultiByteTransfer((recipient == RF24_BROADCAST_ADDRESS ||
noACK) ? RF24_CMD_WRITE_TX_PAYLOAD_NO_ACK :
RF24_CMD_WRITE_TX_PAYLOAD, (uint8_t*)buf, len, false );
RF24_CMD_WRITE_TX_PAYLOAD, (uint8_t *)buf, len, false );
// go, TX starts after ~10us, CE high also enables PA+LNA on supported HW
RF24_ce(HIGH);
// timeout counter to detect HW issues
@@ -337,11 +340,11 @@ LOCAL bool RF24_isDataAvailable(void)
}
LOCAL uint8_t RF24_readMessage(void* buf)
LOCAL uint8_t RF24_readMessage(void *buf)
{
const uint8_t len = RF24_getDynamicPayloadSize();
RF24_DEBUG(PSTR("RF24:RXM:LEN=%" PRIu8 "\n"), len); // read message
RF24_spiMultiByteTransfer(RF24_CMD_READ_RX_PAYLOAD,(uint8_t*)buf,len,true);
RF24_spiMultiByteTransfer(RF24_CMD_READ_RX_PAYLOAD,(uint8_t *)buf,len,true);
// clear RX interrupt
RF24_setStatus(_BV(RF24_RX_DR));
return len;
@@ -500,11 +503,11 @@ LOCAL bool RF24_initialize(void)
RF24_setDynamicPayload(_BV(RF24_DPL_P0 + RF24_BROADCAST_PIPE) | _BV(RF24_DPL_P0));
// listen to broadcast pipe
RF24_BASE_ID[0] = RF24_BROADCAST_ADDRESS;
RF24_setPipeAddress(RF24_REG_RX_ADDR_P0 + RF24_BROADCAST_PIPE, (uint8_t*)&RF24_BASE_ID,
RF24_setPipeAddress(RF24_REG_RX_ADDR_P0 + RF24_BROADCAST_PIPE, (uint8_t *)&RF24_BASE_ID,
RF24_BROADCAST_PIPE > 1 ? 1 : MY_RF24_ADDR_WIDTH);
// pipe 0, set full address, later only LSB is updated
RF24_setPipeAddress(RF24_REG_RX_ADDR_P0, (uint8_t*)&RF24_BASE_ID, MY_RF24_ADDR_WIDTH);
RF24_setPipeAddress(RF24_REG_TX_ADDR, (uint8_t*)&RF24_BASE_ID, MY_RF24_ADDR_WIDTH);
RF24_setPipeAddress(RF24_REG_RX_ADDR_P0, (uint8_t *)&RF24_BASE_ID, MY_RF24_ADDR_WIDTH);
RF24_setPipeAddress(RF24_REG_TX_ADDR, (uint8_t *)&RF24_BASE_ID, MY_RF24_ADDR_WIDTH);
// reset FIFO
RF24_flushRX();
RF24_flushTX();