Unverified Commit 701edffe authored by Brendan's avatar Brendan Committed by GitHub

all single line loops and conditions use curly brackets (#855)

* all single line loops and conditions use curly brackets

also noticed a missing space in doc comment

* change clang-format config

* arduino CI runs on opening PR when lib src changes

* make sure sprintf_P is only defined for Linux

* declare sprintf_P for picoSDK

* use platform config to include stdio,not RF24.cpp
parent 3f786bff
......@@ -14,13 +14,13 @@ AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Always
AllowShortEnumsOnASingleLine: false
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLoopsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
......
......@@ -7,6 +7,7 @@ on:
- ".github/workflows/build_arduino.yml"
- "examples/**"
- "!examples/old_backups/**"
- "RF24.*"
push:
paths:
- ".github/workflows/build_arduino.yml"
......
......@@ -9,7 +9,6 @@
#include "nRF24L01.h"
#include "RF24_config.h"
#include "RF24.h"
#include <stdio.h>
/****************************************************************************/
......@@ -153,7 +152,9 @@ void RF24::read_register(uint8_t reg, uint8_t* buf, uint8_t len)
*ptx++ = (R_REGISTER | reg);
while (len--) *ptx++ = RF24_NOP; // Dummy operation, just for reading
while (len--) {
*ptx++ = RF24_NOP; // Dummy operation, just for reading
}
#if defined(RF24_RP2)
_spi->transfernb((const uint8_t*)spi_txbuff, spi_rxbuff, size);
......@@ -164,7 +165,9 @@ void RF24::read_register(uint8_t reg, uint8_t* buf, uint8_t len)
status = *prx++; // status is 1st byte of receive buffer
// decrement before to skip status byte
while (--size) *buf++ = *prx++;
while (--size) {
*buf++ = *prx++;
}
endTransaction(); // unlocks mutex and setting csn high
......@@ -173,11 +176,15 @@ void RF24::read_register(uint8_t reg, uint8_t* buf, uint8_t len)
beginTransaction();
#if defined(RF24_SPI_PTR)
status = _spi->transfer(R_REGISTER | reg);
while (len--) *buf++ = _spi->transfer(0xFF);
while (len--) {
*buf++ = _spi->transfer(0xFF);
}
#else // !defined(RF24_SPI_PTR)
status = _SPI.transfer(R_REGISTER | reg);
while (len--) *buf++ = _SPI.transfer(0xFF);
while (len--) {
*buf++ = _SPI.transfer(0xFF);
}
#endif // !defined(RF24_SPI_PTR)
endTransaction();
......@@ -237,7 +244,9 @@ void RF24::write_register(uint8_t reg, const uint8_t* buf, uint8_t len)
uint8_t size = static_cast<uint8_t>(len + 1); // Add register value to transmit buffer
*ptx++ = (W_REGISTER | (REGISTER_MASK & reg));
while (len--) *ptx++ = *buf++;
while (len--) {
*ptx++ = *buf++;
}
#if defined(RF24_RP2)
_spi->transfernb((const uint8_t*)spi_txbuff, spi_rxbuff, size);
......@@ -252,11 +261,15 @@ void RF24::write_register(uint8_t reg, const uint8_t* buf, uint8_t len)
beginTransaction();
#if defined(RF24_SPI_PTR)
status = _spi->transfer(W_REGISTER | reg);
while (len--) _spi->transfer(*buf++);
while (len--) {
_spi->transfer(*buf++);
}
#else // !defined(RF24_SPI_PTR)
status = _SPI.transfer(W_REGISTER | reg);
while (len--) _SPI.transfer(*buf++);
while (len--) {
_SPI.transfer(*buf++);
}
#endif // !defined(RF24_SPI_PTR)
endTransaction();
......@@ -341,9 +354,13 @@ void RF24::write_payload(const void* buf, uint8_t data_len, const uint8_t writeT
size = static_cast<uint8_t>(data_len + blank_len + 1); // Add register value to transmit buffer
*ptx++ = writeType;
while (data_len--) *ptx++ = *current++;
while (data_len--) {
*ptx++ = *current++;
}
while (blank_len--) *ptx++ = 0;
while (blank_len--) {
*ptx++ = 0;
}
#if defined(RF24_RP2)
_spi->transfernb((const uint8_t*)spi_txbuff, spi_rxbuff, size);
......@@ -359,15 +376,23 @@ void RF24::write_payload(const void* buf, uint8_t data_len, const uint8_t writeT
beginTransaction();
#if defined(RF24_SPI_PTR)
status = _spi->transfer(writeType);
while (data_len--) _spi->transfer(*current++);
while (data_len--) {
_spi->transfer(*current++);
}
while (blank_len--) _spi->transfer(0);
while (blank_len--) {
_spi->transfer(0);
}
#else // !defined(RF24_SPI_PTR)
status = _SPI.transfer(writeType);
while (data_len--) _SPI.transfer(*current++);
while (data_len--) {
_SPI.transfer(*current++);
}
while (blank_len--) _SPI.transfer(0);
while (blank_len--) {
_SPI.transfer(0);
}
#endif // !defined(RF24_SPI_PTR)
endTransaction();
......@@ -401,7 +426,9 @@ void RF24::read_payload(void* buf, uint8_t data_len)
size = static_cast<uint8_t>(data_len + blank_len + 1); // Add register value to transmit buffer
*ptx++ = R_RX_PAYLOAD;
while (--size) *ptx++ = RF24_NOP;
while (--size) {
*ptx++ = RF24_NOP;
}
size = static_cast<uint8_t>(data_len + blank_len + 1); // Size has been lost during while, re affect
......@@ -415,7 +442,9 @@ void RF24::read_payload(void* buf, uint8_t data_len)
if (data_len > 0) {
// Decrement before to skip 1st status byte
while (--data_len) *current++ = *prx++;
while (--data_len) {
*current++ = *prx++;
}
*current = *prx;
}
......@@ -435,9 +464,13 @@ void RF24::read_payload(void* buf, uint8_t data_len)
#else // !defined(RF24_SPI_PTR)
status = _SPI.transfer(R_RX_PAYLOAD);
while (data_len--) *current++ = _SPI.transfer(0xFF);
while (data_len--) {
*current++ = _SPI.transfer(0xFF);
}
while (blank_len--) _SPI.transfer(0xff);
while (blank_len--) {
_SPI.transfer(0xff);
}
#endif // !defined(RF24_SPI_PTR)
endTransaction();
......@@ -591,8 +624,9 @@ void RF24::setPayloadSize(uint8_t size)
payload_size = static_cast<uint8_t>(rf24_max(1, rf24_min(32, size)));
// write static payload size setting for all pipes
for (uint8_t i = 0; i < 6; ++i)
for (uint8_t i = 0; i < 6; ++i) {
write_register(static_cast<uint8_t>(RX_PW_P0 + i), payload_size);
}
}
/****************************************************************************/
......
......@@ -1064,7 +1064,7 @@ public:
*
* @note ACK payloads are dynamic payloads. Calling enableAckPayload()
* will automatically enable dynamic payloads on pipe 0 (required for TX
* mode when expecting ACK payloads)& pipe 1. To use ACK payloads on any other
* mode when expecting ACK payloads) & pipe 1. To use ACK payloads on any other
* pipe in RX mode, call enableDynamicPayloads().
*
* @param pipe Which pipe# (typically 1-5) will get this response.
......
......@@ -54,6 +54,7 @@
// RaspberryPi rp2xxx-based devices (e.g. RPi Pico board)
#elif defined(PICO_BUILD) && !defined(ARDUINO)
#include "utility/rp2/RF24_arch_config.h"
#define sprintf_P sprintf
#elif (!defined(ARDUINO)) // Any non-arduino device is handled via configure/Makefile
// The configure script detects device and copies the correct includes.h file to /utility/includes.h
......@@ -61,6 +62,10 @@
// The includes.h file defines either RF24_RPi, MRAA, LITTLEWIRE or RF24_SPIDEV and includes the correct RF24_arch_config.h file
#include "utility/includes.h"
#ifndef sprintf_P
#define sprintf_P sprintf
#endif // sprintf_P
//ATTiny
#elif defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny2313__) || defined(__AVR_ATtiny4313__) || defined(__AVR_ATtiny861__) || defined(__AVR_ATtinyX5__) || defined(__AVR_ATtinyX4__) || defined(__AVR_ATtinyX313__) || defined(__AVR_ATtinyX61__)
#define RF24_TINY
......@@ -217,8 +222,4 @@ typedef uint16_t prog_uint16_t;
#define RF24_SPI_TRANSACTIONS
#endif // defined (SPI_HAS_TRANSACTION) && !defined (SPI_UART) && !defined (SOFTSPI)
#ifndef sprintf_P
#define sprintf_P sprintf
#endif // sprintf_P
#endif // __RF24_CONFIG_H__
......@@ -7,67 +7,66 @@
*/
#ifndef __ARCH_CONFIG_H__
#define __ARCH_CONFIG_H__
#define __ARCH_CONFIG_H__
#define RF24_LINUX
#define RF24_LINUX
#include <stddef.h>
#include "spi.h"
#include "gpio.h"
#include "compatibility.h"
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <sys/time.h>
#include <stddef.h>
#include "spi.h"
#include "gpio.h"
#include "compatibility.h"
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <sys/time.h>
//#define RF24_SPI_SPEED RF24_SPIDEV_SPEED
#define _BV(x) (1 << (x))
#define _SPI spi
#define _BV(x) (1 << (x))
#define _SPI spi
//#undef SERIAL_DEBUG
#ifdef SERIAL_DEBUG
#define IF_SERIAL_DEBUG(x) ({ x; })
#else
#define IF_SERIAL_DEBUG(x)
#endif
//#undef SERIAL_DEBUG
#ifdef SERIAL_DEBUG
#define IF_SERIAL_DEBUG(x) ({ x; })
#else
#define IF_SERIAL_DEBUG(x)
#endif
// Avoid spurious warnings
#if 1
#if !defined(NATIVE) && defined(ARDUINO)
#undef PROGMEM
#define PROGMEM __attribute__((section(".progmem.data")))
#undef PSTR
#define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0]; }))
#endif
// Avoid spurious warnings
#if 1
#if !defined(NATIVE) && defined(ARDUINO)
#undef PROGMEM
#define PROGMEM __attribute__((section(".progmem.data")))
#undef PSTR
#define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0]; }))
#endif
#endif
#if RF24_SPI_SPEED > 1000000
#undef RF24_SPI_SPEED
#define RF24_SPI_SPEED 1000000
#endif
#if RF24_SPI_SPEED > 1000000
#undef RF24_SPI_SPEED
#define RF24_SPI_SPEED 1000000
#endif
typedef uint16_t prog_uint16_t;
#define PSTR(x) (x)
#define printf_P printf
#define strlen_P strlen
#define PROGMEM
#define pgm_read_word(p) (*(p))
#define PRIPSTR "%s"
#define pgm_read_byte(p) (*(p))
#define pgm_read_ptr(p) (*(p))
#define PSTR(x) (x)
#define printf_P printf
#define strlen_P strlen
#define PROGMEM
#define pgm_read_word(p) (*(p))
#define PRIPSTR "%s"
#define pgm_read_byte(p) (*(p))
#define pgm_read_ptr(p) (*(p))
// Function, constant map as a result of migrating from Arduino
#define LOW GPIO::OUTPUT_LOW
#define HIGH GPIO::OUTPUT_HIGH
#define INPUT GPIO::DIRECTION_IN
#define OUTPUT GPIO::DIRECTION_OUT
#define digitalWrite(pin, value) GPIO::write(pin, value)
#define pinMode(pin, direction) GPIO::open(pin, direction)
#define delay(milisec) __msleep(milisec)
#define delayMicroseconds(usec) __usleep(usec)
#define millis() __millis()
// Function, constant map as a result of migrating from Arduino
#define LOW GPIO::OUTPUT_LOW
#define HIGH GPIO::OUTPUT_HIGH
#define INPUT GPIO::DIRECTION_IN
#define OUTPUT GPIO::DIRECTION_OUT
#define digitalWrite(pin, value) GPIO::write(pin, value)
#define pinMode(pin, direction) GPIO::open(pin, direction)
#define delay(milisec) __msleep(milisec)
#define delayMicroseconds(usec) __usleep(usec)
#define millis() __millis()
#endif // __ARCH_CONFIG_H__
// vim:ai:cin:sts=2 sw=2 ft=cpp
......@@ -19,6 +19,7 @@
#include "spi.h"
#include "gpio.h"
#include <string.h>
#include <stdio.h>
/** Define a specific platform name for this configuration */
#define RF24_RP2
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment