Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…o ps2_impl
  • Loading branch information
sethp committed Feb 16, 2023
2 parents 81e62bb + de27f57 commit dda3a2e
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 41 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ jobs:
- uses: Swatinem/rust-cache@v2
- uses: actions-rs/cargo@v1
with:
command: check --all-targets
command: check
args: --all-targets

# --------------------------------------------------------------------------
# Fmt
Expand All @@ -37,7 +38,8 @@ jobs:
- uses: Swatinem/rust-cache@v2
- uses: actions-rs/cargo@v1
with:
command: fmt --check
command: fmt
args: --check

# --------------------------------------------------------------------------
# Clippy
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/fixup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -20,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`'
Expand Down
1 change: 0 additions & 1 deletion examples/serial_interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use esp32c3_hal::{
peripherals::{self, Peripherals, UART0},
prelude::*,
timer::TimerGroup,
uart::config::AtCmdConfig,
Cpu, Rtc, Uart,
};
use esp_backtrace as _;
Expand Down
4 changes: 2 additions & 2 deletions examples/spi_dma_loopback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use esp32c3_hal::{
Delay, Rtc,
};
use esp_backtrace as _;
use esp_println::println;

use riscv_rt::entry;

#[entry]
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
Sender {
inner: inner.clone(),
},
Receiver {
inner: inner.clone(),
},
Receiver { inner },
)
}
14 changes: 7 additions & 7 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand All @@ -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
}

Expand Down
16 changes: 8 additions & 8 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ')
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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(
Expand All @@ -260,7 +260,7 @@ impl CharColor {
blink: Option<Blink>,
) -> 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
}

Expand Down
2 changes: 1 addition & 1 deletion src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,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;
}
Expand Down
6 changes: 2 additions & 4 deletions src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -167,9 +167,7 @@ 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;

return reg_value;
l | h << 6 | n << 12 | pre << 18
}

pub trait QuadInstance {
Expand Down
10 changes: 4 additions & 6 deletions src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ 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<RefCell<Option<Timer<Timer0<TIMG0>>>>> = Mutex::new(RefCell::new(None));
static mut TIMER0_CALLBACK: Option<Box<dyn FnMut() -> ()>> = None;
static mut TIMER0_CALLBACK: Option<Box<dyn FnMut()>> = None;
static mut DELAY: Option<Delay> = None;

/// Uses the `SYSTIMER` peripheral for counting clock cycles, as
Expand Down Expand Up @@ -77,7 +75,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) {
Expand Down Expand Up @@ -140,7 +138,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()),
Expand All @@ -153,7 +151,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()),
Expand Down
10 changes: 5 additions & 5 deletions src/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit dda3a2e

Please sign in to comment.