Skip to content
Draft
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
14 changes: 8 additions & 6 deletions radio/src/boards/generic_stm32/rgb_leds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ extern const stm32_pulse_timer_t _led_timer;
static TimerHandle_t rgbLedTimer = nullptr;
static StaticTimer_t rgbLedTimerBuffer;

#if !defined(LED_STRIP_RESERVED)
#define LED_STRIP_RESERVED 0
#endif

void rgbSetLedColor(uint8_t led, uint8_t r, uint8_t g, uint8_t b)
{
#if defined(SIXPOS_SWITCH_INDEX)
ws2812_set_color(led + 6, r, g, b);
#elif defined(RGB_LED_OFFSET)
ws2812_set_color(led + RGB_LED_OFFSET, r, g, b);
#else
led += LED_STRIP_RESERVED;
ws2812_set_color(led, r, g, b);
#endif
}

uint32_t rgbGetLedColor(uint8_t led)
Expand All @@ -77,10 +76,13 @@ void rgbLedClearAll()
ws2812_update(&_led_timer);
}

__WEAK void rgbLedOnUpdate() {}

static void rgbLedTimerCb(TimerHandle_t xTimer)
{
(void)xTimer;

rgbLedOnUpdate();
ws2812_update(&_led_timer);
}

Expand Down
3 changes: 3 additions & 0 deletions radio/src/boards/generic_stm32/rgb_leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ void rgbLedClearAll();

bool rgbGetState(uint8_t led);
void rgbLedColorApply();

// declared "weak"
void rgbLedOnUpdate();
15 changes: 15 additions & 0 deletions radio/src/boards/helloradio/rgb_6pos.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "boards/generic_stm32/rgb_leds.h"
#include "stm32_ws2812.h"

#include "switches.h"
#include "hal.h"

void rgbLedOnUpdate()
{
for (uint8_t i = 0; i < 6; i++) {
ws2812_set_color(i, 0, 0, 0);
}

uint8_t pos = getXPotPosition(SIXPOS_SWITCH_INDEX);
ws2812_set_color(pos, SIXPOS_LED_RED, SIXPOS_LED_GREEN, SIXPOS_LED_BLUE);
}
5 changes: 0 additions & 5 deletions radio/src/hal/adc_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,6 @@ void adcCalibStore()
uint16_t getAnalogValue(uint8_t index)
{
if (index >= MAX_ANALOG_INPUTS) return 0;
#if defined(SIXPOS_SWITCH_INDEX) && !defined(SIMU)
if (index == SIXPOS_SWITCH_INDEX)
return getSixPosAnalogValue(adcValues[index]);
else
#endif
return adcValues[index];
}

Expand Down
4 changes: 3 additions & 1 deletion radio/src/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@

#pragma once

#include <cinttypes>
#include <stdint.h>
#include <stdlib.h>

#include "edgetx_constants.h"
#include "edgetx_types.h"

enum LogicalSwitchFamilies {
LS_FAMILY_OFS,
Expand Down
6 changes: 6 additions & 0 deletions radio/src/targets/horus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ if (PCB STREQUAL X10)
set(FLEXSW "2" CACHE STRING "Max flex inputs usable as switches")
set(AUX2_SERIAL OFF)
set(HAS_CSD203_SENSOR ON)
set(HAS_RGB_6POS ON)
set(FLYSKY_GIMBAL ON)
if (BLUETOOTH)
set(AUX_SERIAL OFF)
Expand Down Expand Up @@ -361,6 +362,11 @@ if(HAS_CSD203_SENSOR)
set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC} csd203_sensor.cpp)
add_definitions(-DCSD203_SENSOR)
endif()

if(HAS_RGB_6POS)
target_sources(board PRIVATE boards/helloradio/rgb_6pos.cpp)
endif()

set(FIRMWARE_SRC
${FIRMWARE_SRC}
targets/common/arm/loadboot.cpp
Expand Down
39 changes: 0 additions & 39 deletions radio/src/targets/horus/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,45 +104,6 @@ void audioInit()
}
#endif

#if defined(SIXPOS_SWITCH_INDEX)
uint8_t lastADCState = 0;
uint8_t sixPosState = 0;
bool dirty = true;
uint16_t getSixPosAnalogValue(uint16_t adcValue)
{
uint8_t currentADCState = 0;
if (adcValue > 3800)
currentADCState = 6;
else if (adcValue > 3100)
currentADCState = 5;
else if (adcValue > 2300)
currentADCState = 4;
else if (adcValue > 1500)
currentADCState = 3;
else if (adcValue > 1000)
currentADCState = 2;
else if (adcValue > 400)
currentADCState = 1;
if (lastADCState != currentADCState) {
lastADCState = currentADCState;
} else if (lastADCState != 0 && lastADCState - 1 != sixPosState) {
sixPosState = lastADCState - 1;
dirty = true;
}
if (dirty) {
for (uint8_t i = 0; i < 6; i++) {
if (i == sixPosState) {
ws2812_set_color(i, SIXPOS_LED_RED, SIXPOS_LED_GREEN, SIXPOS_LED_BLUE);
} else {
ws2812_set_color(i, 0, 0, 0);
}
}
rgbLedColorApply();
}
return (4096/5)*(sixPosState);
}
#endif

void boardInit()
{
#if defined(RADIO_FAMILY_T16)
Expand Down
4 changes: 0 additions & 4 deletions radio/src/targets/horus/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,6 @@ uint32_t pwrPressedDuration();
void usbChargerInit();
bool usbChargerLed();

#if defined(RADIO_V16)
uint16_t getSixPosAnalogValue(uint16_t adcValue);
#endif

// Led driver
void ledInit();
void ledOff();
Expand Down
18 changes: 13 additions & 5 deletions radio/src/targets/horus/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,19 @@
#endif
#endif

// 6POS SW
// V16 6POS SW
#if defined(RADIO_V16)
#define SIXPOS_SWITCH_INDEX 5
#define SIXPOS_LED_RED 255
#define SIXPOS_LED_GREEN 255
#define SIXPOS_LED_BLUE 255
// default calibration
#define DEFAULT_6POS_CALIB {3, 12, 21, 30, 38}
#define DEFAULT_6POS_IDX 5

// index in pots
#define SIXPOS_SWITCH_INDEX 1

// RGB LEDs color
#define SIXPOS_LED_RED 255
#define SIXPOS_LED_GREEN 255
#define SIXPOS_LED_BLUE 255
#endif

// Trims
Expand Down Expand Up @@ -1024,6 +1031,7 @@
#if defined(RADIO_V16)
// LED Strip
#define LED_STRIP_LENGTH 40
#define LED_STRIP_RESERVED 6
#define LED_STRIP_GPIO GPIO_PIN(GPIOA, 10) // PA.10 / TIM1_CH3
#define LED_STRIP_GPIO_AF LL_GPIO_AF_1 // TIM1/2
#define LED_STRIP_TIMER TIM1
Expand Down
6 changes: 6 additions & 0 deletions radio/src/targets/taranis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ elseif(PCB STREQUAL X7)
set(CPU_TYPE_FULL STM32F407xG)
set(ROTARY_ENCODER YES)
set(USB_CHARGER YES)
set(HAS_RGB_6POS ON)
add_definitions(-DRADIO_V12)
add_definitions(-DSTM32_SUPPORT_32BIT_TIMERS)
set(PXX2 ON)
Expand All @@ -417,6 +418,7 @@ elseif(PCB STREQUAL X7)
set(CPU_TYPE_FULL STM32F407xG)
set(ROTARY_ENCODER YES)
set(USB_CHARGER YES)
set(HAS_RGB_6POS ON)
add_definitions(-DRADIO_V14)
add_definitions(-DSTM32_SUPPORT_32BIT_TIMERS)
set(PXX2 ON)
Expand Down Expand Up @@ -679,6 +681,10 @@ if(RGBLEDS)
add_definitions(-DRGBLEDS)
endif()

if(HAS_RGB_6POS)
target_sources(board PRIVATE boards/helloradio/rgb_6pos.cpp)
endif()

if(FLAVOUR STREQUAL gx12)
target_sources(board PRIVATE
drivers/pca95xx.cpp
Expand Down
38 changes: 0 additions & 38 deletions radio/src/targets/taranis/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,44 +68,6 @@ HardwareOptions hardwareOptions;
#include "storage/storage.h"
#endif

#if defined(SIXPOS_SWITCH_INDEX)
uint8_t lastADCState = 0;
uint8_t sixPosState = 0;
bool dirty = true;
uint16_t getSixPosAnalogValue(uint16_t adcValue)
{
uint8_t currentADCState = 0;
if (adcValue > 3800)
currentADCState = 6;
else if (adcValue > 3100)
currentADCState = 5;
else if (adcValue > 2300)
currentADCState = 4;
else if (adcValue > 1500)
currentADCState = 3;
else if (adcValue > 1000)
currentADCState = 2;
else if (adcValue > 400)
currentADCState = 1;
if (lastADCState != currentADCState) {
lastADCState = currentADCState;
} else if (lastADCState != 0 && lastADCState - 1 != sixPosState) {
sixPosState = lastADCState - 1;
dirty = true;
}
if (dirty) {
for (uint8_t i = 0; i < 6; i++) {
if (i == sixPosState)
ws2812_set_color(i, SIXPOS_LED_RED, SIXPOS_LED_GREEN, SIXPOS_LED_BLUE);
else
ws2812_set_color(i, 0, 0, 0);
}
rgbLedColorApply();
}
return (4096/5)*(sixPosState);
}
#endif

void boardInit()
{
LL_APB1_GRP1_EnableClock(AUDIO_RCC_APB1Periph);
Expand Down
4 changes: 0 additions & 4 deletions radio/src/targets/taranis/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,6 @@ void usbChargerInit();
bool usbChargerLed();
#endif

#if defined(RADIO_V14) || defined(RADIO_V12)
uint16_t getSixPosAnalogValue(uint16_t adcValue);
#endif

// LED driver
void ledInit();
void ledOff();
Expand Down
31 changes: 20 additions & 11 deletions radio/src/targets/taranis/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1308,10 +1308,17 @@

// 6POS SW
#if defined(RADIO_V14) || defined(RADIO_V12)
#define SIXPOS_SWITCH_INDEX 6
#define SIXPOS_LED_RED 255
#define SIXPOS_LED_GREEN 255
#define SIXPOS_LED_BLUE 255
// default calibration
#define DEFAULT_6POS_CALIB {3, 12, 21, 30, 38}
#define DEFAULT_6POS_IDX 6

// index in pots
#define SIXPOS_SWITCH_INDEX 2

// RGB LEDs color
#define SIXPOS_LED_RED 255
#define SIXPOS_LED_GREEN 255
#define SIXPOS_LED_BLUE 255
#endif

// ADC
Expand Down Expand Up @@ -1981,13 +1988,15 @@
#define LED_STRIP_TIMER_DMA_IRQHandler DMA2_Stream5_IRQHandler
#define LED_STRIP_REFRESH_PERIOD 50 //ms
#elif defined(RADIO_T14) || defined(RADIO_V14) || defined(RADIO_V12)
#if defined(RADIO_V14)
#define LED_STRIP_LENGTH 38
#elif defined(RADIO_V12)
#define LED_STRIP_LENGTH 6
#else
#define LED_STRIP_LENGTH 1
#endif
#if defined(RADIO_V14)
#define LED_STRIP_LENGTH 38
#define LED_STRIP_RESERVED 6
#elif defined(RADIO_V12)
#define LED_STRIP_LENGTH 6
#define LED_STRIP_RESERVED 6
#else
#define LED_STRIP_LENGTH 1
#endif
#define LED_STRIP_GPIO GPIO_PIN(GPIOA, 10) // PA.10 / TIM1_CH3
#define LED_STRIP_GPIO_AF LL_GPIO_AF_1
#define LED_STRIP_TIMER TIM1
Expand Down