/** * Ds3231Element.ts — `` DS3231 precision RTC module. * * wokwi-elements ships a DS1307 breakout but no DS3231, so we draw our own. * The visual follows the ubiquitous 4-pin DS3231 breakout (blue PCB, SOIC-16 * chip, backup coin cell): a left-edge header with GND / VCC / SDA / SCL — * the same wiring surface as the wokwi DS1307 minus its unused SQW pin. * * The I2C behaviour lives in `simulation/I2CBusManager.ts::VirtualDS3231` * (address 0x68, DS1307-compatible time registers 0x00-0x06 plus control * 0x0E / status 0x0F / temperature 0x11-0x12) and is attached by the * `ds3231` entry in `simulation/parts/ProtocolParts.ts`. * * Per CLAUDE.md §6a this MUST be a real Web Component — the wire system * reads `pinInfo` from the DOM node to place wire endpoints on pin tips. */ const BODY_W = 140; const BODY_H = 84; // Left-edge 0.1" header. `x`/`y` are the pin tips the wire system snaps to. const PIN_X = 9; const PIN_SPACING = 18; const PIN_Y0 = 15; const PIN_NAMES = ['GND', 'VCC', 'SDA', 'SCL'] as const; // Ring colours follow the wokwi DS1307 / velxio SSD1306 pin styling. const PIN_RING = ['#B4AEAB', '#C08540', '#007ADB', '#009E9B']; function signalsFor(name: string) { if (name === 'GND') return [{ type: 'power', signal: 'GND' }]; if (name === 'VCC') return [{ type: 'power', signal: 'VCC' }]; if (name === 'SDA') return [{ type: 'i2c', signal: 'SDA' }]; if (name === 'SCL') return [{ type: 'i2c', signal: 'SCL' }]; return []; } class Ds3231Element extends HTMLElement { /** On-chip temperature in °C — mirrored into the simulated 0x11/0x12 regs. */ temperature = 25; constructor() { super(); this.attachShadow({ mode: 'open' }); } connectedCallback(): void { this.render(); } /** Wire system reads this from the DOM — do NOT memoize. */ get pinInfo() { return PIN_NAMES.map((name, i) => ({ name, x: PIN_X, y: PIN_Y0 + i * PIN_SPACING, number: i + 1, signals: signalsFor(name), })); } private render(): void { if (!this.shadowRoot) return; this.shadowRoot.innerHTML = ` CR2032 ${[0, 1, 2, 3, 4, 5, 6, 7] .map( (i) => ` `, ) .join('')} DS3231 RTC + TEMP ${PIN_NAMES.map( (name, i) => `${name}`, ).join('')} ${PIN_NAMES.map( (_, i) => ``, ).join('')} `; } } if (typeof customElements !== 'undefined' && !customElements.get('velxio-ds3231')) { customElements.define('velxio-ds3231', Ds3231Element); } export type { Ds3231Element };