anchor.diff:         $11 constant RF:PA
          $18 constant RF:LNA
          $1F constant RF:AFC
  -       $21 constant RF:FEI
          $24 constant RF:RSSI
          $27 constant RF:IRQ1
          $28 constant RF:IRQ2
          $2F constant RF:SYN1
  -       $30 constant RF:SYN2
  +       $31 constant RF:SYN3
          $39 constant RF:ADDR
          $3A constant RF:BCAST
          $3C constant RF:THRESH
  
positive.code:      6 bit constant RF:IRQ1_RXRDY
       3 bit constant RF:IRQ1_RSSI
       2 bit constant RF:IRQ1_TIMEOUT
       0 bit constant RF:IRQ1_SMATCH
  
       6 bit constant RF:IRQ2_FIFO_NE
       3 bit constant RF:IRQ2_SENT
       2 bit constant RF:IRQ2_RECVD
  
     0 variable rf.mode
     0 variable rf.last
     0 variable rf.rssi  \ RSSI signal strength of last reception
     0 variable rf.lna   \ Low Noise Amplifier setting (set by AGC)
     0 variable rf.afc   \ Auto Frequency Control offset
  
negative.code:   0 do  dup c@ RF:FIFO rf! 1+  loop drop ;
  
  : rf-parity ( -- u )  \ calculate group parity bits
    RF:SYN3 rf@ dup 4 lshift xor dup 2 lshift xor $C0 and ;
  
  \ this is the intended public API for the RF69 driver
  
  : rf-power ( n -- )  \ change TX power level (0..31)
    RF:PA rf@ $E0 and or RF:PA rf! ;
  
  : rf-sleep ( -- ) RF:M_SLEEP rf!mode ;  \ put radio module to sleep
  
  : rf-recv ( -- b )  \ check whether a packet has been received, return #bytes
    rf.mode @ RF:M_RX <> if
      0 rf.rssi !  0 rf.afc !
      RF:M_RX rf!mode
    else rf-rssi rf-status then
    RF:IRQ2 rf@  RF:IRQ2_CRCOK and if
      RF:FIFO rf@ 66 min \ fetch length and limit
      rf.buf over rf-n@spi
    else 0 then ;
  
  : rf-ack? ( ms -- b ) \ waits ms milliseconds for an ACK and returns #bytes recv'd
    0 rf.rssi !  0 rf.afc !
    RF:M_RX rf!mode
    0 do
      rf-status \ capture rssi, afc etc.
      RF:IRQ2 rf@  RF:IRQ2_CRCOK and if
        RF:FIFO rf@ 66 min \ fetch length and limit
        rf.buf over rf-n@spi
        unloop exit
      then
      1 ms
    loop
    RF:M_STDBY rf!mode \ kill RX
    0 ;
  
  : rf-send ( addr count hdr -- )  \ send out one packet
    RF:M_STDBY rf!mode
  