From b869cf9a38004039c9725054cdad6748c1d8b678 Mon Sep 17 00:00:00 2001 From: Andre Richter Date: Tue, 3 Apr 2018 21:00:14 +0200 Subject: [PATCH] Correct stuff clippy complained about --- 03_uart1/src/gpio.rs | 6 +++--- 03_uart1/src/main.rs | 2 +- 03_uart1/src/uart.rs | 2 +- 04_mailboxes/src/gpio.rs | 6 +++--- 04_mailboxes/src/main.rs | 2 +- 04_mailboxes/src/mbox.rs | 12 ++++++------ 04_mailboxes/src/uart.rs | 2 +- 05_uart0/src/gpio.rs | 6 +++--- 05_uart0/src/main.rs | 4 ++-- 05_uart0/src/mbox.rs | 14 +++++++------- 05_uart0/src/uart.rs | 10 +++++----- 11 files changed, 33 insertions(+), 33 deletions(-) diff --git a/03_uart1/src/gpio.rs b/03_uart1/src/gpio.rs index 03914da2..9db608e8 100644 --- a/03_uart1/src/gpio.rs +++ b/03_uart1/src/gpio.rs @@ -25,6 +25,6 @@ use volatile_register::RW; use super::MMIO_BASE; -pub const GPFSEL1: *const RW = (MMIO_BASE + 0x00200004) as *const RW; -pub const GPPUD: *const RW = (MMIO_BASE + 0x00200094) as *const RW; -pub const GPPUDCLK0: *const RW = (MMIO_BASE + 0x00200098) as *const RW; +pub const GPFSEL1: *const RW = (MMIO_BASE + 0x0020_0004) as *const RW; +pub const GPPUD: *const RW = (MMIO_BASE + 0x0020_0094) as *const RW; +pub const GPPUDCLK0: *const RW = (MMIO_BASE + 0x0020_0098) as *const RW; diff --git a/03_uart1/src/main.rs b/03_uart1/src/main.rs index 012e54a2..018590d6 100644 --- a/03_uart1/src/main.rs +++ b/03_uart1/src/main.rs @@ -28,7 +28,7 @@ extern crate raspi3_glue; extern crate volatile_register; -const MMIO_BASE: u32 = 0x3F000000; +const MMIO_BASE: u32 = 0x3F00_0000; mod gpio; mod uart; diff --git a/03_uart1/src/uart.rs b/03_uart1/src/uart.rs index 09fbe060..ca6316b9 100644 --- a/03_uart1/src/uart.rs +++ b/03_uart1/src/uart.rs @@ -26,7 +26,7 @@ use super::MMIO_BASE; use volatile_register::*; use gpio; -const MINI_UART_BASE: u32 = MMIO_BASE + 0x215000; +const MINI_UART_BASE: u32 = MMIO_BASE + 0x21_5000; /// Auxilary mini UART registers #[allow(non_snake_case)] diff --git a/04_mailboxes/src/gpio.rs b/04_mailboxes/src/gpio.rs index 03914da2..9db608e8 100644 --- a/04_mailboxes/src/gpio.rs +++ b/04_mailboxes/src/gpio.rs @@ -25,6 +25,6 @@ use volatile_register::RW; use super::MMIO_BASE; -pub const GPFSEL1: *const RW = (MMIO_BASE + 0x00200004) as *const RW; -pub const GPPUD: *const RW = (MMIO_BASE + 0x00200094) as *const RW; -pub const GPPUDCLK0: *const RW = (MMIO_BASE + 0x00200098) as *const RW; +pub const GPFSEL1: *const RW = (MMIO_BASE + 0x0020_0004) as *const RW; +pub const GPPUD: *const RW = (MMIO_BASE + 0x0020_0094) as *const RW; +pub const GPPUDCLK0: *const RW = (MMIO_BASE + 0x0020_0098) as *const RW; diff --git a/04_mailboxes/src/main.rs b/04_mailboxes/src/main.rs index f20cae78..54eef1ef 100644 --- a/04_mailboxes/src/main.rs +++ b/04_mailboxes/src/main.rs @@ -29,7 +29,7 @@ extern crate raspi3_glue; extern crate rlibc; // for memset et al.b extern crate volatile_register; -const MMIO_BASE: u32 = 0x3F000000; +const MMIO_BASE: u32 = 0x3F00_0000; mod mbox; mod gpio; diff --git a/04_mailboxes/src/mbox.rs b/04_mailboxes/src/mbox.rs index 9f5845cb..7bad0bfb 100644 --- a/04_mailboxes/src/mbox.rs +++ b/04_mailboxes/src/mbox.rs @@ -59,13 +59,13 @@ pub mod tag { // Responses mod response { - pub const SUCCESS: u32 = 0x80000000; - pub const ERROR: u32 = 0x80000001; // error parsing request buffer (partial response) + pub const SUCCESS: u32 = 0x8000_0000; + pub const ERROR: u32 = 0x8000_0001; // error parsing request buffer (partial response) } pub const REQUEST: u32 = 0; -const FULL: u32 = 0x80000000; -const EMPTY: u32 = 0x40000000; +const FULL: u32 = 0x8000_0000; +const EMPTY: u32 = 0x4000_0000; // Public interface to the mailbox #[repr(C)] @@ -92,7 +92,7 @@ impl Mbox { // wait until we can write to the mailbox loop { unsafe { - if !(((*self.registers).STATUS.read() & FULL) == FULL) { + if ((*self.registers).STATUS.read() & FULL) != FULL { break; } asm!("nop" :::: "volatile"); @@ -111,7 +111,7 @@ impl Mbox { // is there a response? loop { unsafe { - if !(((*self.registers).STATUS.read() & EMPTY) == EMPTY) { + if ((*self.registers).STATUS.read() & EMPTY) != EMPTY { break; } asm!("nop" :::: "volatile"); diff --git a/04_mailboxes/src/uart.rs b/04_mailboxes/src/uart.rs index 31b24c8d..39b0ab08 100644 --- a/04_mailboxes/src/uart.rs +++ b/04_mailboxes/src/uart.rs @@ -26,7 +26,7 @@ use super::MMIO_BASE; use volatile_register::*; use gpio; -const MINI_UART_BASE: u32 = MMIO_BASE + 0x215000; +const MINI_UART_BASE: u32 = MMIO_BASE + 0x21_5000; /// Auxilary mini UART registers #[allow(non_snake_case)] diff --git a/05_uart0/src/gpio.rs b/05_uart0/src/gpio.rs index 03914da2..9db608e8 100644 --- a/05_uart0/src/gpio.rs +++ b/05_uart0/src/gpio.rs @@ -25,6 +25,6 @@ use volatile_register::RW; use super::MMIO_BASE; -pub const GPFSEL1: *const RW = (MMIO_BASE + 0x00200004) as *const RW; -pub const GPPUD: *const RW = (MMIO_BASE + 0x00200094) as *const RW; -pub const GPPUDCLK0: *const RW = (MMIO_BASE + 0x00200098) as *const RW; +pub const GPFSEL1: *const RW = (MMIO_BASE + 0x0020_0004) as *const RW; +pub const GPPUD: *const RW = (MMIO_BASE + 0x0020_0094) as *const RW; +pub const GPPUDCLK0: *const RW = (MMIO_BASE + 0x0020_0098) as *const RW; diff --git a/05_uart0/src/main.rs b/05_uart0/src/main.rs index 8b6c1d12..efe03785 100644 --- a/05_uart0/src/main.rs +++ b/05_uart0/src/main.rs @@ -29,7 +29,7 @@ extern crate raspi3_glue; extern crate rlibc; // for memset et al.b extern crate volatile_register; -const MMIO_BASE: u32 = 0x3F000000; +const MMIO_BASE: u32 = 0x3F00_0000; mod mbox; mod gpio; @@ -42,7 +42,7 @@ fn main() { let uart = uart::Uart::new(); // set up serial console - if let Err(_) = uart.init(&mut mbox) { + if uart.init(&mut mbox).is_err() { return; // If UART fails, abort early } diff --git a/05_uart0/src/mbox.rs b/05_uart0/src/mbox.rs index 537bafbd..3a7676f6 100644 --- a/05_uart0/src/mbox.rs +++ b/05_uart0/src/mbox.rs @@ -60,18 +60,18 @@ pub mod tag { // Clocks pub mod clock { - pub const UART: u32 = 0x000000002; + pub const UART: u32 = 0x0_0000_0002; } // Responses mod response { - pub const SUCCESS: u32 = 0x80000000; - pub const ERROR: u32 = 0x80000001; // error parsing request buffer (partial response) + pub const SUCCESS: u32 = 0x8000_0000; + pub const ERROR: u32 = 0x8000_0001; // error parsing request buffer (partial response) } pub const REQUEST: u32 = 0; -const FULL: u32 = 0x80000000; -const EMPTY: u32 = 0x40000000; +const FULL: u32 = 0x8000_0000; +const EMPTY: u32 = 0x4000_0000; // Public interface to the mailbox #[repr(C)] @@ -98,7 +98,7 @@ impl Mbox { // wait until we can write to the mailbox loop { unsafe { - if !(((*self.registers).STATUS.read() & FULL) == FULL) { + if ((*self.registers).STATUS.read() & FULL) != FULL { break; } asm!("nop" :::: "volatile"); @@ -117,7 +117,7 @@ impl Mbox { // is there a response? loop { unsafe { - if !(((*self.registers).STATUS.read() & EMPTY) == EMPTY) { + if ((*self.registers).STATUS.read() & EMPTY) != EMPTY { break; } asm!("nop" :::: "volatile"); diff --git a/05_uart0/src/uart.rs b/05_uart0/src/uart.rs index a724c8df..b605f8dc 100644 --- a/05_uart0/src/uart.rs +++ b/05_uart0/src/uart.rs @@ -28,7 +28,7 @@ use mbox; use gpio; use core::sync::atomic::{compiler_fence, Ordering}; -const UART_BASE: u32 = MMIO_BASE + 0x201000; +const UART_BASE: u32 = MMIO_BASE + 0x20_1000; // PL011 UART registers #[allow(non_snake_case)] @@ -74,7 +74,7 @@ impl Uart { mbox.buffer[3] = 12; mbox.buffer[4] = 8; mbox.buffer[5] = mbox::clock::UART; // UART clock - mbox.buffer[6] = 4000000; // 4Mhz + mbox.buffer[6] = 4_000_000; // 4Mhz mbox.buffer[7] = 0; // skip turbo setting mbox.buffer[8] = mbox::tag::LAST; @@ -83,7 +83,7 @@ impl Uart { // is done by a store operation as well). compiler_fence(Ordering::SeqCst); - if let Err(_) = mbox.call(mbox::channel::PROP) { + if mbox.call(mbox::channel::PROP).is_err() { return Err(UartError::MailboxError); // Abort if UART clocks couldn't be set }; @@ -124,7 +124,7 @@ impl Uart { unsafe { // wait until we can send loop { - if !(((*self.registers).FR.read() & 0x20) == 0x20) { + if ((*self.registers).FR.read() & 0x20) != 0x20 { break; } asm!("nop" :::: "volatile"); @@ -140,7 +140,7 @@ impl Uart { unsafe { // wait until something is in the buffer loop { - if !(((*self.registers).FR.read() & 0x10) == 0x10) { + if ((*self.registers).FR.read() & 0x10) != 0x10 { break; } asm!("nop" :::: "volatile");