#!/bin/sh # # reset_lgw.sh (libgpiod version) # Replaces legacy /sys/class/gpio export/direction/value usage. # # Usage: # ./reset_lgw.sh start # ./reset_lgw.sh stop # # Environment override: # GPIOCHIP=gpiochip0 ./reset_lgw.sh start # set -eu # --- GPIO mapping (BCM numbers) --- SX1302_RESET_PIN=23 # SX1302 reset SX1302_POWER_EN_PIN=18 # SX1302 power enable SX1261_RESET_PIN=22 # SX1261 reset (LBT / Spectral Scan) AD5338R_RESET_PIN=13 # AD5338R reset (reference design; may be unused on your HAT) CHIP="${GPIOCHIP:-gpiochip0}" # Small sleeps to let rails settle WAIT() { sleep 0.10; } # gpioset helper: # libgpiod v1.x: gpioset defaults to holding the line until the process exits. # Using "-m time -s " makes it deterministic for pulses. #SET_FOR() { # # $1=line $2=value $3=seconds # /usr/sbin/gpioset -m time -s "$3" "$CHIP" "$1=$2" >/dev/null 2>&1 || { # echo "ERROR: gpioset failed on $CHIP line $1=$2 (check chip name/permissions)" >&2 # exit 1 # } #} # #SET_HOLD() { # # Hold briefly but long enough for power enable # # Using time mode too, so we don't leave lines requested forever. # /usr/sbin/gpioset -m time -s 1.0 "$CHIP" "$1=$2" >/dev/null 2>&1 || { # echo "ERROR: gpioset failed on $CHIP line $1=$2" >&2 # exit 1 # } #} SET_FOR_USEC() { # $1=line $2=value $3=usec /usr/sbin/gpioset --mode=time --usec "$3" "$CHIP" "$1=$2" >/dev/null 2>&1 || { echo "ERROR: gpioset failed on $CHIP line $1=$2" >&2 exit 1 } } SET_FOR_SEC() { # $1=line $2=value $3=sec (integer) /usr/sbin/gpioset --mode=time --sec "$3" "$CHIP" "$1=$2" >/dev/null 2>&1 || { echo "ERROR: gpioset failed on $CHIP line $1=$2" >&2 exit 1 } } reset() { echo "CoreCell power enable through ${CHIP} line ${SX1302_POWER_EN_PIN}..." echo "CoreCell reset through ${CHIP} line ${SX1302_RESET_PIN}..." echo "SX1261 reset through ${CHIP} line ${SX1261_RESET_PIN}..." echo "ADC reset through ${CHIP} line ${AD5338R_RESET_PIN}..." # # Power enable ON (hold long enough to cover the reset sequence) # SET_HOLD "$SX1302_POWER_EN_PIN" 1 # WAIT # # # SX1302 reset pulse (many designs are active-low; this matches Semtech script) # SET_FOR "$SX1302_RESET_PIN" 1 0.10 # SET_FOR "$SX1302_RESET_PIN" 0 0.10 # WAIT # # # SX1261 reset pulse # SET_FOR "$SX1261_RESET_PIN" 0 0.10 # SET_FOR "$SX1261_RESET_PIN" 1 0.10 # WAIT # # # Optional ADC reset pulse (harmless if line is unused, but may error if not present) # # If this line causes failure on your HAT, set AD5338R_RESET_PIN to an unused line # # or comment these two lines out. # SET_FOR "$AD5338R_RESET_PIN" 0 0.10 # SET_FOR "$AD5338R_RESET_PIN" 1 0.10 # WAIT # # 2/18/26 8:17 AM below replaces above # # Power enable ON for 1 second (enough to cover reset sequencing) SET_FOR_SEC "$SX1302_POWER_EN_PIN" 1 1 WAIT # SX1302 reset pulse (100ms high then 100ms low) SET_FOR_USEC "$SX1302_RESET_PIN" 1 100000 SET_FOR_USEC "$SX1302_RESET_PIN" 0 100000 WAIT # SX1261 reset pulse (100ms low then 100ms high) SET_FOR_USEC "$SX1261_RESET_PIN" 0 100000 SET_FOR_USEC "$SX1261_RESET_PIN" 1 100000 WAIT # ADC reset pulse (often unused on HATs; safe to try, but you can comment out if needed) SET_FOR_USEC "$AD5338R_RESET_PIN" 0 100000 SET_FOR_USEC "$AD5338R_RESET_PIN" 1 100000 WAIT } case "${1:-}" in start) reset ;; stop) reset ;; *) echo "Usage: $0 {start|stop}" >&2 exit 1 ;; esac exit 0