From e816d52de5b4a9fd5fe74547650f15173068b9ec Mon Sep 17 00:00:00 2001 From: sethp Date: Thu, 16 Feb 2023 16:50:29 +0000 Subject: [PATCH 1/8] chore(fix): `cargo fix` --- examples/serial_interrupt.rs | 1 - examples/spi_dma_loopback.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/serial_interrupt.rs b/examples/serial_interrupt.rs index b99081d..724ff21 100644 --- a/examples/serial_interrupt.rs +++ b/examples/serial_interrupt.rs @@ -14,7 +14,6 @@ use esp32c3_hal::{ peripherals::{self, Peripherals, UART0}, prelude::*, timer::TimerGroup, - uart::config::AtCmdConfig, Cpu, Rtc, Uart, }; use esp_backtrace as _; diff --git a/examples/spi_dma_loopback.rs b/examples/spi_dma_loopback.rs index 3112324..b47c8cd 100644 --- a/examples/spi_dma_loopback.rs +++ b/examples/spi_dma_loopback.rs @@ -29,7 +29,7 @@ use esp32c3_hal::{ Delay, Rtc, }; use esp_backtrace as _; -use esp_println::println; + use riscv_rt::entry; #[entry] From 1bd1bdfeea57b6c0c26905c36db869f4421f7a18 Mon Sep 17 00:00:00 2001 From: sethp Date: Thu, 16 Feb 2023 09:05:55 -0800 Subject: [PATCH 2/8] Update fixup.yml --- .github/workflows/fixup.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/fixup.yml b/.github/workflows/fixup.yml index 7af1adf..258d4e9 100644 --- a/.github/workflows/fixup.yml +++ b/.github/workflows/fixup.yml @@ -10,6 +10,7 @@ jobs: steps: - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v1 + - uses: actions-rs/toolchain@v1 - uses: actions-rs/cargo@v1 with: From fff703a9306ff642601e7329d40b2735407a1091 Mon Sep 17 00:00:00 2001 From: sethp Date: Thu, 16 Feb 2023 09:07:25 -0800 Subject: [PATCH 3/8] Update ci.yml --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 258cff8..796f210 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,8 @@ jobs: - uses: Swatinem/rust-cache@v1 - uses: actions-rs/cargo@v1 with: - command: check --all-targets + command: check + args: --all-targets # -------------------------------------------------------------------------- # Fmt @@ -37,7 +38,8 @@ jobs: - uses: Swatinem/rust-cache@v1 - uses: actions-rs/cargo@v1 with: - command: fmt --check + command: fmt + args: --check # -------------------------------------------------------------------------- # Clippy From 3e6d34627fd1e8fe867b952f19be8a179cdc548b Mon Sep 17 00:00:00 2001 From: sethp Date: Thu, 16 Feb 2023 09:10:05 -0800 Subject: [PATCH 4/8] Update fixup.yml --- .github/workflows/fixup.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/fixup.yml b/.github/workflows/fixup.yml index 258d4e9..4e4befc 100644 --- a/.github/workflows/fixup.yml +++ b/.github/workflows/fixup.yml @@ -10,7 +10,6 @@ jobs: steps: - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v1 - - uses: actions-rs/toolchain@v1 - uses: actions-rs/cargo@v1 with: @@ -21,7 +20,8 @@ jobs: - uses: actions-rs/cargo@v1 with: - command: clippy --fix --all-targets + command: clippy + args: --fix --all-targets - uses: stefanzweifel/git-auto-commit-action@v4 with: commit_message: 'chore(fix): `cargo clippy --fix`' From ebf0beb7adb46117eba710fe0235be0eac37daaf Mon Sep 17 00:00:00 2001 From: sethp Date: Thu, 16 Feb 2023 17:12:10 +0000 Subject: [PATCH 5/8] chore(fix): `cargo clippy --fix` --- examples/spi_dma_loopback.rs | 2 +- src/channel.rs | 2 +- src/color.rs | 14 +++++++------- src/display.rs | 16 ++++++++-------- src/gpio.rs | 10 +++++----- src/spi.rs | 4 ++-- src/timer.rs | 10 +++++----- src/video.rs | 10 +++++----- 8 files changed, 34 insertions(+), 34 deletions(-) diff --git a/examples/spi_dma_loopback.rs b/examples/spi_dma_loopback.rs index b47c8cd..905ee02 100644 --- a/examples/spi_dma_loopback.rs +++ b/examples/spi_dma_loopback.rs @@ -69,7 +69,7 @@ fn main() -> ! { let dma_channel = dma.channel0; let mut descriptors = [0u32; 8 * 3]; - let mut rx_descriptors = [0u32; 1 * 3]; + let mut rx_descriptors = [0u32; 3]; let mut spi = Spi::new_quad_send_only( peripherals.SPI2, diff --git a/src/channel.rs b/src/channel.rs index 91fa9c8..36f8cf2 100644 --- a/src/channel.rs +++ b/src/channel.rs @@ -51,7 +51,7 @@ pub fn channel() -> (Sender, Receiver) { inner: inner.clone(), }, Receiver { - inner: inner.clone(), + inner: inner, }, ) } diff --git a/src/color.rs b/src/color.rs index 79a13ac..6e3083a 100644 --- a/src/color.rs +++ b/src/color.rs @@ -9,9 +9,9 @@ pub fn rgb_from_byte(color: u8) -> (u8, u8, u8) { let highest = shifted >> 7; let rgb = shifted + highest; - let red3 = (rgb & 0b000_000_111) as u8; - let green3 = ((rgb >> 3) & 0b000_000_111) as u8; - let blue3 = ((rgb >> 6) & 0b000_000_111) as u8; + let red3 = (rgb & 0b0_0000_0111) as u8; + let green3 = ((rgb >> 3) & 0b0_0000_0111) as u8; + let blue3 = ((rgb >> 6) & 0b0_0000_0111) as u8; ( color3_to_byte(red3), @@ -26,8 +26,8 @@ pub fn byte_from_rgb(red: u8, green: u8, blue: u8) -> u8 { let b3 = blue / 36; let r: u16 = (r3 & 0b00000111).into(); - let g: u16 = (g3 as u16 & 0b00000111 as u16) << 3; - let b: u16 = (b3 as u16 & 0b00000111 as u16) << 6; + let g: u16 = (g3 as u16 & 0b00000111_u16) << 3; + let b: u16 = (b3 as u16 & 0b00000111_u16) << 6; let rgb3: u16 = r + g + b; // Convert to vgaterm color byte by rshift 1 (rgb3 >> 1) as u8 @@ -39,8 +39,8 @@ pub fn rgb3_from_rgb(red: u8, green: u8, blue: u8) -> u16 { let b3 = blue / 36; let r: u16 = (r3 & 0b00000111).into(); - let g: u16 = (g3 as u16 & 0b00000111 as u16) << 3; - let b: u16 = (b3 as u16 & 0b00000111 as u16) << 6; + let g: u16 = (g3 as u16 & 0b00000111_u16) << 3; + let b: u16 = (b3 as u16 & 0b00000111_u16) << 6; r + g + b } diff --git a/src/display.rs b/src/display.rs index b0e21ef..7c53ad8 100644 --- a/src/display.rs +++ b/src/display.rs @@ -126,7 +126,7 @@ impl Character { } pub fn char(&self) -> char { - let c: u32 = (self.character[0] as u32) + (self.character[1] as u32) << 8; + let c: u32 = ((self.character[0] as u32) + (self.character[1] as u32)) << 8; char::from_u32(c).unwrap_or(' ') } @@ -200,8 +200,8 @@ impl CharColor { pub fn background(&self) -> Rgb3 { let r = ((self.0 & 0b11000000) >> 5) as u8; - let g = ((self.0 & 0b00000011_00000000) >> 7) as u8; - let b = ((self.0 & 0b00001100_00000000) >> 9) as u8; + let g = ((self.0 & 0b0000_0011_0000_0000) >> 7) as u8; + let b = ((self.0 & 0b0000_1100_0000_0000) >> 9) as u8; Rgb3::from_rgb2(r, g, b) } @@ -239,17 +239,17 @@ impl CharColor { pub fn with_foreground(self, color: Rgb3) -> CharColor { let (r2, g2, b2) = color.rgb2(); - let c = (r2 + g2 << 2 + b2 << 4) as u16; + let c = ((r2 + g2) << (2 + b2) << 4) as u16; - CharColor((self.0 & 0b11111111_11000000) | c) + CharColor((self.0 & 0b1111_1111_1100_0000) | c) } pub fn with_background(self, color: Rgb3) -> CharColor { let (r2, g2, b2) = color.rgb2(); // Background starts at bit 6 - let c = ((r2 + g2 << 2 + b2 << 4) as u16) << 6; + let c = (((r2 + g2) << (2 + b2) << 4) as u16) << 6; - CharColor((self.0 & 0b11110000_00111111) | c) + CharColor((self.0 & 0b1111_0000_0011_1111) | c) } pub fn with_decoration( @@ -260,7 +260,7 @@ impl CharColor { blink: Option, ) -> CharColor { let decs = inverse.bit() + underline.bit() + strikethrough.bit() + blink.bit(); - self.0 = (self.0 & 0b00001111_11111111) | decs; + self.0 = (self.0 & 0b0000_1111_1111_1111) | decs; *self } diff --git a/src/gpio.rs b/src/gpio.rs index 1e17547..de4545d 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -13,11 +13,11 @@ pub const GPIO_IN: usize = GPIO_MMIO_ADDRESS + 0x003C; pub const GPIO_OUT_W1TS: usize = GPIO_MMIO_ADDRESS + 0x0008; const EMPTY_PIN: Option> = None; -const EMPTY_CB: Option) -> ()>> = None; +const EMPTY_CB: Option)>> = None; static mut PINS: [Option>; 32] = [EMPTY_PIN; 32]; static mut CALLBACKS: [Option>; 32] = [EMPTY_CB; 32]; -type Callback = dyn FnMut(&mut Box) -> (); +type Callback = dyn FnMut(&mut Box); fn callback_pin(source: usize) { unsafe { @@ -73,7 +73,7 @@ pub fn interrupt_enable(priority: interrupt::Priority) { pub fn pin_interrupt( mut input: impl InterruptPin + 'static, event: Event, - callback: impl FnMut(&mut Box) -> () + 'static, + callback: impl FnMut(&mut Box) + 'static, ) -> PinRef { let n = input.number() as usize; @@ -107,7 +107,7 @@ pub fn interrupt_disable(pin: PinRef) -> PinRef { pub fn pin_reenable( pin: PinRef, event: Event, - callback: impl FnMut(&mut Box) -> () + 'static, + callback: impl FnMut(&mut Box) + 'static, ) -> PinRef { riscv::interrupt::free(|| unsafe { let n = pin.0; @@ -215,7 +215,7 @@ pub fn read_byte_mask(mask: u32) -> u8 { // Shift the value right however many spaces from the mask to // the nth bit in the output value. let nth_value_bit = ((1 << b) & masked) >> (b - n_bit); - value = value | nth_value_bit; + value |= nth_value_bit; n_bit += 1; } diff --git a/src/spi.rs b/src/spi.rs index e942c57..a725272 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -27,7 +27,7 @@ static mut QSPI: Option< > = None; static mut DESCRIPTORS: [u32; 8 * 3] = [0u32; 8 * 3]; -static mut RX_DESCRIPTORS: [u32; 3] = [0u32; 1 * 3]; // should be zero, but dma will get mad +static mut RX_DESCRIPTORS: [u32; 3] = [0u32; 3]; // should be zero, but dma will get mad /// /// Configure and initialize the Quad SPI instance. Once configured @@ -169,7 +169,7 @@ fn clock_register(pre: u32, n: u32) -> u32 { let reg_value = l | h << 6 | n << 12 | pre << 18; - return reg_value; + reg_value } pub trait QuadInstance { diff --git a/src/timer.rs b/src/timer.rs index a28fbb7..608b7c2 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -23,13 +23,13 @@ use esp32c3_hal::{interrupt, interrupt::Priority}; use esp32c3_hal::{prelude::*, timer::Timer}; use fugit::HertzU64; -use riscv; + use alloc::boxed::Box; use core::cell::RefCell; static TIMER0: Mutex>>>> = Mutex::new(RefCell::new(None)); -static mut TIMER0_CALLBACK: Option ()>> = None; +static mut TIMER0_CALLBACK: Option> = None; static mut DELAY: Option = None; /// Uses the `SYSTIMER` peripheral for counting clock cycles, as @@ -77,7 +77,7 @@ impl Delay { pub fn deadline(&self, us: u64) -> u64 { let clocks = (us * self.freq.raw()) / HertzU64::MHz(1).raw(); - return SystemTimer::now().wrapping_add(clocks); + SystemTimer::now().wrapping_add(clocks) } pub fn wait_until(&self, deadline: u64) { @@ -140,7 +140,7 @@ pub fn enable_timer0_interrupt(priority: Priority) { } /// Start timer zero set for t microseconds -pub fn start_timer0_callback(t: u64, callback: impl FnMut() -> () + 'static) { +pub fn start_timer0_callback(t: u64, callback: impl FnMut() + 'static) { critical_section::with(|cs| { match TIMER0.borrow(cs).borrow_mut().as_mut() { Some(timer) => timer.start(t.micros()), @@ -153,7 +153,7 @@ pub fn start_timer0_callback(t: u64, callback: impl FnMut() -> () + 'static) { }) } -pub fn start_repeat_timer0_callback(t: u64, mut callback: impl FnMut() -> () + 'static) { +pub fn start_repeat_timer0_callback(t: u64, mut callback: impl FnMut() + 'static) { critical_section::with(|cs| { match TIMER0.borrow(cs).borrow_mut().as_mut() { Some(timer) => timer.start(t.micros()), diff --git a/src/video.rs b/src/video.rs index 1da0513..7d8b75a 100644 --- a/src/video.rs +++ b/src/video.rs @@ -42,15 +42,15 @@ pub fn four_vertical_columns(a: u8, b: u8, c: u8, d: u8) { BUFFER[i] = a; } - if p >= 160 && p < 320 { + if (160..320).contains(&p) { BUFFER[i] = b; } - if p >= 320 && p < 480 { + if (320..480).contains(&p) { BUFFER[i] = c; } - if p >= 480 && p < 640 { + if (480..640).contains(&p) { BUFFER[i] = d; } } @@ -91,12 +91,12 @@ pub fn test_pattern() -> [u8; 128] { } } } - return pattern; + pattern } pub fn load_from_slice(s: &[u8]) { riscv::interrupt::free(|| unsafe { - for (i, p) in s.into_iter().enumerate() { + for (i, p) in s.iter().enumerate() { if i >= BUFFER.len() { break; } From 2e25925a9ea148a32e78a8d97b686abaeb668b86 Mon Sep 17 00:00:00 2001 From: sethp Date: Thu, 16 Feb 2023 09:14:51 -0800 Subject: [PATCH 6/8] Update fixup.yml --- .github/workflows/fixup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fixup.yml b/.github/workflows/fixup.yml index 4e4befc..3a310ed 100644 --- a/.github/workflows/fixup.yml +++ b/.github/workflows/fixup.yml @@ -9,7 +9,7 @@ jobs: contents: write steps: - uses: actions/checkout@v3 - - uses: Swatinem/rust-cache@v1 + - uses: Swatinem/rust-cache@v2 - uses: actions-rs/cargo@v1 with: From 3adf02154e0e60715dfb8a9ac3a753f5bfb80150 Mon Sep 17 00:00:00 2001 From: sethp Date: Thu, 16 Feb 2023 17:16:54 +0000 Subject: [PATCH 7/8] chore(fix): `cargo clippy --fix` --- src/channel.rs | 2 +- src/spi.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/channel.rs b/src/channel.rs index 36f8cf2..38dbd35 100644 --- a/src/channel.rs +++ b/src/channel.rs @@ -51,7 +51,7 @@ pub fn channel() -> (Sender, Receiver) { inner: inner.clone(), }, Receiver { - inner: inner, + inner, }, ) } diff --git a/src/spi.rs b/src/spi.rs index a725272..d2a9ce6 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -167,9 +167,9 @@ fn clock_register(pre: u32, n: u32) -> u32 { let l = n; let h = ((n + 1) / 2).saturating_sub(1); - let reg_value = l | h << 6 | n << 12 | pre << 18; + - reg_value + l | h << 6 | n << 12 | pre << 18 } pub trait QuadInstance { From de27f576bb9dd41f42a131a8c98a087e1d7c704a Mon Sep 17 00:00:00 2001 From: sethp Date: Thu, 16 Feb 2023 17:20:51 +0000 Subject: [PATCH 8/8] chore(fmt): automated formatting --- src/channel.rs | 4 +--- src/spi.rs | 2 -- src/timer.rs | 2 -- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/channel.rs b/src/channel.rs index 38dbd35..97fec77 100644 --- a/src/channel.rs +++ b/src/channel.rs @@ -50,8 +50,6 @@ pub fn channel() -> (Sender, Receiver) { Sender { inner: inner.clone(), }, - Receiver { - inner, - }, + Receiver { inner }, ) } diff --git a/src/spi.rs b/src/spi.rs index d2a9ce6..5b58c33 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -167,8 +167,6 @@ fn clock_register(pre: u32, n: u32) -> u32 { let l = n; let h = ((n + 1) / 2).saturating_sub(1); - - l | h << 6 | n << 12 | pre << 18 } diff --git a/src/timer.rs b/src/timer.rs index 608b7c2..e557876 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -23,8 +23,6 @@ use esp32c3_hal::{interrupt, interrupt::Priority}; use esp32c3_hal::{prelude::*, timer::Timer}; use fugit::HertzU64; - - use alloc::boxed::Box; use core::cell::RefCell;