From db94099429b341c60ceb1be6523d7b6e0d1f6bc3 Mon Sep 17 00:00:00 2001 From: benstrb Date: Mon, 20 Apr 2026 22:54:40 +0200 Subject: [PATCH] fixed --- src/main.rs | 173 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 132 insertions(+), 41 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1fd6e31..f69e75f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,6 +39,12 @@ const DIGIT_HEIGHT: usize = 350; const DIGIT_WIDTH: usize = 150; const DIGIT_MARGIN: usize = 20; +const FIRST_DIGIT: usize = DIGIT_WIDTH; +const SECOND_DIGIT: usize = DIGIT_WIDTH * 2 + DIGIT_MARGIN; +const THIRD_DIGIT: usize = WIDTH - DIGIT_WIDTH - DIGIT_MARGIN; +const FOURTH_DIGIT: usize = WIDTH; +const COLON: usize = WIDTH / 2 + LINE_WIDTH / 2; + #[entry] fn main() -> ! { let peripherals = Peripherals::take().unwrap(); @@ -259,31 +265,8 @@ fn main() -> ! { (0..480 * 800).for_each(|i| BUFF[i] = 0xFF000000); } - draw_0(&mut display, ltdc::Layer::L1, (DIGIT_WIDTH, 65), 0xFFFFFFFF); - draw_5( - &mut display, - ltdc::Layer::L1, - (DIGIT_WIDTH * 2 + DIGIT_MARGIN, 65), - 0xFFFFFFFF, - ); - draw_colon( - &mut display, - ltdc::Layer::L1, - (WIDTH / 2 + LINE_WIDTH / 2, 65), - 0xFFFFFFFF, - ); - draw_2( - &mut display, - ltdc::Layer::L1, - (WIDTH - DIGIT_WIDTH - DIGIT_MARGIN, 65), - 0xFFFFFFFF, - ); - draw_8(&mut display, ltdc::Layer::L1, (WIDTH, 65), 0xFFFFFFFF); - - display.reload(); - gpiog.pg6.into_push_pull_output().set_low(); - let mut led = gpiod.pd4.into_push_pull_output(); + gpiod.pd4.into_push_pull_output().set_low(); gpiod.pd5.into_push_pull_output().set_low(); peripherals .GPIOK @@ -292,11 +275,119 @@ fn main() -> ! { .into_push_pull_output() .set_low(); + let mut counter = 0; + let array_of_positions = [FOURTH_DIGIT, THIRD_DIGIT, SECOND_DIGIT, FIRST_DIGIT]; + + draw_colon(&mut display, ltdc::Layer::L1, (COLON, 65), 0xFFFFFFFF); + + let mut last = 0; + loop { - if enabled_rtc.get_datetime().time().second() == 20 { - led.set_low(); - } else { - led.set_high(); + let now = enabled_rtc.get_datetime().second(); + if now - last > 1 { + last = now; + unsafe { + (0..480 * 800).for_each(|i| BUFF[i] = 0xFF000000); + } + + let mut copy = counter; + + let digit1 = copy % 10; + copy /= 10; + let digit2 = copy % 10; + copy /= 10; + let digit3 = copy % 10; + copy /= 10; + let digit4 = copy % 10; + + let array_of_digits = [digit1, digit2, digit3, digit4]; + (0..array_of_digits.len()).for_each(|i| match array_of_digits[i] { + 0 => { + draw_0( + &mut display, + ltdc::Layer::L1, + (array_of_positions[i], 65), + 0xFFFFFFFF, + ); + } + 1 => { + draw_1( + &mut display, + ltdc::Layer::L1, + (array_of_positions[i], 65), + 0xFFFFFFFF, + ); + } + 2 => { + draw_2( + &mut display, + ltdc::Layer::L1, + (array_of_positions[i], 65), + 0xFFFFFFFF, + ); + } + 3 => { + draw_3( + &mut display, + ltdc::Layer::L1, + (array_of_positions[i], 65), + 0xFFFFFFFF, + ); + } + 4 => { + draw_4( + &mut display, + ltdc::Layer::L1, + (array_of_positions[i], 65), + 0xFFFFFFFF, + ); + } + 5 => { + draw_5( + &mut display, + ltdc::Layer::L1, + (array_of_positions[i], 65), + 0xFFFFFFFF, + ); + } + 6 => { + draw_6( + &mut display, + ltdc::Layer::L1, + (array_of_positions[i], 65), + 0xFFFFFFFF, + ); + } + 7 => { + draw_7( + &mut display, + ltdc::Layer::L1, + (array_of_positions[i], 65), + 0xFFFFFFFF, + ); + } + 8 => { + draw_8( + &mut display, + ltdc::Layer::L1, + (array_of_positions[i], 65), + 0xFFFFFFFF, + ); + } + 9 => { + draw_9( + &mut display, + ltdc::Layer::L1, + (array_of_positions[i], 65), + 0xFFFFFFFF, + ); + } + _ => {} + }); + draw_colon(&mut display, ltdc::Layer::L1, (COLON, 65), 0xFFFFFFFF); + + counter += 1; + display.reload(); } } } @@ -369,12 +460,7 @@ fn draw_b( top_left: (usize, usize), color: u32, ) { - draw_vertical_line( - display, - layer, - (top_left.0 - DIGIT_WIDTH + LINE_WIDTH, top_left.1), - color, - ); + draw_vertical_line(display, layer, (top_left.0, top_left.1), color); } fn draw_c( @@ -386,10 +472,7 @@ fn draw_c( draw_vertical_line( display, layer, - ( - top_left.0 - DIGIT_WIDTH + LINE_WIDTH, - top_left.1 + DIGIT_HEIGHT / 2 - LINE_WIDTH, - ), + (top_left.0, top_left.1 + DIGIT_HEIGHT / 2), color, ); } @@ -417,7 +500,10 @@ fn draw_e( draw_vertical_line( display, layer, - (top_left.0, top_left.1 + DIGIT_HEIGHT / 2 - LINE_WIDTH), + ( + top_left.0 - DIGIT_WIDTH + LINE_WIDTH, + top_left.1 + DIGIT_HEIGHT / 2, + ), color, ); } @@ -428,7 +514,12 @@ fn draw_f( top_left: (usize, usize), color: u32, ) { - draw_vertical_line(display, layer, (top_left.0, top_left.1), color); + draw_vertical_line( + display, + layer, + (top_left.0 - DIGIT_WIDTH + LINE_WIDTH, top_left.1), + color, + ); } fn draw_g( @@ -440,7 +531,7 @@ fn draw_g( draw_horizontal_line( display, layer, - (top_left.0, top_left.1 + DIGIT_HEIGHT / 2 - LINE_WIDTH), + (top_left.0, top_left.1 + DIGIT_HEIGHT / 2 - LINE_WIDTH / 2), color, ); }