/* ****************************************************************************
 * File:      fet
 * Date:      15 Apr 2026
 * Author:    Andrew Levido
 *
 * Copyright 2026 Imbrius Pty Ltd - All Rights Reserved
 *
 *****************************************************************************/
#ifndef _mosfet_H
#define _mosfet_H

#ifdef __cplusplus
extern "C" {
#endif

/* Description ---------------------------------------------------------------*/

/* Includes ------------------------------------------------------------------*/
#include "app.h"
#include "analyser.h"

/* Defines -------------------------------------------------------------------*/
// Thresholds for characterisation

#define AX_MFET_ON_I              5000L      // 5mA in µA 
#define AX_MFET_V_STEP_LO         100L      // 10 mV
#define AX_MFET_V_STEP_HI         500L    // 100 mV

#define AX_JFET_PINCH_I           10L       // 10 µA  - pinch-off current

#define AX_FET_MAX_V              12000L    // 12V in mV

#define AX_JFET_V_STEP_HI         1000      // 1V     - big vg steps
#define AX_JFET_I_THR_MED         500L      // 500µA  - I threshold -> medium
#define AX_JFET_V_STEP_MED        100L      // 100mV  - medium vg steps
#define AX_JFET_I_THR_LO          50L       // 50µA   - I threshold -> little
#define AX_JFET_V_STEP_LO         10L       // 10 mV  - little vg steps

/* Typedefs & Enumerations ---------------------------------------------------*/

/* Public Functions Declarations ---------------------------------------------*/

/** Measure J-FET pinch-off voltage and display appropriate screen
 * @param gate         Gate lead
 * @param sd1          Source/Drain lead 1
 * @param sd2          Source/Drain lead 2 
 */
void ax_test_jfet(lead_t gate, lead_t sd1, lead_t sd2, bool pch);

/** Measure Enhancement MOSFET-FET Vgs(on) voltage and display appropriate screen
 * @param gate         Gate lead
 * @param source       Source lead
 * @param drain        Drain lead 
 * @param pch          True for P-Channel, False for N-Channel
 */
void ax_test_mosfet_enhancement(lead_t gate, lead_t source, lead_t drain, bool pch);

/** Measure IGBT Vgs(on) voltage and display appropriate screen
 * @param gate         Gate lead
 * @param emitter      Emitter lead
 * @param collector    Collector lead 
 * @param fwd          True for Frewheel diode, False for none
 */
void ax_test_igbt(lead_t gate, lead_t emitter, lead_t collector, bool fwd);

/** Measure Depletion MOSFET pinch-off voltage and display appropriate screen
 * @param gate         Gate lead
 * @param source       Source lead
 * @param drain        Drain lead 
 */
void ax_test_mosfet_depletion(lead_t gate, lead_t source, lead_t drain);

#ifdef __cplusplus
}
#endif

#endif

/* End mosfet */