LCC Fusion Project 1.0
LCC Automation
Loading...
Searching...
No Matches
PstTestPins Class Reference

One-stop pin self-test utility with a single dispatcher entry point. More...

#include <PstTestPins.h>

Public Types

enum class  Type : uint8_t {
  IO , Input , Output , OpenDrain ,
  ADC , I2C_SDA , I2C_SCL , PWM ,
  Button , UART_RX , UART_TX , McpInput ,
  Unknown
}
 Declares the intended role of the pin so the dispatcher can run sensible tests. More...
 

Public Member Functions

 PstTestPins ()
 Default constructor (no configuration needed for ESP32).
 
bool testPin (uint8_t pin, Type type, const char *label=nullptr) const
 Run the appropriate self-test(s) for a pin based on its Type. More...
 
bool testMcpInput (Adafruit_MCP23017 *pMcp, uint8_t mcpPin, const char *name) const
 Run an input-only test on a port expander pin. More...
 
bool testOpen (uint8_t pin, const char *label=nullptr, bool gentle=false) const
 Run only the "open" heuristic on a pin. More...
 
bool testShorted (uint8_t pin, const char *label=nullptr, bool gentle=false) const
 Run only the "shorted" heuristic on a pin. More...
 

Static Public Member Functions

static void set_led (uint8_t pin, bool on)
 Convenience: drive an indicator LED with active-LOW polarity. More...
 
static void init_led (uint8_t pin)
 Initialize an indicator LED pin (OUTPUT, start OFF). More...
 

Private Member Functions

bool _testUartTx (uint8_t pin, const char *label) const
 UART-aware TX test (no loopback/jumpers required). More...
 
bool _testOpen (uint8_t pin, const char *name, bool gentle=false) const
 Heuristic "open” check using internal pulls. More...
 
bool _testShorted (uint8_t pin, const char *name, bool gentle=false) const
 Detects pins stuck HIGH or LOW using internal pulls. More...
 
bool _testDriveRead (uint8_t pin, const char *name) const
 Output toggle/readback sanity check. More...
 
bool _testOpenDrain (uint8_t pin, const char *name) const
 Open-drain verification: LOW drive then released HIGH (via pull-up). More...
 
bool _testAdc (uint8_t pin, const char *name) const
 ADC sanity check using ESP32 calibrated read (millivolts). More...
 
bool _testI2cLineCheck (uint8_t pin, const char *name, const char *lineName) const
 Preferred I²C line health check (no pulls, then diagnostic “nudge”). More...
 

Static Private Member Functions

static bool _isInputOnly (uint8_t pin)
 Returns true if a GPIO is input-only on ESP32 (GPIO 34-39). More...
 
static bool _hasInternalPulls (uint8_t pin)
 Returns true if the pin supports internal pull resistors. More...
 

Detailed Description

One-stop pin self-test utility with a single dispatcher entry point.

GPIO self‑test utility for LCC Fusion cards.

The dispatcher PstTestPins::testPin chooses appropriate checks based on PstTestPins::Type:

  • IO / Output: shorted check, open check, drive/readback
  • Input / Button: shorted check, open check
  • OpenDrain: open-drain specific drive/release behavior
  • ADC: reads calibrated millivolts and flags stuck-low/high
  • I2C_SDA / I2C_SCL: verifies bus lines idle HIGH without our pulls; diagnoses missing pull-ups vs. stuck-low
  • PWM: basic HIGH/LOW toggle sanity
  • UART_RX / UART_TX: UART-aware prep (gentle open/short on RX, idle HIGH on TX) then delegate to Input/Output paths
  • Mcp Input / Button: shorted check, open check

PstTestPins performs a suite of simple electrical checks on ESP32 pins (and MCP23017 expander pins) to help builders verify correct wiring and soldering before firmware initialization. Tests include checking for stuck pins, opens, shorts between power rails, basic drive/readback functionality and, for open‑drain and UART pins, appropriate biasing. Results are printed via the global g_serialIO using human‑readable language. Use testPin() to run tests appropriate for a given pin’s intended role (see Type).

Definition at line 62 of file PstTestPins.h.

Member Enumeration Documentation

◆ Type

enum class PstTestPins::Type : uint8_t
strong

Declares the intended role of the pin so the dispatcher can run sensible tests.

Enumerator
IO 

General‑purpose pin capable of input and output

Input 

Digital input only

Output 

Digital output

OpenDrain 

Open‑drain output: active LOW when driven, HIGH when released

ADC 

Analog input channel

I2C_SDA 

I²C data line (SDA); should idle HIGH

I2C_SCL 

I²C clock line (SCL); should idle HIGH

PWM 

PWM‑capable output; test performs a simple HIGH/LOW toggle

Button 

Momentary input such as a push‑button

UART_RX 

UART receive pin; DFPlayer TX -> ESP32 RX; uses gentle bias

UART_TX 

UART transmit pin; ESP32 TX -> DFPlayer RX; idles HIGH

McpInput 

Input on an MCP23017 expander; tested via testMcpInput()

Unknown 

Unspecified or unsupported pin type

Definition at line 68 of file PstTestPins.h.

Member Function Documentation

◆ _hasInternalPulls()

static bool PstTestPins::_hasInternalPulls ( uint8_t  pin)
inlinestaticprivate

Returns true if the pin supports internal pull resistors.

Parameters
pinGPIO number.
Note
On ESP32, GPIO 34-39 are input-only and lack internal pulls.

Definition at line 295 of file PstTestPins.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _isInputOnly()

static bool PstTestPins::_isInputOnly ( uint8_t  pin)
inlinestaticprivate

Returns true if a GPIO is input-only on ESP32 (GPIO 34-39).

Parameters
pinGPIO number.
Note
Used to skip drive tests and internal pull "nudges” where unsupported.

Definition at line 285 of file PstTestPins.h.

Here is the caller graph for this function:

◆ _testAdc()

bool PstTestPins::_testAdc ( uint8_t  pin,
const char *  name 
) const
inlineprivate

ADC sanity check using ESP32 calibrated read (millivolts).

Sets 11 dB attenuation (valid up to ~3.3 V), averages several samples, and flags likely shorts: near 0 mV (short to GND) or near 3.3 V (short to 3V3).

Parameters
pinADC-capable GPIO (ADC1 recommended).
nameLabel printed in logs.
Returns
true if value is in a reasonable range; false if near-0 or near-full-scale.

Definition at line 532 of file PstTestPins.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _testDriveRead()

bool PstTestPins::_testDriveRead ( uint8_t  pin,
const char *  name 
) const
inlineprivate

Output toggle/readback sanity check.

Skips driving input-only pins. For others:

  • Drive HIGH → expect to read HIGH
  • Drive LOW → expect to read LOW
Parameters
pinGPIO under test.
nameLabel printed in logs.
Returns
true if both levels read back as expected; false otherwise.

Definition at line 459 of file PstTestPins.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _testI2cLineCheck()

bool PstTestPins::_testI2cLineCheck ( uint8_t  pin,
const char *  name,
const char *  lineName 
) const
inlineprivate

Preferred I²C line health check (no pulls, then diagnostic “nudge”).

Note
Assumes external 3.3 V pull-ups (≈2.2–10 kΩ) are present and powered on the bus. On a bare bench (no pull-ups / unpowered target), this test will report “missing pull-up” by design.

Procedure: 1) Observe the line as INPUT (no internal pull). A healthy, powered bus idles HIGH. 2) If LOW, briefly enable INPUT_PULLUP:

  • If it goes HIGH, likely missing/not-powered external pull-up.
  • If it stays LOW, likely shorted or a device is holding the line.
Parameters
pinGPIO to check.
nameLabel for logs.
lineName"SDA" or "SCL" (for messages).
Returns
true if line is HIGH at idle without our pulls; false otherwise.

Definition at line 575 of file PstTestPins.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _testOpen()

bool PstTestPins::_testOpen ( uint8_t  pin,
const char *  name,
bool  gentle = false 
) const
inlineprivate

Heuristic "open” check using internal pulls.

When gentle is false (default), performs a full up/down nudge:

  • INPUT_PULLUP → read
  • INPUT_PULLDOWN → read A good open net follows both nudges (HIGH with PULLUP, LOW with PULLDOWN).

When gentle is true (UART-safe), avoids PULLDOWN (never weakly drives LOW):

  • unbiased INPUT → read (idle)
  • INPUT_PULLUP → read (up)

Skips nudges on input-only pins (no internal pulls).

Parameters
pinGPIO under test.
nameLabel printed in logs.
gentleIf true, avoid INPUT_PULLDOWN and use a UART-safe probe.
Returns
true if behavior matches expectations; false if stuck or odd readings.

Definition at line 319 of file PstTestPins.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _testOpenDrain()

bool PstTestPins::_testOpenDrain ( uint8_t  pin,
const char *  name 
) const
inlineprivate

Open-drain verification: LOW drive then released HIGH (via pull-up).

Procedure:

  • Actively drive LOW and confirm readback LOW.
  • Switch to INPUT_PULLUP (release) and confirm readback HIGH.
Parameters
pinGPIO under test.
nameLabel printed in logs.
Returns
true on expected behavior; false if mismatch.

Definition at line 496 of file PstTestPins.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _testShorted()

bool PstTestPins::_testShorted ( uint8_t  pin,
const char *  name,
bool  gentle = false 
) const
inlineprivate

Detects pins stuck HIGH or LOW using internal pulls.

When gentle is false (default), performs a full up/down nudge:

  • INPUT_PULLUP → read
  • INPUT_PULLDOWN → read If both reads are LOW → likely shorted LOW. If both HIGH → likely shorted HIGH.

When gentle is true (UART-safe), avoids PULLDOWN; we only test the ability to go HIGH:

  • unbiased INPUT → read
  • INPUT_PULLUP → read

Skips nudges on input-only pins (no internal pulls).

Parameters
pinGPIO under test.
nameLabel printed in logs.
gentleIf true, avoid INPUT_PULLDOWN and use a UART-safe probe.
Returns
true if not obviously stuck; false if likely shorted.

Definition at line 397 of file PstTestPins.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _testUartTx()

bool PstTestPins::_testUartTx ( uint8_t  pin,
const char *  label 
) const
inlineprivate

UART-aware TX test (no loopback/jumpers required).

Behavior:

  • Sets UART idle level HIGH (OUTPUT, HIGH) before testing to avoid sending long LOW pulses into a receiver.
  • Delegates to the standard Output checks (shorted + drive/readback) for consistent reporting.
Parameters
pinESP32 TX GPIO (connected to DFPlayer RX).
labelLabel printed in logs.
Returns
true if delegated Output tests pass; false otherwise.

Definition at line 267 of file PstTestPins.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_led()

static void PstTestPins::init_led ( uint8_t  pin)
inlinestatic

Initialize an indicator LED pin (OUTPUT, start OFF).

Parameters
pinLED GPIO.

Definition at line 115 of file PstTestPins.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_led()

static void PstTestPins::set_led ( uint8_t  pin,
bool  on 
)
inlinestatic

Convenience: drive an indicator LED with active-LOW polarity.

Parameters
pinLED GPIO.
onTrue to turn LED on (drives LOW), false to turn off (drives HIGH).

Definition at line 106 of file PstTestPins.h.

Here is the caller graph for this function:

◆ testMcpInput()

bool PstTestPins::testMcpInput ( Adafruit_MCP23017 *  pMcp,
uint8_t  mcpPin,
const char *  name 
) const
inline

Run an input-only test on a port expander pin.

Configures the specified MCP23017 pin as a pulled‑up input and prints whether it reads LOW (wired to ground) or HIGH (floating). It does not drive the pin or change its OLAT register, so it is safe to call for unconnected inputs. If pMcp is null the function logs a warning and returns false.

Parameters
pMcpPointer to a configured Adafruit_MCP23017 instance.
mcpPinMCP23017 pin number (0–15) to test.
nameOptional label used in log messages; defaults to "MCP_PIN".
Return values
trueThe test completed (always informational; does not flag failure).
falsepMcp was null and the test did not run.

Definition at line 205 of file PstTestPins.h.

Here is the call graph for this function:

◆ testOpen()

bool PstTestPins::testOpen ( uint8_t  pin,
const char *  label = nullptr,
bool  gentle = false 
) const
inline

Run only the "open" heuristic on a pin.

Parameters
pinGPIO under test.
labelOptional label for logs.
gentleIf true, performs a gentle open check (avoids INPUT_PULLDOWN; uses only unbiased read + PULLUP).
Returns
true if behavior matches an open/floatable net; false if stuck or odd readings.

Definition at line 238 of file PstTestPins.h.

Here is the call graph for this function:

◆ testPin()

bool PstTestPins::testPin ( uint8_t  pin,
Type  type,
const char *  label = nullptr 
) const
inline

Run the appropriate self-test(s) for a pin based on its Type.

Parameters
pinESP32 GPIO number (e.g., 21).
typeIntended role (determines which checks run).
labelOptional user label for messages (e.g., "I2C_SDA"); falls back to "PIN".
Returns
true if all checks for that type pass; false if any check flags an issue.

Dispatch map:

  • IO: shorted + open + drive/readback
  • Input: shorted + open (no driving)
  • Output: shorted + drive/readback
  • OpenDrain: open-drain pattern (LOW drive, released HIGH)
  • ADC: calibrated mV reading; warns on near-0 or near-3V3 values
  • I2C_SDA/SCL:observe idle without our pulls; diagnose missing pull-ups vs. stuck-low
  • PWM: same as Output minimal toggle
  • Button: same as Input
  • UART_RX: UART-aware RX (gentle short/open) then Input checks
  • UART_TX: UART-aware TX (idle HIGH) then Output checks

Definition at line 143 of file PstTestPins.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ testShorted()

bool PstTestPins::testShorted ( uint8_t  pin,
const char *  label = nullptr,
bool  gentle = false 
) const
inline

Run only the "shorted" heuristic on a pin.

Parameters
pinGPIO under test.
labelOptional label for logs.
gentleIf true, performs a gentle short check (avoids INPUT_PULLDOWN; uses only unbiased read + PULLUP).
Returns
true if not obviously stuck; false if likely shorted.

Definition at line 250 of file PstTestPins.h.

Here is the call graph for this function:

The documentation for this class was generated from the following file: