From 3a19a9fb778852a2753557a11b3048a6109f82d8 Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 30 Jan 2017 07:28:45 +0000 Subject: [PATCH] firmware: minor cleanup in board::si5324. --- artiq/firmware/libboard/si5324.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/artiq/firmware/libboard/si5324.rs b/artiq/firmware/libboard/si5324.rs index c58f20b41..dcf8d9556 100644 --- a/artiq/firmware/libboard/si5324.rs +++ b/artiq/firmware/libboard/si5324.rs @@ -1,11 +1,14 @@ +use core::result; use i2c; use clock; +type Result = result::Result; + const BUSNO: u8 = 0; const ADDRESS: u8 = 0x68; #[cfg(soc_platform = "kc705")] -fn pca9548_select(channel: u8) -> Result<(), &'static str> { +fn pca9548_select(channel: u8) -> Result<()> { i2c::start(BUSNO); if !i2c::write(BUSNO, (0x74 << 1)) { return Err("PCA9548 failed to ack write address") @@ -30,7 +33,7 @@ pub struct FrequencySettings { n32: u32 } -fn map_frequency_settings(settings: &FrequencySettings) -> Result { +fn map_frequency_settings(settings: &FrequencySettings) -> Result { if settings.nc1_ls != 0 && (settings.nc1_ls % 2) == 1 { return Err("NC1_LS must be 0 or even") } @@ -80,7 +83,7 @@ fn map_frequency_settings(settings: &FrequencySettings) -> Result Result<(), &'static str> { +fn write(reg: u8, val: u8) -> Result<()> { i2c::start(BUSNO); if !i2c::write(BUSNO, (ADDRESS << 1)) { return Err("Si5324 failed to ack write address") @@ -95,7 +98,7 @@ fn write(reg: u8, val: u8) -> Result<(), &'static str> { Ok(()) } -fn read(reg: u8) -> Result { +fn read(reg: u8) -> Result { i2c::start(BUSNO); if !i2c::write(BUSNO, (ADDRESS << 1)) { return Err("Si5324 failed to ack write address") @@ -112,15 +115,15 @@ fn read(reg: u8) -> Result { Ok(val) } -fn ident() -> Result { +fn ident() -> Result { Ok(((read(134)? as u16) << 8) | (read(135)? as u16)) } -fn locked() -> Result { +fn locked() -> Result { Ok((read(130)? & 0x01) == 0) // LOL_INT=1 } -pub fn setup_hitless_clock_switching(settings: &FrequencySettings) -> Result<(), &'static str> { +pub fn setup_hitless_clock_switching(settings: &FrequencySettings) -> Result<()> { let s = map_frequency_settings(settings)?; #[cfg(soc_platform = "kc705")]