Skip to content

Commit

Permalink
Detect and configure WLAN Pi Go at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
jiribrejcha authored Aug 29, 2024
1 parent 5f46e61 commit dc07aed
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 5 deletions.
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
wlanpi-common (1.1.23) unstable; urgency=medium

* Detect and configure WLAN Pi Go at startup

-- Jiri Brejcha <[email protected]> Thu, 29 Aug 2024 23:02:00 +0100

wlanpi-common (1.1.22-1) unstable; urgency=medium

* wlanpi-model command executed on M4+ now shows USB mode (host/OTG)
Expand Down
4 changes: 3 additions & 1 deletion etc/update-motd.d/00-wlanpi-motd
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ elif [[ "$MODEL" == "Mcuzone M4+" ]]; then
WLAN_PI_MODEL="WLAN Pi M4+"
elif [[ "$MODEL" == "Mcuzone M4" ]]; then
WLAN_PI_MODEL="WLAN Pi M4"
elif [[ "$MODEL" == "Oscium Go" ]]; then
WLAN_PI_MODEL="WLAN Pi Go"
else
WLAN_PI_MODEL="Unsupported hardware platform"
fi
Expand Down Expand Up @@ -114,4 +116,4 @@ fi
if [ -n "$SOFTWARE_UPDATES" ]; then
echo " Software updates are available " | toilet -f term --filter border:metal
echo -e "$SOFTWARE_UPDATES"
fi
fi
66 changes: 62 additions & 4 deletions opt/wlanpi-common/wlanpi-config-at-startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ debugger() {
fi
}

# Set baud rate for WLAN Pi Go discover port
stty -F /dev/ttyAMA0 115200 2>/dev/null

# Get WLAN Pi model
MODEL=$(wlanpi-model | grep "Main board:" | cut -d ":" -f2 | xargs)
debugger "Detected WLAN Pi model: $MODEL"
Expand Down Expand Up @@ -224,8 +227,8 @@ if [[ "$MODEL" == "Mcuzone M4+" ]]; then
# Create temporary file to collect ping results
RESULT_FILE=$(mktemp)

# Wait for usb0 interface to become available and for far end RNDIS device to obtain IP address
sleep 2
# Wait for usb0 interface to become available, Mac user to accept security dialog, and for far end RNDIS device to obtain IP address
sleep 5

# Ping the specified IP addresses in parallel
for i in $(seq $START $END); do
Expand Down Expand Up @@ -309,7 +312,7 @@ if [[ "$MODEL" == "Mcuzone M4+" ]]; then
debugger "Detected 1 line in lsusb output"
# Ping remote device via OTG usb0 link to see if OTG is operational
ping_otg

if [ -n "$OTG_PING_SUCCESS" ]; then
debugger "Operating correctly in USB OTG mode, do nothing"
elif grep -q -E "^\s*otg_mode=1" /boot/config.txt ; then
Expand Down Expand Up @@ -345,6 +348,61 @@ if [[ "$MODEL" == "Mcuzone M4+" ]]; then
fi
fi


########## Go ##########

# Apply Go platform specific settings
if [[ "$MODEL" == "Oscium Go" ]]; then
echo "Applying WLAN Pi Go settings"
debugger "Disabling FPMS service"
systemctl disable wlanpi-fpms.service

# Disable RTC
if grep -q -E "^\s*dtoverlay=i2c-rtc,pcf85063a,addr=0x51" /boot/config.txt; then
debugger "RTC is enabled, disabling it now"
sed -i "s/^\s*dtoverlay=i2c-rtc,pcf85063a,addr=0x51/#dtoverlay=i2c-rtc,pcf85063a,addr=0x51/" /boot/config.txt
REQUIRES_REBOOT=1
else
debugger "RTC is already disabled, no action needed"
fi

# Disable battery gauge
if grep -q -E "^\s*dtoverlay=battery_gauge" /boot/config.txt; then
debugger "Battery gauge is enabled, disabling it now"
sed -i "s/^\s*dtoverlay=battery_gauge/#dtoverlay=battery_gauge/" /boot/config.txt
REQUIRES_REBOOT=1
else
debugger "Battery gauge is already disabled, no action needed"
fi

# Set USB mode to OTG mode
CM4_LINE_NUMBER=$(grep -n "\[cm4\]" /boot/config.txt | cut -d ":" -f1)
LINES_BELOW_CM4=$(sed -n '/\[cm4\]/,/\[*\]/p' /boot/config.txt | grep -n "dtoverlay=dwc2,dr_mode=host" | cut -d ":" -f1)
if [[ $CM4_LINE_NUMBER -gt 0 ]] && [[ $LINES_BELOW_CM4 -gt 0 ]]; then
DR_MODE_LINE_NUMBER=$(($CM4_LINE_NUMBER + $LINES_BELOW_CM4 - 1))
debugger "Found \"dtoverlay=dwc2,dr_mode=host\" CM4 config on line $DR_MODE_LINE_NUMBER"
debugger "Setting CM4 USB to otg mode"
sed -i "${DR_MODE_LINE_NUMBER}s/.*/dtoverlay=dwc2,dr_mode=otg/" /boot/config.txt
REQUIRES_REBOOT=1
elif ! sed -n '/\[cm4\]/,/\[*\]/p' /boot/config.txt | grep -q "^\s*dtoverlay=dwc2,dr_mode=otg"; then
debugger "USB mode setting not found in config file, creating a new line in CM4 section"
sed -i "s/\[cm4\]/&\ndtoverlay=dwc2,dr_mode=otg\n/" /boot/config.txt
REQUIRES_REBOOT=1
else
debugger "USB mode is already set to OTG mode, no action needed"
fi

# Comment otg_mode=1 line out to enable OTG
if grep -q -E "^\s*otg_mode=1" /boot/config.txt ; then
debugger "Found otg_mode=1 in config file"
debugger "Commenting otg_mode=1 out"
sed -i "s/^\s*otg_mode=1/#otg_mode=1/" /boot/config.txt
REQUIRES_REBOOT=1
fi

fi


########## Pro ##########

# Apply WLAN Pi Pro platform specific settings
Expand Down Expand Up @@ -395,4 +453,4 @@ fi
if [ "$REQUIRES_REBOOT" -gt 0 ]; then
echo "Reboot required, rebooting now"
reboot
fi
fi
12 changes: 12 additions & 0 deletions opt/wlanpi-common/wlanpi-model.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ elif grep -q "Raspberry Pi Compute Module 4" /proc/cpuinfo; then

# It is powered by CM4 but it isn't Pro


# Is it Go?
elif timeout 2 grep -q -m 1 -E "^14," /dev/ttyAMA0 2>/dev/null; then
debugger "Detected Go"
if [ "$BRIEF_OUTPUT" -ne 0 ]; then
echo "Go"
else
echo "Model: WLAN Pi Go"
echo "Main board: Oscium Go"
fi
debugger "End script now. Platform is Go."

# Is it M4+?
elif i2cdetect -y 1 2>/dev/null | grep -q "50: 50"; then
debugger "Detected M4+ Mcuzone EEPROM"
Expand Down

0 comments on commit dc07aed

Please sign in to comment.