Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

Updated the GPIO Trigger functionality to allow custom GPIO ports - New PR due to master gaining new changes #546

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,15 @@ To force Recovery Mode to be entered on boot and to show the NOOBS interface, yo

To force Recovery Mode being entered on boot, connect GPIO pin 3 on header P1 to GND (pin 25). If GPIO pin 3 remains unconnected then it will boot through to the installed OS as normal.

##### Modifying the GPIO Trigger
If you would like to use a different GPIO pin, for example if you have a push button or similar mechanism, to trigger the Recovery Mode append the `gpiotriggerenable` as described above and then perform the following steps:
1. Append `gpiochannel=[gpiopin]` to the argument list in the `recovery.cmdline` file which is found in the root NOOBS directory. `[gpiopin]` should be the GPIO pin number you wish to use, for example to use GPIO 15 you would append: `gpiochannel=15`
2. Reboot

If you would like the GPIO pin to only trigger the Recovery Mode when the GPIO value becomes high instead of low (default) perform the following steps:
1. Append `gpiochannelvalue=[value]` to the argument list in the `recovery.cmdline` file which is found in the root NOOBS directory. `[value]` should be `1` if you want the trigger when the GPIO pin is high and `0` when the pin is low (default). For example to continue our example from above using GPIO 15, if we want to have it trigger when the pin is high you would append: `gpiochannelvalue=1` in addition to the `gpiochannel` argument already added.
2. Reboot

#### How to force Recovery Mode being entered on boot (overrides GPIO or keyboard input)

Alternatively, if you are unable to use either the GPIO or keyboard to trigger entering Recovery Mode, you can:
Expand Down
10 changes: 9 additions & 1 deletion buildroot/package/recovery/init
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ else
DEFAULT_KBD=
DEFAULT_DISPLAY=
DEFAULT_PARTITION=
GPIO_CHANNEL=
GPIO_CHANNEL_VALUE=

if grep -q runinstaller /proc/cmdline; then
RUN_INSTALLER=-runinstaller
Expand All @@ -88,9 +90,15 @@ else
if [ "${p%%=*}" == "partition" ] ; then
DEFAULT_PARTITION="-partition ${p#*=}"
fi
if [ "${p%%=*}" == "gpiochannel" ] ; then
GPIO_CHANNEL="-gpiochannel ${p#*=}"
fi
if [ "${p%%=*}" == "gpiochannelvalue" ] ; then
GPIO_CHANNEL_VALUE="-gpiochannelvalue ${p#*=}"
fi
done

/usr/bin/recovery $RUN_INSTALLER $GPIO_TRIGGER $KEYBOARD_NO_TRIGGER $FORCE_TRIGGER $DEFAULT_KBD $DEFAULT_LANG $DEFAULT_DISPLAY $DEFAULT_PARTITION -qws 2>/tmp/debug
/usr/bin/recovery $RUN_INSTALLER $GPIO_TRIGGER $KEYBOARD_NO_TRIGGER $FORCE_TRIGGER $DEFAULT_KBD $DEFAULT_LANG $DEFAULT_DISPLAY $DEFAULT_PARTITION $GPIO_CHANNEL $GPIO_CHANNEL_VALUE -qws 2>/tmp/debug

fi

Expand Down
18 changes: 16 additions & 2 deletions recovery/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ int main(int argc, char *argv[])
qDebug() << "Board revision is " << rev;

int gpioChannel;
int gpioChannelValue = 0;

if (rev == 2 || rev == 3)
gpioChannel = 0;
Expand All @@ -134,7 +135,6 @@ int main(int argc, char *argv[])
QApplication a(argc, argv);
RightButtonFilter rbf;
LongPressHandler lph;
GpioInput gpio(gpioChannel);

bool runinstaller = false;
bool gpio_trigger = false;
Expand Down Expand Up @@ -185,8 +185,22 @@ int main(int argc, char *argv[])
if (argc > i+1)
defaultPartition = argv[i+1];
}
// Allow gpio channel to be specified in commandline
else if (strcmp(argv[i], "-gpiochannel") == 0)
{
if (argc > i+1)
gpioChannel = atoi(argv[i+1]);
}
// Allow gpio channel value i.e pull up or pull down to be specified in commandline
else if (strcmp(argv[i], "-gpiochannelvalue") == 0)
{
if (argc > i+1)
gpioChannelValue = atoi(argv[i+1]);
}
}

GpioInput gpio(gpioChannel);

// Intercept right mouse clicks sent to the title bar
a.installEventFilter(&rbf);

Expand Down Expand Up @@ -252,7 +266,7 @@ int main(int argc, char *argv[])
// or no OS is installed (/settings/installed_os.json does not exist)
bool bailout = !runinstaller
&& !force_trigger
&& !(gpio_trigger && (gpio.value() == 0 ))
&& !(gpio_trigger && (gpio.value() == gpioChannelValue))
&& hasInstalledOS(drive);

if (bailout && keyboard_trigger)
Expand Down