wokwi / rp2040js

A Raspberry Pi Pico Emulator in JavaScript
MIT License
384 stars 40 forks source link

fix(adc): add error flag just if an error appeared and 16 bit resolution is configured (therefore byte_shift flag for 8 bit DMA transfers is disabled) #113

Closed sreimchen closed 1 year ago

sreimchen commented 1 year ago

At the moment the error flag is always set (15th bit) if full resolution (12 bit) reads are configured which are stored as 2 byte samples in the ADC's FIFO. That is wrong in my opinion because the error flag should just be set if an error appeared. An error appears if the ADC concludes that there was an error after sampling.

sreimchen commented 1 year ago

Documentation says: err_in_fifo – If enabled, bit 15 of the FIFO contains error flag for each sample byte_shift – Shift FIFO contents to be one byte in size (for byte DMA) - enables DMA to byte buffers.

I didn't find much information about the error flag but I think it should just be set if an error appeared while reading the sample by the ADC. In the simulation that never happens at the moment which is fine. I don't know why it is called err_in_fifo in the SDK because that doesn't make sense to me: If the FIFO is full then the sample is dropped anyway... I think the naming chosen by the RP team is confusing... in my opinion it should be named like "error_adc_reading" or am I missing something important?