/*
 * slic.h — K50835F / AG1171-class SLIC control (ESP-IDF port of Ks0835SlicController).
 *
 * Pins (A1S board, from board_config.h):
 *   RM  GPIO18  Ring Mode output     — HIGH = ring burst active
 *   FR  GPIO5   Forward/Reverse out  — toggled at ~25 Hz during ring to drive bell
 *   SHK GPIO23  Switch Hook input    — HIGH = off-hook (active-high)
 *   PD  GPIO19  Power Down (OD)      — HIGH = SLIC powered (released open-drain)
 *
 * Power-up: PD is open-drain, written HIGH → high-impedance → SLIC active.
 * Power-down: PD driven LOW → SLIC off (no audio, no hook sense).
 *
 * Ring: slic_ring_start() sets RM=1 and spawns/enables a 20 ms FR-toggle task.
 *       slic_ring_stop()  clears RM=0, FR=0, pauses the toggle task.
 *
 * Hook: slic_is_offhook() reads SHK; HIGH = off-hook (matches A252ConfigStore default).
 */

#pragma once

#include <stdbool.h>
#include "esp_err.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
 * Initialise SLIC GPIO and power up the SLIC.
 * Must be called early in boot, before audio init.
 * Returns ESP_OK on success.
 */
esp_err_t slic_init(void);

/**
 * Returns true when the handset is off-hook (SHK GPIO23 HIGH).
 */
bool slic_is_offhook(void);

/**
 * Activate ringing: RM=HIGH + FR toggles at ~25 Hz (20 ms period).
 * No-op if already ringing.
 */
void slic_ring_start(void);

/**
 * Stop ringing: RM=LOW, FR=LOW, FR toggle suspended.
 * No-op if not ringing.
 */
void slic_ring_stop(void);

/**
 * Returns true if slic_ring_start() was called and not yet stopped.
 */
bool slic_is_ringing(void);

#ifdef __cplusplus
}
#endif
