Skip to content

Commit

Permalink
Merge branch 'master' of github.com:maniacbug/RF24
Browse files Browse the repository at this point in the history
  • Loading branch information
maniacbug committed Dec 18, 2011
2 parents 291621c + 26ea458 commit bc7e422
Show file tree
Hide file tree
Showing 25 changed files with 1,089 additions and 489 deletions.
52 changes: 17 additions & 35 deletions RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,11 @@
version 2 as published by the Free Software Foundation.
*/

#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24_config.h"
#include "RF24.h"

#undef SERIAL_DEBUG
#ifdef SERIAL_DEBUG
#define IF_SERIAL_DEBUG(x) ({x;})
#else
#define IF_SERIAL_DEBUG(x)
#endif

// Avoid spurious warnings
#ifndef NATIVE
#undef PROGMEM
#define PROGMEM __attribute__(( section(".progmem.data") ))
#undef PSTR
#define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); &__c[0];}))
#endif

/****************************************************************************/

void RF24::csn(int mode)
Expand All @@ -39,9 +19,11 @@ void RF24::csn(int mode)
// If we assume 2Mbs data rate and 16Mhz clock, a
// divider of 4 is the minimum we want.
// CLK:BUS 8Mhz:2Mhz, 16Mhz:4Mhz, or 20Mhz:5Mhz
#ifdef ARDUINO
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(SPI_CLOCK_DIV4);
#endif
digitalWrite(csn_pin,mode);
}

Expand Down Expand Up @@ -102,7 +84,7 @@ uint8_t RF24::write_register(uint8_t reg, uint8_t value)
{
uint8_t status;

IF_SERIAL_DEBUG(printf_P(PSTR("write_register(%02x,%02x)\n\r"),reg,value));
IF_SERIAL_DEBUG(printf_P(PSTR("write_register(%02x,%02x)\r\n"),reg,value));

csn(LOW);
status = SPI.transfer( W_REGISTER | ( REGISTER_MASK & reg ) );
Expand Down Expand Up @@ -202,7 +184,7 @@ uint8_t RF24::get_status(void)

void RF24::print_status(uint8_t status)
{
printf_P(PSTR("STATUS\t\t = 0x%02x RX_DR=%x TX_DS=%x MAX_RT=%x RX_P_NO=%x TX_FULL=%x\n\r"),
printf_P(PSTR("STATUS\t\t = 0x%02x RX_DR=%x TX_DS=%x MAX_RT=%x RX_P_NO=%x TX_FULL=%x\r\n"),
status,
(status & _BV(RX_DR))?1:0,
(status & _BV(TX_DS))?1:0,
Expand All @@ -216,7 +198,7 @@ void RF24::print_status(uint8_t status)

void RF24::print_observe_tx(uint8_t value)
{
printf_P(PSTR("OBSERVE_TX=%02x: POLS_CNT=%x ARC_CNT=%x\n\r"),
printf_P(PSTR("OBSERVE_TX=%02x: POLS_CNT=%x ARC_CNT=%x\r\n"),
value,
(value >> PLOS_CNT) & B1111,
(value >> ARC_CNT) & B1111
Expand All @@ -228,18 +210,18 @@ void RF24::print_observe_tx(uint8_t value)
void RF24::print_byte_register(prog_char* name, uint8_t reg, uint8_t qty)
{
char extra_tab = strlen_P(name) < 8 ? '\t' : 0;
printf_P(PSTR("%S\t%c ="),name,extra_tab);
printf_P(PSTR(PRIPSTR"\t%c ="),name,extra_tab);
while (qty--)
printf_P(PSTR(" 0x%02x"),read_register(reg++));
printf_P(PSTR("\n\r"));
printf_P(PSTR("\r\n"));
}

/****************************************************************************/

void RF24::print_address_register(prog_char* name, uint8_t reg, uint8_t qty)
{
char extra_tab = strlen_P(name) < 8 ? '\t' : 0;
printf_P(PSTR("%S\t%c ="),name,extra_tab);
printf_P(PSTR(PRIPSTR"\t%c ="),name,extra_tab);

while (qty--)
{
Expand All @@ -252,7 +234,7 @@ void RF24::print_address_register(prog_char* name, uint8_t reg, uint8_t qty)
printf_P(PSTR("%02x"),*bufptr);
}

printf_P(PSTR("\n\r"));
printf_P(PSTR("\r\n"));
}

/****************************************************************************/
Expand Down Expand Up @@ -313,10 +295,10 @@ void RF24::printDetails(void)
const char * rf24_crclength_e_str[] = { "Disabled", "8 bits", "16 bits" } ;
const char * rf24_pa_dbm_e_str[] = { "PA_MIN", "PA_LOW", "LA_MED", "PA_HIGH"} ;

printf_P(PSTR("Data Rate\t = %s\n\r"),rf24_datarate_e_str[getDataRate()]);
printf_P(PSTR("Model\t\t = %s\n\r"),rf24_model_e_str[isPVariant()]);
printf_P(PSTR("CRC Length\t = %s\n\r"),rf24_crclength_e_str[getCRCLength()]);
printf_P(PSTR("PA Power\t = %s\n\r"),rf24_pa_dbm_e_str[getPALevel()]);
printf_P(PSTR("Data Rate\t = %s\r\n"),rf24_datarate_e_str[getDataRate()]);
printf_P(PSTR("Model\t\t = %s\r\n"),rf24_model_e_str[isPVariant()]);
printf_P(PSTR("CRC Length\t = %s\r\n"),rf24_crclength_e_str[getCRCLength()]);
printf_P(PSTR("PA Power\t = %s\r\n"),rf24_pa_dbm_e_str[getPALevel()]);
}

/****************************************************************************/
Expand Down Expand Up @@ -470,7 +452,7 @@ bool RF24::write( const void* buf, uint8_t len )
bool tx_ok, tx_fail;
whatHappened(tx_ok,tx_fail,ack_payload_available);

//printf("%u%u%u\n\r",tx_ok,tx_fail,ack_payload_available);
//printf("%u%u%u\r\n",tx_ok,tx_fail,ack_payload_available);

result = tx_ok;
IF_SERIAL_DEBUG(Serial.print(result?"...OK.":"...Failed"));
Expand Down Expand Up @@ -670,7 +652,7 @@ void RF24::enableDynamicPayloads(void)
write_register(FEATURE,read_register(FEATURE) | _BV(EN_DPL) );
}

IF_SERIAL_DEBUG(printf("FEATURE=%i\n\r",read_register(FEATURE)));
IF_SERIAL_DEBUG(printf("FEATURE=%i\r\n",read_register(FEATURE)));

// Enable dynamic payload on all pipes
//
Expand Down Expand Up @@ -699,7 +681,7 @@ void RF24::enableAckPayload(void)
write_register(FEATURE,read_register(FEATURE) | _BV(EN_ACK_PAY) | _BV(EN_DPL) );
}

IF_SERIAL_DEBUG(printf("FEATURE=%i\n\r",read_register(FEATURE)));
IF_SERIAL_DEBUG(printf("FEATURE=%i\r\n",read_register(FEATURE)));

//
// Enable dynamic payload on pipes 0 & 1
Expand Down
3 changes: 1 addition & 2 deletions RF24.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
#ifndef __RF24_H__
#define __RF24_H__

#include <stddef.h>
#include <avr/pgmspace.h>
#include <RF24_config.h>

typedef enum { RF24_PA_MIN = 0,RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX, RF24_PA_ERROR } rf24_pa_dbm_e ;
typedef enum { RF24_1MBPS = 0, RF24_2MBPS, RF24_250KBPS } rf24_datarate_e;
Expand Down
61 changes: 61 additions & 0 deletions RF24_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

/*
Copyright (C) 2011 James Coliz, Jr. <maniacbug@ymail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/

#ifndef __RF24_CONFIG_H__
#define __RF24_CONFIG_H__

#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif

#include <stddef.h>

// Stuff that is normally provided by Arduino
#ifndef ARDUINO
#include <stdint.h>
#include <stdio.h>
#include <string.h>
extern HardwareSPI SPI;
#define _BV(x) (1<<(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 ! defined( NATIVE ) && defined( ARDUINO )
#undef PROGMEM
#define PROGMEM __attribute__(( section(".progmem.data") ))
#undef PSTR
#define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); &__c[0];}))
#endif

// Progmem is Arduino-specific
#ifdef ARDUINO
#include <avr/pgmspace.h>
#define PRIPSTR "%S"
#else
typedef char const prog_char;
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"
#endif

#endif // __RF24_CONFIG_H__
// vim:ai:cin:sts=2 sw=2 ft=cpp
Loading

0 comments on commit bc7e422

Please sign in to comment.