/* ****************************************************************************
 * File:      bipolar
 * Date:      10 Apr 2026
 * Author:    Andrew Levido
 *
 * Copyright 2026 Imbrius Pty Ltd - All Rights Reserved
 *
 *****************************************************************************/
#ifndef _bipolar_H
#define _bipolar_H

#ifdef __cplusplus
extern "C" {
#endif

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

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

/* Defines -------------------------------------------------------------------*/
//  Vbe=0 test (for JFET)
#define AX_BJT_VB0_TEST_I             8000L       // 8 mA in µA

// Emitter/Collector test
#define AX_BJT_EC_TEST_I              500L        // 500 µA

// Vbe Test
#define AX_BJT_VBE_TEST_I             1000L       // 1mA
#define AX_BJT_VBE_DARL_V             800L        // Vbe > 800 mV = Darlington

// Hfe Test
#define AX_BJT_HFE_LO_IB              10L         // 10nA in nA
#define AX_BJT_HFE_MID_IB             250000L     // 250uA in nA
#define AX_BJT_HFE_HI_IB              2000000L    // 2mA in nA
#define AX_BJT_HFE_TEST_IC            8500L       // 8.5 mA
#define AX_BJT_HFE_TOL_IC             500L        // ±0.5mA
#define AX_BJT_HFE_MAX_ITER           20UL        // Should converge in <= 16

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

/* Public Functions Declarations ---------------------------------------------*/
/** Test NPN BJT &
 * Measures Vbe and flags darlington, measures Hfe and diplays the appropriate 
  * screen
  * @param base           Base
  * @param emitter        Emitter
  * @param collector      Collector
  * @param fwd            True if BJT has a freewheel diode
  */
void ax_test_bjt_npn(lead_t base, lead_t emitter, lead_t collector, bool fwd);
/** Test NPN BJT & display results
 * Measures Vbe and flags darlington, measures Hfe and diplays the appropriate 
  * screen
  * @param base           Base
  * @param emitter        Emitter
  * @param collector      Collector
  * @param fwd            True if BJT has a freewheel diode
  */
void ax_test_bjt_npn(lead_t base, lead_t emitter, lead_t collector, bool fwd);

/** Test PNP BJT & display results
 * Measures Vbe and flags darlington, measures Hfe and diplays the appropriate 
  * screen
  * @param base           Base
  * @param emitter        Emitter
  * @param collector      Collector
  * @param fwd            True if BJT has a freewheel diode
  */
void ax_test_bjt_pnp(lead_t base, lead_t emitter, lead_t collector, bool fwd);


/* Task Function -------------------------------------------------------------*/

/* Interrupt Service Routine Declarations ------------------------------------*/

#ifdef __cplusplus
}
#endif

#endif

/* End bipolar */