diff options
| author | Apexo | 2026-03-28 23:40:53 +0100 |
|---|---|---|
| committer | Apexo | 2026-03-28 23:40:53 +0100 |
| commit | 1b194ac4578dea8e71b0d61d1cb4d875f435ba71 (patch) | |
| tree | 786019a0c6f34b458f3272bf2ecbde0de1976e0a /src/peripherals/avrdx-dac.ts | |
| download | anduril-sim-1b194ac4578dea8e71b0d61d1cb4d875f435ba71.tar.gz anduril-sim-1b194ac4578dea8e71b0d61d1cb4d875f435ba71.tar.bz2 anduril-sim-1b194ac4578dea8e71b0d61d1cb4d875f435ba71.zip | |
D3AA simulator
Diffstat (limited to 'src/peripherals/avrdx-dac.ts')
| -rw-r--r-- | src/peripherals/avrdx-dac.ts | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/peripherals/avrdx-dac.ts b/src/peripherals/avrdx-dac.ts new file mode 100644 index 0000000..d4843ca --- /dev/null +++ b/src/peripherals/avrdx-dac.ts @@ -0,0 +1,30 @@ +// AVR-Dx DAC0 peripheral +// 10-bit DAC with output enable, used for LED brightness control on the D3AA + +import type { CPU } from 'avr8js/cpu/cpu'; + +const CTRLA = 0x00; +// const DATA = 0x02; // 16-bit (DATAL + DATAH) +const DATAL = 0x02; +const DATAH = 0x03; + +const ENABLE_bm = 0x01; +const OUTEN_bm = 0x40; + +export class AVRDxDAC { + constructor(private cpu: CPU, private base: number) { + } + + /** Whether DAC is enabled and output is enabled */ + get enabled(): boolean { + const ctrla = this.cpu.data[this.base + CTRLA]; + return !!(ctrla & ENABLE_bm) && !!(ctrla & OUTEN_bm); + } + + /** Get the current 10-bit DAC value (0-1023). + * DAC0.DATA is left-aligned: the 10-bit value sits in bits [15:6]. */ + get value(): number { + const raw16 = this.cpu.data[this.base + DATAL] | (this.cpu.data[this.base + DATAH] << 8); + return raw16 >> 6; + } +} |
