RF24 v1
RF24.h
Go to the documentation of this file.
00001 /*
00002  Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
00003 
00004  This program is free software; you can redistribute it and/or
00005  modify it under the terms of the GNU General Public License
00006  version 2 as published by the Free Software Foundation.
00007  */
00008 
00015 #ifndef __RF24_H__
00016 #define __RF24_H__
00017 
00018 #include <RF24_config.h>
00019 
00025 typedef enum { RF24_PA_MIN = 0,RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX, RF24_PA_ERROR } rf24_pa_dbm_e ;
00026 
00032 typedef enum { RF24_1MBPS = 0, RF24_2MBPS, RF24_250KBPS } rf24_datarate_e;
00033 
00039 typedef enum { RF24_CRC_DISABLED = 0, RF24_CRC_8, RF24_CRC_16 } rf24_crclength_e;
00040 
00045 class RF24
00046 {
00047 private:
00048   uint8_t ce_pin; 
00049   uint8_t csn_pin; 
00050   bool wide_band; /* 2Mbs data rate in use? */
00051   bool p_variant; /* False for RF24L01 and true for RF24L01P */
00052   uint8_t payload_size; 
00053   bool ack_payload_available; 
00054   bool dynamic_payloads_enabled; 
00055   uint8_t ack_payload_length; 
00056   uint64_t pipe0_reading_address; 
00058 protected:
00078   void csn(int mode);
00079 
00086   void ce(int level);
00087 
00096   uint8_t read_register(uint8_t reg, uint8_t* buf, uint8_t len);
00097 
00104   uint8_t read_register(uint8_t reg);
00105 
00114   uint8_t write_register(uint8_t reg, const uint8_t* buf, uint8_t len);
00115 
00123   uint8_t write_register(uint8_t reg, uint8_t value);
00124 
00134   uint8_t write_payload(const void* buf, uint8_t len);
00135 
00145   uint8_t read_payload(void* buf, uint8_t len);
00146 
00152   uint8_t flush_rx(void);
00153 
00159   uint8_t flush_tx(void);
00160 
00166   uint8_t get_status(void);
00167 
00175   void print_status(uint8_t status);
00176 
00184   void print_observe_tx(uint8_t value);
00185 
00197   void print_byte_register(prog_char* name, uint8_t reg, uint8_t qty = 1);
00198 
00210   void print_address_register(prog_char* name, uint8_t reg, uint8_t qty = 1);
00211 
00218   void toggle_features(void);
00221 public:
00238   RF24(uint8_t _cepin, uint8_t _cspin);
00239 
00245   void begin(void);
00246 
00254   void startListening(void);
00255 
00261   void stopListening(void);
00262 
00281   bool write( const void* buf, uint8_t len );
00282 
00288   bool available(void);
00289 
00304   bool read( void* buf, uint8_t len );
00305 
00324   void openWritingPipe(uint64_t address);
00325 
00350   void openReadingPipe(uint8_t number, uint64_t address);
00351 
00368   void setRetries(uint8_t delay, uint8_t count);
00369 
00375   void setChannel(uint8_t channel);
00376 
00389   void setPayloadSize(uint8_t size);
00390 
00398   uint8_t getPayloadSize(void);
00399 
00408   uint8_t getDynamicPayloadSize(void);
00409   
00418   void enableAckPayload(void);
00419 
00428   void enableDynamicPayloads(void);
00429 
00436   bool isPVariant(void) ;
00437 
00446   void setAutoAck(bool enable);
00447 
00457   void setAutoAck( uint8_t pipe, bool enable ) ;
00458 
00468   void setPALevel( rf24_pa_dbm_e level ) ;
00469 
00478   rf24_pa_dbm_e getPALevel( void ) ;
00479 
00488   bool setDataRate(rf24_datarate_e speed);
00489   
00497   rf24_datarate_e getDataRate( void ) ;
00498 
00504   void setCRCLength(rf24_crclength_e length);
00505 
00511   rf24_crclength_e getCRCLength(void);
00512 
00517   void disableCRC( void ) ;
00518 
00532   void printDetails(void);
00533 
00540   void powerDown(void);
00541 
00547   void powerUp(void) ;
00548 
00558   bool available(uint8_t* pipe_num);
00559 
00573   void startWrite( const void* buf, uint8_t len );
00574 
00589   void writeAckPayload(uint8_t pipe, const void* buf, uint8_t len);
00590 
00604   bool isAckPayloadAvailable(void);
00605 
00616   void whatHappened(bool& tx_ok,bool& tx_fail,bool& rx_ready);
00617 
00626   bool testCarrier(void);
00627 
00638   bool testRPD(void) ;
00639 
00641 };
00642 
00808 #endif // __RF24_H__
00809 // vim:ai:cin:sts=2 sw=2 ft=cpp
00810 
 All Classes Files Functions Enumerations