fixed
This commit is contained in:
parent
b27a706d74
commit
db94099429
1 changed files with 132 additions and 41 deletions
173
src/main.rs
173
src/main.rs
|
|
@ -39,6 +39,12 @@ const DIGIT_HEIGHT: usize = 350;
|
||||||
const DIGIT_WIDTH: usize = 150;
|
const DIGIT_WIDTH: usize = 150;
|
||||||
const DIGIT_MARGIN: usize = 20;
|
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]
|
#[entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
let peripherals = Peripherals::take().unwrap();
|
let peripherals = Peripherals::take().unwrap();
|
||||||
|
|
@ -259,31 +265,8 @@ fn main() -> ! {
|
||||||
(0..480 * 800).for_each(|i| BUFF[i] = 0xFF000000);
|
(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();
|
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();
|
gpiod.pd5.into_push_pull_output().set_low();
|
||||||
peripherals
|
peripherals
|
||||||
.GPIOK
|
.GPIOK
|
||||||
|
|
@ -292,11 +275,119 @@ fn main() -> ! {
|
||||||
.into_push_pull_output()
|
.into_push_pull_output()
|
||||||
.set_low();
|
.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 {
|
loop {
|
||||||
if enabled_rtc.get_datetime().time().second() == 20 {
|
let now = enabled_rtc.get_datetime().second();
|
||||||
led.set_low();
|
if now - last > 1 {
|
||||||
} else {
|
last = now;
|
||||||
led.set_high();
|
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),
|
top_left: (usize, usize),
|
||||||
color: u32,
|
color: u32,
|
||||||
) {
|
) {
|
||||||
draw_vertical_line(
|
draw_vertical_line(display, layer, (top_left.0, top_left.1), color);
|
||||||
display,
|
|
||||||
layer,
|
|
||||||
(top_left.0 - DIGIT_WIDTH + LINE_WIDTH, top_left.1),
|
|
||||||
color,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_c(
|
fn draw_c(
|
||||||
|
|
@ -386,10 +472,7 @@ fn draw_c(
|
||||||
draw_vertical_line(
|
draw_vertical_line(
|
||||||
display,
|
display,
|
||||||
layer,
|
layer,
|
||||||
(
|
(top_left.0, top_left.1 + DIGIT_HEIGHT / 2),
|
||||||
top_left.0 - DIGIT_WIDTH + LINE_WIDTH,
|
|
||||||
top_left.1 + DIGIT_HEIGHT / 2 - LINE_WIDTH,
|
|
||||||
),
|
|
||||||
color,
|
color,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -417,7 +500,10 @@ fn draw_e(
|
||||||
draw_vertical_line(
|
draw_vertical_line(
|
||||||
display,
|
display,
|
||||||
layer,
|
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,
|
color,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -428,7 +514,12 @@ fn draw_f(
|
||||||
top_left: (usize, usize),
|
top_left: (usize, usize),
|
||||||
color: u32,
|
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(
|
fn draw_g(
|
||||||
|
|
@ -440,7 +531,7 @@ fn draw_g(
|
||||||
draw_horizontal_line(
|
draw_horizontal_line(
|
||||||
display,
|
display,
|
||||||
layer,
|
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,
|
color,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue