rpi4b/autoleds: Auto-LED implementation

Added autoled implementation for the Pi4B. Status LED is used as NuttX
start indicator, while power LED is used for panic/assert indication.

Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
This commit is contained in:
Matteo Golin
2025-09-27 01:06:39 -04:00
committed by Xiang Xiao
parent 706d389b37
commit e10c79b744
5 changed files with 133 additions and 0 deletions

View File

@@ -2045,6 +2045,7 @@ config ARCH_BOARD_RASPBERRYPI_PICO_W
config ARCH_BOARD_RASPBERRYPI_4B
bool "Raspberry Pi Model 4B"
depends on ARCH_CHIP_BCM2711
select ARCH_HAVE_LEDS
---help---
This is a port to the Raspberry Pi Model 4B.

View File

@@ -38,6 +38,17 @@
#define STATUS_LED (42) /* Green LED */
#define POWER_LED (130) /* Red LED */
/* Auto-LED definitions */
#define LED_STARTED 0
#define LED_HEAPALLOCATE 0
#define LED_IRQSENABLED 0
#define LED_STACKCREATED 1
#define LED_INIRQ 2
#define LED_SIGNAL 2
#define LED_ASSERTION 3
#define LED_PANIC 4
/* TODO: define all the GPIO pins properly */
#define BOARD_NGPIOOUT 1

View File

@@ -20,6 +20,10 @@
set(SRCS rpi4b_boardinitialize.c rpi4b_bringup.c)
if(CONFIG_ARCH_LEDS)
list(APPEND SRCS rpi4b_autoleds.c)
endif()
if(CONFIG_BOARDCTL)
list(APPEND SRCS rpi4b_appinit.c)
endif()

View File

@@ -22,6 +22,10 @@ include $(TOPDIR)/Make.defs
CSRCS += rpi4b_boardinitialize.c rpi4b_bringup.c
ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += rpi4b_autoleds.c
endif
ifeq ($(CONFIG_BOARDCTL),y)
CSRCS += rpi4b_appinit.c
endif

View File

@@ -0,0 +1,113 @@
/****************************************************************************
* boards/arm64/bcm2711/raspberrypi-4b/src/rpi4b_autoleds.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* LEDs
*
* There are two LEDs on the Pi 4B:
*
* - Power LED, which is red
* - Status LED, which is green
*
* These LEDs are under the control of the BCM2711 firmware when the board is
* going through the proprietary boot process. Afterwards, they can be
* accessed by NuttX through the mailbox API. NuttX will use the status LED
* for indication of LED_STARTED, and the power LED for indication of
* LED_PANIC (since it is red).
*
* ------------------- ----------------------- ------ ------
* SYMBOL Meaning STATUS POWER
* ------------------- ----------------------- ------ ------
* LED_STARTED NuttX has been started ON OFF
* LED_HEAPALLOCATE Heap has been allocated N/C OFF
* LED_IRQSENABLED Interrupts enabled N/C OFF
* LED_STACKCREATED Idle stack created N/C OFF
* LED_INIRQ In an interrupt N/C OFF
* LED_SIGNAL In a signal handler N/C OFF
* LED_ASSERTION An assertion failed N/C OFF
* LED_PANIC The system has crashed N/C FLASH
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <debug.h>
#include <nuttx/config.h>
#include <arch/board/board.h>
#include <nuttx/board.h>
#include "bcm2711_mailbox.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_autoled_initialize
****************************************************************************/
void board_autoled_initialize(void)
{
/* Make sure that power LED is off and status LED is on.
* NOTE: the POWER_LED is inverted (true -> off, false -> on)
*/
bcm2711_mbox_ledset(STATUS_LED, true);
bcm2711_mbox_ledset(POWER_LED, true);
}
/****************************************************************************
* Name: board_autoled_on
****************************************************************************/
void board_autoled_on(int led)
{
switch (led)
{
case LED_STARTED:
bcm2711_mbox_ledset(STATUS_LED, true);
break;
case LED_PANIC:
case LED_ASSERTION:
bcm2711_mbox_ledset(POWER_LED, false);
break;
}
}
/****************************************************************************
* Name: board_autoled_off
****************************************************************************/
void board_autoled_off(int led)
{
switch (led)
{
case LED_STARTED:
bcm2711_mbox_ledset(STATUS_LED, false);
break;
case LED_PANIC:
case LED_ASSERTION:
bcm2711_mbox_ledset(POWER_LED, true);
break;
}
}