WE DONE (almost)
10:15am-7pm
4/25 Friday
8.75 hours
Ok, was unable to solve with Brian last night what caused the pio machine not to work
For the first part of today without Brian, i decided to reimplement in a new RAM module the original code instead of trying to integrate the original bus code with the RAM file. I ran that however it still failed due to borrowing issues. Chatgpt kept using take() and unwrap() to pass the references to the RAM object without dropping them:
let mut sm0 = pio1.sm0.take().unwrap();
let mut sm1 = pio0.sm1.take().unwrap();
let mut sm2 = pio0.sm2.take().unwrap();
let mut irq2 = pio0.irq2.take().unwrap();
However, the state machines do not allow them to be taken or unwrapped so this did not work.
I then tried another approach that was close to the original implementation where I used closures inside the main loop instead of making a struct cause I anticipated references were getting dropped. That worked.
I then tried calling the closures from inside of a RAM class like this in order to be able to have methods that could be called by the CPU class to do read and write operations on

As you can see though, I get an error that the dynamic environment can’t be captured. So I don’t think closures are the answer.
I then tried looking up other ways embassy can handle dynamically changing peripherals in other parts (functions) of the code.
I saw that embassy-executor provided functions for notating the main and task functions. I could store things in task functions, however that wouldn’t really help as task functions are supposed to be run 24/7 and not listen exactly for requests.
I also found Mutexes, Channels, and interrupts. I found this in the embassy book. I gave had chatgpt the examples and my code and had it try rewriting my code to use them to pass messages between the main thread and other running tasks that would handle reading and writing. It tried, however, it kept running into using .take() and unwrap() and didn’t fully know how to use mutexes, so I didn’t bother.
Brian then came around this time and I asked him to look into the problem because he is more experienced with Rust borrowing than I am. Over the next 2 hours and while we did our first demo he figured out how to use closuers and keep them alive using the nightly Rust development channel so that we could have the reads and writes work. That approach worked.