Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
RF24.h
1 /*
2  Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public License
6  version 2 as published by the Free Software Foundation.
7  */
8 
15 #ifndef __RF24_H__
16 #define __RF24_H__
17 
18 #include "RF24_config.h"
19 
25 typedef enum { RF24_PA_MIN = 0,RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX, RF24_PA_ERROR } rf24_pa_dbm_e ;
26 
32 typedef enum { RF24_1MBPS = 0, RF24_2MBPS, RF24_250KBPS } rf24_datarate_e;
33 
39 typedef enum { RF24_CRC_DISABLED = 0, RF24_CRC_8, RF24_CRC_16 } rf24_crclength_e;
40 
45 class RF24
46 {
47 private:
48  uint8_t ce_pin;
49  uint8_t csn_pin;
50  bool wide_band; /* 2Mbs data rate in use? */
51  bool p_variant; /* False for RF24L01 and true for RF24L01P */
52  uint8_t payload_size;
53  bool ack_payload_available;
54  bool dynamic_payloads_enabled;
55  uint8_t ack_payload_length;
56  uint64_t pipe0_reading_address;
58 protected:
78  void csn(int mode);
79 
86  void ce(int level);
87 
96  uint8_t read_register(uint8_t reg, uint8_t* buf, uint8_t len);
97 
104  uint8_t read_register(uint8_t reg);
105 
114  uint8_t write_register(uint8_t reg, const uint8_t* buf, uint8_t len);
115 
123  uint8_t write_register(uint8_t reg, uint8_t value);
124 
134  uint8_t write_payload(const void* buf, uint8_t len);
135 
145  uint8_t read_payload(void* buf, uint8_t len);
146 
152  uint8_t flush_rx(void);
153 
159  uint8_t flush_tx(void);
160 
166  uint8_t get_status(void);
167 
175  void print_status(uint8_t status);
176 
184  void print_observe_tx(uint8_t value);
185 
197  void print_byte_register(const char* name, uint8_t reg, uint8_t qty = 1);
198 
210  void print_address_register(const char* name, uint8_t reg, uint8_t qty = 1);
211 
218  void toggle_features(void);
221 public:
238  RF24(uint8_t _cepin, uint8_t _cspin);
239 
245  void begin(void);
246 
254  void startListening(void);
255 
261  void stopListening(void);
262 
281  bool write( const void* buf, uint8_t len );
282 
288  bool available(void);
289 
304  bool read( void* buf, uint8_t len );
305 
324  void openWritingPipe(uint64_t address);
325 
350  void openReadingPipe(uint8_t number, uint64_t address);
351 
368  void setRetries(uint8_t delay, uint8_t count);
369 
375  void setChannel(uint8_t channel);
376 
389  void setPayloadSize(uint8_t size);
390 
398  uint8_t getPayloadSize(void);
399 
408  uint8_t getDynamicPayloadSize(void);
409 
418  void enableAckPayload(void);
419 
428  void enableDynamicPayloads(void);
429 
436  bool isPVariant(void) ;
437 
446  void setAutoAck(bool enable);
447 
457  void setAutoAck( uint8_t pipe, bool enable ) ;
458 
468  void setPALevel( rf24_pa_dbm_e level ) ;
469 
478  rf24_pa_dbm_e getPALevel( void ) ;
479 
488  bool setDataRate(rf24_datarate_e speed);
489 
497  rf24_datarate_e getDataRate( void ) ;
498 
504  void setCRCLength(rf24_crclength_e length);
505 
511  rf24_crclength_e getCRCLength(void);
512 
517  void disableCRC( void ) ;
518 
532  void printDetails(void);
533 
540  void powerDown(void);
541 
547  void powerUp(void) ;
548 
558  bool available(uint8_t* pipe_num);
559 
573  void startWrite( const void* buf, uint8_t len );
574 
589  void writeAckPayload(uint8_t pipe, const void* buf, uint8_t len);
590 
604  bool isAckPayloadAvailable(void);
605 
616  void whatHappened(bool& tx_ok,bool& tx_fail,bool& rx_ready);
617 
626  bool testCarrier(void);
627 
638  bool testRPD(void) ;
639 
647  bool isValid() { return ce_pin != 0xff && csn_pin != 0xff; }
648 
650 };
651 
817 #endif // __RF24_H__
818 // vim:ai:cin:sts=2 sw=2 ft=cpp
819 
void setAutoAck(bool enable)
rf24_pa_dbm_e getPALevel(void)
bool read(void *buf, uint8_t len)
void printDetails(void)
rf24_datarate_e getDataRate(void)
void setChannel(uint8_t channel)
void print_status(uint8_t status)
uint8_t read_register(uint8_t reg, uint8_t *buf, uint8_t len)
bool testRPD(void)
void whatHappened(bool &tx_ok, bool &tx_fail, bool &rx_ready)
uint8_t get_status(void)
void print_observe_tx(uint8_t value)
void begin(void)
void startWrite(const void *buf, uint8_t len)
void setRetries(uint8_t delay, uint8_t count)
void disableCRC(void)
void powerDown(void)
void print_byte_register(const char *name, uint8_t reg, uint8_t qty=1)
bool write(const void *buf, uint8_t len)
uint8_t flush_tx(void)
uint8_t read_payload(void *buf, uint8_t len)
void ce(int level)
void setPayloadSize(uint8_t size)
bool testCarrier(void)
void powerUp(void)
bool isPVariant(void)
uint8_t getDynamicPayloadSize(void)
void startListening(void)
bool available(void)
void enableDynamicPayloads(void)
bool isAckPayloadAvailable(void)
RF24(uint8_t _cepin, uint8_t _cspin)
void enableAckPayload(void)
uint8_t flush_rx(void)
void openReadingPipe(uint8_t number, uint64_t address)
void setCRCLength(rf24_crclength_e length)
void stopListening(void)
bool setDataRate(rf24_datarate_e speed)
uint8_t write_payload(const void *buf, uint8_t len)
uint8_t getPayloadSize(void)
void setPALevel(rf24_pa_dbm_e level)
void print_address_register(const char *name, uint8_t reg, uint8_t qty=1)
Definition: RF24.h:45
void csn(int mode)
void openWritingPipe(uint64_t address)
void toggle_features(void)
bool isValid()
Definition: RF24.h:647
void writeAckPayload(uint8_t pipe, const void *buf, uint8_t len)
uint8_t write_register(uint8_t reg, const uint8_t *buf, uint8_t len)
void delay(uint32_t time)
Pause execution.
rf24_crclength_e getCRCLength(void)