From 059423ca66b01a4ae15f9a127add0d09f12d78de Mon Sep 17 00:00:00 2001 From: Jonas Arnold Date: Fri, 21 Oct 2022 13:22:17 +0200 Subject: [PATCH] implemented GPIO Raspi Shutdown indicator, added documentation for dtoverlay --- ADIS_tinyK22_RpiHat/raspi-overlayconfig.txt | 10 ++++- ADIS_tinyK22_RpiHat/source/application.c | 45 ++++++++++++++++----- ADIS_tinyK22_RpiHat/source/platform.c | 1 - 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/ADIS_tinyK22_RpiHat/raspi-overlayconfig.txt b/ADIS_tinyK22_RpiHat/raspi-overlayconfig.txt index 135fdef..e290283 100644 --- a/ADIS_tinyK22_RpiHat/raspi-overlayconfig.txt +++ b/ADIS_tinyK22_RpiHat/raspi-overlayconfig.txt @@ -1,11 +1,17 @@ To use GPIO shutdown for the Raspberry Pi, add following lines in the file /boot/config.txt +- Only one signal can be used (only one gpio-poweroff) +- When gpio-poweroff and gpio-shutdown is used, the gpio-shutdown can only shutdown the Pi, not start +- When only gpio-shutdown is used, the gpio-shutdown can also start the Pi edit file: sudo nano /boot/config.txt # signal power off with green led dtoverlay=gpio-poweroff,gpiopin=16 +# signal power off to GPIO GP1 pin +dtoverlay=gpio-poweroff,gpiopin=18 + # shutdown Pi when joystick button is pressed -dtoverlay=gpio-shutdown,gpio_pin=26,gpio-pull=up +dtoverlay=gpio-shutdown,gpio_pin=26,gpio_pull=up # shutdown Pi when GPIO GP0 on Hat is set to low -dtoverlay=gpio-shutdown,gpio_pin=17 \ No newline at end of file +dtoverlay=gpio-shutdown,gpio_pin=17,gpio_pull=up \ No newline at end of file diff --git a/ADIS_tinyK22_RpiHat/source/application.c b/ADIS_tinyK22_RpiHat/source/application.c index 915b139..cc33123 100644 --- a/ADIS_tinyK22_RpiHat/source/application.c +++ b/ADIS_tinyK22_RpiHat/source/application.c @@ -23,6 +23,7 @@ /* vars */ static McuLED_Handle_t LED_blue; static McuGPIO_Handle_t GPIO_PowerRaspi; +static McuGPIO_Handle_t GPIO_RaspiShutdownIndicator; static uint32_t taskParameter1 = 5; static TaskHandle_t appTaskHandle = NULL; static QueueHandle_t eventQueueHandle = NULL; @@ -41,13 +42,26 @@ void App_Init(void){ config.hw.pin = LED_BLUE_PIN; LED_blue = McuLED_InitLed(&config); - /* configure gpio raspi power disable */ - McuGPIO_Config_t config_gpio; - McuGPIO_GetDefaultConfig(&config_gpio); - config_gpio.hw.gpio = GPIOA; - config_gpio.hw.port = PORTA; - config_gpio.hw.pin = 1U; - GPIO_PowerRaspi = McuGPIO_InitGPIO(&config_gpio); + /* configure gpio raspi power off GPIO (GP_0)*/ + McuGPIO_Config_t config_gp0; + McuGPIO_GetDefaultConfig(&config_gp0); + config_gp0.hw.gpio = GPIOA; + config_gp0.hw.port = PORTA; + config_gp0.hw.pin = 1U; + config_gp0.isInput = false; // Output + config_gp0.isHighOnInit = true; // active low + config_gp0.hw.pull = McuGPIO_PULL_DISABLE; // disable pull + GPIO_PowerRaspi = McuGPIO_InitGPIO(&config_gp0); + + /* configure gpio raspi shutdown indicator (GP_1) */ + McuGPIO_Config_t config_gp1; + McuGPIO_GetDefaultConfig(&config_gp1); + config_gp1.hw.gpio = GPIOA; + config_gp1.hw.port = PORTA; + config_gp1.hw.pin = 2U; + config_gp1.isInput = true; // input + config_gp1.hw.pull = McuGPIO_PULL_DISABLE; // disable pull + GPIO_RaspiShutdownIndicator = McuGPIO_InitGPIO(&config_gp1); // get the event queue handle from debounce eventQueueHandle = Debounce_GetEventQueueHandle(); @@ -57,9 +71,11 @@ void App_Init(void){ static void App_Task(void* pv){ McuLog_info("Application Task starting"); - Debounce_event_e event = Event_None; while(1){ + + Debounce_event_e event = Event_None; + // get event data from queue if it can be reached if(eventQueueHandle != NULL) { @@ -67,12 +83,21 @@ static void App_Task(void* pv){ xQueueReceive(eventQueueHandle, &event, pdMS_TO_TICKS(20)); } - if(event == Button_Center_Pressed){ + // turn off raspberry pi if requested by button press + if(event == Button_Up_Pressed){ McuGPIO_SetLow(GPIO_PowerRaspi); - vTaskDelay(pdMS_TO_TICKS(5000)); + vTaskDelay(pdMS_TO_TICKS(1000)); McuGPIO_SetHigh(GPIO_PowerRaspi); } + // turn on led if the power off indicator is on (Raspi is shut down) + if(McuGPIO_IsHigh(GPIO_RaspiShutdownIndicator)){ + McuLED_On(LED_blue); + }else{ + McuLED_Off(LED_blue); + } + + vTaskDelay(pdMS_TO_TICKS(100)); } } diff --git a/ADIS_tinyK22_RpiHat/source/platform.c b/ADIS_tinyK22_RpiHat/source/platform.c index 189ee96..d0acfaa 100644 --- a/ADIS_tinyK22_RpiHat/source/platform.c +++ b/ADIS_tinyK22_RpiHat/source/platform.c @@ -25,7 +25,6 @@ void PL_Init(void){ CLOCK_EnableClock(kCLOCK_PortA); CLOCK_EnableClock(kCLOCK_PortB); CLOCK_EnableClock(kCLOCK_PortC); - CLOCK_EnableClock(kCLOCK_PortD); McuLib_Init(); McuRTOS_Init();