From 4649e68fdee25102d59397b61b6fce47eeff14d8 Mon Sep 17 00:00:00 2001
From: Matt Johnston <matt@ucc.asn.au>
Date: Sat, 1 Oct 2022 21:08:06 +0800
Subject: [PATCH] Add some other cap measurements

---
 examples/rp/src/bin/usb_serial.rs | 40 +++++++++++++++++++++++++++----
 1 file changed, 35 insertions(+), 5 deletions(-)

diff --git a/examples/rp/src/bin/usb_serial.rs b/examples/rp/src/bin/usb_serial.rs
index c976bbec..a0eb9e3a 100644
--- a/examples/rp/src/bin/usb_serial.rs
+++ b/examples/rp/src/bin/usb_serial.rs
@@ -28,9 +28,12 @@ async fn main(_spawner: Spawner) {
 
     let mut cp = cortex_m::peripheral::Peripherals::take().unwrap();
 
-    let mut gpio6 = Flex::new(p.PIN_6);
+    // XXX: Can we get the number from the pin?
+    let mut gpio = (Flex::new(p.PIN_6), 6);
+    // let mut gpio = (Flex::new(p.PIN_10), 10);
+    // let mut gpio = (Flex::new(p.PIN_13), 13);
 
-    run(&mut gpio6, &mut cp.SYST).await;
+    run(&mut gpio.0, gpio.1, &mut cp.SYST);
 
     // // Do stuff with the class!
     // let echo_fut = async {
@@ -86,7 +89,7 @@ impl core::fmt::Write for FmtBuf {
     }
 }
 
-async fn run<'d, P: Pin>(pin: &mut Flex<'d, P>, syst: &mut SYST) -> Result<(), Disconnected> {
+fn run<'d, P: Pin>(pin: &mut Flex<'d, P>, pin_num: usize, syst: &mut SYST) -> Result<(), Disconnected> {
     info!("hello");
 
     syst.set_reload(10_000_000-1);
@@ -95,11 +98,11 @@ async fn run<'d, P: Pin>(pin: &mut Flex<'d, P>, syst: &mut SYST) -> Result<(), D
     syst.enable_counter();
 
     unsafe{ pac::ROSC.ctrl().modify(|s| s.set_enable(pac::rosc::vals::Enable::DISABLE)) };
-    unsafe{ pac::PADS_BANK0.gpio(6).modify(|s| s.set_schmitt(false)) };
+    unsafe{ pac::PADS_BANK0.gpio(pin_num).modify(|s| s.set_schmitt(false)) };
 
 
     // get it near the threshold
-    critical_section::with(|_cs| {
+    let del = critical_section::with(|_cs| {
         pin.set_as_output();
         pin.set_high();
         // // approx 1ms
@@ -107,9 +110,14 @@ async fn run<'d, P: Pin>(pin: &mut Flex<'d, P>, syst: &mut SYST) -> Result<(), D
         cortex_m::asm::delay(1200);
         pin.set_as_input();
         pin.set_pull(Pull::Down);
+        syst.clear_current();
+        let t1 = SYST::get_current();
         // Get it near the threshold to begin.
         while pin.is_high() {}
+        let t2 = SYST::get_current();
+        t1 - t2
     });
+    info!("initial pulldown del is {}", del);
 
     let mut up_x = 1u32;
     let mut down_x = 1u32;
@@ -145,6 +153,28 @@ async fn run<'d, P: Pin>(pin: &mut Flex<'d, P>, syst: &mut SYST) -> Result<(), D
     The random output is t_down and t_up time.
     */
 
+    /* Experimental values:
+    0.1uF "monolithic" perhaps from futurlec?
+    GPIO6
+    0.003717 INFO  initial pulldown del is 346730
+    0.003710 INFO  initial pulldown del is 345770
+    less than ~13000 overshoot had lots of no-delays
+
+    Altronics R8617 • 0.01uF 50V Y5V 0805 SMD Chip Capacitor PK 10
+    GPIO10
+    0.001292 INFO  initial pulldown del is 43234
+    0.001294 INFO  initial pulldown del is 43598
+
+
+    Altronics R8629 • 0.047uF 50V X7R 0805 SMD Chip Capacitor PK 10
+    GPIO13
+    0.002497 INFO  initial pulldown del is 193878
+    0.002547 INFO  initial pulldown del is 200170
+
+
+    */
+
+
     loop {
         // number of iterations per interrupt-free block
         const LOOP: usize = 2000;
-- 
GitLab