summaryrefslogtreecommitdiff
path: root/src/peripherals
diff options
context:
space:
mode:
authorApexo2026-04-02 20:53:36 +0200
committerApexo2026-04-02 20:53:36 +0200
commit8926144705a8899a38e320696e7a03c256b406be (patch)
treea58fb0839671b60f65673c62bbf33d88c6eb9d20 /src/peripherals
parentimprove main loop (diff)
downloadanduril-sim-8926144705a8899a38e320696e7a03c256b406be.tar.gz
anduril-sim-8926144705a8899a38e320696e7a03c256b406be.tar.bz2
anduril-sim-8926144705a8899a38e320696e7a03c256b406be.zip
ADC: stop conversion when disabled via CTRLA
Diffstat (limited to 'src/peripherals')
-rw-r--r--src/peripherals/avrdx-adc.ts17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/peripherals/avrdx-adc.ts b/src/peripherals/avrdx-adc.ts
index dc95d86..ed49ce6 100644
--- a/src/peripherals/avrdx-adc.ts
+++ b/src/peripherals/avrdx-adc.ts
@@ -81,6 +81,12 @@ export class AVRDxADC {
enableMask: ADC_RESRDY_bm,
} as const;
+ cpu.writeHooks[base + CTRLA] = (value) => {
+ cpu.data[base + CTRLA] = value;
+ if (!(value & ADC_ENABLE_bm)) this.stop();
+ return true;
+ };
+
// COMMAND register - writing STCONV starts a conversion
cpu.writeHooks[base + COMMAND] = (value) => {
cpu.data[base + COMMAND] = value;
@@ -113,6 +119,13 @@ export class AVRDxADC {
cpu.writeHooks[base + RESH] = () => true;
}
+ private stop() {
+ if (this.conversionCallback) {
+ this.cpu.clearClockEvent(this.conversionCallback);
+ this.conversionCallback = null;
+ }
+ }
+
/** Set the voltage at the ADC pin (volts, after external divider).
* The ADC result is computed at conversion time from this voltage,
* the current VREF selection, and the accumulation count. */
@@ -140,9 +153,7 @@ export class AVRDxADC {
const cpuCycles = adcCycles * prescDiv;
// Schedule completion
- if (this.conversionCallback) {
- this.cpu.clearClockEvent(this.conversionCallback);
- }
+ this.stop();
// TODO: do ADC CPU cycles depend on clock scaling?
this.conversionCallback = this.cpu.addClockEvent(() => this.completeConversion(), cpuCycles);
}
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.