Skip to content

Commit

Permalink
FMU PWM added to 14 channels
Browse files Browse the repository at this point in the history
  • Loading branch information
CUAVcaijie authored and bkueng committed Mar 25, 2020
1 parent 23f2fb9 commit 66e78e8
Show file tree
Hide file tree
Showing 6 changed files with 611 additions and 40 deletions.
54 changes: 27 additions & 27 deletions boards/cuav/nora/init/rc.board_defaults
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,35 @@ set LOGGER_BUF 64

safety_button start

# fmu mode_pwm
# pwm rate -a -r 400
fmu mode_pwm
pwm rate -a -r 400

# pwm disarmed -m 0x100 -p p:PWM_MAIN_DIS9
# pwm disarmed -m 0x200 -p p:PWM_MAIN_DIS10
# pwm disarmed -m 0x400 -p p:PWM_MAIN_DIS11
# pwm disarmed -m 0x800 -p p:PWM_MAIN_DIS12
# pwm disarmed -m 0x1000 -p p:PWM_MAIN_DIS13
# pwm disarmed -m 0x2000 -p p:PWM_MAIN_DIS14
pwm disarmed -m 0x100 -p p:PWM_MAIN_DIS9
pwm disarmed -m 0x200 -p p:PWM_MAIN_DIS10
pwm disarmed -m 0x400 -p p:PWM_MAIN_DIS11
pwm disarmed -m 0x800 -p p:PWM_MAIN_DIS12
pwm disarmed -m 0x1000 -p p:PWM_MAIN_DIS13
pwm disarmed -m 0x2000 -p p:PWM_MAIN_DIS14

# pwm min -m 0x100 -p p:PWM_MAIN_MIN9
# pwm min -m 0x200 -p p:PWM_MAIN_MIN10
# pwm min -m 0x400 -p p:PWM_MAIN_MIN11
# pwm min -m 0x800 -p p:PWM_MAIN_MIN12
# pwm min -m 0x1000 -p p:PWM_MAIN_MIN13
# pwm min -m 0x2000 -p p:PWM_MAIN_MIN14
pwm min -m 0x100 -p p:PWM_MAIN_MIN9
pwm min -m 0x200 -p p:PWM_MAIN_MIN10
pwm min -m 0x400 -p p:PWM_MAIN_MIN11
pwm min -m 0x800 -p p:PWM_MAIN_MIN12
pwm min -m 0x1000 -p p:PWM_MAIN_MIN13
pwm min -m 0x2000 -p p:PWM_MAIN_MIN14

# pwm max -m 0x100 -p p:PWM_MAIN_MAX9
# pwm max -m 0x200 -p p:PWM_MAIN_MAX10
# pwm max -m 0x400 -p p:PWM_MAIN_MAX11
# pwm max -m 0x800 -p p:PWM_MAIN_MAX12
# pwm max -m 0x1000 -p p:PWM_MAIN_MAX13
# pwm max -m 0x2000 -p p:PWM_MAIN_MAX14
pwm max -m 0x100 -p p:PWM_MAIN_MAX9
pwm max -m 0x200 -p p:PWM_MAIN_MAX10
pwm max -m 0x400 -p p:PWM_MAIN_MAX11
pwm max -m 0x800 -p p:PWM_MAIN_MAX12
pwm max -m 0x1000 -p p:PWM_MAIN_MAX13
pwm max -m 0x2000 -p p:PWM_MAIN_MAX14

# pwm failsafe -m 0x100 -p p:PWM_MAIN_FAIL9
# pwm failsafe -m 0x200 -p p:PWM_MAIN_FAIL10
# pwm failsafe -m 0x400 -p p:PWM_MAIN_FAIL11
# pwm failsafe -m 0x800 -p p:PWM_MAIN_FAIL12
# pwm failsafe -m 0x1000 -p p:PWM_MAIN_FAIL13
# pwm failsafe -m 0x2000 -p p:PWM_MAIN_FAIL14
pwm failsafe -m 0x100 -p p:PWM_MAIN_FAIL9
pwm failsafe -m 0x200 -p p:PWM_MAIN_FAIL10
pwm failsafe -m 0x400 -p p:PWM_MAIN_FAIL11
pwm failsafe -m 0x800 -p p:PWM_MAIN_FAIL12
pwm failsafe -m 0x1000 -p p:PWM_MAIN_FAIL13
pwm failsafe -m 0x2000 -p p:PWM_MAIN_FAIL14

# set PWM_RATE none
set PWM_RATE none
6 changes: 3 additions & 3 deletions boards/cuav/nora/src/board_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@

/* PWM
*/
#define DIRECT_PWM_OUTPUT_CHANNELS 8
#define DIRECT_INPUT_TIMER_CHANNELS 8
#define DIRECT_PWM_OUTPUT_CHANNELS 14
#define DIRECT_INPUT_TIMER_CHANNELS 14
#define BOARD_NUM_IO_TIMERS 4

#define BOARD_HAS_LED_PWM 1
Expand All @@ -341,7 +341,7 @@
#define BOARD_HAS_UI_LED_PWM 1
#define BOARD_UI_LED_PWM_DRIVE_ACTIVE_LOW 1

#define BOARD_DSHOT_MOTOR_ASSIGNMENT {3, 2, 1, 0, 4, 5, 6, 7};
#define BOARD_DSHOT_MOTOR_ASSIGNMENT {3, 2, 1, 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};

/* Power supply control and monitoring GPIOs */

Expand Down
12 changes: 6 additions & 6 deletions boards/cuav/nora/src/timer_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ constexpr timer_io_channels_t timer_io_channels[MAX_TIMER_IO_CHANNELS] = {
initIOTimerChannel(io_timers, {Timer::Timer4, Timer::Channel2}, {GPIO::PortD, GPIO::Pin13}),
initIOTimerChannel(io_timers, {Timer::Timer4, Timer::Channel1}, {GPIO::PortD, GPIO::Pin12}),

// initIOTimerChannel(io_timers, {Timer::Timer1, Timer::Channel4}, {GPIO::PortE, GPIO::Pin14}),
// initIOTimerChannel(io_timers, {Timer::Timer1, Timer::Channel3}, {GPIO::PortA, GPIO::Pin10}),
// initIOTimerChannel(io_timers, {Timer::Timer1, Timer::Channel2}, {GPIO::PortE, GPIO::Pin11}),
// initIOTimerChannel(io_timers, {Timer::Timer1, Timer::Channel1}, {GPIO::PortE, GPIO::Pin9}),
initIOTimerChannel(io_timers, {Timer::Timer1, Timer::Channel4}, {GPIO::PortE, GPIO::Pin14}),
initIOTimerChannel(io_timers, {Timer::Timer1, Timer::Channel3}, {GPIO::PortA, GPIO::Pin10}),
initIOTimerChannel(io_timers, {Timer::Timer1, Timer::Channel2}, {GPIO::PortE, GPIO::Pin11}),
initIOTimerChannel(io_timers, {Timer::Timer1, Timer::Channel1}, {GPIO::PortE, GPIO::Pin9}),

// initIOTimerChannel(io_timers, {Timer::Timer12, Timer::Channel2}, {GPIO::PortH, GPIO::Pin9}),
// initIOTimerChannel(io_timers, {Timer::Timer12, Timer::Channel1}, {GPIO::PortH, GPIO::Pin6}),
initIOTimerChannel(io_timers, {Timer::Timer12, Timer::Channel2}, {GPIO::PortH, GPIO::Pin9}),
initIOTimerChannel(io_timers, {Timer::Timer12, Timer::Channel1}, {GPIO::PortH, GPIO::Pin6}),

};

Expand Down
29 changes: 29 additions & 0 deletions src/drivers/dshot/dshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ enum PortMode {
PORT_MODE_UNSET = 0,
PORT_FULL_GPIO,
PORT_FULL_PWM,
PORT_PWM14,
PORT_PWM8,
PORT_PWM6,
PORT_PWM5,
Expand Down Expand Up @@ -971,6 +972,13 @@ DShotOutput::pwm_ioctl(file *filp, int cmd, unsigned long arg)
break;
#endif

#if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM >=14

case 14:
set_mode(MODE_14PWM);
break;
#endif

#if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM >=8

case 8:
Expand Down Expand Up @@ -1040,6 +1048,10 @@ DShotOutput::pwm_ioctl(file *filp, int cmd, unsigned long arg)
ret = set_mode(MODE_8PWM);
break;

case PWM_SERVO_MODE_14PWM:
ret = set_mode(MODE_14PWM);
break;

case PWM_SERVO_MODE_4CAP:
ret = set_mode(MODE_4CAP);
break;
Expand Down Expand Up @@ -1274,7 +1286,13 @@ DShotOutput::module_new_mode(PortMode new_mode)
/* select 2-pin PWM mode */
mode = DShotOutput::MODE_1PWM;
break;
#if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM >= 14

case PORT_PWM14:
/* select 14-pin PWM mode */
mode = DShotOutput::MODE_14PWM;
break;
#endif
#if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM >= 8

case PORT_PWM8:
Expand Down Expand Up @@ -1520,6 +1538,12 @@ int DShotOutput::custom_command(int argc, char *argv[])
new_mode = PORT_PWM2CAP2;
# endif
#endif
#if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM >= 14

} else if (!strcmp(verb, "mode_pwm14")) {
new_mode = PORT_PWM14;
#endif

#if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM >= 8

} else if (!strcmp(verb, "mode_pwm8")) {
Expand Down Expand Up @@ -1569,6 +1593,8 @@ int DShotOutput::print_status()

case MODE_8PWM: mode_str = "outputs8"; break;

case MODE_14PWM: mode_str = "outputs14"; break;

case MODE_4CAP: mode_str = "cap4"; break;

case MODE_5CAP: mode_str = "cap5"; break;
Expand Down Expand Up @@ -1627,6 +1653,9 @@ After saving, the reversed direction will be regarded as the normal one. So to r

PRINT_MODULE_USAGE_COMMAND("mode_gpio");
PRINT_MODULE_USAGE_COMMAND_DESCR("mode_pwm", "Select all available pins as PWM");
#if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM >= 14
PRINT_MODULE_USAGE_COMMAND("mode_pwm14");
#endif
#if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM >= 8
PRINT_MODULE_USAGE_COMMAND("mode_pwm8");
#endif
Expand Down
38 changes: 34 additions & 4 deletions src/drivers/px4fmu/fmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ enum PortMode {
PORT_MODE_UNSET = 0,
PORT_FULL_GPIO,
PORT_FULL_PWM,
PORT_PWM14,
PORT_PWM8,
PORT_PWM6,
PORT_PWM5,
Expand Down Expand Up @@ -1118,10 +1119,10 @@ PX4FMU::pwm_ioctl(file *filp, int cmd, unsigned long arg)
case PWM_SERVO_SET(10):
case PWM_SERVO_SET(9):
case PWM_SERVO_SET(8):
if (_mode < MODE_14PWM) {
ret = -EINVAL;
break;
}
// if (_mode < MODE_14PWM) {
// ret = -EINVAL;
// break;
// }

#endif
#if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM >= 8
Expand Down Expand Up @@ -1377,6 +1378,13 @@ PX4FMU::pwm_ioctl(file *filp, int cmd, unsigned long arg)
break;
#endif

#if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM >=14

case 14:
set_mode(MODE_14PWM);
break;
#endif

default:
ret = -EINVAL;
break;
Expand Down Expand Up @@ -1439,6 +1447,10 @@ PX4FMU::pwm_ioctl(file *filp, int cmd, unsigned long arg)
ret = set_mode(MODE_8PWM);
break;

case PWM_SERVO_MODE_14PWM:
ret = set_mode(MODE_14PWM);
break;

case PWM_SERVO_MODE_4CAP:
ret = set_mode(MODE_4CAP);
break;
Expand Down Expand Up @@ -1703,6 +1715,13 @@ PX4FMU::fmu_new_mode(PortMode new_mode)
servo_mode = PX4FMU::MODE_1PWM;
break;

#if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM >= 14

case PORT_PWM14:
/* select 14-pin PWM mode */
servo_mode = PX4FMU::MODE_14PWM;
break;
#endif
#if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM >= 8

case PORT_PWM8:
Expand Down Expand Up @@ -2161,6 +2180,12 @@ int PX4FMU::custom_command(int argc, char *argv[])
new_mode = PORT_PWM2CAP2;
# endif
#endif
#if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM >= 14

} else if (!strcmp(verb, "mode_pwm14")) {
new_mode = PORT_PWM14;
#endif

#if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM >= 8

} else if (!strcmp(verb, "mode_pwm8")) {
Expand Down Expand Up @@ -2219,6 +2244,8 @@ int PX4FMU::print_status()

case MODE_8PWM: mode_str = "pwm8"; break;

case MODE_14PWM: mode_str = "pwm14"; break;

case MODE_4CAP: mode_str = "cap4"; break;

case MODE_5CAP: mode_str = "cap5"; break;
Expand Down Expand Up @@ -2283,6 +2310,9 @@ mixer files.

PRINT_MODULE_USAGE_COMMAND("mode_gpio");
PRINT_MODULE_USAGE_COMMAND_DESCR("mode_pwm", "Select all available pins as PWM");
#if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM >= 14
PRINT_MODULE_USAGE_COMMAND("mode_pwm14");
#endif
#if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM >= 8
PRINT_MODULE_USAGE_COMMAND("mode_pwm8");
#endif
Expand Down
Loading

0 comments on commit 66e78e8

Please sign in to comment.