Skip to content

Commit dda3a2e

Browse files
committed
Merge branch 'main' of https://github.com/rustbox/esp32c3-vgaterm into ps2_impl
2 parents 81e62bb + de27f57 commit dda3a2e

File tree

11 files changed

+37
-41
lines changed

11 files changed

+37
-41
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ jobs:
2424
- uses: Swatinem/rust-cache@v2
2525
- uses: actions-rs/cargo@v1
2626
with:
27-
command: check --all-targets
27+
command: check
28+
args: --all-targets
2829

2930
# --------------------------------------------------------------------------
3031
# Fmt
@@ -37,7 +38,8 @@ jobs:
3738
- uses: Swatinem/rust-cache@v2
3839
- uses: actions-rs/cargo@v1
3940
with:
40-
command: fmt --check
41+
command: fmt
42+
args: --check
4143

4244
# --------------------------------------------------------------------------
4345
# Clippy

.github/workflows/fixup.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
contents: write
1010
steps:
1111
- uses: actions/checkout@v3
12-
- uses: Swatinem/rust-cache@v1
12+
- uses: Swatinem/rust-cache@v2
1313

1414
- uses: actions-rs/cargo@v1
1515
with:
@@ -20,7 +20,8 @@ jobs:
2020

2121
- uses: actions-rs/cargo@v1
2222
with:
23-
command: clippy --fix --all-targets
23+
command: clippy
24+
args: --fix --all-targets
2425
- uses: stefanzweifel/git-auto-commit-action@v4
2526
with:
2627
commit_message: 'chore(fix): `cargo clippy --fix`'

examples/serial_interrupt.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use esp32c3_hal::{
1414
peripherals::{self, Peripherals, UART0},
1515
prelude::*,
1616
timer::TimerGroup,
17-
uart::config::AtCmdConfig,
1817
Cpu, Rtc, Uart,
1918
};
2019
use esp_backtrace as _;

examples/spi_dma_loopback.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use esp32c3_hal::{
2929
Delay, Rtc,
3030
};
3131
use esp_backtrace as _;
32-
use esp_println::println;
32+
3333
use riscv_rt::entry;
3434

3535
#[entry]
@@ -69,7 +69,7 @@ fn main() -> ! {
6969
let dma_channel = dma.channel0;
7070

7171
let mut descriptors = [0u32; 8 * 3];
72-
let mut rx_descriptors = [0u32; 1 * 3];
72+
let mut rx_descriptors = [0u32; 3];
7373

7474
let mut spi = Spi::new_quad_send_only(
7575
peripherals.SPI2,

src/channel.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
5050
Sender {
5151
inner: inner.clone(),
5252
},
53-
Receiver {
54-
inner: inner.clone(),
55-
},
53+
Receiver { inner },
5654
)
5755
}

src/color.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ pub fn rgb_from_byte(color: u8) -> (u8, u8, u8) {
99
let highest = shifted >> 7;
1010
let rgb = shifted + highest;
1111

12-
let red3 = (rgb & 0b000_000_111) as u8;
13-
let green3 = ((rgb >> 3) & 0b000_000_111) as u8;
14-
let blue3 = ((rgb >> 6) & 0b000_000_111) as u8;
12+
let red3 = (rgb & 0b0_0000_0111) as u8;
13+
let green3 = ((rgb >> 3) & 0b0_0000_0111) as u8;
14+
let blue3 = ((rgb >> 6) & 0b0_0000_0111) as u8;
1515

1616
(
1717
color3_to_byte(red3),
@@ -26,8 +26,8 @@ pub fn byte_from_rgb(red: u8, green: u8, blue: u8) -> u8 {
2626
let b3 = blue / 36;
2727

2828
let r: u16 = (r3 & 0b00000111).into();
29-
let g: u16 = (g3 as u16 & 0b00000111 as u16) << 3;
30-
let b: u16 = (b3 as u16 & 0b00000111 as u16) << 6;
29+
let g: u16 = (g3 as u16 & 0b00000111_u16) << 3;
30+
let b: u16 = (b3 as u16 & 0b00000111_u16) << 6;
3131
let rgb3: u16 = r + g + b;
3232
// Convert to vgaterm color byte by rshift 1
3333
(rgb3 >> 1) as u8
@@ -39,8 +39,8 @@ pub fn rgb3_from_rgb(red: u8, green: u8, blue: u8) -> u16 {
3939
let b3 = blue / 36;
4040

4141
let r: u16 = (r3 & 0b00000111).into();
42-
let g: u16 = (g3 as u16 & 0b00000111 as u16) << 3;
43-
let b: u16 = (b3 as u16 & 0b00000111 as u16) << 6;
42+
let g: u16 = (g3 as u16 & 0b00000111_u16) << 3;
43+
let b: u16 = (b3 as u16 & 0b00000111_u16) << 6;
4444
r + g + b
4545
}
4646

src/display.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl Character {
126126
}
127127

128128
pub fn char(&self) -> char {
129-
let c: u32 = (self.character[0] as u32) + (self.character[1] as u32) << 8;
129+
let c: u32 = ((self.character[0] as u32) + (self.character[1] as u32)) << 8;
130130
char::from_u32(c).unwrap_or(' ')
131131
}
132132

@@ -200,8 +200,8 @@ impl CharColor {
200200

201201
pub fn background(&self) -> Rgb3 {
202202
let r = ((self.0 & 0b11000000) >> 5) as u8;
203-
let g = ((self.0 & 0b00000011_00000000) >> 7) as u8;
204-
let b = ((self.0 & 0b00001100_00000000) >> 9) as u8;
203+
let g = ((self.0 & 0b0000_0011_0000_0000) >> 7) as u8;
204+
let b = ((self.0 & 0b0000_1100_0000_0000) >> 9) as u8;
205205
Rgb3::from_rgb2(r, g, b)
206206
}
207207

@@ -239,17 +239,17 @@ impl CharColor {
239239

240240
pub fn with_foreground(self, color: Rgb3) -> CharColor {
241241
let (r2, g2, b2) = color.rgb2();
242-
let c = (r2 + g2 << 2 + b2 << 4) as u16;
242+
let c = ((r2 + g2) << (2 + b2) << 4) as u16;
243243

244-
CharColor((self.0 & 0b11111111_11000000) | c)
244+
CharColor((self.0 & 0b1111_1111_1100_0000) | c)
245245
}
246246

247247
pub fn with_background(self, color: Rgb3) -> CharColor {
248248
let (r2, g2, b2) = color.rgb2();
249249
// Background starts at bit 6
250-
let c = ((r2 + g2 << 2 + b2 << 4) as u16) << 6;
250+
let c = (((r2 + g2) << (2 + b2) << 4) as u16) << 6;
251251

252-
CharColor((self.0 & 0b11110000_00111111) | c)
252+
CharColor((self.0 & 0b1111_0000_0011_1111) | c)
253253
}
254254

255255
pub fn with_decoration(
@@ -260,7 +260,7 @@ impl CharColor {
260260
blink: Option<Blink>,
261261
) -> CharColor {
262262
let decs = inverse.bit() + underline.bit() + strikethrough.bit() + blink.bit();
263-
self.0 = (self.0 & 0b00001111_11111111) | decs;
263+
self.0 = (self.0 & 0b0000_1111_1111_1111) | decs;
264264
*self
265265
}
266266

src/gpio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ pub fn read_byte_mask(mask: u32) -> u8 {
286286
// Shift the value right however many spaces from the mask to
287287
// the nth bit in the output value.
288288
let nth_value_bit = ((1 << b) & masked) >> (b - n_bit);
289-
value = value | nth_value_bit;
289+
value |= nth_value_bit;
290290

291291
n_bit += 1;
292292
}

src/spi.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static mut QSPI: Option<
2727
> = None;
2828

2929
static mut DESCRIPTORS: [u32; 8 * 3] = [0u32; 8 * 3];
30-
static mut RX_DESCRIPTORS: [u32; 3] = [0u32; 1 * 3]; // should be zero, but dma will get mad
30+
static mut RX_DESCRIPTORS: [u32; 3] = [0u32; 3]; // should be zero, but dma will get mad
3131

3232
///
3333
/// Configure and initialize the Quad SPI instance. Once configured
@@ -167,9 +167,7 @@ fn clock_register(pre: u32, n: u32) -> u32 {
167167
let l = n;
168168
let h = ((n + 1) / 2).saturating_sub(1);
169169

170-
let reg_value = l | h << 6 | n << 12 | pre << 18;
171-
172-
return reg_value;
170+
l | h << 6 | n << 12 | pre << 18
173171
}
174172

175173
pub trait QuadInstance {

src/timer.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ use esp32c3_hal::{interrupt, interrupt::Priority};
2323
use esp32c3_hal::{prelude::*, timer::Timer};
2424
use fugit::HertzU64;
2525

26-
use riscv;
27-
2826
use alloc::boxed::Box;
2927
use core::cell::RefCell;
3028

3129
static TIMER0: Mutex<RefCell<Option<Timer<Timer0<TIMG0>>>>> = Mutex::new(RefCell::new(None));
32-
static mut TIMER0_CALLBACK: Option<Box<dyn FnMut() -> ()>> = None;
30+
static mut TIMER0_CALLBACK: Option<Box<dyn FnMut()>> = None;
3331
static mut DELAY: Option<Delay> = None;
3432

3533
/// Uses the `SYSTIMER` peripheral for counting clock cycles, as
@@ -77,7 +75,7 @@ impl Delay {
7775

7876
pub fn deadline(&self, us: u64) -> u64 {
7977
let clocks = (us * self.freq.raw()) / HertzU64::MHz(1).raw();
80-
return SystemTimer::now().wrapping_add(clocks);
78+
SystemTimer::now().wrapping_add(clocks)
8179
}
8280

8381
pub fn wait_until(&self, deadline: u64) {
@@ -140,7 +138,7 @@ pub fn enable_timer0_interrupt(priority: Priority) {
140138
}
141139

142140
/// Start timer zero set for t microseconds
143-
pub fn start_timer0_callback(t: u64, callback: impl FnMut() -> () + 'static) {
141+
pub fn start_timer0_callback(t: u64, callback: impl FnMut() + 'static) {
144142
critical_section::with(|cs| {
145143
match TIMER0.borrow(cs).borrow_mut().as_mut() {
146144
Some(timer) => timer.start(t.micros()),
@@ -153,7 +151,7 @@ pub fn start_timer0_callback(t: u64, callback: impl FnMut() -> () + 'static) {
153151
})
154152
}
155153

156-
pub fn start_repeat_timer0_callback(t: u64, mut callback: impl FnMut() -> () + 'static) {
154+
pub fn start_repeat_timer0_callback(t: u64, mut callback: impl FnMut() + 'static) {
157155
critical_section::with(|cs| {
158156
match TIMER0.borrow(cs).borrow_mut().as_mut() {
159157
Some(timer) => timer.start(t.micros()),

src/video.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ pub fn four_vertical_columns(a: u8, b: u8, c: u8, d: u8) {
4242
BUFFER[i] = a;
4343
}
4444

45-
if p >= 160 && p < 320 {
45+
if (160..320).contains(&p) {
4646
BUFFER[i] = b;
4747
}
4848

49-
if p >= 320 && p < 480 {
49+
if (320..480).contains(&p) {
5050
BUFFER[i] = c;
5151
}
5252

53-
if p >= 480 && p < 640 {
53+
if (480..640).contains(&p) {
5454
BUFFER[i] = d;
5555
}
5656
}
@@ -91,12 +91,12 @@ pub fn test_pattern() -> [u8; 128] {
9191
}
9292
}
9393
}
94-
return pattern;
94+
pattern
9595
}
9696

9797
pub fn load_from_slice(s: &[u8]) {
9898
riscv::interrupt::free(|| unsafe {
99-
for (i, p) in s.into_iter().enumerate() {
99+
for (i, p) in s.iter().enumerate() {
100100
if i >= BUFFER.len() {
101101
break;
102102
}

0 commit comments

Comments
 (0)