system/factory_reset_gpio/main.c

/*******************************************************************************
* # License
* Copyright 2019 Silicon Laboratories Inc. www.silabs.com
*******************************************************************************
*
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
******************************************************************************/
/* Documentation for this app is available online.
* See https://docs.silabs.com/gecko-os/4/standard/latest/sdk/examples/system/factory-reset-gpio
*/
#include "gos.h"
#define APPLICATION_START_LINE "\r\nFactory Reset GPIO example starting ..."
#define NEW_FACTORY_RESET_GPIO GOS_GPIO_0
#define NEW_FACTORY_RESET_LEVEL true
/*************************************************************************************************
* This is called BEFORE the system is initialized.
* EXTREME care must be given to the operations that are executed here.
*
* NOTE: Log prints will NOT work here!!
*
*/
void gos_app_preinit(void)
{
// Configure the new factory reset GPIO
// NOTE: Since this is being configured here, in gos_app_preinit(),
// the updated factory reset GPIO will be updated BEFORE the GPIO is tested by the system.
gos_system_set_factory_reset_gpio(NEW_FACTORY_RESET_GPIO, NEW_FACTORY_RESET_LEVEL);
}
/*************************************************************************************************/
void gos_app_init(void)
{
gos_result_t result;
gos_gpio_t factory_reset_gpio;
bool gpio_level;
GOS_LOG(APPLICATION_START_LINE);
if(GOS_FAILED(result, gos_system_get_factory_reset_gpio(&factory_reset_gpio, &gpio_level)))
{
GOS_LOG("Failed to retrieve the factory reset GPIO config, err:%d", result);
}
else
{
GOS_LOG("Factory reset GPIO: %d, active: %s", factory_reset_gpio, gpio_level ? "HIGH" : "LOW");
GOS_LOG("\r\nTo invoke a factory reset via GPIO, do the following:");
GOS_LOG("1. Assert and hold GPIO%d %s", factory_reset_gpio, gpio_level ? "HIGH" : "LOW");
GOS_LOG("2. Reset the device (via reset signal or issue the 'reboot' command)");
GOS_LOG("3. Continue to hold GPIO%d %s for ~10s", factory_reset_gpio, gpio_level ? "HIGH" : "LOW");
GOS_LOG("4. De-assert GPIO%d", factory_reset_gpio);
GOS_LOG("\r\nThis should cause the device to revert to its factory default settings");
}
}