system_config Reference

Global runtime configuration struct holding all Bus Pirate settings, state, and pin assignments.


Overview

The system_config struct is a single global instance (extern struct _system_config system_config) defined in src/system_config.h. It is initialized by system_init() at startup and read/written throughout the firmware. Most uint32_t fields use that width to standardize JSON parsing for persisted settings.

#include "system_config.h"

// Access anywhere in the firmware:
if (system_config.mode == 0) { /* HiZ */ }

Mode & Protocol State

FieldTypeDefaultPurpose
modeuint8_t0Current active protocol mode enum
hizuint8_t1Currently in HiZ (high-impedance) mode
displayuint8_t0Current display mode enum
subprotocol_nameconst char*NULLOptional sub-protocol name string
mode_activeuint8_t0Mode is fully initialized and running
num_bitsuint8_t8Number of data bits per transfer
bit_orderuint8_t0Bit order: 0 = MSB first, 1 = LSB first
write_with_readuint8_t0Write-with-read enabled
open_drainuint8_t0Open drain pin mode (1 = enabled)
pullup_enableduint8_t0Pull-up resistors enabled (0 = off, 1 = on)
display_formatuint32_tdf_autoNumber display format (decimal, hex, octal, binary)

Pin Tracking

FieldTypeDefaultPurpose
pin_labels[HW_PINS]const char*[]Per-pinHuman-readable label for each header pin
pin_func[HW_PINS]enum bp_pin_func[]Per-pinFunction assigned to each pin (BP_PIN_IO, BP_PIN_VREF, etc.)
pin_changeduint32_t0xFFFFFFFFBitmask of pins whose labels/functions changed (triggers UI update)
info_bar_changedboolfalseStatus bar needs a full redraw

Pin 0 is initialized to BP_PIN_VREF and pin 9 to BP_PIN_GROUND. All other pins default to BP_PIN_IO. Use the helper functions rather than writing these fields directly.


Error Handling

FieldTypeDefaultPurpose
erroruint8_t0Error flag for command chaining

Set system_config.error = true in error paths to signal the command dispatcher. The syntax engine uses this flag to evaluate chained operators (;, ||, &&). See error_handling_reference.md for conventions.


Terminal Settings

FieldTypeDefaultPurpose
terminal_languageuint32_t0UI language selection index
terminal_usb_enableuint32_ttrueEnable USB CDC terminal
terminal_uart_enableuint32_tfalseEnable UART terminal on IO pins
terminal_uart_numberuint32_t1Which UART to use for terminal (0 or 1)
terminal_ansi_rowsuint8_t24Terminal height in rows
terminal_ansi_columnsuint8_t80Terminal width in columns
terminal_ansi_coloruint32_tUI_TERM_NO_COLORANSI color scheme
terminal_ansi_statusbaruint32_t0Status bar display mode
terminal_ansi_statusbar_updateboolfalseStatus bar needs update
terminal_ansi_statusbar_pauseboolfalseStatus bar updates paused
terminal_hide_cursorboolfalseHide terminal cursor
terminal_updateuint8_t0Terminal update flags

LED & LCD Settings

FieldTypeDefaultPurpose
led_coloruint32_t0xFF0000RGB color value (0xRRGGBB)
led_brightness_divisoruint32_t10Brightness divisor (10 = 10%, 5 = 20%, 4 = 25%)
led_effectled_effect_tLED_EFFECT_DISABLEDCurrent LED animation effect
led_effect_as_uint32uint32_tUnion alias of led_effect for JSON parsing
lcd_screensaver_activeuint32_tfalseLCD screensaver currently active
lcd_timeoutuint32_t0LCD screensaver timeout in seconds (0 = disabled)

The led_effect / led_effect_as_uint32 union allows the LED effect enum to be read/written as a uint32_t for JSON serialization.


Storage

FieldTypeDefaultPurpose
storage_availableuint8_t0Storage device detected and available
storage_mount_erroruint8_t3Storage mount error code
storage_fat_typeuint8_t5FAT filesystem type (12/16/32)
storage_sizefloat0Storage size in MB

See storage_guide.md for details on storage initialization and error codes.


Debug Settings

FieldTypeDefaultPurpose
debug_uart_enableuint32_tfalseInitialize a UART for developer debugging
debug_uart_numberuint32_t0Which UART to use for debug (0 or 1)
bpio_debug_enableuint32_tfalseEnable debug output for BPIO binary protocol

Configuration & Hardware

FieldTypeDefaultPurpose
config_loaded_from_fileboolfalseTrue if config was loaded from storage (bpconfig.bp)
disable_unique_usb_serial_numberuint32_tfalseDisable unique USB serial number (for manufacturing)
hardware_revisionuint8_t0Hardware revision number

PWM, Frequency & Auxiliary Pins

FieldTypeDefaultPurpose
pwm_activeuint8_t0Bitmask of active PWM channels (one bit per pin)
freq_config[BIO_MAX_PINS]_pwm_config[]zeroedPWM/frequency settings per pin (period + duty cycle)
freq_activeuint8_t0Bitmask of active frequency measurement channels
aux_activeuint8_t0Bitmask of user-controlled auxiliary output pins

The _pwm_config struct holds float period (seconds) and float dutycycle (0.0–1.0).


Binary Mode

FieldTypeDefaultPurpose
binmode_usb_rx_queue_enablebooltrueEnable binmode RX queue (false = direct TinyUSB access)
binmode_usb_tx_queue_enablebooltrueEnable binmode TX queue (false = direct TinyUSB access)
binmode_selectuint8_t0Index of currently active binary mode
binmode_lock_terminalboolfalseLock (disable) terminal while in binary mode

Miscellaneous

FieldTypeDefaultPurpose
big_buffer_owneruint32_tBP_BIG_BUFFER_NONECurrent owner of the shared big buffer
rtsboolfalseRTS flow control state

When to Read vs. Write

  • Read freelysystem_config.mode, system_config.hiz, pin state, storage status, display format
  • Write carefullysystem_config.error (set in error paths only), pin_labels/pin_func (in setup_exc/cleanup only, prefer helper functions)
  • Never write directlysystem_config.mode (changed by the mode selection system), storage_* fields (managed by the storage subsystem)

Helper Functions

Defined in src/system_config.h and implemented in src/system_config.c:

// Initialize all fields to defaults — call once at startup
void system_init(void);

// Update a header pin's function and label (by absolute pin index)
// Refuses to modify pins reserved for debug UART
void system_pin_update_purpose_and_label(bool enable, uint8_t pin, enum bp_pin_func func, const char* label);

// Update a BIO pin's function and label (by BIO pin index, offset +1 internally)
void system_bio_update_purpose_and_label(bool enable, uint8_t bio_pin, enum bp_pin_func func, const char* label);

// Track pin active state in a function register bitmask (pwm_active, freq_active, aux_active)
void system_set_active(bool active, uint8_t bio_pin, uint8_t* function_register);

Usage example — claiming a pin for PWM:

system_bio_update_purpose_and_label(true, bio_pin, BP_PIN_PWM, "PWM");
system_set_active(true, bio_pin, &system_config.pwm_active);

Usage example — releasing a pin:

system_bio_update_purpose_and_label(false, bio_pin, BP_PIN_IO, NULL);
system_set_active(false, bio_pin, &system_config.pwm_active);