From c3bbbbd67239c00802d359f41441b84b9f5c9073 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 5 Jul 2024 01:59:14 +0800 Subject: [PATCH] fix bug in i2c library where i/o was not set low you have to write *0* to the clear register to set the port low. always the weird gotcha on that one... --- libs/xous-bio-bdma/src/bio_tests/units.rs | 2 ++ libs/xous-bio-bdma/src/i2c.rs | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/xous-bio-bdma/src/bio_tests/units.rs b/libs/xous-bio-bdma/src/bio_tests/units.rs index 6a4b2ca7c..9522fb499 100644 --- a/libs/xous-bio-bdma/src/bio_tests/units.rs +++ b/libs/xous-bio-bdma/src/bio_tests/units.rs @@ -26,6 +26,8 @@ pub fn hello_world() -> usize { #[rustfmt::skip] bio_code!(hello_world_code, HELLO_START, HELLO_END, "add x1, zero, 0x10", + // "li x2, 0xFFFFFFFF", // set all pins to outputs + // "mv x24, x2", "0:", "add x1, x1, 0x1", "mv x21, x1", diff --git a/libs/xous-bio-bdma/src/i2c.rs b/libs/xous-bio-bdma/src/i2c.rs index fc3611502..43bf4ef14 100644 --- a/libs/xous-bio-bdma/src/i2c.rs +++ b/libs/xous-bio-bdma/src/i2c.rs @@ -219,7 +219,9 @@ bio_code!( // setup gpios "mv x20, x0", // sync to clock stream "or x26, x4, x5", // set GPIO mask - "or x23, x4, x5", // clear SCL/SDA pins to 0 for "output low" + "or x12, x4, x5", // form bitmask in true sense + "xori x12, x12, -1", // invert because you need to write 0 to set outputs to low + "mv x23, x12", // clear SCL/SDA pins to 0 for "output low" "or x25, x4, x5", // SCL/SDA to inputs // setup done "mv x20, x0", // sync to clock stream