Test io bus

This commit is contained in:
Geens 2025-06-23 19:46:39 +02:00
parent f3bab9461e
commit 63d5522fd9
5 changed files with 264 additions and 88 deletions

View File

@ -7,6 +7,9 @@ members = [
"simulator",
"xtask",
]
exclude = [
"firmware",
]
[workspace.dependencies]
bytes = "1.0"

View File

@ -22,3 +22,11 @@ lto = true # Link-time optimization
codegen-units = 1 # Better optimization
panic = 'abort' # Reduce binary size
strip = false # Keep symbols for debugging
[profile.dev]
debug = true # Keep debug info for better debugging
opt-level = "s" # Optimize for size
lto = true # Link-time optimization
codegen-units = 1 # Better optimization
panic = 'abort' # Reduce binary size
strip = false # Keep symbols for debugging

View File

@ -4,11 +4,22 @@
use panic_halt as _;
use cortex_m_rt::entry;
use stm32f0xx_hal::{
prelude::*,
stm32,
delay::Delay,
delay::Delay, prelude::*, stm32
};
struct Bus {
latch_en: stm32f0xx_hal::gpio::gpioa::PA0<stm32f0xx_hal::gpio::Output<stm32f0xx_hal::gpio::PushPull>>,
select_en: stm32f0xx_hal::gpio::gpiob::PB8<stm32f0xx_hal::gpio::Output<stm32f0xx_hal::gpio::OpenDrain>>,
pb0: stm32f0xx_hal::gpio::gpiob::PB0<stm32f0xx_hal::gpio::Output<stm32f0xx_hal::gpio::PushPull>>,
pb1: stm32f0xx_hal::gpio::gpiob::PB1<stm32f0xx_hal::gpio::Output<stm32f0xx_hal::gpio::PushPull>>,
pb2: stm32f0xx_hal::gpio::gpiob::PB2<stm32f0xx_hal::gpio::Output<stm32f0xx_hal::gpio::PushPull>>,
pb3: stm32f0xx_hal::gpio::gpiob::PB3<stm32f0xx_hal::gpio::Output<stm32f0xx_hal::gpio::PushPull>>,
pb4: stm32f0xx_hal::gpio::gpiob::PB4<stm32f0xx_hal::gpio::Output<stm32f0xx_hal::gpio::PushPull>>,
pb5: stm32f0xx_hal::gpio::gpiob::PB5<stm32f0xx_hal::gpio::Output<stm32f0xx_hal::gpio::PushPull>>,
pb6: stm32f0xx_hal::gpio::gpiob::PB6<stm32f0xx_hal::gpio::Output<stm32f0xx_hal::gpio::PushPull>>,
pb7: stm32f0xx_hal::gpio::gpiob::PB7<stm32f0xx_hal::gpio::Output<stm32f0xx_hal::gpio::PushPull>>,
}
#[entry]
fn main() -> ! {
// Get device peripherals
@ -28,18 +39,161 @@ fn main() -> ! {
// Configure GPIO
let gpioa = dp.GPIOA.split(&mut rcc);
let gpiob = dp.GPIOB.split(&mut rcc);
// Configure PA5 as push-pull output (common LED pin)
let mut led = cortex_m::interrupt::free(|cs| {
gpioa.pa9.into_push_pull_output(cs)
let mut bus = cortex_m::interrupt::free(|cs| {
Bus {
latch_en: gpioa.pa0.into_push_pull_output(cs),
select_en: gpiob.pb8.into_open_drain_output(cs),
pb0: gpiob.pb0.into_push_pull_output(cs),
pb1: gpiob.pb1.into_push_pull_output(cs),
pb2: gpiob.pb2.into_push_pull_output(cs),
pb3: gpiob.pb3.into_push_pull_output(cs),
pb4: gpiob.pb4.into_push_pull_output(cs),
pb5: gpiob.pb5.into_push_pull_output(cs),
pb6: gpiob.pb6.into_push_pull_output(cs),
pb7: gpiob.pb7.into_push_pull_output(cs),
}
});
// Blink loop
// Loop
loop {
led.set_high().ok();
delay.delay_ms(2000u16);
led.set_low().ok();
delay.delay_ms(2000u16);
for ic in 0..=2 {
for i in 0..256 {
bus.output(ic, 1 << i, &mut delay);
delay.delay_ms(100u16);
}
}
}
}
impl Bus {
fn output(&mut self, ic: u8, data: u8, delay: &mut Delay) {
match ic {
0 => self.select(1, delay),
1 => self.select(0, delay),
2 => self.select(5, delay),
3 => self.select(1, delay),
10 => self.select(0, delay),
11 => self.select(5, delay),
_ => self.select(2, delay),
}
delay.delay_ms(10u16);
self.select_en(true);
delay.delay_ms(10u16);
self.write(data);
delay.delay_ms(10u16);
self.select_en(false);
}
fn write(&mut self, data: u8) {
self.pb0.set_state((data & 0b00000001 != 0).into()).ok();
self.pb1.set_state((data & 0b00000010 != 0).into()).ok();
self.pb2.set_state((data & 0b00000100 != 0).into()).ok();
self.pb3.set_state((data & 0b00001000 != 0).into()).ok();
self.pb4.set_state((data & 0b00010000 != 0).into()).ok();
self.pb5.set_state((data & 0b00100000 != 0).into()).ok();
self.pb6.set_state((data & 0b01000000 != 0).into()).ok();
self.pb7.set_state((data & 0b10000000 != 0).into()).ok();
}
fn select_en(&mut self, enable: bool) {
self.select_en.set_state(enable.into()).ok();
}
fn select(&mut self, line: u8, delay: &mut Delay) {
self.select_en.set_low().ok();
delay.delay_ms(10u16);
match line {
0 => {
self.pb0.set_low().ok();
self.pb1.set_low().ok();
self.pb2.set_low().ok();
self.pb3.set_low().ok();
self.pb4.set_low().ok();
self.pb5.set_low().ok();
self.pb6.set_low().ok();
self.pb7.set_low().ok();
}
1 => {
self.pb0.set_high().ok();
self.pb1.set_low().ok();
self.pb2.set_low().ok();
self.pb3.set_low().ok();
self.pb4.set_low().ok();
self.pb5.set_low().ok();
self.pb6.set_low().ok();
self.pb7.set_low().ok();
}
2 => {
self.pb0.set_low().ok();
self.pb1.set_high().ok();
self.pb2.set_low().ok();
self.pb3.set_low().ok();
self.pb4.set_low().ok();
self.pb5.set_low().ok();
self.pb6.set_low().ok();
self.pb7.set_low().ok();
}
3 => {
self.pb0.set_high().ok();
self.pb1.set_high().ok();
self.pb2.set_low().ok();
self.pb3.set_low().ok();
self.pb4.set_low().ok();
self.pb5.set_low().ok();
self.pb6.set_low().ok();
self.pb7.set_low().ok();
}
4 => {
self.pb0.set_low().ok();
self.pb1.set_low().ok();
self.pb2.set_high().ok();
self.pb3.set_low().ok();
self.pb4.set_low().ok();
self.pb5.set_low().ok();
self.pb6.set_low().ok();
self.pb7.set_low().ok();
}
5 => {
self.pb0.set_high().ok();
self.pb1.set_low().ok();
self.pb2.set_high().ok();
self.pb3.set_low().ok();
self.pb4.set_low().ok();
self.pb5.set_low().ok();
self.pb6.set_low().ok();
self.pb7.set_low().ok();
}
6 => {
self.pb0.set_low().ok();
self.pb1.set_high().ok();
self.pb2.set_high().ok();
self.pb3.set_low().ok();
self.pb4.set_low().ok();
self.pb5.set_low().ok();
self.pb6.set_low().ok();
self.pb7.set_low().ok();
}
7 => {
self.pb0.set_high().ok();
self.pb1.set_high().ok();
self.pb2.set_high().ok();
self.pb3.set_low().ok();
self.pb4.set_low().ok();
self.pb5.set_low().ok();
self.pb6.set_low().ok();
self.pb7.set_low().ok();
}
_ => {}
}
delay.delay_ms(10u16);
self.latch_en.set_high().ok();
delay.delay_ms(10u16);
self.latch_en.set_low().ok();
delay.delay_ms(10u16);
self.select_en.set_high().ok();
}
}

View File

@ -16,17 +16,17 @@
"zones": 1.0
},
"selection_filter": {
"dimensions": false,
"footprints": false,
"graphics": false,
"keepouts": false,
"dimensions": true,
"footprints": true,
"graphics": true,
"keepouts": true,
"lockedItems": false,
"otherItems": false,
"pads": false,
"otherItems": true,
"pads": true,
"text": true,
"tracks": false,
"vias": false,
"zones": false
"tracks": true,
"vias": true,
"zones": true
},
"visible_items": [
"vias",

View File

@ -3305,6 +3305,17 @@
(embedded_fonts no)
)
)
(text "pull-up & IC5 E2"
(exclude_from_sim no)
(at 78.74 111.76 0)
(effects
(font
(size 1.27 1.27)
)
(justify left)
)
(uuid "5985935c-bc7c-49a9-8497-c38580b571f4")
)
(junction
(at 210.82 99.06)
(diameter 0)
@ -6422,7 +6433,7 @@
(in_bom yes)
(on_board yes)
(dnp no)
(uuid "00f6857f-3297-45a4-af3d-067e1f2262d5")
(uuid "00f6857f-3297-45a4-af3d-067e1f2262d6")
(property "Reference" "U4"
(at 266.7 133.35 0)
(do_not_autoplace yes)
@ -6494,40 +6505,40 @@
)
)
(pin "2"
(uuid "e8571b87-6af9-4125-886e-7e3a2e3bc2d8")
(uuid "e8571b87-6af9-4125-886e-7e3a2e3bc2d9")
)
(pin "10"
(uuid "5b31965e-bfff-47ff-80ed-c641340f8533")
(uuid "5b31965e-bfff-47ff-80ed-c641340f8534")
)
(pin "3"
(uuid "3ca0ebe1-7992-4400-99c9-495c07a5b9e2")
(uuid "3ca0ebe1-7992-4400-99c9-495c07a5b9e3")
)
(pin "9"
(uuid "c57c75d2-6693-43e0-b009-d99de2079ec1")
(uuid "c57c75d2-6693-43e0-b009-d99de2079ec2")
)
(pin "11"
(uuid "c3142a81-ac1c-445f-839d-da97f9d7f04f")
(uuid "c3142a81-ac1c-445f-839d-da97f9d7f050")
)
(pin "1"
(uuid "e3ab6c61-5d1b-4d91-8a96-2473d6bf67b1")
(uuid "e3ab6c61-5d1b-4d91-8a96-2473d6bf67b2")
)
(pin "5"
(uuid "87d6a406-5429-40b6-b8d9-3c96c4ca9cbe")
(uuid "87d6a406-5429-40b6-b8d9-3c96c4ca9cbf")
)
(pin "6"
(uuid "42f7f3ce-6f2a-46ae-9c56-47f0ba8d74eb")
(uuid "42f7f3ce-6f2a-46ae-9c56-47f0ba8d74ec")
)
(pin "4"
(uuid "c0746d9b-7764-4eda-8d1a-1d97c6a56e0b")
(uuid "c0746d9b-7764-4eda-8d1a-1d97c6a56e0c")
)
(pin "12"
(uuid "5993ecfa-c5cd-47d3-90bc-33dac7fb49f4")
(uuid "5993ecfa-c5cd-47d3-90bc-33dac7fb49f5")
)
(pin "8"
(uuid "70b7ffbe-f616-411e-9191-d33c9d947633")
(uuid "70b7ffbe-f616-411e-9191-d33c9d947634")
)
(pin "7"
(uuid "81a3e163-9cdc-4212-a73d-85e604630068")
(uuid "81a3e163-9cdc-4212-a73d-85e604630069")
)
(instances
(project "FCB1010_controller"
@ -8590,7 +8601,7 @@
(on_board yes)
(dnp no)
(fields_autoplaced yes)
(uuid "671a9e66-b03d-43a0-b8e0-89ba26a28242")
(uuid "671a9e66-b03d-43a0-b8e0-89ba26a28243")
(property "Reference" "U5"
(at 266.7 138.43 0)
(do_not_autoplace yes)
@ -8662,40 +8673,40 @@
)
)
(pin "2"
(uuid "364dbbe3-8edc-4e45-8112-449a71ea2a26")
(uuid "364dbbe3-8edc-4e45-8112-449a71ea2a27")
)
(pin "10"
(uuid "a79f95a5-53fc-4da1-a140-d3c6c620847d")
(uuid "a79f95a5-53fc-4da1-a140-d3c6c620847e")
)
(pin "3"
(uuid "ec77776f-3286-4ebc-8dbf-be4a05a4a205")
(uuid "ec77776f-3286-4ebc-8dbf-be4a05a4a206")
)
(pin "9"
(uuid "199e5305-e860-420f-a6c4-2b45550acd7e")
(uuid "199e5305-e860-420f-a6c4-2b45550acd7f")
)
(pin "11"
(uuid "4d1d6219-52fc-4b4f-8889-b5d72f2f3aa8")
(uuid "4d1d6219-52fc-4b4f-8889-b5d72f2f3aa9")
)
(pin "1"
(uuid "52a066f2-4110-4fa6-812c-f4a620513ae0")
(uuid "52a066f2-4110-4fa6-812c-f4a620513ae1")
)
(pin "5"
(uuid "da812571-2529-4072-984f-3b153236f4e8")
(uuid "da812571-2529-4072-984f-3b153236f4e9")
)
(pin "6"
(uuid "24c5ba84-126f-4c8b-9da7-b3e311e90f0e")
(uuid "24c5ba84-126f-4c8b-9da7-b3e311e90f0f")
)
(pin "4"
(uuid "80a27a29-5bbf-43b9-b752-7a84a2e1aa8a")
(uuid "80a27a29-5bbf-43b9-b752-7a84a2e1aa8b")
)
(pin "12"
(uuid "0ca6525b-b471-4bbe-9900-ca104a6a0089")
(uuid "0ca6525b-b471-4bbe-9900-ca104a6a008a")
)
(pin "8"
(uuid "0d4580b5-cfc4-4875-a018-3318e218039f")
(uuid "0d4580b5-cfc4-4875-a018-3318e21803a0")
)
(pin "7"
(uuid "2b3bf6e5-e71b-4ffa-a253-19e25276e535")
(uuid "2b3bf6e5-e71b-4ffa-a253-19e25276e536")
)
(instances
(project "FCB1010_controller"
@ -8715,7 +8726,7 @@
(on_board yes)
(dnp no)
(fields_autoplaced yes)
(uuid "671a9e66-b03d-43a0-b8e0-89ba26a28242")
(uuid "671a9e66-b03d-43a0-b8e0-89ba26a28244")
(property "Reference" "U5"
(at 266.7 143.51 0)
(do_not_autoplace yes)
@ -8787,40 +8798,40 @@
)
)
(pin "2"
(uuid "364dbbe3-8edc-4e45-8112-449a71ea2a26")
(uuid "364dbbe3-8edc-4e45-8112-449a71ea2a28")
)
(pin "10"
(uuid "a79f95a5-53fc-4da1-a140-d3c6c620847d")
(uuid "a79f95a5-53fc-4da1-a140-d3c6c620847f")
)
(pin "3"
(uuid "ec77776f-3286-4ebc-8dbf-be4a05a4a205")
(uuid "ec77776f-3286-4ebc-8dbf-be4a05a4a207")
)
(pin "9"
(uuid "199e5305-e860-420f-a6c4-2b45550acd7e")
(uuid "199e5305-e860-420f-a6c4-2b45550acd80")
)
(pin "11"
(uuid "4d1d6219-52fc-4b4f-8889-b5d72f2f3aa8")
(uuid "4d1d6219-52fc-4b4f-8889-b5d72f2f3aaa")
)
(pin "1"
(uuid "52a066f2-4110-4fa6-812c-f4a620513ae0")
(uuid "52a066f2-4110-4fa6-812c-f4a620513ae2")
)
(pin "5"
(uuid "da812571-2529-4072-984f-3b153236f4e8")
(uuid "da812571-2529-4072-984f-3b153236f4ea")
)
(pin "6"
(uuid "24c5ba84-126f-4c8b-9da7-b3e311e90f0e")
(uuid "24c5ba84-126f-4c8b-9da7-b3e311e90f10")
)
(pin "4"
(uuid "80a27a29-5bbf-43b9-b752-7a84a2e1aa8a")
(uuid "80a27a29-5bbf-43b9-b752-7a84a2e1aa8c")
)
(pin "12"
(uuid "0ca6525b-b471-4bbe-9900-ca104a6a0089")
(uuid "0ca6525b-b471-4bbe-9900-ca104a6a008b")
)
(pin "8"
(uuid "0d4580b5-cfc4-4875-a018-3318e218039f")
(uuid "0d4580b5-cfc4-4875-a018-3318e21803a1")
)
(pin "7"
(uuid "2b3bf6e5-e71b-4ffa-a253-19e25276e535")
(uuid "2b3bf6e5-e71b-4ffa-a253-19e25276e537")
)
(instances
(project "FCB1010_controller"
@ -9322,16 +9333,16 @@
)
)
(pin "2"
(uuid "e8571b87-6af9-4125-886e-7e3a2e3bc2d9")
(uuid "e8571b87-6af9-4125-886e-7e3a2e3bc2da")
)
(pin "10"
(uuid "5b31965e-bfff-47ff-80ed-c641340f8534")
(uuid "5b31965e-bfff-47ff-80ed-c641340f8535")
)
(pin "3"
(uuid "3ca0ebe1-7992-4400-99c9-495c07a5b9e3")
(uuid "3ca0ebe1-7992-4400-99c9-495c07a5b9e4")
)
(pin "9"
(uuid "c57c75d2-6693-43e0-b009-d99de2079ec2")
(uuid "c57c75d2-6693-43e0-b009-d99de2079ec3")
)
(pin "11"
(uuid "14870ff4-7358-481e-946d-8159a9219fc9")
@ -9340,22 +9351,22 @@
(uuid "d4f029c8-cf44-4480-b65a-7a52168c9fd7")
)
(pin "5"
(uuid "87d6a406-5429-40b6-b8d9-3c96c4ca9cbf")
(uuid "87d6a406-5429-40b6-b8d9-3c96c4ca9cc0")
)
(pin "6"
(uuid "3535401f-3608-4e7d-ad61-1a26f195891e")
)
(pin "4"
(uuid "c0746d9b-7764-4eda-8d1a-1d97c6a56e0c")
(uuid "c0746d9b-7764-4eda-8d1a-1d97c6a56e0d")
)
(pin "12"
(uuid "fe6ae119-a983-4136-abf2-f74c9b4f7f3f")
)
(pin "8"
(uuid "70b7ffbe-f616-411e-9191-d33c9d947634")
(uuid "70b7ffbe-f616-411e-9191-d33c9d947635")
)
(pin "7"
(uuid "81a3e163-9cdc-4212-a73d-85e604630069")
(uuid "81a3e163-9cdc-4212-a73d-85e60463006a")
)
(instances
(project "FCB1010_controller"
@ -9880,40 +9891,40 @@
)
)
(pin "2"
(uuid "364dbbe3-8edc-4e45-8112-449a71ea2a27")
(uuid "364dbbe3-8edc-4e45-8112-449a71ea2a29")
)
(pin "10"
(uuid "a79f95a5-53fc-4da1-a140-d3c6c620847e")
(uuid "a79f95a5-53fc-4da1-a140-d3c6c6208480")
)
(pin "3"
(uuid "ec77776f-3286-4ebc-8dbf-be4a05a4a206")
(uuid "ec77776f-3286-4ebc-8dbf-be4a05a4a208")
)
(pin "9"
(uuid "199e5305-e860-420f-a6c4-2b45550acd7f")
(uuid "199e5305-e860-420f-a6c4-2b45550acd81")
)
(pin "11"
(uuid "4d1d6219-52fc-4b4f-8889-b5d72f2f3aa9")
(uuid "4d1d6219-52fc-4b4f-8889-b5d72f2f3aab")
)
(pin "1"
(uuid "52a066f2-4110-4fa6-812c-f4a620513ae1")
(uuid "52a066f2-4110-4fa6-812c-f4a620513ae3")
)
(pin "5"
(uuid "da812571-2529-4072-984f-3b153236f4e9")
(uuid "da812571-2529-4072-984f-3b153236f4eb")
)
(pin "6"
(uuid "24c5ba84-126f-4c8b-9da7-b3e311e90f0f")
(uuid "24c5ba84-126f-4c8b-9da7-b3e311e90f11")
)
(pin "4"
(uuid "80a27a29-5bbf-43b9-b752-7a84a2e1aa8b")
(uuid "80a27a29-5bbf-43b9-b752-7a84a2e1aa8d")
)
(pin "12"
(uuid "0ca6525b-b471-4bbe-9900-ca104a6a008a")
(uuid "0ca6525b-b471-4bbe-9900-ca104a6a008c")
)
(pin "8"
(uuid "0d4580b5-cfc4-4875-a018-3318e21803a0")
(uuid "0d4580b5-cfc4-4875-a018-3318e21803a2")
)
(pin "7"
(uuid "2b3bf6e5-e71b-4ffa-a253-19e25276e536")
(uuid "2b3bf6e5-e71b-4ffa-a253-19e25276e538")
)
(instances
(project "FCB1010_controller"
@ -10070,16 +10081,16 @@
)
)
(pin "2"
(uuid "e8571b87-6af9-4125-886e-7e3a2e3bc2da")
(uuid "e8571b87-6af9-4125-886e-7e3a2e3bc2db")
)
(pin "10"
(uuid "5b31965e-bfff-47ff-80ed-c641340f8535")
(uuid "5b31965e-bfff-47ff-80ed-c641340f8536")
)
(pin "3"
(uuid "3ca0ebe1-7992-4400-99c9-495c07a5b9e4")
(uuid "3ca0ebe1-7992-4400-99c9-495c07a5b9e5")
)
(pin "9"
(uuid "c57c75d2-6693-43e0-b009-d99de2079ec3")
(uuid "c57c75d2-6693-43e0-b009-d99de2079ec4")
)
(pin "11"
(uuid "14870ff4-7358-481e-946d-8159a9219fca")
@ -10088,22 +10099,22 @@
(uuid "d4f029c8-cf44-4480-b65a-7a52168c9fd8")
)
(pin "5"
(uuid "87d6a406-5429-40b6-b8d9-3c96c4ca9cc0")
(uuid "87d6a406-5429-40b6-b8d9-3c96c4ca9cc1")
)
(pin "6"
(uuid "3535401f-3608-4e7d-ad61-1a26f195891f")
)
(pin "4"
(uuid "c0746d9b-7764-4eda-8d1a-1d97c6a56e0d")
(uuid "c0746d9b-7764-4eda-8d1a-1d97c6a56e0e")
)
(pin "12"
(uuid "fe6ae119-a983-4136-abf2-f74c9b4f7f40")
)
(pin "8"
(uuid "70b7ffbe-f616-411e-9191-d33c9d947635")
(uuid "70b7ffbe-f616-411e-9191-d33c9d947636")
)
(pin "7"
(uuid "81a3e163-9cdc-4212-a73d-85e60463006a")
(uuid "81a3e163-9cdc-4212-a73d-85e60463006b")
)
(instances
(project "FCB1010_controller"