diff --git a/libs/hw---gdk/analog.ts b/libs/hw---gdk/analog.ts new file mode 100644 index 0000000000..9a5ea0408e --- /dev/null +++ b/libs/hw---gdk/analog.ts @@ -0,0 +1,15 @@ +namespace gdk { + /** + * Blocking single-shot ADC read of P0 (P0.02 / AIN0). Returns 0..1023 (same + * scale as pins.analogReadPin), or -1 on hardware timeout. + * + * On micro:bit V2 the native SAADC implementation in analog.cpp is used. + * The body below is the simulator fallback: there is no SAADC in the + * simulator, so it reports a full battery (1023) to keep the battery + * monitor and any game running without a runtime error. + */ + //% shim=gdk::readP0Adc + export function readP0Adc(): number { + return 1023; + } +} diff --git a/libs/hw---gdk/pxt.json b/libs/hw---gdk/pxt.json index 4e69a8afbd..d49b48e17c 100644 --- a/libs/hw---gdk/pxt.json +++ b/libs/hw---gdk/pxt.json @@ -4,9 +4,9 @@ "files": [ "config.ts", "init.ts", + "analog.ts", "batteryled.ts", "device.d.ts", - "shims.d.ts", "analog.cpp" ], "card": { diff --git a/libs/hw---gdk/shims.d.ts b/libs/hw---gdk/shims.d.ts deleted file mode 100644 index 99c7b5341c..0000000000 --- a/libs/hw---gdk/shims.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -// Auto-generated. Do not edit. -declare namespace gdk { - - /** - * Blocking single-shot ADC read of P0 (P0.02 / AIN0). Returns 0..1023 (same - * scale as pins.analogReadPin), or -1 on hardware timeout. - * - * Absolute internal 0.6V reference + gain 1/6 => full scale 3.6V (VDD-independent, - * so the reading stays correct as the battery/VDD drains). 40us acquisition suits - * the on-board ~82k divider. - * - * Owns the SAADC exclusively for the ~50us the conversion takes, then fully - * disables it. It does NOT touch PPI/timers/IRQs, so it cannot disturb the - * display or audio. The complete manual sequence is: - * ENABLE -> START -> (STARTED) -> SAMPLE -> (END) -> STOP -> (STOPPED) -> DISABLE - * The SAMPLE task is the critical step the previous version was missing. - */ - //% shim=gdk::readP0Adc - function readP0Adc(): int32; -} - -// Auto-generated. Do not edit. Really.