23 #if !defined(BOARD_ATTINYX5) 29 #define REG_VALUE8(reg,value) (reg), (uint8_t) (value) 30 #define REG_VALUE16(reg,value) \ 31 REG_VALUE8(reg,value >> 8), \ 32 REG_VALUE8(reg+1,value) 33 #define REG_VALUE24(reg,value) \ 34 REG_VALUE8(reg,value >> 16), \ 35 REG_VALUE8(reg+1,value >> 8), \ 36 REG_VALUE8(reg+2,value) 39 #define FXOSC 32000000L 40 #define FSTEP (FXOSC >> 19) 43 #define FRF_315_MHZ 0x4EC000L 44 #define FRF_434_MHZ 0x6C8000L 45 #define FRF_868_MHZ 0xD90000L 46 #define FRF_915_MHZ 0xE4C000L 47 #define FRF_SETTING FRF_868_MHZ 50 #define BITRATE_1200_BPS 0x682B 51 #define BITRATE_2400_BPS 0x3415 52 #define BITRATE_4800_BPS 0x1A0B 53 #define BITRATE_9600_BPS 0x0D05 54 #define BITRATE_19200_BPS 0x0683 55 #define BITRATE_38400_BPS 0x0341 56 #define BITRATE_57600_BPS 0x022C 57 #define BITRATE_76800_BPS 0x01A1 58 #define BITRATE_115200_BPS 0x0116 59 #define BITRATE_153600_BPS 0x00D0 60 #define BITRATE_SETTING BITRATE_4800_BPS 63 #define FDEV_SETTING 0x0052 74 REG_VALUE8(OP_MODE, SEQUENCER_ON | LISTEN_OFF | STANDBY_MODE),
75 REG_VALUE8(DATA_MODUL, PACKET_MODE | FSK_MODULATION | FSK_NO_SHAPING),
81 REG_VALUE8(PA_LEVEL, PA0_ON | PA1_OFF | PA2_OFF | FULL_OUTPUT_POWER),
84 REG_VALUE8(LNA, ZIN_200_OHM | (1 << CURRENT_GAIN)),
86 REG_VALUE8(RX_BW, (2 << DCC_FREQ) | BW_MANT_24 | (5 << BW_EXP)),
93 REG_VALUE8(SYNC_CONFIG, SYNC_ON | FIFO_FILL_AUTO
94 | ((
sizeof(int16_t) - 1) << SYNC_SIZE)),
95 REG_VALUE8(PACKET_CONFIG1, VARIABLE_LENGTH | WHITENING
96 | CRC_ON | CRC_AUTO_CLEAR_ON
100 REG_VALUE8(FIFO_THRESHOLD, TX_START_NOT_EMPTY | 15),
101 REG_VALUE8(PACKET_CONFIG2, (1 << INTER_PACKET_RX_DELAY)
106 REG_VALUE8(TEST_DAGC, TEST_DAGC_IMPROVED_MARGIN_AFC_LOG_BETA_OFF),
113 SPI::Driver(csn,
SPI::ACTIVE_LOW,
SPI::DIV4_CLOCK, 0,
SPI::MSB_ORDER, &m_irq),
120 RFM69::IRQPin::on_interrupt(uint16_t arg)
127 if (m_rf->m_opmode == RECEIVER_MODE)
128 m_rf->m_avail =
true;
129 else if (m_rf->m_opmode == TRANSMITTER_MODE)
134 RFM69::set(Mode mode)
136 write(OP_MODE, (read(OP_MODE) & ~MODE_MASK) | mode);
137 while ((read(IRQ_FLAGS1) & MODE_READY) == 0x00)
DELAY(10);
145 do write(SYNC_VALUE1, 0xaa);
while (read(SYNC_VALUE1) != 0xaa);
146 do write(SYNC_VALUE1, 0x55);
while (read(SYNC_VALUE1) != 0x55);
149 const uint8_t* cp = RFM69::config;
151 if (config !=
NULL) cp = (
const uint8_t*) config;
152 while ((reg = (Reg) pgm_read_byte(cp++)) != 0)
153 write(reg, pgm_read_byte(cp++));
157 write(SYNC_VALUE1, &sync,
sizeof(sync));
204 set(TRANSMITTER_MODE);
205 while (!m_done)
yield();
213 RFM69::send(uint8_t dest, uint8_t port,
const void* buf,
size_t len)
219 return (
send(dest, port, vec));
223 RFM69::recv(uint8_t& src, uint8_t& port,
void* buf,
size_t len, uint32_t ms)
274 if (dBm < -18) dBm = -18;
else if (dBm > 13) dBm = 13;
275 uint8_t level = (dBm + 18) & OUTPUT_POWER_MASK;
276 uint8_t pa_level = read(PA_LEVEL) & ~OUTPUT_POWER_MASK;
277 write(PA_LEVEL, pa_level | level);
283 return ((-read(RSSI_VALUE)) >> 1);
290 write(TEMP1, TEMP_MEAS_START);
291 while (read(TEMP1) & TEMP_MEAS_RUNNING)
DELAY(100);
292 return (-read(TEMP2));
298 write(OSC1, RC_CAL_START);
299 while ((read(OSC1) & RC_CAL_DONE) == 0x00)
DELAY(100);
addr_t m_addr
Current network and device address.
uint8_t transfer(uint8_t data)
#define REG_VALUE16(reg, value)
void acquire(Driver *dev)
volatile bool m_avail
Message available. May be set by ISR.
static const size_t PAYLOAD_MAX
void read(void *buf, size_t count)
uint8_t m_dest
Latest message destination device address.
uint8_t device
Device address (LSB).
static uint32_t since(uint32_t start)
int16_t network
Network address.
const uint8_t RFM69::config[] __PROGMEM
void write(const void *buf, size_t count)
virtual void output_power_level(int8_t dBm)
virtual int send(uint8_t dest, uint8_t port, const iovec_t *vec)
RFM69(uint16_t net, uint8_t dev, Board::DigitalPin csn=Board::D10, Board::ExternalInterruptPin irq=Board::EXT0)
virtual bool begin(const void *config=NULL)
virtual void wakeup_on_radio()
#define REG_VALUE24(reg, value)
static const size_t HEADER_MAX
virtual int input_power_level()
virtual int recv(uint8_t &src, uint8_t &port, void *buf, size_t len, uint32_t ms=0L)
void iovec_arg(iovec_t *&vp, const void *buf, size_t size)
void iovec_end(iovec_t *&vp)
size_t iovec_size(const iovec_t *vec)
#define REG_VALUE8(reg, value)