RFM73library
Main Page
Related Pages
Modules
Classes
Files
File List
All
Classes
Functions
Typedefs
Groups
Pages
rfm73.h
1
2
3
4
5
6
7
8
9
10
11
12
13
//***************************************************************************//
14
//
15
// COPYRIGHT NOTICE (zlib license)
16
//
17
// Loosely based on the example application provided by HopeRF
18
//
19
// (c) Wouter van Ooijen - wouter@voti.nl
20
//
21
// This software is provided 'as-is', without any express or implied
22
// warranty. In no event will the authors be held liable for any damages
23
// arising from the use of this software.
24
//
25
// Permission is granted to anyone to use this software for any purpose,
26
// including commercial applications, and to alter it and redistribute it
27
// freely, subject to the following restrictions:
28
//
29
// 1. The origin of this software must not be misrepresented; you must not
30
// claim that you wrote the original software. If you use this software
31
// in a product, an acknowledgment in the product documentation would be
32
// appreciated but is not required.
33
// 2. Altered source versions must be plainly marked as such, and must not be
34
// misrepresented as being the original software.
35
// 3. This notice may not be removed or altered from any source distribution.
36
//
37
//***************************************************************************//
38
39
#ifndef _RFM73_H_
40
#define _RFM73_H_
41
42
//***************************************************************************//
43
//
65
//
66
//***************************************************************************//
67
68
//***************************************************************************//
69
//
82
//
83
//***************************************************************************//
84
85
87
//
89
#define RFM73_LIB_VERSION "V1.03 (2012-11-16)"
90
92
//
94
#define RFM73_MAX_PACKET_LEN 32
95
97
//
99
typedef
unsigned
char
rfm73_buffer
[
RFM73_MAX_PACKET_LEN
];
100
101
102
//***************************************************************************//
103
//
104
// RFM73 SPI commands
105
//
106
//***************************************************************************//
107
110
112
#define RFM73_CMD_R_RX_PAYLOAD 0x61
113
115
#define RFM73_CMD_W_TX_PAYLOAD 0xA0
116
118
#define RFM73_CMD_FLUSH_TX 0xE1
119
121
#define RFM73_CMD_FLUSH_RX 0xE2
122
124
#define RFM73_CMD_REUSE_TX_PL 0xE3
125
127
#define RFM73_CMD_W_TX_PAYLOAD_NOACK 0xB0
128
130
#define RFM73_CMD_W_ACK_PAYLOAD 0xA8
131
133
#define RFM73_CMD_ACTIVATE 0x50
134
136
#define RFM73_CMD_R_RX_PL_WID 0x60
137
139
#define RFM73_CMD_NOP 0xFF
140
141
//***************************************************************************//
142
//
143
// RFM73 register addresses
144
//
145
//***************************************************************************//
146
148
//
158
#define RFM73_REG_CONFIG 0x00
159
161
//
170
#define RFM73_REG_EN_AA 0x01
171
173
//
182
#define RFM73_REG_EN_RXADDR 0x02
183
185
//
189
#define RFM73_REG_SETUP_AW 0x03
190
192
//
196
#define RFM73_REG_SETUP_RETR 0x04
197
199
//
201
#define RFM73_REG_RF_CH 0x05
202
204
//
210
#define RFM73_REG_RF_SETUP 0x06
211
213
//
229
#define RFM73_REG_STATUS 0x07
230
232
//
242
#define RFM73_REG_OBSERVE_TX 0x08
243
245
//
249
#define RFM73_REG_CD 0x09
250
252
//
256
#define RFM73_REG_RX_ADDR_P0 0x0A
257
259
//
263
#define RFM73_REG_RX_ADDR_P1 0x0B
264
266
//
270
#define RFM73_REG_RX_ADDR_P2 0x0C
271
273
//
277
#define RFM73_REG_RX_ADDR_P3 0x0D
278
280
//
284
#define RFM73_REG_RX_ADDR_P4 0x0E
285
287
//
291
#define RFM73_REG_RX_ADDR_P5 0x0F
292
294
//
298
#define RFM73_REG_TX_ADDR 0x10
299
301
//
304
#define RFM73_REG_RX_PW_P0 0x11
305
307
//
310
#define RFM73_REG_RX_PW_P1 0x12
311
313
//
316
#define RFM73_REG_RX_PW_P2 0x13
317
319
//
322
#define RFM73_REG_RX_PW_P3 0x14
323
325
//
328
#define RFM73_REG_RX_PW_P4 0x15
329
331
//
334
#define RFM73_REG_RX_PW_P5 0x16
335
337
//
346
#define RFM73_REG_FIFO_STATUS 0x17
347
349
//
360
#define RFM73_REG_DYNPD 0x1C
361
363
//
369
#define RFM73_REG_FEATURE 0x1D
370
372
373
374
namespace
pins {
375
377
class
output_pin
{
378
public
:
379
381
virtual
void
set
(
bool
x )=0;
382
384
virtual
void
direction_set_output
(){}
385
};
386
388
class
input_pin
{
389
public
:
390
392
virtual
bool
get
()=0;
393
395
virtual
void
direction_set_input
(){}
396
};
397
398
enum
direction { input, output };
399
401
class
input_output_pin
:
public
output_pin
,
public
input_pin
{
402
public
:
403
405
virtual
void
direction_set
( direction d ){
406
if
( d == input ){
407
direction_set_input
();
408
}
else
{
409
direction_set_output
();
410
}
411
}
412
414
void
direction_set_input
(){
415
direction_set
( input );
416
}
417
419
void
direction_set_output
(){
420
direction_set
( output );
421
}
422
};
423
425
class
uc_pin
:
public
pins::input_output_pin
{
426
private
:
427
428
unsigned
char
nr;
429
430
public
:
431
433
uc_pin
(
unsigned
char
nr ): nr( nr ){}
434
436
void
direction_set_output
(){
437
pinMode( nr, OUTPUT );
438
}
439
441
void
direction_set_input
(){
442
pinMode( nr, INPUT );
443
}
444
446
bool
get
(){
447
return
digitalRead( nr );
448
}
449
451
void
set
(
bool
x ){
452
digitalWrite( nr, x );
453
}
454
455
};
456
457
};
458
459
460
461
463
class
rfm73
{
464
465
private
:
466
pins::output_pin
&sclk;
467
pins::output_pin
&mosi;
468
pins::input_pin
&miso;
469
pins::output_pin
&csn;
470
pins::output_pin
&ce;
471
472
// void(*wait_ms)(unsigned int);
473
// void(*wait_us)(unsigned int);
474
475
unsigned
char
SPI_RW(
unsigned
char
value );
476
477
public
:
479
//
484
rfm73
(
485
pins::output_pin
&sclk,
486
pins::output_pin
&mosi,
487
pins::input_pin
&miso,
488
pins::output_pin
&csn,
489
pins::output_pin
&ce
490
491
// ,void(*wait_ms)(unsigned int)
492
// ,void(*wait_us)(unsigned int)
493
494
):
495
sclk( sclk ),
496
mosi( mosi ),
497
miso( miso ),
498
csn( csn ),
499
ce( ce )
500
// ,wait_ms( wait_ms )
501
// ,wait_us( wait_us )
502
{}
503
504
private
:
505
void
bank(
unsigned
char
b );
506
void
init_bank1();
507
508
public
:
509
510
512
//
529
void
init
(
void
);
530
532
//
536
unsigned
char
register_read
(
unsigned
char
reg );
537
539
//
543
void
buffer_read
(
544
unsigned
char
reg,
545
unsigned
char
buf[],
546
unsigned
char
length
547
);
548
550
//
554
void
register_write
(
unsigned
char
reg,
unsigned
char
val );
555
557
//
562
void
buffer_write
(
563
char
reg,
564
const
unsigned
char
buf[],
565
unsigned
char
length
566
);
567
568
//***************************************************************************//
569
//
570
// high-level interface
571
//
572
//***************************************************************************//
573
575
//
581
bool
is_present
(
void
);
582
584
//
588
void
mode_transmit
(
void
);
589
591
//
595
void
mode_receive
(
void
);
596
598
//
606
void
mode_standby
(
void
);
607
609
//
614
void
mode_powerdown
(
void
);
615
617
//
621
void
lna_low
(
void
);
622
624
//
628
void
lna_high
(
void
);
629
631
//
638
void
channel
(
unsigned
char
ch );
639
641
//
651
void
air_data_rate
(
unsigned
char
rate );
652
654
//
662
void
crc_length
(
unsigned
char
len );
663
665
//
672
void
address_length
(
unsigned
char
len );
673
675
//
684
void
power
(
unsigned
char
level );
685
687
//
703
void
retransmit_delay_attempts
(
unsigned
char
d,
unsigned
char
n );
704
706
//
711
unsigned
char
retransmit_count
(
void
);
712
714
//
722
unsigned
char
lost_packets_count
(
void
);
723
725
//
729
void
lost_packets_reset
(
void
);
730
732
//
739
void
pipe_autoack
(
unsigned
char
pipe,
bool
enabled );
740
742
//
748
void
pipe_enable
(
unsigned
char
d,
bool
enabled );
749
751
//
760
void
receive_address_p0
(
const
unsigned
char
address[ 5 ] );
761
763
//
772
void
receive_address_p1
(
const
unsigned
char
address[ 5 ] );
773
775
//
780
void
receive_address_pn
(
unsigned
char
channel
,
unsigned
char
address );
781
783
//
790
void
channel_payload_size
(
unsigned
char
n,
unsigned
char
size );
791
793
//
797
void
transmit_address
(
const
unsigned
char
address[] );
798
800
//
803
bool
transmit_fifo_full
(
void
);
804
806
//
809
bool
receive_fifo_empty
(
void
);
810
812
//
827
void
transmit_message
(
828
const
unsigned
char
buf[],
829
unsigned
char
length
830
);
831
833
//
846
void
transmit_message_once
(
847
const
unsigned
char
buf[],
848
unsigned
char
length
849
);
850
852
//
859
unsigned
char
receive_next_pipe
(
void
);
860
862
//
869
unsigned
char
receive_next_length
(
void
);
870
872
//
887
bool
receive
(
888
unsigned
char
& pipe,
889
unsigned
char
buf[],
890
unsigned
char
& length
891
);
892
893
894
};
// class frm70
895
896
897
#endif
Generated on Sun May 12 2013 11:43:55 for RFM73library by
1.8.2