07-01-2023, 02:54 AM
(This post was last modified: 07-01-2023, 03:07 AM by WhiteHexagon.)
(06-21-2023, 03:18 AM)lupyuen Wrote: I hope this will get you started :-)
Indeed, a fun week was had I decided to start simple. At first I was looking for the RGB LEDs (a green one triggers when the demo boots) but I couldnt find it, so maybe they are hardware controlled.
Anyway I decided to try the VOL +/- buttons, since I wanted something very simple to see how the nuttx layer interacts with the Zig layer. The C include on the Zig side was a bit of a pain, until I remembered you mentioned somewhere only to include C stuff once, after that fix it was easier, although my include is deep into the nuttx layer, since I added the ADC logic under the src/a64 folder.
Polling the ADC was defaulting to high value, not zero, maybe that is a pull-up? resister on the schematic (page 12). And my microelectronics knowledge is poor and 30 years old hehe but it looks like the two resistors are designed to generate two different voltages for the ADC. I tried to calculate the voltages there, 3V in, but ADC expecting 2V, and I think the signals work with the ADC default config of 1.7V, although then I was suspecting the pull-up acts in parallel... as I said, very rusty old brain. The KEYADC_DATA_REG (page 277 A64 user manual) produced some different values when I finally realised I needed to enable the CTRL register (KEYADC_EN).
I was expecting something like + at 1.64V and - at 1.8V, but with a 6 bit resolution, and assuming 2V spread, I see .35V and .16V, and assuming these pull down from 2V, that would give 1.65V and 1.84V, close enough... and either side of the configured 1.7V. Phew, I am sure I am totally wrong with all that but it works! ie value 5 for VOL+ and value 11 for VOL-, but since this is ADC I suspect I should be doing a +-2 range check... oh and I somehow expected both buttons together would generate a different value, but they dont.
Not quite the simple start I expected but good fun.
I didn't try the IRQ approach so far... since that would mean calling from C to Zig, gulp! My next challenge
PS congrats on your article re RISC-V, it was no. 12 on HN when I spotted it