Skip to content

Commit

Permalink
Add RGB LEDs to boot and app states
Browse files Browse the repository at this point in the history
Signed-off-by: dirksavage88 <[email protected]>
  • Loading branch information
dirksavage88 committed Jan 27, 2023
1 parent f1835df commit 14342b3
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 125 deletions.
1 change: 1 addition & 0 deletions boards/aa/cannode/default.px4board
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CONFIG_DRIVERS_BAROMETER_DPS310=y
CONFIG_DRIVERS_BOOTLOADERS=y
CONFIG_DRIVERS_DIFFERENTIAL_PRESSURE_MS4525DO=y
CONFIG_DRIVERS_GPS=y
CONFIG_DRIVERS_LIGHTS_RGBLED=y
CONFIG_DRIVERS_MAGNETOMETER_QMC5883L=y
CONFIG_BOARD_UAVCAN_INTERFACES=1
CONFIG_DRIVERS_UAVCANNODE=y
Expand Down
6 changes: 2 additions & 4 deletions boards/aa/cannode/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ if("${PX4_BOARD_LABEL}" STREQUAL "canbootloader")
add_library(drivers_board
boot_config.h
boot.c
#led.c
#led.h
led.c
)
target_link_libraries(drivers_board
PRIVATE
Expand All @@ -53,8 +52,7 @@ else()
init.c
can.c
spi.cpp
#usb.c
#led.c
led.c
)

target_link_libraries(drivers_board
Expand Down
52 changes: 31 additions & 21 deletions boards/aa/cannode/src/board_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTAGPIO_CNF_OUTOD BILITY AND
*FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
Expand All @@ -39,40 +39,50 @@

#pragma once

#include <px4_platform_common/px4_config.h>
#include <nuttx/compiler.h>
#include <px4_platform_common/px4_config.h>
#include <stdint.h>

/* Boot config */
#define GPIO_BOOT_CONFIG /* PB6 */ (GPIO_INPUT|GPIO_PORTB|GPIO_PIN6|GPIO_EXTI)

//#define GPIO_CAN1_SILENT_S0 /* PB5 */ (GPIO_OUTPUT|GPIO_SPEED_2MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTB|GPIO_PIN5)
#define GPIO_BOOT_CONFIG /* PB6 */ \
(GPIO_INPUT | GPIO_PORTB | GPIO_PIN6 | GPIO_EXTI)

/* LEDs */
//#define GPIO_LED_BLUE /* PA4 */ (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTA|GPIO_PIN4)

//#define GPIO_BTN_SAFETY (GPIO_INPUT|GPIO_PORTC|GPIO_PIN13)
#define GPIO_nLED_BLUE /* PA10 */ \
(GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_2MHz | GPIO_OUTPUT_SET | \
GPIO_PORTA | GPIO_PIN10 | GPIO_OUTPUT_CLEAR)
#define GPIO_nLED_GREEN /* PA9 */ \
(GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_2MHz | GPIO_OUTPUT_SET | \
GPIO_PORTA | GPIO_PIN9 | GPIO_OUTPUT_CLEAR)
#define GPIO_nLED_RED /* PA8 */ \
(GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_2MHz | GPIO_OUTPUT_SET | \
GPIO_PORTA | GPIO_PIN8 | GPIO_OUTPUT_CLEAR)

#define FLASH_BASED_PARAMS
#define CONFIG_I2C 1

#define GPIO_USART2_RX_GPIO (GPIO_INPUT|GPIO_SPEED_50MHz|GPIO_PORTA|GPIO_PIN3)
#define GPIO_USART2_TX_GPIO (GPIO_OUTPUT|GPIO_SPEED_50MHz|GPIO_PORTA|GPIO_PIN2)
#define GPIO_USART2_RX_GPIO \
(GPIO_INPUT | GPIO_SPEED_50MHz | GPIO_PORTA | GPIO_PIN3)
#define GPIO_USART2_TX_GPIO \
(GPIO_OUTPUT | GPIO_SPEED_50MHz | GPIO_PORTA | GPIO_PIN2)

//#define GPIO_USART3_RX_GPIO (GPIO_INPUT|GPIO_SPEED_50MHz|GPIO_PORTB|GPIO_PIN11)
//#define GPIO_USART3_TX_GPIO (GPIO_OUTPUT|GPIO_SPEED_50MHz|GPIO_PORTB|GPIO_PIN10)
// #define GPIO_USART3_RX_GPIO
// (GPIO_INPUT|GPIO_SPEED_50MHz|GPIO_PORTB|GPIO_PIN11) #define
// GPIO_USART3_TX_GPIO (GPIO_OUTPUT|GPIO_SPEED_50MHz|GPIO_PORTB|GPIO_PIN10)

#define GPIO_UART4_RX_GPIO (GPIO_INPUT|GPIO_SPEED_50MHz|GPIO_PORTC|GPIO_PIN11)
#define GPIO_UART4_TX_GPIO (GPIO_OUTPUT|GPIO_SPEED_50MHz|GPIO_PORTC|GPIO_PIN10)
#define GPIO_UART4_RX_GPIO \
(GPIO_INPUT | GPIO_SPEED_50MHz | GPIO_PORTC | GPIO_PIN11)
#define GPIO_UART4_TX_GPIO \
(GPIO_OUTPUT | GPIO_SPEED_50MHz | GPIO_PORTC | GPIO_PIN10)

/* High-resolution timer */
#define HRT_TIMER 3 /* use timer 3 for the HRT */
#define HRT_TIMER_CHANNEL 4 /* use capture/compare channel 4 */
#define HRT_TIMER 3 /* use timer 3 for the HRT */
#define HRT_TIMER_CHANNEL 4 /* use capture/compare channel 4 */

#define BOARD_HAS_CONTROL_STATUS_LEDS 1

#define PX4_GPIO_INIT_LIST { \
GPIO_CAN1_TX, \
GPIO_CAN1_RX, \
}
#define PX4_GPIO_INIT_LIST \
{ GPIO_CAN1_TX, GPIO_CAN1_RX, }

__BEGIN_DECLS

Expand Down
75 changes: 44 additions & 31 deletions boards/aa/cannode/src/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,30 @@
* Included Files
****************************************************************************/

#include <px4_config.h>
#include <stdint.h>
#include "boot_config.h"
#include "board.h"
#include "led.h"
#include "boot_config.h"
#include <arch/board/board.h>
#include <debug.h>
#include <px4_config.h>
#include <stdint.h>
#include <string.h>
#include <arch/board/board.h>

#include <nuttx/board.h>
#include <sys/cdefs.h>

__BEGIN_DECLS
void led_init(void);
extern void bootloader_led_on(int led);
extern void bootloader_led_off(int led);
__END_DECLS

/************************************************************************************
* Name: stm32_boardinitialize
*
* Description:
* All STM32 architectures must provide the following entry point. This entry point
* is called early in the initialization -- after all memory has been configured
* and mapped but before any devices have been initialized.
* All STM32 architectures must provide the following entry point. This entry
*point is called early in the initialization -- after all memory has been
*configured and mapped but before any devices have been initialized.
*
************************************************************************************/

Expand All @@ -64,15 +70,16 @@ __EXPORT void stm32_boardinitialize(void)
putreg32(getreg32(STM32_RCC_APB1ENR) | RCC_APB1ENR_CAN1EN, STM32_RCC_APB1ENR);
stm32_configgpio(GPIO_CAN1_RX);
stm32_configgpio(GPIO_CAN1_TX);
putreg32(getreg32(STM32_RCC_APB1RSTR) | RCC_APB1RSTR_CAN1RST, STM32_RCC_APB1RSTR);
putreg32(getreg32(STM32_RCC_APB1RSTR) & ~RCC_APB1RSTR_CAN1RST, STM32_RCC_APB1RSTR);
putreg32(getreg32(STM32_RCC_APB1RSTR) | RCC_APB1RSTR_CAN1RST,
STM32_RCC_APB1RSTR);
putreg32(getreg32(STM32_RCC_APB1RSTR) & ~RCC_APB1RSTR_CAN1RST,
STM32_RCC_APB1RSTR);

// led_init();
// led_init();

#if defined(OPT_WAIT_FOR_GETNODEINFO_JUMPER_GPIO)
stm32_configgpio(GPIO_GETNODEINFO_JUMPER);
#endif

}

/************************************************************************************
Expand All @@ -86,7 +93,8 @@ __EXPORT void stm32_boardinitialize(void)

void board_deinitialize(void)
{
putreg32(getreg32(STM32_RCC_APB1RSTR) | RCC_APB1RSTR_CAN1RST, STM32_RCC_APB1RSTR);
putreg32(getreg32(STM32_RCC_APB1RSTR) | RCC_APB1RSTR_CAN1RST,
STM32_RCC_APB1RSTR);
}

/****************************************************************************
Expand Down Expand Up @@ -135,7 +143,7 @@ size_t board_get_hardware_version(uavcan_HardwareVersion_t *hw_version)
hw_version->major = HW_VERSION_MAJOR;
hw_version->minor = HW_VERSION_MINOR;

return board_get_mfguid(*(mfguid_t *) hw_version->unique_id);
return board_get_mfguid(*(mfguid_t *)hw_version->unique_id);
}

/****************************************************************************
Expand All @@ -152,24 +160,29 @@ size_t board_get_hardware_version(uavcan_HardwareVersion_t *hw_version)
* None
*
****************************************************************************/

void board_indicate(uiindication_t indication)
{
switch (indication) {
case off:
//led_off(GPIO_LED_BLUE);
break;

case reset:
//led_toggle(GPIO_LED_BLUE);
break;

case jump_to_app:
//led_on(GPIO_LED_BLUE);
break;

default:
break;
if (indication == off) {
bootloader_led_off(GPIO_nLED_RED);
bootloader_led_off(GPIO_nLED_BLUE);

} else if (indication == fw_update_start) {
bootloader_led_on(GPIO_nLED_RED);
bootloader_led_on(GPIO_nLED_BLUE);

} else if ((indication == fw_update_erase_fail) ||
(indication == fw_update_invalid_response) ||
(indication == fw_update_timeout) ||
(indication == fw_update_invalid_crc)) {
bootloader_led_on(GPIO_nLED_RED);
bootloader_led_off(GPIO_nLED_BLUE);

} else if (indication == allocation_start) {
bootloader_led_on(GPIO_nLED_RED);
bootloader_led_off(GPIO_nLED_BLUE);

} else {
bootloader_led_off(GPIO_nLED_RED);
bootloader_led_on(GPIO_nLED_BLUE);
}

}
31 changes: 20 additions & 11 deletions boards/aa/cannode/src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,40 +44,45 @@
#include <px4_platform_common/px4_config.h>
#include <px4_platform_common/tasks.h>

#include <debug.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <debug.h>
#include <errno.h>

#include <nuttx/board.h>

#include <stm32.h>
#include "board_config.h"
#include "led.h"
#include <stm32.h>
#include <stm32_uart.h>

#include <arch/board/board.h>

#include <drivers/drv_hrt.h>
#include <drivers/drv_board_led.h>
#include <drivers/drv_hrt.h>

#include <systemlib/px4_macros.h>

#include <px4_platform_common/init.h>
#include <px4_platform/gpio.h>
#include <px4_platform_common/init.h>

#if defined(FLASH_BASED_PARAMS)
#include <parameters/flashparams/flashfs.h>
#endif

__BEGIN_DECLS
extern void led_init(void);
extern void led_on(int led);
extern void led_off(int led);
__END_DECLS

/************************************************************************************
* Name: stm32_boardinitialize
*
* Description:
* All STM32 architectures must provide the following entry point. This entry point
* is called early in the initialization -- after all memory has been configured
* and mapped but before any devices have been initialized.
* All STM32 architectures must provide the following entry point. This entry
*point is called early in the initialization -- after all memory has been
*configured and mapped but before any devices have been initialized.
*
************************************************************************************/

Expand Down Expand Up @@ -142,8 +147,12 @@ __EXPORT int board_app_initialize(uintptr_t arg)

#endif // FLASH_BASED_PARAMS

//drv_led_start();
//led_on(LED_BLUE);
drv_led_start();
led_off(LED_RED);
led_off(LED_BLUE);

/* No safety LED, however use SAFETY in place of GREEN */
led_on(LED_SAFETY);

/* Configure the HW based on the manifest */

Expand Down
44 changes: 26 additions & 18 deletions boards/aa/cannode/src/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@

#include <stdbool.h>

#include "stm32.h"
#include "board_config.h"
#include "led.h"
#include "stm32.h"

#include <arch/board/board.h>

Expand All @@ -54,42 +53,51 @@
* separate switch, we need to build independent of the
* CONFIG_ARCH_LEDS configuration switch.
*/
static uint32_t g_ledmap[] = {
GPIO_LED_BLUE,
};
__BEGIN_DECLS
extern void led_init(void);
extern void bootloader_led_on(int led);
extern void bootloader_led_off(int led);
extern void led_on(int led);
extern void led_off(int led);
extern void led_toggle(int led);
__END_DECLS

#define xlat(p) (p)
static uint32_t g_ledmap[] = {GPIO_nLED_BLUE, GPIO_nLED_RED, GPIO_nLED_GREEN};

__EXPORT void led_init(void)
{
/* Configure LED GPIOs for output */
for (size_t l = 0; l < (sizeof(g_ledmap) / sizeof(g_ledmap[0])); l++) {
stm32_configgpio(g_ledmap[l]);
stm32_gpiowrite(g_ledmap[l], true);
}
}

static void phy_set_led(int led, bool state)
__EXPORT void bootloader_led_on(int led)
{
/* Pull Down to switch on */
stm32_gpiowrite(g_ledmap[led], !state);
stm32_gpiowrite(led, false);
}

static bool phy_get_led(int led)
__EXPORT void bootloader_led_off(int led)
{

return !stm32_gpioread(g_ledmap[led]);
/* Pull Up to switch on */
stm32_gpiowrite(led, true);
}

__EXPORT void led_on(int led)
static void phy_set_led(int led, bool state)
{
phy_set_led(led, true);
/* Pull Down to switch on */
stm32_gpiowrite(g_ledmap[led], !state);
}

__EXPORT void led_off(int led)
{
phy_set_led(led, false);
}
static bool phy_get_led(int led) { return !stm32_gpioread(g_ledmap[led]); }

__EXPORT void led_on(int led) { phy_set_led(xlat(led), true); }

__EXPORT void led_off(int led) { phy_set_led(xlat(led), false); }

__EXPORT void led_toggle(int led)
{
phy_set_led(led, !phy_get_led(led));
phy_set_led(xlat(led), !phy_get_led(xlat(led)));
}
Loading

0 comments on commit 14342b3

Please sign in to comment.