Skip to content

Commit

Permalink
boards/raspberrypi-pico: Add autoleds and userleds support
Browse files Browse the repository at this point in the history
  • Loading branch information
acassis committed Feb 18, 2024
1 parent de61a8e commit 68f1d20
Show file tree
Hide file tree
Showing 7 changed files with 450 additions and 0 deletions.
1 change: 1 addition & 0 deletions boards/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1827,6 +1827,7 @@ config ARCH_BOARD_INTEL64_QEMU
config ARCH_BOARD_RASPBERRYPI_PICO
bool "Raspberry Pi Pico board (not W)"
depends on ARCH_CHIP_RP2040
select ARCH_HAVE_LEDS
---help---
This is a port to the Raspberry Pi Pico board.

Expand Down
42 changes: 42 additions & 0 deletions boards/arm/rp2040/raspberrypi-pico/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,48 @@
#define BOARD_NGPIOIN 1
#define BOARD_NGPIOINT 1

/* LED definitions **********************************************************/

/* If CONFIG_ARCH_LEDS is not defined, then the user can control the LEDs
* in any way. The following definitions are used to access individual LEDs.
*/

/* LED index values for use with board_userled() */

#define BOARD_LED1 0
#define BOARD_NLEDS 1

#define BOARD_LED_GREEN BOARD_LED1

/* LED bits for use with board_userled_all() */

#define BOARD_LED1_BIT (1 << BOARD_LED1)

/* This LED is not used by the board port unless CONFIG_ARCH_LEDS is
* defined. In that case, the usage by the board port is defined in
* include/board.h and src/rp2040_autoleds.c. The LED is used to encode
* OS-related events as follows:
*
* -------------------- ----------------------------- ------
* SYMBOL Meaning LED
* -------------------- ----------------------------- ------
*/

#define LED_STARTED 0 /* NuttX has been started OFF */
#define LED_HEAPALLOCATE 0 /* Heap has been allocated OFF */
#define LED_IRQSENABLED 0 /* Interrupts enabled OFF */
#define LED_STACKCREATED 1 /* Idle stack created ON */
#define LED_INIRQ 2 /* In an interrupt N/C */
#define LED_SIGNAL 2 /* In a signal handler N/C */
#define LED_ASSERTION 2 /* An assertion failed N/C */
#define LED_PANIC 3 /* The system has crashed FLASH */
#undef LED_IDLE /* Not used */

/* Thus if the LED is statically on, NuttX has successfully booted and is,
* apparently, running normally. If the LED is flashing at approximately
* 2Hz, then a fatal error has been detected and the system has halted.
*/

/****************************************************************************
* Public Types
****************************************************************************/
Expand Down
6 changes: 6 additions & 0 deletions boards/arm/rp2040/raspberrypi-pico/src/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ ifeq ($(CONFIG_DEV_GPIO),y)
CSRCS += rp2040_gpio.c
endif

ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += rp2040_autoleds.c
else
CSRCS += rp2040_userleds.c
endif

DEPPATH += --dep-path board
VPATH += :board
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board
167 changes: 167 additions & 0 deletions boards/arm/rp2040/raspberrypi-pico/src/rp2040_autoleds.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/****************************************************************************
* boards/arm/rp2040/raspberrypi-pico/src/rp2040_autoleds.c
*
* 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.
*
****************************************************************************/

/* There are four LED status indicators located on the EVK Board. The
* functions of these LEDs include:
*
* - Main Power Supply(D3)
* Green: DC 5V main supply is normal.
* Red: J2 input voltage is over 5.6V.
* Off: The board is not powered.
* - Reset RED LED(D15)
* - OpenSDA LED(D16)
* - USER LED(D18)
*
* Only a single LED, D18, is under software control.
*
* This LED is not used by the board port unless CONFIG_ARCH_LEDS is
* defined. In that case, the usage by the board port is defined in
* include/board.h and src/rp2040_autoleds.c. The LED is used to encode
* OS-related events as follows:
*
* -------------------- ----------------------- ------
* SYMBOL Meaning LED
* -------------------- ----------------------- ------
*
* LED_STARTED 0 NuttX has been started OFF
* LED_HEAPALLOCATE 0 Heap has been allocated OFF
* LED_IRQSENABLED 0 Interrupts enabled OFF
* LED_STACKCREATED 1 Idle stack created ON
* LED_INIRQ 2 In an interrupt N/C
* LED_SIGNAL 2 In a signal handler N/C
* LED_ASSERTION 2 An assertion failed N/C
* LED_PANIC 3 The system has crashed FLASH
* LED_IDLE Not used
*
* Thus if the LED is statically on, NuttX has successfully booted and is,
* apparently, running normally. If the LED is flashing at approximately
* 2Hz, then a fatal error has been detected and the system has halted.
*/

/****************************************************************************
* Included Files
****************************************************************************/

#include <nuttx/config.h>
#include <nuttx/board.h>
#include <arch/board/board.h>

#include "arm_internal.h"
#include "chip.h"
#include "rp2040_gpio.h"

#include "rp2040_pico.h"

#ifdef CONFIG_ARCH_LEDS

/****************************************************************************
* Public Functions
****************************************************************************/

/****************************************************************************
* Name: rp2040_autoled_initialize
*
* Description:
* Initialize NuttX-controlled LED logic
*
* Input Parameters:
* None
*
* Returned Value:
* None
*
****************************************************************************/

void board_autoled_initialize(void)
{
/* Configure LED GPIO for output */

rp2040_gpio_init(GPIO_LED1);
rp2040_gpio_setdir(GPIO_LED1, true);
}

/****************************************************************************
* Name: board_autoled_on
*
* Description:
* Turn on the "logical" LED state
*
* Input Parameters:
* led - Identifies the "logical" LED state (see definitions in
* include/board.h)
*
* Returned Value:
* None
*
****************************************************************************/

void board_autoled_on(int led)
{
bool ledon = true;

switch (led)
{
case 0: /* LED Off */
ledon = false;
break;

case 2: /* LED No change */
return;

case 1: /* LED On */
case 3: /* LED On */
break;
}

rp2040_gpio_put(GPIO_LED1, ledon); /* High illuminates */
}

/****************************************************************************
* Name: board_autoled_off
*
* Description:
* Turn off the "logical" LED state
*
* Input Parameters:
* led - Identifies the "logical" LED state (see definitions in
* include/board.h)
*
* Returned Value:
* None
*
****************************************************************************/

void board_autoled_off(int led)
{
switch (led)
{
case 0: /* LED Off */
case 1: /* LED Off */
case 3: /* LED Off */
break;

case 2: /* LED No change */
return;
}

rp2040_gpio_put(GPIO_LED1, false); /* High illuminates */
}

#endif /* CONFIG_ARCH_LEDS */
15 changes: 15 additions & 0 deletions boards/arm/rp2040/raspberrypi-pico/src/rp2040_bringup.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#include "rp2040_common_bringup.h"
#endif /* CONFIG_ARCH_BOARD_COMMON */

#ifdef CONFIG_USERLED
# include <nuttx/leds/userled.h>
#endif

/****************************************************************************
* Public Functions
****************************************************************************/
Expand All @@ -59,5 +63,16 @@ int rp2040_bringup(void)

/* --- Place any board specific bringup code here --- */

#ifdef CONFIG_USERLED
/* Register the LED driver */

ret = userled_lower_initialize("/dev/userleds");
if (ret < 0)
{
syslog(LOG_ERR, \
"ERROR: userled_lower_initialize() failed: %d\n", ret);
}
#endif

return OK;
}
4 changes: 4 additions & 0 deletions boards/arm/rp2040/raspberrypi-pico/src/rp2040_pico.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@

#include <nuttx/config.h>

/* LEDs */

#define GPIO_LED1 25 /* The board's LED is connected to this pin */

int rp2040_bringup(void);

#ifdef CONFIG_DEV_GPIO
Expand Down
Loading

0 comments on commit 68f1d20

Please sign in to comment.