Skip to main content

Data Structures

All structs are defined in Inc/npz.h unless otherwise noted.


Configuration Structs

npz_device_config_s

Top-level device configuration. Pass a pointer to npz_device_configure().

typedef struct {
// Power Switch Control (PSWCTL)
uint8_t power_switch_normal_mode_per1 : 1;
uint8_t power_switch_normal_mode_per2 : 1;
uint8_t power_switch_normal_mode_per3 : 1;
uint8_t power_switch_normal_mode_per4 : 1;
npz_host_power_mode_e host_power_mode;

// System Config 1 (SYSCFG1) — wake-up sources
uint8_t wake_up_per1 : 1;
uint8_t wake_up_per2 : 1;
uint8_t wake_up_per3 : 1;
uint8_t wake_up_per4 : 1;
npz_wakeup_e wake_up_any_or_all : 1;

// System Config 2 (SYSCFG2) — clock
npz_sclk_div_e system_clock_divider;
npz_sclk_sel_e system_clock_source;

// System Config 3 (SYSCFG3) — pins
npz_io_str_e io_strength;
npz_i2c_pull_sel_e i2c_pull_mode;
npz_spi_auto_e spi_auto;
npz_xo_clkout_div_e xo_clock_out_sel;

// Global timeout (TOUT) — 16-bit system clock periods
uint16_t global_timeout;

// Interrupt pin pull-ups (INTCFG)
npz_int_pin_pull_e interrupt_pin_pull_up_pin1;
npz_int_pin_pull_e interrupt_pin_pull_up_pin2;
npz_int_pin_pull_e interrupt_pin_pull_up_pin3;
npz_int_pin_pull_e interrupt_pin_pull_up_pin4;

// Peripheral configurations (NULL = disabled)
npz_peripheral_config_s *peripherals[4];

// ADC (SYSCFG2)
uint8_t adc_ext_sampling_enable : 1;
npz_adc_clk_e adc_clock_sel;
npz_adc_config_channels_s *adc_channels[2]; // [0]=internal, [1]=external
} npz_device_config_s;
FieldTypeDescription
power_switch_normal_mode_perNuint8_t : 1Normal-mode power switch state for peripheral N (0/1).
host_power_modenpz_host_power_mode_eSW_HP pin behaviour (power switch or logic output).
wake_up_perNuint8_t : 1Allow peripheral N to wake the host.
wake_up_any_or_allnpz_wakeup_eWake on any trigger (WAKEUP_ANY) or require all to fire (WAKEUP_ALL).
system_clock_dividernpz_sclk_div_eSystem clock divider.
system_clock_sourcenpz_sclk_sel_e10 Hz internal oscillator or 16 Hz clock generated by the 32 kHz crystal.
io_strengthnpz_io_str_eI/O output strength (normal / high).
i2c_pull_modenpz_i2c_pull_sel_eInternal I2C pull-up control.
spi_autonpz_spi_auto_eSPI pin hi-Z in sleep.
xo_clock_out_selnpz_xo_clkout_div_eCLK_OUT frequency (off, 32 kHz … 1 kHz).
global_timeoutuint16_tSystem clock periods before unconditional host wake. Must be > 0.
interrupt_pin_pull_up_pinNnpz_int_pin_pull_ePull-up strength for INT pin N.
peripherals[4]npz_peripheral_config_s*Array of peripheral configs; set to NULL to disable.
adc_ext_sampling_enableuint8_t : 1Enable external ADC_IN pin sampling (halves ADC rate when enabled).
adc_clock_selnpz_adc_clk_eADC sampling frequency.
adc_channels[2]npz_adc_config_channels_s*[0] = internal (VBAT), [1] = external (ADC_IN). Both must be non-NULL.

npz_peripheral_config_s

Configuration for one peripheral slot (I2C or SPI).

typedef struct {
npz_com_protocol_e communication_protocol;
npz_power_mode_e power_mode;
npz_polling_mode_e polling_mode;
npz_power_switch_mode_e power_switch_mode;
npz_interrupt_pin_mode_e interrupt_pin_mode;
npz_comparison_mode_e comparison_mode;
npz_data_type_e sensor_data_type;
npz_multibyte_e multi_byte_transfer_enable : 1;
npz_endianess_e swap_registers : 1;
uint16_t polling_period; // NOTE: zero is invalid

union {
struct { // I²C
uint8_t command_num;
uint8_t sensor_address;
uint8_t reg_address_value;
uint8_t wake_on_nak : 1;
uint8_t num_of_retries_on_nak : 2;
uint8_t bytes_from_sram[40];
} i2c_cfg;
struct { // SPI
uint8_t bytes_from_sram_num;
uint8_t bytes_from_sram_read_num;
uint8_t bytes_from_sram[40];
uint8_t bytes_from_sram_read[40];
npz_spimod_e mode;
} spi_cfg;
};

uint16_t threshold_over;
uint16_t threshold_under;
uint8_t time_to_wait;
npz_pre_wait_time_e pre_wait_time;
npz_post_wait_time_e post_wait_time;
} npz_peripheral_config_s;
FieldTypeDescription
communication_protocolnpz_com_protocol_eCOM_I2C or COM_SPI. Selects which union member applies.
power_modenpz_power_mode_eDisabled, periodic, or always-on.
polling_modenpz_polling_mode_eHow the IC polls: periodic read/compare, wait-for-interrupt, or async.
power_switch_modenpz_power_switch_mode_eSW_LP pin behavior.
interrupt_pin_modenpz_interrupt_pin_mode_eINT pin as input (active high/low) or trigger output.
comparison_modenpz_comparison_mode_eInside or outside threshold triggers wake.
sensor_data_typenpz_data_type_euint16, int16, or uint8.
multi_byte_transfer_enablenpz_multibyte_e : 1Send address + value as a single multi-byte I2C write.
swap_registersnpz_endianess_e : 1Swap high/low bytes for big-endian sensors.
polling_perioduint16_tPeriod in system clock periods. Never set to 0.
i2c_cfg.command_numuint8_tNumber of {reg, value} pairs to send from SRAM for init.
i2c_cfg.sensor_addressuint8_t7-bit I2C address of the sensor.
i2c_cfg.reg_address_valueuint8_tRegister on the sensor that holds the measurement value.
i2c_cfg.wake_on_nakuint8_t : 1Wake host if sensor NAKs its address.
i2c_cfg.num_of_retries_on_nakuint8_t : 2Retry count on NAK (0 = no retries).
i2c_cfg.bytes_from_sram[40]uint8_t[]Flat byte array: {reg0, val0, reg1, val1, …} for init.
spi_cfg.bytes_from_sram_numuint8_tTotal bytes to send from SRAM during init.
spi_cfg.bytes_from_sram_read_numuint8_tBytes from SRAM to use as the SPI read command.
spi_cfg.bytes_from_sram[40]uint8_t[]Bytes for SPI init sequence.
spi_cfg.bytes_from_sram_read[40]uint8_t[]Bytes for SPI read command.
spi_cfg.modenpz_spimod_eSPI mode (CPOL/CPHA).
threshold_overuint16_tUpper threshold (must match sensor_data_type).
threshold_underuint16_tLower threshold.
time_to_waituint8_tWait units (x256 or x4096 of internal 400 kHz clock).
pre_wait_timenpz_pre_wait_time_eApply wait before init sequence, after peripheral power up
post_wait_timenpz_post_wait_time_eApply wait after init sequence, before peripheral read

npz_adc_config_channels_s

Configuration for one ADC channel.

typedef struct {
uint8_t over_threshold; // 5-bit unsigned
uint8_t under_threshold; // 5-bit unsigned
uint8_t wakeup_enable : 1;
} npz_adc_config_channels_s;
FieldTypeDescription
over_thresholduint8_t5-bit/6-bit code — reading at or above this value triggers wake-up (if enabled).
under_thresholduint8_t5-bit/6-bit code — reading at or below this value triggers wake-up (if enabled).
wakeup_enableuint8_t : 11 = this ADC channel can wake the host.

Register Structs

These map directly to IC hardware registers. Used with the low-level npz_read_* / npz_write_* functions.

npz_register_sta1_s

typedef struct {
npz_resetsource_e reset_source : 3;
uint8_t padding : 2;
uint8_t ext_adc_triggered : 1;
uint8_t int_adc_triggered : 1;
uint8_t global_timeout_triggered : 1;
} npz_register_sta1_s;
FieldDescription
reset_sourceLast reset cause — power-on, external (RST pin), or soft reset.
ext_adc_triggeredExternal ADC (ADC_IN) threshold crossed.
int_adc_triggeredInternal ADC (VBAT) threshold crossed.
global_timeout_triggeredGlobal timeout expired before any other wake-up source triggered.

npz_register_sta2_s

typedef struct {
uint8_t per1_triggered : 1;
uint8_t per1_global_timeout : 1;
uint8_t per2_triggered : 1;
uint8_t per2_global_timeout : 1;
uint8_t per3_triggered : 1;
uint8_t per3_global_timeout : 1;
uint8_t per4_triggered : 1;
uint8_t per4_global_timeout : 1;
} npz_register_sta2_s;

Each peripheral has a _triggered bit (threshold crossed) and a _global_timeout bit (IC timed out waiting for that peripheral).


npz_register_pswctl_s

typedef struct {
uint8_t pswint_p1 : 1;
uint8_t pswint_p2 : 1;
uint8_t pswint_p3 : 1;
uint8_t pswint_p4 : 1;
npz_host_power_mode_e pswh_mode : 2;
uint8_t psw_en_vn : 1;
uint8_t psw_vn_on : 1;
} npz_register_pswctl_s;
FieldDescription
pswint_pNControls power switch output state for peripheral N.
pswh_modeHost SW_HP pin mode — power switch or logic output.
psw_en_vnGate boost enable for reduced Rds(on). NOTE: Not functional in the nPZero G1S!
psw_vn_onRead-only: 1 when gate boost is active.

npz_register_cfgp_s

typedef struct {
npz_power_mode_e pwmod : 2;
npz_polling_mode_e tmod : 2;
npz_power_switch_mode_e pswmod : 2;
npz_interrupt_pin_mode_e intmod : 2;
} npz_register_cfgp_s;

npz_register_modp_s

typedef struct {
npz_comparison_mode_e cmod : 1;
npz_data_type_e dtype : 2;
uint8_t seqrw : 1;
uint8_t wunak : 1;
uint8_t swprreg : 1;
npz_spimod_e spimod : 2;
} npz_register_modp_s;

Other Register Structs

StructRegisterKey Fields
npz_register_idle_rst_sIDLE_RSTvalue (0xFF = enter idle, 0xA5 = soft reset)
npz_register_id_sIDid (read-only chip ID)
npz_register_syscfg1_sSYSCFG1wup1wup4, ADC wake enables, wake_up_any_or_all
npz_register_syscfg2_sSYSCFG2sclk_div_en, sclk_div_sel, sclk_sel, adc_ext_on, adc_clk_sel
npz_register_syscfg3_sSYSCFG3io_str, i2c_pup_en, i2c_pup_auto, spi_auto, xo_clkout_div
npz_register_tout_sTOUT_L/Htout_l, tout_h (16-bit timeout)
npz_register_intcfg_sINTCFGpu_intN, pu_s_intN for N=1-4
npz_register_perp_sPERP_L/Hperp_l, perp_h (16-bit polling period)
npz_register_ncmdp_sNCMDPncmdp (7-bit command count)
npz_register_addrp_sADDRPaddrp (7-bit I2C addr / SPI byte count), spi_en
npz_register_rregp_sRREGPrregp (sensor data register address)
npz_register_throvp_sTHROVP_L/Hthrovp_l, throvp_h
npz_register_thrunp_sTHRUNP_L/Hthrunp_l, thrunp_h
npz_register_twtp_sTWTPtwtp (wait time units)
npz_register_tcfgp_sTCFGPtwt_en, twt_ext, tinit_en, tinit_ext, i2cret
npz_register_throva1_sTHROVA1throva (5-bit internal ADC over threshold)
npz_register_thruna1_sTHRUNA1thruna (5-bit internal ADC under threshold)
npz_register_throva2_sTHROVA2throva (6-bit external ADC over threshold)
npz_register_thruna2_sTHRUNA2thruna (6-bit external ADC under threshold)
npz_register_valp_sVALP_L/Hvalp_l, valp_h (last read peripheral value)
npz_register_adc_core_sADC_COREadc_core (5-bit VBAT ADC code)
npz_register_adc_ext_sADC_EXTadc_ext (6-bit ADC_IN code)
npz_register_sram_sSRAMvalue[128]
npz_status_sSTA1/2status1 (STA1), status2 (STA2)