Skip to content

RGB LED blink #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 186 additions & 0 deletions Inc/blink_patterns.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/*
* blink_pattterns.h
*
* Created on: July 9, 2023
* Author: frank26080115
*/

#ifndef _BLINK_PATTERNS_H_
#define _BLINK_PATTERNS_H_

// this header file is only included by led.c once

#define BLINK_TIME_MASK 0x1F
#define BLINK_STOP 0
#define BLINK_LOOP 0 // same as stop
#define BLINK_RGB_TIME(r, g, b, t) ((((r) ? 1 : 0) << 5) | (((g) ? 1 : 0) << 6) | (((b) ? 1 : 0) << 7) | ((t) & BLINK_TIME_MASK))
#define BLINK_ON_TIME(t) BLINK_RGB_TIME(1, 0, 0, t) // borrow above macro
#define BLINK_OFF_TIME(t) BLINK_RGB_TIME(0, 0, 0, t)

#define BLINK_GET_TIME(x) ((x) & BLINK_TIME_MASK)
#define BLINK_IS_RED(x) (((x) & (1 << 5)) != 0)
#define BLINK_IS_GREEN(x) (((x) & (1 << 6)) != 0)
#define BLINK_IS_BLUE(x) (((x) & (1 << 7)) != 0)
#define BLINK_IS_OFF(x) (((x) & 0xE0) == 0)
#define BLINK_IS_ON(x) (!BLINK_IS_OFF(x))

// patterns are defined here
// each byte is a frame
// the top 3 bits indicate which of the RGB LEDs is on or off_type
// the bottom 5 bits is the time span of the frame
// time span is in units of 100ms, if 5 bits is not enough, then simply duplicate the frame
// each pattern must end with a 0 byte, and will be looped or stopped on that frame

#if defined(USE_RGB_LED) || defined(USE_LED_STRIP)

const uint8_t blinkpattern_start[] = {
BLINK_RGB_TIME(1, 0, 0, 1),
BLINK_RGB_TIME(0, 1, 0, 1),
BLINK_RGB_TIME(0, 0, 1, 1),
BLINK_RGB_TIME(1, 1, 0, 1),
BLINK_RGB_TIME(1, 0, 1, 1),
BLINK_OFF_TIME(2),
BLINK_LOOP,
};

const uint8_t blinkpattern_unarmed[] = {
// unarmed should just make red LED stay on always
// note: the firmware reboots if no signal is detected, so any animation has the risk of being interrupted
BLINK_RGB_TIME(1, 0, 0, 1),
BLINK_LOOP,
};

const uint8_t blinkpattern_armed[] = {
BLINK_RGB_TIME(0, 1, 0, 1),
BLINK_OFF_TIME(4),
BLINK_LOOP,
};

const uint8_t blinkpattern_running[] = {
BLINK_RGB_TIME(0, 1, 0, 2),
BLINK_OFF_TIME(2),
BLINK_RGB_TIME(0, 1, 0, 2),
BLINK_OFF_TIME(2),
BLINK_LOOP,
};

const uint8_t blinkpattern_currentlimited[] = {
BLINK_RGB_TIME(1, 0, 1, 3),
BLINK_OFF_TIME(1),
BLINK_RGB_TIME(1, 0, 1, 1),
BLINK_OFF_TIME(5),
BLINK_RGB_TIME(1, 0, 1, 3),
BLINK_OFF_TIME(1),
BLINK_RGB_TIME(1, 0, 1, 1),
BLINK_OFF_TIME(5),
BLINK_STOP,
};

const uint8_t blinkpattern_stalled[] = {
BLINK_RGB_TIME(0, 0, 1, 3),
BLINK_OFF_TIME(1),
BLINK_RGB_TIME(1, 0, 1, 1),
BLINK_OFF_TIME(5),
BLINK_RGB_TIME(0, 0, 1, 3),
BLINK_OFF_TIME(1),
BLINK_RGB_TIME(1, 0, 1, 1),
BLINK_OFF_TIME(5),
BLINK_STOP,
};

const uint8_t blinkpattern_desync[] = {
BLINK_RGB_TIME(0, 1, 0, 1),
BLINK_OFF_TIME(1),
BLINK_RGB_TIME(0, 1, 0, 1),
BLINK_OFF_TIME(1),
BLINK_RGB_TIME(1, 0, 0, 1),
BLINK_OFF_TIME(1),
BLINK_RGB_TIME(0, 0, 1, 1),
BLINK_OFF_TIME(1),
BLINK_STOP,
};

const uint8_t blinkpattern_lowbatt[] = {
BLINK_RGB_TIME(1, 0, 0, 2),
BLINK_OFF_TIME(5),
BLINK_RGB_TIME(0, 0, 1, 2),
BLINK_OFF_TIME(5),
BLINK_STOP,
};

#else

const uint8_t blinkpattern_start[] = {
BLINK_ON_TIME(1),
BLINK_OFF_TIME(1),
BLINK_ON_TIME(1),
BLINK_OFF_TIME(1),
BLINK_ON_TIME(1),
BLINK_OFF_TIME(1),
BLINK_ON_TIME(1),
BLINK_OFF_TIME(1),
BLINK_ON_TIME(1),
BLINK_OFF_TIME(1),
BLINK_LOOP,
};

const uint8_t blinkpattern_unarmed[] = {
// unarmed should just make red LED stay on always
// note: the firmware reboots if no signal is detected, so any animation has the risk of being interrupted
BLINK_ON_TIME(5),
BLINK_LOOP,
};

const uint8_t blinkpattern_armed[] = {
BLINK_ON_TIME(1),
BLINK_OFF_TIME(1),
BLINK_ON_TIME(1),
BLINK_OFF_TIME(7),
BLINK_LOOP,
};

const uint8_t blinkpattern_running[] = {
BLINK_ON_TIME(1),
BLINK_OFF_TIME(1),
BLINK_ON_TIME(1),
BLINK_OFF_TIME(1),
BLINK_LOOP,
};

const uint8_t blinkpattern_currentlimited[] = {
BLINK_ON_TIME(3),
BLINK_OFF_TIME(1),
BLINK_ON_TIME(1),
BLINK_OFF_TIME(5),
BLINK_STOP,
};

const uint8_t blinkpattern_stalled[] = {
BLINK_ON_TIME(3),
BLINK_OFF_TIME(1),
BLINK_ON_TIME(3),
BLINK_OFF_TIME(5),
BLINK_STOP,
};

const uint8_t blinkpattern_desync[] = {
BLINK_ON_TIME(1),
BLINK_OFF_TIME(1),
BLINK_ON_TIME(1),
BLINK_OFF_TIME(1),
BLINK_ON_TIME(1),
BLINK_OFF_TIME(5),
BLINK_STOP,
};

const uint8_t blinkpattern_lowbatt[] = {
BLINK_RGB_TIME(1, 0, 0, 2),
BLINK_OFF_TIME(5),
BLINK_RGB_TIME(0, 0, 1, 2),
BLINK_OFF_TIME(5),
BLINK_STOP,
};

#endif

#endif
32 changes: 32 additions & 0 deletions Inc/led.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* led.h
*
* Created on: July 9, 2023
* Author: frank26080115
*/

#ifndef _LED_H_
#define _LED_H_

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>

void led_init(); // called from main, initalizes GPIO structures and clocks

void led_blink_100ms(); // call this every 100ms

// use these functions in the main application
void led_set_unarmed();
void led_set_armed();
void led_set_armstate(bool);
void led_set_running();
void led_sig_currentlimited();
void led_sig_stalled();
void led_sig_lowbatt();
void led_sig_desync();
void led_set_red();
void led_set_green();
void led_set_blue();

#endif
55 changes: 54 additions & 1 deletion Inc/targets.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

//GLOBAL
//#define USE_ADC_INPUT
//#define USE_ALKAS_DEBUG_LED

/******************************* L431 Targets ***************************************/
#ifdef NEUTRON_L431
Expand Down Expand Up @@ -236,6 +235,25 @@
#define PA6_VOLTAGE
#endif

#ifdef ARIA70A_F051
#define FILE_NAME "ARIA70A_F051"
#define FIRMWARE_NAME "Aria 70A"
#define DEAD_TIME 45
#define HARDWARE_GROUP_F0_A
//#define USE_SERIAL_TELEMETRY
#define PA6_VOLTAGE
#define USE_RGB_LED

#define RGBLED_RED_GPIOx GPIOA
#define RGBLED_RED_PIN LL_GPIO_PIN_15
#define RGBLED_GREEN_GPIOx GPIOB
#define RGBLED_GREEN_PIN LL_GPIO_PIN_3
#define RGBLED_BLUE_GPIOx GPIOB
#define RGBLED_BLUE_PIN LL_GPIO_PIN_4
#define LED_IS_OPENDRAIN true

#endif

#ifdef HVFLYCOLOR_F051
#define FILE_NAME "HVFLYCOLOR_F051"
#define FIRMWARE_NAME "FLYCOLOR HV "
Expand Down Expand Up @@ -1358,6 +1376,41 @@
#define TARGET_MIN_BEMF_COUNTS 6
//#define USE_SERIAL_TELEMETRY // moved to individual ESCs
#define USE_ADC

#ifdef USE_RGB_LED
#ifndef RGBLED_RED_GPIOx
#define RGBLED_RED_GPIOx GPIOB
#endif
#ifndef RGBLED_GREEN_GPIOx
#define RGBLED_GREEN_GPIOx GPIOB
#endif
#ifndef RGBLED_BLUE_GPIOx
#define RGBLED_BLUE_GPIOx GPIOB
#endif
#ifndef RGBLED_RED_PIN
#define RGBLED_RED_PIN LL_GPIO_PIN_8
#endif
#ifndef RGBLED_GREEN_PIN
#define RGBLED_GREEN_PIN LL_GPIO_PIN_3
#endif
#ifndef RGBLED_BLUE_PIN
#define RGBLED_BLUE_PIN LL_GPIO_PIN_5
#endif
#ifndef LED_IS_OPENDRAIN
#define LED_IS_OPENDRAIN true
#endif
#else
#ifndef LED_GPIOx
#define LED_GPIOx GPIOA
#endif
#ifndef LED_PIN
#define LED_PIN LL_GPIO_PIN_15
#endif
#ifndef LED_IS_OPENDRAIN
#define LED_IS_OPENDRAIN true
#endif
#endif

#endif


Expand Down
15 changes: 0 additions & 15 deletions Mcu/f051/Src/peripherals.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,21 +387,6 @@ void MX_GPIO_Init(void)
/* GPIO Ports Clock Enable */
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA);
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB);

/**/
LL_GPIO_ResetOutputPin(GPIOA, LL_GPIO_PIN_15);

/**/
#ifdef USE_ALKAS_DEBUG_LED
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};

GPIO_InitStruct.Pin = LL_GPIO_PIN_15;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
#endif
}


Expand Down
7 changes: 0 additions & 7 deletions Mcu/g071/Src/peripherals.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
#include "targets.h"
#include "serial_telemetry.h"

#ifdef USE_LED_STRIP
#include "WS2812.h"
#endif

//extern uint16_t DEAD_TIME;


Expand Down Expand Up @@ -45,9 +41,6 @@ void initCorePeripherals(void){
MX_TIM17_Init();
MX_TIM6_Init();
telem_UART_Init();
#ifdef USE_LED_STRIP
WS2812_Init();
#endif

}

Expand Down
6 changes: 2 additions & 4 deletions Mcu/l431/Src/peripherals.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
#include "targets.h"
#include "serial_telemetry.h"

#ifdef USE_LED_STRIP
#include "WS2812.h"
#endif

//extern uint16_t DEAD_TIME;


Expand All @@ -36,10 +32,12 @@ void initCorePeripherals(void){
MX_TIM7_Init();
MX_TIM6_Init();
telem_UART_Init();

//#ifdef USE_LED_STRIP
//WS2812_Init();
//#endif


}

void initAfterJump(){
Expand Down
Loading