[][src]Struct ham::rfm69::Rfm69

pub struct Rfm69 { /* fields omitted */ }

Implementations

impl Rfm69[src]

pub fn new(rst: Line, en: Line, spi: Spidev) -> Result<Self, Error>[src]

Creates a new instance of the device to control the RFM69HCW chip.

rst represents the reset pin on the chip. en should be enable pin on the chip. spi uses the all of the SPI pins, including the corresponding CS/CE pins. All SPI commands performed by Rfm69 are atomic allowing other SPI devices to be used alongside with the RFM69 chip. By default, the DIO pins are not used by this driver. This function configures some the RFM69 registers to recommened values and does some basic validation to ensure the device appears to be wired correctly.

Example

// On a Raspberry Pi 3
use gpio_cdev::Chip;
use spidev::Spidev;
use ham::rfm69::Rfm69;

let mut chip = Chip::new("/dev/gpiochip0").unwrap();
let rst = chip.get_line(24).unwrap();
let en = chip.get_line(3).unwrap();
let spidev = Spidev::open("/dev/spidev0.0").unwrap();
let rfm = Rfm69::new(rst, en, spidev).unwrap();
assert_eq!(0x24, rfm.version().unwrap());

pub fn set_mode(&mut self, mode: Mode) -> Result<(), Error>[src]

Sets the Mode of the Rfm69 chip and waits until device signals is ready.

If the Rfm69's mode is already in the given mode then this function does nothing. After setting the mode on the device this method will wait up to 10 ms, before timing out. The device starts in Standby mode.

This function changes OpMode on the RFM69 chip.

pub fn mode(&self) -> Mode[src]

Returns the Mode of the device stored by the controller.

The value returned is the Mode stored by the controller. This could differ from the actual device's mode if an error has occurred or if the write()/write_many() methods are used directly are used directly. mode_dev() will get the Mode from the device, instead of the stored mode.

Example

use ham::rfm69::{Rfm69,Mode};

let rfm = Rfm69::new(rst, en, spidev).unwrap();
assert_eq!(rfm.mode(), Mode::Standby);

pub fn mode_dev(&self) -> Result<Mode, Error>[src]

Returns the Mode of the actual RFM69 device.

The value returned is the Mode stored on the actual device. This is in contrast to mode() which gets the stored Mode from the controller.

use ham::rfm69::{Rfm69,Mode};

let rfm = Rfm69::new(rst, en, spidev).unwrap();
assert_eq!(rfm.mode_dev().unwrap(), Mode::Standby);

pub fn set_bitrate(&mut self, bitrate: u32) -> Result<(), Error>[src]

Sets the bitrate of the RFM69 device.

The RFM69 device will have better range at a lower. This function sets the BitrateMsb/Lsb registers. This function returns Err if bitrate is out of range or on IO errorswrite()/write_many()

Example

use ham::rfm69::Rfm69;

let mut rfm = Rfm69::new(rst, en, spidev).unwrap();
rfm.set_bitrate(50_000).unwrap(); // 50 kbps
assert_eq!(rfm.bitrate(), 50_000);
assert_eq!(rfm.bitrate_dev().unwrap(), 50_000);

pub fn bitrate(&self) -> u32[src]

Returns the bitrate of the device stored by the controller in bits per second.

The difference between this function and [bitrate_dev()] is this function returns a stored bitrate, while bitrate_dev() reads from the RFM69 chip and computes the bitrate. This function is faster but may differ from the actual device bitrate if write()/write_many() are used.

Example

use ham::rfm69::Rfm69;

let rfm = Rfm69::new(rst, en, spidev).unwrap();
assert_eq!(rfm.bitrate(), 4800); // 4.8 kpbs

[bitrate_dev()]:

pub fn bitrate_dev(&self) -> Result<u32, Error>[src]

Returns the bitrate from the RFM69 chip in bits per second.

The difference between this function and [bitrate()] is this function returns the bitrate from the actual device, while bitrate() read a value stored by the controller. Reads from the BitrateMsb/Lsb registers. This function returns Err if there is an SPI IO error.

Example

use ham::rfm69::Rfm69;

let rfm = Rfm69::new(rst, en, spidev).unwrap();
assert_eq!(rfm.bitrate_dev().unwrap(), 4800); // 4.8 kpbs

pub fn set_frequency(&self, frequency: u32) -> Result<(), Error>[src]

pub fn frequency(&self) -> Result<u32, Error>[src]

pub fn set_config(&mut self, config: PacketConfig) -> Result<(), Error>[src]

Sets the packet configuration of the RFM69 chip.

config represents a variety of different options to configure the RFM69 chip. Before writing the configuration to the device, the configuration is validated with PacketConfig::validate() to ensure make sure there are no conflicting options set. By default these options are set to the Default implementation for PacketConfig values when the RFM69 controller is created. These options are detailed more on the PacketConfig page. This function sets the PacketConfig1, PacketConfig2, PayloadLength, NodeAddrs, BroadcastAddrs, and FifoThresh registers. This function returns Err if the configuration fails to validate or there is an SPI IO error.

Example

use ham::rfm69::{Rfm69,PacketConfig};

let mut rfm = Rfm69::new(rst, en, spidev).unwrap();
let mut pc = PacketConfig::default();
pc = pc.set_variable(true); // set the RFM69 chip the receive packets in variable format
pc = pc.set_len(128); // set the maximum length of packets to be received.
rfm.set_config(pc).unwrap();
assert_eq!(rfm.config(), pc);
assert_eq!(rfm.config_dev().unwrap(), pc);

pub fn config(&self) -> PacketConfig[src]

Returns the packet configuration from the controller.

The difference between this function and config_dev() is this function returns the configuration stored by the controller, while the latter reads the configuration from the RFM69 chip. This function is faster but may differ from the device configuration if write()/write_many() are used.

Example

use ham::rfm69::{Rfm69,PacketConfig};

let rfm = Rfm69::new(rst, en, spidev).unwrap();
assert_eq!(rfm.config(), PacketConfig::default());

pub fn config_dev(&self) -> Result<PacketConfig, Error>[src]

Reads and returns the packet configuration from the RFM69 chip.

The difference between this function and config() is that this function reads the configuration for the actual device, while the latter returns the configuration stored by the controller. This function reads the PacketConfig1, PacketConfig2, PayloadLength, NodeAddrs, BroadcastAddrs, and FifoThresh registers. This function returns Err if there is an SPI IO error.

Example

use ham::rfm69::{Rfm69,PacketConfig};

let rfm = Rfm69::new(rst, en, spidev).unwrap();
assert_eq!(rfm.config_dev().unwrap(), PacketConfig::default());

pub fn set_sync<T: AsRef<SyncConfig>>(&mut self, config: T) -> Result<(), Error>[src]

Sets the sync word configuration of the RFM69 chip.

config represents the Sync word ocnfiguration used to tell which packets should be received by the Rfm69 chip. By default, the sync word configuration is set to the values specified by the Default implementation for SyncConfig when the controller is created. More information on sync word configuration options can be found on SyncConfig page. This function sets the SyncConfig, and SyncValue1-9 registers This function returns Err if there is an SPI IO error.

Example

use ham::rfm69::{Rfm69,SyncConfig};

let mut rfm = Rfm69::new(rst, en, spidev).unwrap();
let sc = *SyncConfig::default().set_sync_word(&[0x56, 0xa9, 0x0b, 0x9a]).set_len(4); // this is the configuration used by the PacketReceiver/Sender impls
rfm.set_sync(sc).unwrap();
assert_eq!(rfm.sync(), sc);
assert_eq!(rfm.sync_dev().unwrap(), sc);

pub fn sync(&self) -> SyncConfig[src]

Returns the sync word configuration from the controller.

The difference between this function and sync_dev() is this function returns the configuration stored by the controller, while the latter reads the configuration from the RFM69 chip. This function is faster but may differ from the actual device bitrate if write()/write_many() are used.

Example

use ham::rfm69::{Rfm69,SyncConfig};

let mut rfm = Rfm69::new(rst, en, spidev).unwrap();
assert_eq!(rfm.sync(), SyncConfig::default());

pub fn sync_dev(&self) -> Result<SyncConfig, Error>[src]

Reads and returns the sync word configuration from the RFM69 chip.

The difference between this function and sync() is this function reads the sync word configuration from the actual device, while the latter returns the configuration stored by the controller. This function reads the SyncConfig, and SyncValue1-9 registers This function returns Err if there is an SPI IO error.

Example

use ham::rfm69::{Rfm69,SyncConfig};

let mut rfm = Rfm69::new(rst, en, spidev).unwrap();
assert_eq!(rfm.sync_dev().unwrap(), SyncConfig::default());

pub fn set_aes(&self, key: &[u8; 16]) -> Result<(), Error>[src]

Sets the AES key to be used when sending or receiving packets.

This method only sets the AES key; it does not enable AES encryption/decryption. It can be enabled with set_config(). This function set the AesKey1-16 registers. This function returns Err if there is an SPI IO error. set_config(): AesKey1-16:

Example

use ham::rfm69::{Rfm69};

let mut rfm = Rfm69::new(rst, en, spidev).unwrap();

pub fn set_preamble_len(&mut self, len: u16) -> Result<(), Error>[src]

Sets the preamble length in bytes of the packets sent or received by the RFM69 chip

This function sets the PreambleMsb/Lsb on the device. This function returns Err if there is an SPI IO error.

Example

use ham::rfm69::Rfm69;

let mut rfm = Rfm69::new(rst, en, spidev).unwrap();
rfm.set_preamble_len(1024).unwrap();
assert_eq!(rfm.preamble_len(), 1024);
assert_eq!(rfm.preamble_len_dev().unwrap(), 1024);

pub fn preamble_len(&self) -> u16[src]

Returns the preamble length in bytes of packets.

The difference between this function and preamble_len_dev() is this function returns the preamble length stored by the controller, while the latter reads the actual preamble length from the device. This function is faster but may differ from the actual device if write()/write_many() are used.

Example

use ham::rfm69::Rfm69;

let rfm = Rfm69::new(rst, en, spidev).unwrap();
assert_eq!(rfm.preamble_len(), 3);

pub fn preamble_len_dev(&self) -> Result<u16, Error>[src]

Returns the preamble length in bytes of packet.

The difference between this function and preamble_len(), is this function returns the preamble length from the actual device, while the latter returns the preamble length from a stored value by the controller. This function returns Err if there is an SPI IO error.

Example

use ham::rfm69::Rfm69;

let rfm = Rfm69::new(rst, en, spidev).unwrap();
assert_eq!(rfm.preamble_len_dev().unwrap(), 3);

pub fn set_dios(&mut self, dios: &[Option<Line>])[src]

Adds or removes Gpio lines to correspond to the different DIO pins.

The RFM69 chip has 6 DIO pins that provide various configurable interrupts. If dios is shorter than 6 elements, then only the first lines are overwritten while the remaining remain intact. If dios is longer than 6 elements, then the remainging elements after the first 6 are ignored. This controller can operate without using any DIO pins by repeatingly querying the device over SPI for the status of certain interrupts. Adding them may improve CPU usage by eliminating busy waiting for certain operations.

Example

use gpio_cdev::Chip;
use spidev::Spidev;
use ham::rfm69::{Rfm69};

let mut chip = Chip::new("/dev/gpiochip0").unwrap();
let rst = chip.get_line(24).unwrap();
let en = chip.get_line(3).unwrap();
let spidev = Spidev::open("/dev/spidev0.0").unwrap();
let mut rfm = Rfm69::new(rst, en, spidev).unwrap();
let d0 = chip.get_line(17).unwrap();
let d1 = chip.get_line(27).unwrap();
rfm.set_dios(&[Some(d0), Some(d1)]);

pub fn set_dio(&mut self, index: u8, dio: Option<Line>)[src]

Adds or removes GPIO lines that correspond to the different DIO pins.

The RFM69 chip has 6 DIO pins that provide various configurable interrupts. This controller can operate without using any DIO pins by repeatingly querying the device over SPI for the status of certain interrupts. Adding them may improve CPU usage by eliminating busy waiting for certain operations.

Example

use gpio_cdev::Chip;
use spidev::Spidev;
use ham::rfm69::{Rfm69};

let mut chip = Chip::new("/dev/gpiochip0").unwrap();
let rst = chip.get_line(24).unwrap();
let en = chip.get_line(3).unwrap();
let spidev = Spidev::open("/dev/spidev0.0").unwrap();
let mut rfm = Rfm69::new(rst, en, spidev).unwrap();
let d0 = chip.get_line(17).unwrap();
rfm.set_dio(0, Some(d0)); // set the DIO pin zero

Panics

This function will panic if index is greater than or equal to 6.

pub fn dios(&self) -> &[Option<Line>; 6][src]

pub fn set_dio_mapping(&mut self, dio_map: DioMapping) -> Result<(), Error>[src]

pub fn dio_mapping(&self) -> DioMapping[src]

pub fn dio_mapping_dev(&self) -> Result<DioMapping, Error>[src]

pub fn configure_defaults(&mut self) -> Result<(), Error>[src]

Configures the RFM69 chip its recommended default settings.

The method is called by new() during initialization. This method the PacketConfig, SyncConfig, and DioMapping to their Default values.

Example

use ham::rfm69::{Rfm69,PacketConfig};

let mut rfm = Rfm69::new(rst, en, spidev).unwrap().reset().unwrap();
assert_eq!(rfm.config_dev().unwrap(), PacketConfig::rst_value());
rfm.configure_defaults().unwrap();
assert_eq!(rfm.config_dev().unwrap(), PacketConfig::default());

pub fn reset(self) -> Result<Self, Error>[src]

Resets the RFM69 chip using the RST pin, and then performs simple validations on the chip.

Resetting the RFM69 chip clears every register on the device, and resets them to their built-in reset values. It is important to note that these values differ from the default values set by Rfm69::new() . When new() is called it configures the Rfm69 chip to recommended defaults provided by the default methods for the different configuration structs. This method is the easiest way to restore the built-in reset values. This function will return Err if the device version fails to validate after the reset or if the Mode is not reset to Standby.

Example

use ham::rfm69::{Rfm69,PacketConfig};

let rfm = Rfm69::new(rst, en, spidev).unwrap();
assert_eq!(rfm.config_dev().unwrap(), PacketConfig::default()); // config is set to recommended values
let rfm = rfm.reset().unwrap(); // Reset the chip
assert_eq!(rfm.config_dev().unwrap(), PacketConfig::rst_value()); // config is now set to reset values

pub fn validate_dev(&self) -> Result<(), Error>[src]

pub fn read(&self, reg: Register) -> Result<u8, Error>[src]

pub fn read_many(&self, reg: Register, buf: &mut [u8]) -> Result<(), Error>[src]

pub fn write(&self, reg: Register, val: u8) -> Result<(), Error>[src]

pub fn write_many(&self, reg: Register, buf: &[u8]) -> Result<(), Error>[src]

pub fn rssi(&self) -> Result<f32, Error>[src]

pub fn read_all(&self) -> Result<[u8; 78], Error>[src]

pub fn set_power(&self, power: i8) -> Result<(), Error>[src]

pub fn power(&self) -> Result<i8, Error>[src]

pub fn temp(&self) -> Result<i8, Error>[src]

pub fn send(&mut self, payload: &[u8]) -> Result<(), Error>[src]

pub fn recv(
    &mut self,
    buf: &mut [u8],
    timeout: Duration
) -> Result<usize, Error>
[src]

pub fn set_rxbw(&self, bw: Bw) -> Result<(), Error>[src]

pub fn rxbw(&self) -> Result<Bw, Error>[src]

pub fn set_afcbw(&self, bw: Bw) -> Result<(), Error>[src]

pub fn afcbw(&self) -> Result<Bw, Error>[src]

pub fn set_verbose(&mut self, verbose: bool)[src]

Sets if the controller should write debug information to stderr.

By default verbose is false. This function has no affect on the actual operation of the RFm69 chip.

Example

use ham::rfm69::Rfm69;

let mut rfm = Rfm69::new(rst, en, spidev).unwrap();
rfm.set_verbose(true); // defaults to false

pub fn version(&self) -> Result<u8, Error>[src]

Reads and returns the version from the device.

This value is read from the Version register. The version should always be 0x24 (36).

Example

use ham::rfm69::Rfm69;

let rfm = Rfm69::new(rst, en, spidev).unwrap();
assert_eq!(rfm.version().unwrap(), 0x24);

Trait Implementations

impl Drop for Rfm69[src]

impl IntoPacketReceiver for Rfm69[src]

impl IntoPacketSender for Rfm69[src]

type Send = Rfm69PS

Auto Trait Implementations

impl RefUnwindSafe for Rfm69

impl Send for Rfm69

impl Sync for Rfm69

impl Unpin for Rfm69

impl UnwindSafe for Rfm69

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> IntoPacketReceiver for T where
    T: PacketReceiver
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.