summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Barrios Romero <eldruin@gmail.com>2020-06-21 23:23:16 +0200
committerDiego Barrios Romero <eldruin@gmail.com>2020-06-21 23:23:16 +0200
commit570e89a0133f994a16aee320a6fa95fdc9d13073 (patch)
treece9fa539916537e5ad565179cda7c180f9064a97
parent39f90fde30125f649f2bbdc5497e9a119d0691ef (diff)
downloadads1x1x-async-570e89a0133f994a16aee320a6fa95fdc9d13073.tar.gz
ads1x1x-async-570e89a0133f994a16aee320a6fa95fdc9d13073.tar.xz
ads1x1x-async-570e89a0133f994a16aee320a6fa95fdc9d13073.zip
Add alternative address helper creation methods
-rw-r--r--src/types.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/types.rs b/src/types.rs
index c6bda1a..5ceabc4 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -176,6 +176,38 @@ impl SlaveAddr {
SlaveAddr::Alternative(a1, a0) => default | ((a1 as u8) << 1) | a0 as u8,
}
}
+
+ /// Create `SlaveAddr` instance corresponding to the address
+ /// effective when connecting the pin `ADDR` to GND (0x48).
+ ///
+ /// See [Table 4 in the datasheet](https://www.ti.com/lit/ds/symlink/ads1115.pdf#%5B%7B%22num%22%3A716%2C%22gen%22%3A0%7D%2C%7B%22name%22%3A%22XYZ%22%7D%2C0%2C602.2%2C0%5D).
+ pub fn new_gnd() -> Self {
+ SlaveAddr::default()
+ }
+
+ /// Create `SlaveAddr` instance corresponding to the address
+ /// effective when connecting the pin `ADDR` to VDD (0x49).
+ ///
+ /// See [Table 4 in the datasheet](https://www.ti.com/lit/ds/symlink/ads1115.pdf#%5B%7B%22num%22%3A716%2C%22gen%22%3A0%7D%2C%7B%22name%22%3A%22XYZ%22%7D%2C0%2C602.2%2C0%5D).
+ pub fn new_vdd() -> Self {
+ SlaveAddr::Alternative(false, true)
+ }
+
+ /// Create `SlaveAddr` instance corresponding to the address
+ /// effective when connecting the pin `ADDR` to SDA (0x4A).
+ ///
+ /// See [Table 4 in the datasheet](https://www.ti.com/lit/ds/symlink/ads1115.pdf#%5B%7B%22num%22%3A716%2C%22gen%22%3A0%7D%2C%7B%22name%22%3A%22XYZ%22%7D%2C0%2C602.2%2C0%5D).
+ pub fn new_sda() -> Self {
+ SlaveAddr::Alternative(true, false)
+ }
+
+ /// Create `SlaveAddr` instance corresponding to the address
+ /// effective when connecting the pin `ADDR` to SCL (0x4B).
+ ///
+ /// See [Table 4 in the datasheet](https://www.ti.com/lit/ds/symlink/ads1115.pdf#%5B%7B%22num%22%3A716%2C%22gen%22%3A0%7D%2C%7B%22name%22%3A%22XYZ%22%7D%2C0%2C602.2%2C0%5D).
+ pub fn new_scl() -> Self {
+ SlaveAddr::Alternative(true, true)
+ }
}
#[derive(Debug, Clone, PartialEq)]
@@ -243,4 +275,12 @@ mod tests {
assert_eq!(0b100_1010, SlaveAddr::Alternative(true, false).addr(ADDR));
assert_eq!(0b100_1011, SlaveAddr::Alternative(true, true).addr(ADDR));
}
+
+ #[test]
+ fn can_generate_alternative_addresses_using_helper_constructors() {
+ assert_eq!(0b100_1000, SlaveAddr::new_gnd().addr(ADDR));
+ assert_eq!(0b100_1001, SlaveAddr::new_vdd().addr(ADDR));
+ assert_eq!(0b100_1010, SlaveAddr::new_sda().addr(ADDR));
+ assert_eq!(0b100_1011, SlaveAddr::new_scl().addr(ADDR));
+ }
}