Skip to content

Commit 09d2c25

Browse files
raphaelcoefficpfeerick
authored andcommitted
Make it a tool
1 parent b9a8705 commit 09d2c25

File tree

6 files changed

+109
-21
lines changed

6 files changed

+109
-21
lines changed

radio/src/gui/common/stdlcd/menus_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ void menuRadioSpectrumAnalyser(event_t event);
140140
void menuRadioPowerMeter(event_t event);
141141
void menuRadioCalibration(event_t event);
142142
void menuGhostModuleConfig(event_t event);
143+
void menuServoPwmTool(event_t event);
143144

144145
void menuModelSelect(event_t event);
145146
void menuModelSetup(event_t event);
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (C) EdgeTX
3+
*
4+
* Based on code named
5+
* opentx - https://github.com/opentx/opentx
6+
* th9x - http://code.google.com/p/th9x
7+
* er9x - http://code.google.com/p/er9x
8+
* gruvin9x - http://code.google.com/p/gruvin9x
9+
*
10+
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11+
*
12+
* This program is free software; you can redistribute it and/or modify
13+
* it under the terms of the GNU General Public License version 2 as
14+
* published by the Free Software Foundation.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*/
21+
22+
#include "edgetx.h"
23+
#include "os/sleep.h"
24+
25+
#if defined(SERVO_PWM)
26+
27+
#if LCD_W >= 212
28+
#define HW_SETTINGS_COLUMN1 12*FW
29+
#define HW_SETTINGS_COLUMN2 (20*FW - 3)
30+
#define HW_SETTINGS_COLUMN3 HW_SETTINGS_COLUMN2
31+
#else
32+
#define HW_SETTINGS_COLUMN1 30
33+
#define HW_SETTINGS_COLUMN2 (HW_SETTINGS_COLUMN1 + 5*FW)
34+
#define HW_SETTINGS_COLUMN3 HW_SETTINGS_COLUMN2 + FW
35+
#endif
36+
37+
#if !defined(SIMU)
38+
extern void pwmOutputDisable();
39+
extern void pwmOutputInit();
40+
extern void pwmOutputEnable(uint16_t pulse_width_us);
41+
#else
42+
void pwmOutputDisable() {}
43+
void pwmOutputInit() {}
44+
void pwmOutputEnable(uint16_t) {}
45+
#endif
46+
47+
static uint8_t pwmOutputSource;
48+
49+
enum {
50+
ITEM_PWM_SOURCE,
51+
ITEM_SERVO_PWM_MAX,
52+
};
53+
54+
void menuServoPwmTool(event_t event)
55+
{
56+
SUBMENU(STR_PWM_OUTPUT, 0, {0});
57+
58+
if (menuEvent == EVT_ENTRY_UP) {
59+
TRACE("stopping servo pwm...");
60+
pwmOutputDisable();
61+
return;
62+
}
63+
64+
if (event == EVT_ENTRY) {
65+
TRACE("starting servo pwm...");
66+
pwmOutputSource = MIXSRC_NONE;
67+
pwmOutputInit();
68+
}
69+
70+
if (pwmOutputSource > MIXSRC_NONE) {
71+
mixsrc_t chan = pwmOutputSource - MIXSRC_FIRST;
72+
pwmOutputEnable(PPM_CH_CENTER(chan) + channelOutputs[chan] / 2);
73+
} else {
74+
pwmOutputDisable();
75+
}
76+
77+
for (int i = 0; i < ITEM_SERVO_PWM_MAX; i++) {
78+
LcdFlags attr = (menuVerticalPosition == i ? (s_editMode > 0 ? INVERS | BLINK : INVERS) : 0);
79+
coord_t y = MENU_HEADER_HEIGHT + 12 + i * FH;
80+
81+
switch (i) {
82+
case ITEM_PWM_SOURCE:
83+
lcdDrawTextAlignedLeft(y, STR_PWM_OUTPUT);
84+
drawSource(HW_SETTINGS_COLUMN2, y, pwmOutputSource, attr);
85+
if (attr & BLINK)
86+
CHECK_INCDEC_GENVAR(event, pwmOutputSource, 0, MAX_OUTPUT_CHANNELS);
87+
break;
88+
}
89+
}
90+
}
91+
92+
#endif
93+

radio/src/gui/common/stdlcd/radio_tools.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ void menuRadioTools(event_t event)
214214
addRadioModuleToolHandler(index++, "Ghost Menu", menuGhostModuleConfig, EXTERNAL_MODULE);
215215
#endif
216216

217+
#if defined(SERVO_PWM)
218+
addRadioModuleToolHandler(index++, STR_PWM_OUTPUT, menuServoPwmTool, 0);
219+
#endif
220+
217221
#endif
218222

219223
if (index == 0) {

radio/src/targets/simu/simpgmspace.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,3 @@ struct TouchState getInternalTouchState()
504504
return simTouchState;
505505
}
506506
#endif
507-
508-
#if defined(SERVO_PWM)
509-
void pwmOutputEnable(uint16_t pulse_width_us) {}
510-
#endif

radio/src/targets/taranis/CMakeLists.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -623,12 +623,6 @@ if(BLUETOOTH)
623623
)
624624
endif()
625625

626-
if(PCBREV STREQUAL MT12)
627-
list(APPEND BOARD_COMMON_SRC
628-
${TARGET_SRC_DIR}/pwm_ch_driver.cpp
629-
)
630-
endif()
631-
632626
# Bootloader board library
633627
add_library(board_bl OBJECT EXCLUDE_FROM_ALL
634628
${BOARD_COMMON_SRC}
@@ -702,6 +696,15 @@ if(FLAVOUR STREQUAL xlites)
702696
)
703697
endif()
704698

699+
if(FLAVOUR STREQUAL mt12)
700+
target_sources(board PRIVATE
701+
${TARGET_SRC_DIR}/pwm_ch_driver.cpp
702+
)
703+
set(SRC ${SRC}
704+
gui/common/stdlcd/radio_servo_pwm.cpp
705+
)
706+
endif()
707+
705708
set(SRC ${SRC}
706709
io/frsky_firmware_update.cpp
707710
io/multi_firmware_update.cpp

radio/src/targets/taranis/pwm_ch_driver.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@
1919
* GNU General Public License for more details.
2020
*/
2121

22-
#include "hal/gpio.h"
23-
#include "stm32_gpio.h"
24-
#include "stm32_timer.h"
2522
#include "stm32_pulse_driver.h"
23+
#include "stm32_gpio.h"
2624

2725
#include "edgetx_types.h"
2826
#include "board.h"
2927

30-
3128
static const stm32_pulse_timer_t _pwm_timer = {
3229
.GPIO = (gpio_t)PWM_GPIO,
3330
.GPIO_Alternate = PWM_GPIO_AF,
@@ -42,12 +39,6 @@ static const stm32_pulse_timer_t _pwm_timer = {
4239
.DMA_TC_CallbackPtr = nullptr,
4340
};
4441

45-
void pwmOutputLowInit()
46-
{
47-
gpio_init(PWM_GPIO, GPIO_OUT, GPIO_PIN_SPEED_LOW);
48-
gpio_clear(PWM_GPIO);
49-
}
50-
5142
void pwmOutputDisable()
5243
{
5344
stm32_pulse_stop(&_pwm_timer);
@@ -65,4 +56,4 @@ void pwmOutputEnable(uint16_t pulse_width_us)
6556
{
6657
stm32_pulse_set_cmp_val(&_pwm_timer, pulse_width_us);
6758
stm32_pulse_start(&_pwm_timer);
68-
}
59+
}

0 commit comments

Comments
 (0)