main
John Lauer Studio: project overview, how it works, lights, charging, battery life, firmware source, dashboard screenshots; license… c2eaf61 3d ago
/*
 * echo.h : the hardware IR transponder (AC0 -> EVSYS -> TCB0/TCB1 single-shot)
 */
#ifndef ECHO_H
#define ECHO_H

#include <stdint.h>
#include <stdbool.h>

#define EMIT_850   0x01      /* TCB0 WO, PA5 */
#define EMIT_940   0x02      /* TCB1 WO, PA3 */
#define EMIT_BOTH  (EMIT_850 | EMIT_940)

typedef struct {
    uint32_t t;              /* RTC ticks (1/1024 s) at the end of the pulse / echo */
    uint16_t width_cyc;      /* listen mode: faucet pulse width in CLK_PER cycles (0.2 us) */
} echo_pulse_t;

void     echo_init(void);              /* pins safe, peripherals off (call once at boot) */
void     echo_rx_on(void);             /* powers the receiver, AC0, DAC0, event channel, EVOUT2 */
void     echo_rx_off(void);            /* everything off, emitters off, back to the sleep state */
uint16_t echo_calibrate(void);         /* noise floor -> threshold; returns threshold mV */

void     echo_listen_start(void);      /* TCB0 pulse-width capture, emitters disabled */
void     echo_arm(uint8_t width_us);   /* TCB0/TCB1 single-shot echo, emitters per echo_set() */
void     echo_set(bool enabled, uint8_t emitters);

bool     echo_pop(echo_pulse_t *p);    /* next captured pulse, false if none */
bool     echo_blanking(void);          /* true while the comparator is blanked (sleep IDLE, not STANDBY) */
bool     echo_quiet(void);             /* no echo or blanking in progress: safe for an LED write */
void     echo_hold(bool hold);         /* disconnect the event users (around LED writes) */

uint8_t  echo_width_us(void);

#endif