diff --git a/ROMFS/px4fmu_common/init.d/rc.interface b/ROMFS/px4fmu_common/init.d/rc.interface index e0ee2dffd4..3143b2c034 100644 --- a/ROMFS/px4fmu_common/init.d/rc.interface +++ b/ROMFS/px4fmu_common/init.d/rc.interface @@ -9,7 +9,7 @@ # Otherwise, the variable name goes to the end of the argument. # -set FMU_CMD fmu +set OUTPUT_CMD pwm_out set MIXER_AUX_FILE none set OUTPUT_AUX_DEV /dev/pwm_output1 set OUTPUT_DEV none @@ -45,16 +45,16 @@ then set OUTPUT_MODE io if param greater DSHOT_CONFIG 0 then - set FMU_CMD dshot + set OUTPUT_CMD dshot fi fi else if param greater DSHOT_CONFIG 0 then set OUTPUT_MODE dshot - set FMU_CMD dshot + set OUTPUT_CMD dshot else - set OUTPUT_MODE fmu + set OUTPUT_MODE pwm_out fi fi fi @@ -91,11 +91,11 @@ then fi fi - if [ $OUTPUT_MODE = $FMU_CMD ] + if [ $OUTPUT_MODE = $OUTPUT_CMD ] then - if ! $FMU_CMD mode_$FMU_MODE + if ! $OUTPUT_CMD mode_$FMU_MODE then - echo "$FMU_CMD start failed" >> $LOG_FILE + echo "$OUTPUT_CMD start failed" >> $LOG_FILE # Error tune. tune_control play -t 2 fi @@ -206,7 +206,7 @@ then if [ $MIXER_AUX_FILE != none ] then - if $FMU_CMD mode_${AUX_MODE} + if $OUTPUT_CMD mode_${AUX_MODE} then # Append aux mixer to main device. if param greater SYS_HITL 0 @@ -233,14 +233,14 @@ then set FAILSAFE_AUX none fi else - echo "ERROR: Could not start: fmu mode_pwm" >> $LOG_FILE + echo "ERROR: Could not start: pwm_out mode_pwm" >> $LOG_FILE tune_control play -t 20 set PWM_AUX_OUT none set FAILSAFE_AUX none fi # for DShot do not configure pwm values - if [ $FMU_CMD != dshot ] + if [ $OUTPUT_CMD != dshot ] then # Set min / max for aux out and rates. if [ $PWM_AUX_OUT != none ] @@ -322,7 +322,7 @@ then fi fi -if [ $OUTPUT_MODE = fmu -o $OUTPUT_MODE = io ] +if [ $OUTPUT_MODE = pwm_out -o $OUTPUT_MODE = io ] then if [ $PWM_OUT != none ] then @@ -401,7 +401,7 @@ then pwm failsafe -c 8 -p p:PWM_MAIN_FAIL8 fi -unset FMU_CMD +unset OUTPUT_CMD unset MIXER_AUX_FILE unset OUTPUT_AUX_DEV unset OUTPUT_DEV diff --git a/ROMFS/px4fmu_common/init.d/rc.sensors b/ROMFS/px4fmu_common/init.d/rc.sensors index 931e5f661e..2380707ccc 100644 --- a/ROMFS/px4fmu_common/init.d/rc.sensors +++ b/ROMFS/px4fmu_common/init.d/rc.sensors @@ -11,8 +11,9 @@ then then # Configure all I2C buses to 100 KHz as they # are all external or slow - fmu i2c 1 100000 - fmu i2c 2 100000 + # TODO: move this + pwm_out i2c 1 100000 + pwm_out i2c 2 100000 fi fi diff --git a/ROMFS/px4fmu_test/init.d/rc.sensors b/ROMFS/px4fmu_test/init.d/rc.sensors index e23d322ef2..e36ca9c674 100644 --- a/ROMFS/px4fmu_test/init.d/rc.sensors +++ b/ROMFS/px4fmu_test/init.d/rc.sensors @@ -3,11 +3,6 @@ # Standard startup script for onboard sensor drivers. # -# Configure all I2C buses to 100 KHz as they -# are all external or slow -fmu i2c 1 100000 -fmu i2c 2 100000 - if ms5611 -s start then fi diff --git a/boards/airmind/mindpx-v2/default.cmake b/boards/airmind/mindpx-v2/default.cmake index 75a847c7e9..d38f6617d4 100644 --- a/boards/airmind/mindpx-v2/default.cmake +++ b/boards/airmind/mindpx-v2/default.cmake @@ -43,7 +43,7 @@ px4_add_board( #protocol_splitter pwm_input pwm_out_sim - px4fmu + pwm_out rc_input roboclaw tap_esc diff --git a/boards/av/x-v1/default.cmake b/boards/av/x-v1/default.cmake index ceb753274b..78e8091f8e 100644 --- a/boards/av/x-v1/default.cmake +++ b/boards/av/x-v1/default.cmake @@ -43,7 +43,7 @@ px4_add_board( #protocol_splitter #pwm_input pwm_out_sim - px4fmu + pwm_out rc_input roboclaw tap_esc diff --git a/boards/bitcraze/crazyflie/default.cmake b/boards/bitcraze/crazyflie/default.cmake index c3eeca6398..93d73ad0aa 100644 --- a/boards/bitcraze/crazyflie/default.cmake +++ b/boards/bitcraze/crazyflie/default.cmake @@ -12,7 +12,7 @@ px4_add_board( gps imu/mpu9250 optical_flow/pmw3901 - px4fmu + pwm_out MODULES attitude_estimator_q #camera_feedback diff --git a/boards/holybro/durandal-v1/default.cmake b/boards/holybro/durandal-v1/default.cmake index 60ab65ff0b..7d004966d3 100644 --- a/boards/holybro/durandal-v1/default.cmake +++ b/boards/holybro/durandal-v1/default.cmake @@ -48,7 +48,7 @@ px4_add_board( # pwm_input - Need to create arch/stm32 arch/stm32h7 arch/kinetis and reloacate # all arch dependant code there pwm_out_sim - px4fmu + pwm_out px4io roboclaw tap_esc diff --git a/boards/holybro/durandal-v1/stackcheck.cmake b/boards/holybro/durandal-v1/stackcheck.cmake index d9634fe66c..d200ccc629 100644 --- a/boards/holybro/durandal-v1/stackcheck.cmake +++ b/boards/holybro/durandal-v1/stackcheck.cmake @@ -49,7 +49,7 @@ px4_add_board( # pwm_input - Need to create arch/stm32 arch/stm32h7 arch/kinetis and reloacate # all arch dependant code there pwm_out_sim - px4fmu + pwm_out px4io #roboclaw #tap_esc diff --git a/boards/holybro/kakutef7/default.cmake b/boards/holybro/kakutef7/default.cmake index b3db1fd2e7..bad2aa6f5e 100644 --- a/boards/holybro/kakutef7/default.cmake +++ b/boards/holybro/kakutef7/default.cmake @@ -24,7 +24,7 @@ px4_add_board( optical_flow/px4flow osd pwm_out_sim - px4fmu + pwm_out rc_input telemetry tone_alarm diff --git a/boards/intel/aerofc-v1/default.cmake b/boards/intel/aerofc-v1/default.cmake index 3f65e3140f..51eb435b36 100644 --- a/boards/intel/aerofc-v1/default.cmake +++ b/boards/intel/aerofc-v1/default.cmake @@ -25,7 +25,7 @@ px4_add_board( #optical_flow/px4flow #protocol_splitter pwm_out_sim - px4fmu + pwm_out rc_input tap_esc #telemetry # all available telemetry drivers diff --git a/boards/intel/aerofc-v1/rtps.cmake b/boards/intel/aerofc-v1/rtps.cmake index e071118aa3..245b60a165 100644 --- a/boards/intel/aerofc-v1/rtps.cmake +++ b/boards/intel/aerofc-v1/rtps.cmake @@ -25,7 +25,7 @@ px4_add_board( #optical_flow/px4flow protocol_splitter pwm_out_sim - px4fmu + pwm_out rc_input tap_esc #telemetry # all available telemetry drivers diff --git a/boards/modalai/fc-v1/default.cmake b/boards/modalai/fc-v1/default.cmake index 7200eab389..7d70ac4e5a 100644 --- a/boards/modalai/fc-v1/default.cmake +++ b/boards/modalai/fc-v1/default.cmake @@ -42,7 +42,7 @@ px4_add_board( #protocol_splitter #pwm_input pwm_out_sim - px4fmu + pwm_out rc_input roboclaw safety_button diff --git a/boards/mro/ctrl-zero-f7/default.cmake b/boards/mro/ctrl-zero-f7/default.cmake index c4f7aeefeb..189cf85ea4 100644 --- a/boards/mro/ctrl-zero-f7/default.cmake +++ b/boards/mro/ctrl-zero-f7/default.cmake @@ -45,7 +45,7 @@ px4_add_board( #protocol_splitter #pwm_input pwm_out_sim - px4fmu + pwm_out rc_input roboclaw safety_button diff --git a/boards/mro/x21-777/default.cmake b/boards/mro/x21-777/default.cmake index 7f34d7dd32..633cc19bc6 100644 --- a/boards/mro/x21-777/default.cmake +++ b/boards/mro/x21-777/default.cmake @@ -40,7 +40,7 @@ px4_add_board( #protocol_splitter pwm_input pwm_out_sim - px4fmu + pwm_out px4io roboclaw tap_esc diff --git a/boards/mro/x21/default.cmake b/boards/mro/x21/default.cmake index 0ae2dcbe69..d35df95d18 100644 --- a/boards/mro/x21/default.cmake +++ b/boards/mro/x21/default.cmake @@ -43,7 +43,7 @@ px4_add_board( #protocol_splitter pwm_input pwm_out_sim - px4fmu + pwm_out px4io roboclaw tap_esc diff --git a/boards/nxp/fmuk66-v3/default.cmake b/boards/nxp/fmuk66-v3/default.cmake index 0f1a57ca73..8a29200831 100644 --- a/boards/nxp/fmuk66-v3/default.cmake +++ b/boards/nxp/fmuk66-v3/default.cmake @@ -44,7 +44,7 @@ px4_add_board( power_monitor/ina226 #protocol_splitter pwm_out_sim - px4fmu + pwm_out rc_input roboclaw safety_button diff --git a/boards/nxp/fmurt1062-v1/default.cmake b/boards/nxp/fmurt1062-v1/default.cmake index 92afa69022..0d71e263c6 100644 --- a/boards/nxp/fmurt1062-v1/default.cmake +++ b/boards/nxp/fmurt1062-v1/default.cmake @@ -40,7 +40,7 @@ px4_add_board( optical_flow # all available optical flow drivers # pwm_input - not ptorable pwm_out_sim - px4fmu + pwm_out rc_input roboclaw safety_button diff --git a/boards/nxp/rddrone-uavcan146/default.cmake b/boards/nxp/rddrone-uavcan146/default.cmake index 9787daf67f..3853ea52f8 100644 --- a/boards/nxp/rddrone-uavcan146/default.cmake +++ b/boards/nxp/rddrone-uavcan146/default.cmake @@ -39,7 +39,7 @@ px4_add_board( #lights #magnetometer # all available magnetometer drivers #optical_flow # all available optical flow drivers - #px4fmu + #pwm_out #safety_button #tone_alarm #uavcannode # TODO: CAN driver needed diff --git a/boards/omnibus/f4sd/default.cmake b/boards/omnibus/f4sd/default.cmake index 88d9cccdea..1e3ccda4f3 100644 --- a/boards/omnibus/f4sd/default.cmake +++ b/boards/omnibus/f4sd/default.cmake @@ -36,7 +36,7 @@ px4_add_board( #pca9685 #pwm_input #pwm_out_sim - px4fmu + pwm_out rc_input #tap_esc #telemetry # all available telemetry drivers diff --git a/boards/px4/fmu-v2/default.cmake b/boards/px4/fmu-v2/default.cmake index 26db738c19..bbcdb0fa96 100644 --- a/boards/px4/fmu-v2/default.cmake +++ b/boards/px4/fmu-v2/default.cmake @@ -55,7 +55,7 @@ px4_add_board( #protocol_splitter #pwm_input #pwm_out_sim - px4fmu + pwm_out px4io #roboclaw #tap_esc diff --git a/boards/px4/fmu-v2/fixedwing.cmake b/boards/px4/fmu-v2/fixedwing.cmake index eb6a7b9b2a..5f4a416b58 100644 --- a/boards/px4/fmu-v2/fixedwing.cmake +++ b/boards/px4/fmu-v2/fixedwing.cmake @@ -33,7 +33,7 @@ px4_add_board( lights/rgbled #magnetometer # all available magnetometer drivers magnetometer/hmc5883 - px4fmu + pwm_out px4io #telemetry # all available telemetry drivers telemetry/iridiumsbd diff --git a/boards/px4/fmu-v2/lpe.cmake b/boards/px4/fmu-v2/lpe.cmake index 039cf3a78e..deffd4ce11 100644 --- a/boards/px4/fmu-v2/lpe.cmake +++ b/boards/px4/fmu-v2/lpe.cmake @@ -50,7 +50,7 @@ px4_add_board( #protocol_splitter #pwm_input pwm_out_sim - px4fmu + pwm_out px4io #tap_esc #telemetry # all available telemetry drivers diff --git a/boards/px4/fmu-v2/multicopter.cmake b/boards/px4/fmu-v2/multicopter.cmake index af1fcc85c8..5115db6954 100644 --- a/boards/px4/fmu-v2/multicopter.cmake +++ b/boards/px4/fmu-v2/multicopter.cmake @@ -31,7 +31,7 @@ px4_add_board( lights/rgbled magnetometer/hmc5883 #optical_flow/px4flow - px4fmu + pwm_out px4io tone_alarm MODULES diff --git a/boards/px4/fmu-v2/rover.cmake b/boards/px4/fmu-v2/rover.cmake index f86769502d..8e331004a3 100644 --- a/boards/px4/fmu-v2/rover.cmake +++ b/boards/px4/fmu-v2/rover.cmake @@ -31,7 +31,7 @@ px4_add_board( lights/rgbled magnetometer/hmc5883 optical_flow/px4flow - px4fmu + pwm_out px4io tone_alarm diff --git a/boards/px4/fmu-v2/test.cmake b/boards/px4/fmu-v2/test.cmake index ebe1510e6b..18168e49bf 100644 --- a/boards/px4/fmu-v2/test.cmake +++ b/boards/px4/fmu-v2/test.cmake @@ -53,7 +53,7 @@ px4_add_board( #protocol_splitter #pwm_input #pwm_out_sim - px4fmu + pwm_out px4io #roboclaw #tap_esc diff --git a/boards/px4/fmu-v3/default.cmake b/boards/px4/fmu-v3/default.cmake index b598b073b7..8b91b5f565 100644 --- a/boards/px4/fmu-v3/default.cmake +++ b/boards/px4/fmu-v3/default.cmake @@ -52,7 +52,7 @@ px4_add_board( #protocol_splitter pwm_input pwm_out_sim - px4fmu + pwm_out px4io roboclaw tap_esc diff --git a/boards/px4/fmu-v3/rtps.cmake b/boards/px4/fmu-v3/rtps.cmake index 9c5b853b5a..795910a48d 100644 --- a/boards/px4/fmu-v3/rtps.cmake +++ b/boards/px4/fmu-v3/rtps.cmake @@ -52,7 +52,7 @@ px4_add_board( protocol_splitter pwm_input pwm_out_sim - px4fmu + pwm_out px4io roboclaw tap_esc diff --git a/boards/px4/fmu-v3/stackcheck.cmake b/boards/px4/fmu-v3/stackcheck.cmake index 22bae677e6..2b03d15d72 100644 --- a/boards/px4/fmu-v3/stackcheck.cmake +++ b/boards/px4/fmu-v3/stackcheck.cmake @@ -48,7 +48,7 @@ px4_add_board( protocol_splitter pwm_input pwm_out_sim - px4fmu + pwm_out px4io roboclaw tap_esc diff --git a/boards/px4/fmu-v4/cannode.cmake b/boards/px4/fmu-v4/cannode.cmake index 12a346b854..d345d61c57 100644 --- a/boards/px4/fmu-v4/cannode.cmake +++ b/boards/px4/fmu-v4/cannode.cmake @@ -52,7 +52,7 @@ px4_add_board( #lights/rgbled_ncp5623c #magnetometer # all available magnetometer drivers #optical_flow # all available optical flow drivers - #px4fmu + #pwm_out #safety_button #tone_alarm uavcannode diff --git a/boards/px4/fmu-v4/default.cmake b/boards/px4/fmu-v4/default.cmake index de3e7ecfa1..ba3d1b1a20 100644 --- a/boards/px4/fmu-v4/default.cmake +++ b/boards/px4/fmu-v4/default.cmake @@ -46,7 +46,7 @@ px4_add_board( #protocol_splitter pwm_input pwm_out_sim - px4fmu + pwm_out rc_input roboclaw safety_button diff --git a/boards/px4/fmu-v4/optimized.cmake b/boards/px4/fmu-v4/optimized.cmake index c7c7a2d86f..c99124da2a 100644 --- a/boards/px4/fmu-v4/optimized.cmake +++ b/boards/px4/fmu-v4/optimized.cmake @@ -46,7 +46,7 @@ px4_add_board( optical_flow # all available optical flow drivers #pwm_input pwm_out_sim - px4fmu + pwm_out rc_input #roboclaw safety_button diff --git a/boards/px4/fmu-v4/rtps.cmake b/boards/px4/fmu-v4/rtps.cmake index 67dca406b0..539043bbd5 100644 --- a/boards/px4/fmu-v4/rtps.cmake +++ b/boards/px4/fmu-v4/rtps.cmake @@ -45,7 +45,7 @@ px4_add_board( protocol_splitter pwm_input pwm_out_sim - px4fmu + pwm_out rc_input roboclaw safety_button diff --git a/boards/px4/fmu-v4/stackcheck.cmake b/boards/px4/fmu-v4/stackcheck.cmake index a342f33e4b..46522497f0 100644 --- a/boards/px4/fmu-v4/stackcheck.cmake +++ b/boards/px4/fmu-v4/stackcheck.cmake @@ -45,7 +45,7 @@ px4_add_board( #protocol_splitter pwm_input pwm_out_sim - px4fmu + pwm_out rc_input #roboclaw safety_button diff --git a/boards/px4/fmu-v4pro/default.cmake b/boards/px4/fmu-v4pro/default.cmake index 63b3644d0d..7ec90e3a76 100644 --- a/boards/px4/fmu-v4pro/default.cmake +++ b/boards/px4/fmu-v4pro/default.cmake @@ -48,7 +48,7 @@ px4_add_board( #protocol_splitter pwm_input pwm_out_sim - px4fmu + pwm_out px4io roboclaw tap_esc diff --git a/boards/px4/fmu-v4pro/rtps.cmake b/boards/px4/fmu-v4pro/rtps.cmake index 4b18bf554e..67b427be08 100644 --- a/boards/px4/fmu-v4pro/rtps.cmake +++ b/boards/px4/fmu-v4pro/rtps.cmake @@ -48,7 +48,7 @@ px4_add_board( protocol_splitter pwm_input pwm_out_sim - px4fmu + pwm_out px4io roboclaw tap_esc diff --git a/boards/px4/fmu-v5/critmonitor.cmake b/boards/px4/fmu-v5/critmonitor.cmake index 4ce1743d47..199f59be2a 100644 --- a/boards/px4/fmu-v5/critmonitor.cmake +++ b/boards/px4/fmu-v5/critmonitor.cmake @@ -46,7 +46,7 @@ px4_add_board( #protocol_splitter pwm_input pwm_out_sim - px4fmu + pwm_out px4io rc_input roboclaw diff --git a/boards/px4/fmu-v5/default.cmake b/boards/px4/fmu-v5/default.cmake index fc49507669..f462445ff2 100644 --- a/boards/px4/fmu-v5/default.cmake +++ b/boards/px4/fmu-v5/default.cmake @@ -48,7 +48,7 @@ px4_add_board( #protocol_splitter pwm_input pwm_out_sim - px4fmu + pwm_out px4io rc_input roboclaw diff --git a/boards/px4/fmu-v5/fixedwing.cmake b/boards/px4/fmu-v5/fixedwing.cmake index 75da10aa68..ac309b82c4 100644 --- a/boards/px4/fmu-v5/fixedwing.cmake +++ b/boards/px4/fmu-v5/fixedwing.cmake @@ -35,7 +35,7 @@ px4_add_board( magnetometer # all available magnetometer drivers pwm_input pwm_out_sim - px4fmu + pwm_out px4io rc_input safety_button diff --git a/boards/px4/fmu-v5/irqmonitor.cmake b/boards/px4/fmu-v5/irqmonitor.cmake index 986a875505..f7e031736c 100644 --- a/boards/px4/fmu-v5/irqmonitor.cmake +++ b/boards/px4/fmu-v5/irqmonitor.cmake @@ -46,7 +46,7 @@ px4_add_board( #protocol_splitter pwm_input pwm_out_sim - px4fmu + pwm_out px4io rc_input roboclaw diff --git a/boards/px4/fmu-v5/multicopter.cmake b/boards/px4/fmu-v5/multicopter.cmake index 1f9febb998..02de57b66c 100644 --- a/boards/px4/fmu-v5/multicopter.cmake +++ b/boards/px4/fmu-v5/multicopter.cmake @@ -39,7 +39,7 @@ px4_add_board( optical_flow # all available optical flow drivers pwm_input pwm_out_sim - px4fmu + pwm_out px4io rc_input roboclaw diff --git a/boards/px4/fmu-v5/optimized.cmake b/boards/px4/fmu-v5/optimized.cmake index 92ce6b5435..22bc269221 100644 --- a/boards/px4/fmu-v5/optimized.cmake +++ b/boards/px4/fmu-v5/optimized.cmake @@ -43,7 +43,7 @@ px4_add_board( optical_flow # all available optical flow drivers #pwm_input pwm_out_sim - px4fmu + pwm_out px4io rc_input #roboclaw diff --git a/boards/px4/fmu-v5/rover.cmake b/boards/px4/fmu-v5/rover.cmake index f7389fe63c..1c25c9a0d8 100644 --- a/boards/px4/fmu-v5/rover.cmake +++ b/boards/px4/fmu-v5/rover.cmake @@ -36,7 +36,7 @@ px4_add_board( pca9685 pwm_input pwm_out_sim - px4fmu + pwm_out px4io rc_input roboclaw diff --git a/boards/px4/fmu-v5/rtps.cmake b/boards/px4/fmu-v5/rtps.cmake index db21de11b3..f0ae7d2368 100644 --- a/boards/px4/fmu-v5/rtps.cmake +++ b/boards/px4/fmu-v5/rtps.cmake @@ -46,7 +46,7 @@ px4_add_board( protocol_splitter pwm_input pwm_out_sim - px4fmu + pwm_out px4io rc_input roboclaw diff --git a/boards/px4/fmu-v5/stackcheck.cmake b/boards/px4/fmu-v5/stackcheck.cmake index c78a7fe4ab..b86ff4d42a 100644 --- a/boards/px4/fmu-v5/stackcheck.cmake +++ b/boards/px4/fmu-v5/stackcheck.cmake @@ -47,7 +47,7 @@ px4_add_board( #protocol_splitter pwm_input pwm_out_sim - px4fmu + pwm_out px4io rc_input #roboclaw diff --git a/boards/px4/fmu-v5x/default.cmake b/boards/px4/fmu-v5x/default.cmake index 1ce6bb2c59..fe5d7b16b2 100644 --- a/boards/px4/fmu-v5x/default.cmake +++ b/boards/px4/fmu-v5x/default.cmake @@ -47,7 +47,7 @@ px4_add_board( #protocol_splitter pwm_input pwm_out_sim - px4fmu + pwm_out px4io rc_input roboclaw diff --git a/boards/px4/fmu-v5x/p2_base_phy_LAN8742Ai.cmake b/boards/px4/fmu-v5x/p2_base_phy_LAN8742Ai.cmake index 25ce33cc0e..04f093581a 100644 --- a/boards/px4/fmu-v5x/p2_base_phy_LAN8742Ai.cmake +++ b/boards/px4/fmu-v5x/p2_base_phy_LAN8742Ai.cmake @@ -47,7 +47,7 @@ px4_add_board( #protocol_splitter pwm_input pwm_out_sim - px4fmu + pwm_out px4io rc_input roboclaw diff --git a/boards/uvify/core/default.cmake b/boards/uvify/core/default.cmake index 448d0f0e7c..495de91816 100644 --- a/boards/uvify/core/default.cmake +++ b/boards/uvify/core/default.cmake @@ -33,7 +33,7 @@ px4_add_board( pca9685 pwm_input pwm_out_sim - px4fmu + pwm_out rc_input tone_alarm uavcan diff --git a/cmake/px4_add_board.cmake b/cmake/px4_add_board.cmake index e658e15479..d385ca8903 100644 --- a/cmake/px4_add_board.cmake +++ b/cmake/px4_add_board.cmake @@ -102,7 +102,7 @@ # imu/bmi055 # imu/mpu6000 # magnetometer/ist8310 -# px4fmu +# pwm_out # px4io # rgbled # MODULES diff --git a/src/drivers/px4fmu/CMakeLists.txt b/src/drivers/pwm_out/CMakeLists.txt similarity index 92% rename from src/drivers/px4fmu/CMakeLists.txt rename to src/drivers/pwm_out/CMakeLists.txt index f3854322cc..017865fdb4 100644 --- a/src/drivers/px4fmu/CMakeLists.txt +++ b/src/drivers/pwm_out/CMakeLists.txt @@ -1,6 +1,6 @@ ############################################################################ # -# Copyright (c) 2015 PX4 Development Team. All rights reserved. +# Copyright (c) 2015-2020 PX4 Development Team. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -31,11 +31,12 @@ # ############################################################################ px4_add_module( - MODULE drivers__px4fmu - MAIN fmu + MODULE drivers__pwm_out + MAIN pwm_out COMPILE_FLAGS SRCS - fmu.cpp + PWMOut.cpp + PWMOut.hpp DEPENDS arch_io_pins mixer diff --git a/src/drivers/px4fmu/fmu.cpp b/src/drivers/pwm_out/PWMOut.cpp similarity index 86% rename from src/drivers/px4fmu/fmu.cpp rename to src/drivers/pwm_out/PWMOut.cpp index 866962772b..83d6e118ef 100644 --- a/src/drivers/px4fmu/fmu.cpp +++ b/src/drivers/pwm_out/PWMOut.cpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (c) 2012-2019 PX4 Development Team. All rights reserved. + * Copyright (c) 2012-2020 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,184 +31,9 @@ * ****************************************************************************/ -/** - * @file fmu.cpp - * - * Driver/configurator for the PX4 FMU - */ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace time_literals; - -/** Mode given via CLI */ -enum PortMode { - PORT_MODE_UNSET = 0, - PORT_FULL_GPIO, - PORT_FULL_PWM, - PORT_PWM8, - PORT_PWM6, - PORT_PWM5, - PORT_PWM4, - PORT_PWM3, - PORT_PWM2, - PORT_PWM1, - PORT_PWM3CAP1, - PORT_PWM4CAP1, - PORT_PWM4CAP2, - PORT_PWM5CAP1, - PORT_PWM2CAP2, - PORT_CAPTURE, -}; - -#if !defined(BOARD_HAS_PWM) -# error "board_config.h needs to define BOARD_HAS_PWM" -#endif - -#define PX4FMU_DEVICE_PATH "/dev/px4fmu" - - -class PX4FMU : public cdev::CDev, public ModuleBase, public OutputModuleInterface -{ -public: - enum Mode { - MODE_NONE, - MODE_1PWM, - MODE_2PWM, - MODE_2PWM2CAP, - MODE_3PWM, - MODE_3PWM1CAP, - MODE_4PWM, - MODE_4PWM1CAP, - MODE_4PWM2CAP, - MODE_5PWM, - MODE_5PWM1CAP, - MODE_6PWM, - MODE_8PWM, - MODE_14PWM, - MODE_4CAP, - MODE_5CAP, - MODE_6CAP, - }; - PX4FMU(); - virtual ~PX4FMU(); - - /** @see ModuleBase */ - static int task_spawn(int argc, char *argv[]); - - /** @see ModuleBase */ - static int custom_command(int argc, char *argv[]); - - /** @see ModuleBase */ - static int print_usage(const char *reason = nullptr); - - void Run() override; - - /** @see ModuleBase::print_status() */ - int print_status() override; - - /** change the FMU mode of the running module */ - static int fmu_new_mode(PortMode new_mode); - - static int test(); - - static int fake(int argc, char *argv[]); - - virtual int ioctl(file *filp, int cmd, unsigned long arg); - - virtual int init(); - - int set_mode(Mode mode); - Mode get_mode() { return _mode; } - - static int set_i2c_bus_clock(unsigned bus, unsigned clock_hz); - - static void capture_trampoline(void *context, uint32_t chan_index, - hrt_abstime edge_time, uint32_t edge_state, - uint32_t overflow); +#include "PWMOut.hpp" - void update_pwm_trims(); - - bool updateOutputs(bool stop_motors, uint16_t outputs[MAX_ACTUATORS], - unsigned num_outputs, unsigned num_control_groups_updated) override; - -private: - static constexpr int FMU_MAX_ACTUATORS = DIRECT_PWM_OUTPUT_CHANNELS; - static_assert(FMU_MAX_ACTUATORS <= MAX_ACTUATORS, "Increase MAX_ACTUATORS if this fails"); - - MixingOutput _mixing_output{FMU_MAX_ACTUATORS, *this, MixingOutput::SchedulingPolicy::Auto, true}; - - Mode _mode{MODE_NONE}; - - unsigned _pwm_default_rate{50}; - unsigned _pwm_alt_rate{50}; - uint32_t _pwm_alt_rate_channels{0}; - - unsigned _current_update_rate{0}; - - uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)}; - - - unsigned _num_outputs{0}; - int _class_instance{-1}; - - bool _pwm_on{false}; - uint32_t _pwm_mask{0}; - bool _pwm_initialized{false}; - bool _test_mode{false}; - - unsigned _num_disarmed_set{0}; - - perf_counter_t _cycle_perf; - - void capture_callback(uint32_t chan_index, - hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow); - void update_current_rate(); - int set_pwm_rate(unsigned rate_map, unsigned default_rate, unsigned alt_rate); - int pwm_ioctl(file *filp, int cmd, unsigned long arg); - void update_pwm_rev_mask(); - void update_pwm_out_state(bool on); - - void update_params(); - - static void sensor_reset(int ms); - static void peripheral_reset(int ms); - - int capture_ioctl(file *filp, int cmd, unsigned long arg); - - PX4FMU(const PX4FMU &) = delete; - PX4FMU operator=(const PX4FMU &) = delete; - -}; - -PX4FMU::PX4FMU() : +PWMOut::PWMOut() : CDev(PX4FMU_DEVICE_PATH), OutputModuleInterface(MODULE_NAME, px4::wq_configurations::hp_default), _cycle_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": cycle")) @@ -218,7 +43,7 @@ PX4FMU::PX4FMU() : } -PX4FMU::~PX4FMU() +PWMOut::~PWMOut() { /* make sure servos are off */ up_pwm_servo_deinit(); @@ -229,8 +54,7 @@ PX4FMU::~PX4FMU() perf_free(_cycle_perf); } -int -PX4FMU::init() +int PWMOut::init() { /* do regular cdev init */ int ret = CDev::init(); @@ -263,8 +87,7 @@ PX4FMU::init() return 0; } -int -PX4FMU::set_mode(Mode mode) +int PWMOut::set_mode(Mode mode) { unsigned old_mask = _pwm_mask; @@ -489,8 +312,7 @@ PX4FMU::set_mode(Mode mode) * For Oneshot there is no rate, 0 is therefore used * to select Oneshot mode */ -int -PX4FMU::set_pwm_rate(uint32_t rate_map, unsigned default_rate, unsigned alt_rate) +int PWMOut::set_pwm_rate(uint32_t rate_map, unsigned default_rate, unsigned alt_rate) { PX4_DEBUG("set_pwm_rate %x %u %u", rate_map, default_rate, alt_rate); @@ -557,14 +379,12 @@ PX4FMU::set_pwm_rate(uint32_t rate_map, unsigned default_rate, unsigned alt_rate return OK; } -int -PX4FMU::set_i2c_bus_clock(unsigned bus, unsigned clock_hz) +int PWMOut::set_i2c_bus_clock(unsigned bus, unsigned clock_hz) { return device::I2C::set_bus_clock(bus, clock_hz); } -void -PX4FMU::update_current_rate() +void PWMOut::update_current_rate() { /* * Adjust actuator topic update rate to keep up with @@ -586,8 +406,7 @@ PX4FMU::update_current_rate() _mixing_output.setMaxTopicUpdateRate(update_interval_in_us); } -void -PX4FMU::update_pwm_rev_mask() +void PWMOut::update_pwm_rev_mask() { uint16_t &reverse_pwm_mask = _mixing_output.reverseOutputMask(); reverse_pwm_mask = 0; @@ -620,8 +439,7 @@ PX4FMU::update_pwm_rev_mask() } } -void -PX4FMU::update_pwm_trims() +void PWMOut::update_pwm_trims() { PX4_DEBUG("update_pwm_trims"); @@ -664,10 +482,9 @@ PX4FMU::update_pwm_trims() PX4_DEBUG("set %d trims", n_out); } -int -PX4FMU::task_spawn(int argc, char *argv[]) +int PWMOut::task_spawn(int argc, char *argv[]) { - PX4FMU *instance = new PX4FMU(); + PWMOut *instance = new PWMOut(); if (instance) { _object.store(instance); @@ -688,23 +505,20 @@ PX4FMU::task_spawn(int argc, char *argv[]) return PX4_ERROR; } -void -PX4FMU::capture_trampoline(void *context, uint32_t chan_index, - hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow) +void PWMOut::capture_trampoline(void *context, uint32_t chan_index, + hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow) { - PX4FMU *dev = static_cast(context); + PWMOut *dev = static_cast(context); dev->capture_callback(chan_index, edge_time, edge_state, overflow); } -void -PX4FMU::capture_callback(uint32_t chan_index, - hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow) +void PWMOut::capture_callback(uint32_t chan_index, + hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow) { fprintf(stdout, "FMU: Capture chan:%d time:%lld state:%d overflow:%d\n", chan_index, edge_time, edge_state, overflow); } -void -PX4FMU::update_pwm_out_state(bool on) +void PWMOut::update_pwm_out_state(bool on) { if (on && !_pwm_initialized && _pwm_mask != 0) { up_pwm_servo_init(_pwm_mask); @@ -715,8 +529,7 @@ PX4FMU::update_pwm_out_state(bool on) up_pwm_servo_arm(on); } - -bool PX4FMU::updateOutputs(bool stop_motors, uint16_t outputs[MAX_ACTUATORS], +bool PWMOut::updateOutputs(bool stop_motors, uint16_t outputs[MAX_ACTUATORS], unsigned num_outputs, unsigned num_control_groups_updated) { if (_test_mode) { @@ -740,8 +553,7 @@ bool PX4FMU::updateOutputs(bool stop_motors, uint16_t outputs[MAX_ACTUATORS], return true; } -void -PX4FMU::Run() +void PWMOut::Run() { if (should_exit()) { ScheduleClear(); @@ -783,7 +595,7 @@ PX4FMU::Run() perf_end(_cycle_perf); } -void PX4FMU::update_params() +void PWMOut::update_params() { update_pwm_rev_mask(); update_pwm_trims(); @@ -791,8 +603,7 @@ void PX4FMU::update_params() updateParams(); } -int -PX4FMU::ioctl(file *filp, int cmd, unsigned long arg) +int PWMOut::ioctl(file *filp, int cmd, unsigned long arg) { int ret; @@ -840,12 +651,11 @@ PX4FMU::ioctl(file *filp, int cmd, unsigned long arg) return ret; } -int -PX4FMU::pwm_ioctl(file *filp, int cmd, unsigned long arg) +int PWMOut::pwm_ioctl(file *filp, int cmd, unsigned long arg) { int ret = OK; - PX4_DEBUG("fmu ioctl cmd: %d, arg: %ld", cmd, arg); + PX4_DEBUG("ioctl cmd: %d, arg: %ld", cmd, arg); lock(); @@ -1490,8 +1300,7 @@ PX4FMU::pwm_ioctl(file *filp, int cmd, unsigned long arg) return ret; } -void -PX4FMU::sensor_reset(int ms) +void PWMOut::sensor_reset(int ms) { if (ms < 1) { ms = 1; @@ -1500,8 +1309,7 @@ PX4FMU::sensor_reset(int ms) board_spi_reset(ms, 0xffff); } -void -PX4FMU::peripheral_reset(int ms) +void PWMOut::peripheral_reset(int ms) { if (ms < 1) { ms = 10; @@ -1510,8 +1318,7 @@ PX4FMU::peripheral_reset(int ms) board_peripheral_reset(ms); } -int -PX4FMU::capture_ioctl(struct file *filp, int cmd, unsigned long arg) +int PWMOut::capture_ioctl(struct file *filp, int cmd, unsigned long arg) { int ret = -EINVAL; @@ -1662,16 +1469,15 @@ PX4FMU::capture_ioctl(struct file *filp, int cmd, unsigned long arg) return ret; } -int -PX4FMU::fmu_new_mode(PortMode new_mode) +int PWMOut::fmu_new_mode(PortMode new_mode) { if (!is_running()) { return -1; } - PX4FMU::Mode servo_mode; + PWMOut::Mode servo_mode; - servo_mode = PX4FMU::MODE_NONE; + servo_mode = PWMOut::MODE_NONE; switch (new_mode) { case PORT_FULL_GPIO: @@ -1682,44 +1488,44 @@ PX4FMU::fmu_new_mode(PortMode new_mode) #if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM == 4 /* select 4-pin PWM mode */ - servo_mode = PX4FMU::MODE_4PWM; + servo_mode = PWMOut::MODE_4PWM; #endif #if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM == 5 - servo_mode = PX4FMU::MODE_5PWM; + servo_mode = PWMOut::MODE_5PWM; #endif #if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM == 6 - servo_mode = PX4FMU::MODE_6PWM; + servo_mode = PWMOut::MODE_6PWM; #endif #if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM == 8 - servo_mode = PX4FMU::MODE_8PWM; + servo_mode = PWMOut::MODE_8PWM; #endif #if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM == 14 - servo_mode = PX4FMU::MODE_14PWM; + servo_mode = PWMOut::MODE_14PWM; #endif break; case PORT_PWM1: /* select 2-pin PWM mode */ - servo_mode = PX4FMU::MODE_1PWM; + servo_mode = PWMOut::MODE_1PWM; break; #if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM >= 8 case PORT_PWM8: /* select 8-pin PWM mode */ - servo_mode = PX4FMU::MODE_8PWM; + servo_mode = PWMOut::MODE_8PWM; break; #endif #if defined(BOARD_HAS_PWM) && BOARD_HAS_PWM >= 6 case PORT_PWM6: /* select 6-pin PWM mode */ - servo_mode = PX4FMU::MODE_6PWM; + servo_mode = PWMOut::MODE_6PWM; break; case PORT_PWM5: /* select 5-pin PWM mode */ - servo_mode = PX4FMU::MODE_5PWM; + servo_mode = PWMOut::MODE_5PWM; break; @@ -1727,14 +1533,14 @@ PX4FMU::fmu_new_mode(PortMode new_mode) case PORT_PWM5CAP1: /* select 5-pin PWM mode 1 capture */ - servo_mode = PX4FMU::MODE_5PWM1CAP; + servo_mode = PWMOut::MODE_5PWM1CAP; break; # endif case PORT_PWM4: /* select 4-pin PWM mode */ - servo_mode = PX4FMU::MODE_4PWM; + servo_mode = PWMOut::MODE_4PWM; break; @@ -1742,39 +1548,39 @@ PX4FMU::fmu_new_mode(PortMode new_mode) case PORT_PWM4CAP1: /* select 4-pin PWM mode 1 capture */ - servo_mode = PX4FMU::MODE_4PWM1CAP; + servo_mode = PWMOut::MODE_4PWM1CAP; break; case PORT_PWM4CAP2: /* select 4-pin PWM mode 2 capture */ - servo_mode = PX4FMU::MODE_4PWM2CAP; + servo_mode = PWMOut::MODE_4PWM2CAP; break; # endif case PORT_PWM3: /* select 3-pin PWM mode */ - servo_mode = PX4FMU::MODE_3PWM; + servo_mode = PWMOut::MODE_3PWM; break; # if defined(BOARD_HAS_CAPTURE) case PORT_PWM3CAP1: /* select 3-pin PWM mode 1 capture */ - servo_mode = PX4FMU::MODE_3PWM1CAP; + servo_mode = PWMOut::MODE_3PWM1CAP; break; # endif case PORT_PWM2: /* select 2-pin PWM mode */ - servo_mode = PX4FMU::MODE_2PWM; + servo_mode = PWMOut::MODE_2PWM; break; # if defined(BOARD_HAS_CAPTURE) case PORT_PWM2CAP2: /* select 2-pin PWM mode 2 capture */ - servo_mode = PX4FMU::MODE_2PWM2CAP; + servo_mode = PWMOut::MODE_2PWM2CAP; break; # endif @@ -1784,7 +1590,7 @@ PX4FMU::fmu_new_mode(PortMode new_mode) return -1; } - PX4FMU *object = get_instance(); + PWMOut *object = get_instance(); if (servo_mode != object->get_mode()) { /* (re)set the PWM output mode */ @@ -1800,13 +1606,12 @@ namespace int fmu_new_i2c_speed(unsigned bus, unsigned clock_hz) { - return PX4FMU::set_i2c_bus_clock(bus, clock_hz); + return PWMOut::set_i2c_bus_clock(bus, clock_hz); } } // namespace -int -PX4FMU::test() +int PWMOut::test() { int fd; unsigned servo_count = 0; @@ -1862,8 +1667,8 @@ PX4FMU::test() } else { input_capture_config_t conf = capture_conf[i].chan; - conf.callback = &PX4FMU::capture_trampoline; - conf.context = PX4FMU::get_instance(); + conf.callback = &PWMOut::capture_trampoline; + conf.context = PWMOut::get_instance(); if (::ioctl(fd, INPUT_CAP_SET_CALLBACK, (unsigned long)&conf) == 0) { capture_conf[i].valid = true; @@ -1997,8 +1802,7 @@ err_out_no_test: return rv; } -int -PX4FMU::fake(int argc, char *argv[]) +int PWMOut::fake(int argc, char *argv[]) { if (argc < 5) { print_usage("not enough arguments"); @@ -2040,7 +1844,7 @@ PX4FMU::fake(int argc, char *argv[]) return 0; } -int PX4FMU::custom_command(int argc, char *argv[]) +int PWMOut::custom_command(int argc, char *argv[]) { PortMode new_mode = PORT_MODE_UNSET; const char *verb = argv[0]; @@ -2091,7 +1895,7 @@ int PX4FMU::custom_command(int argc, char *argv[]) /* start the FMU if not running */ if (!is_running()) { - int ret = PX4FMU::task_spawn(argc, argv); + int ret = PWMOut::task_spawn(argc, argv); if (ret) { return ret; @@ -2172,7 +1976,7 @@ int PX4FMU::custom_command(int argc, char *argv[]) if (new_mode != PORT_MODE_UNSET) { /* switch modes */ - return PX4FMU::fmu_new_mode(new_mode); + return PWMOut::fmu_new_mode(new_mode); } if (!strcmp(verb, "test")) { @@ -2186,7 +1990,7 @@ int PX4FMU::custom_command(int argc, char *argv[]) return print_usage("unknown command"); } -int PX4FMU::print_status() +int PWMOut::print_status() { PX4_INFO("Max update rate: %i Hz", _current_update_rate); @@ -2239,7 +2043,7 @@ int PX4FMU::print_status() return 0; } -int PX4FMU::print_usage(const char *reason) +int PWMOut::print_usage(const char *reason) { if (reason) { PX4_WARN("%s\n", reason); @@ -2256,7 +2060,7 @@ It listens on the actuator_controls topics, does the mixing and writes the PWM o The module is configured via mode_* commands. This defines which of the first N pins the driver should occupy. By using mode_pwm4 for example, pins 5 and 6 can be used by the camera trigger driver or by a PWM rangefinder -driver. Alternatively, the fmu can be started in one of the capture modes, and then drivers can register a capture +driver. Alternatively, pwm_out can be started in one of the capture modes, and then drivers can register a capture callback with ioctl calls. ### Implementation @@ -2264,22 +2068,22 @@ By default the module runs on a work queue with a callback on the uORB actuator_ ### Examples It is typically started with: -$ fmu mode_pwm +$ pwm_out mode_pwm To drive all available pins. -Capture input (rising and falling edges) and print on the console: start the fmu in one of the capture modes: -$ fmu mode_pwm3cap1 +Capture input (rising and falling edges) and print on the console: start pwm_out in one of the capture modes: +$ pwm_out mode_pwm3cap1 This will enable capturing on the 4th pin. Then do: -$ fmu test +$ pwm_out test Use the `pwm` command for further configurations (PWM rate, levels, ...), and the `mixer` command to load mixer files. )DESCR_STR"); - PRINT_MODULE_USAGE_NAME("fmu", "driver"); + PRINT_MODULE_USAGE_NAME("pwm_out", "driver"); PRINT_MODULE_USAGE_COMMAND_DESCR("start", "Start the task (without any mode set, use any of the mode_* cmds)"); - PRINT_MODULE_USAGE_PARAM_COMMENT("All of the mode_* commands will start the fmu if not running already"); + PRINT_MODULE_USAGE_PARAM_COMMENT("All of the mode_* commands will start pwm_out if not running already"); PRINT_MODULE_USAGE_COMMAND("mode_gpio"); PRINT_MODULE_USAGE_COMMAND_DESCR("mode_pwm", "Select all available pins as PWM"); @@ -2318,7 +2122,7 @@ mixer files. return 0; } -extern "C" __EXPORT int fmu_main(int argc, char *argv[]) +extern "C" __EXPORT int pwm_out_main(int argc, char *argv[]) { - return PX4FMU::main(argc, argv); + return PWMOut::main(argc, argv); } diff --git a/src/drivers/pwm_out/PWMOut.hpp b/src/drivers/pwm_out/PWMOut.hpp new file mode 100644 index 0000000000..14817035fa --- /dev/null +++ b/src/drivers/pwm_out/PWMOut.hpp @@ -0,0 +1,205 @@ +/**************************************************************************** + * + * Copyright (c) 2012-2020 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * 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 + * 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 + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#pragma once + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace time_literals; + +/** Mode given via CLI */ +enum PortMode { + PORT_MODE_UNSET = 0, + PORT_FULL_GPIO, + PORT_FULL_PWM, + PORT_PWM8, + PORT_PWM6, + PORT_PWM5, + PORT_PWM4, + PORT_PWM3, + PORT_PWM2, + PORT_PWM1, + PORT_PWM3CAP1, + PORT_PWM4CAP1, + PORT_PWM4CAP2, + PORT_PWM5CAP1, + PORT_PWM2CAP2, + PORT_CAPTURE, +}; + +#if !defined(BOARD_HAS_PWM) +# error "board_config.h needs to define BOARD_HAS_PWM" +#endif + +// TODO: keep in sync with drivers/camera_capture +#define PX4FMU_DEVICE_PATH "/dev/px4fmu" + +class PWMOut : public cdev::CDev, public ModuleBase, public OutputModuleInterface +{ +public: + enum Mode { + MODE_NONE, + MODE_1PWM, + MODE_2PWM, + MODE_2PWM2CAP, + MODE_3PWM, + MODE_3PWM1CAP, + MODE_4PWM, + MODE_4PWM1CAP, + MODE_4PWM2CAP, + MODE_5PWM, + MODE_5PWM1CAP, + MODE_6PWM, + MODE_8PWM, + MODE_14PWM, + MODE_4CAP, + MODE_5CAP, + MODE_6CAP, + }; + PWMOut(); + virtual ~PWMOut(); + + /** @see ModuleBase */ + static int task_spawn(int argc, char *argv[]); + + /** @see ModuleBase */ + static int custom_command(int argc, char *argv[]); + + /** @see ModuleBase */ + static int print_usage(const char *reason = nullptr); + + void Run() override; + + /** @see ModuleBase::print_status() */ + int print_status() override; + + /** change the FMU mode of the running module */ + static int fmu_new_mode(PortMode new_mode); + + static int test(); + + static int fake(int argc, char *argv[]); + + virtual int ioctl(file *filp, int cmd, unsigned long arg); + + virtual int init(); + + int set_mode(Mode mode); + Mode get_mode() { return _mode; } + + static int set_i2c_bus_clock(unsigned bus, unsigned clock_hz); + + static void capture_trampoline(void *context, uint32_t chan_index, + hrt_abstime edge_time, uint32_t edge_state, + uint32_t overflow); + + void update_pwm_trims(); + + bool updateOutputs(bool stop_motors, uint16_t outputs[MAX_ACTUATORS], + unsigned num_outputs, unsigned num_control_groups_updated) override; + +private: + static constexpr int FMU_MAX_ACTUATORS = DIRECT_PWM_OUTPUT_CHANNELS; + static_assert(FMU_MAX_ACTUATORS <= MAX_ACTUATORS, "Increase MAX_ACTUATORS if this fails"); + + MixingOutput _mixing_output{FMU_MAX_ACTUATORS, *this, MixingOutput::SchedulingPolicy::Auto, true}; + + Mode _mode{MODE_NONE}; + + unsigned _pwm_default_rate{50}; + unsigned _pwm_alt_rate{50}; + uint32_t _pwm_alt_rate_channels{0}; + + unsigned _current_update_rate{0}; + + uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)}; + + + unsigned _num_outputs{0}; + int _class_instance{-1}; + + bool _pwm_on{false}; + uint32_t _pwm_mask{0}; + bool _pwm_initialized{false}; + bool _test_mode{false}; + + unsigned _num_disarmed_set{0}; + + perf_counter_t _cycle_perf; + + void capture_callback(uint32_t chan_index, + hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow); + void update_current_rate(); + int set_pwm_rate(unsigned rate_map, unsigned default_rate, unsigned alt_rate); + int pwm_ioctl(file *filp, int cmd, unsigned long arg); + void update_pwm_rev_mask(); + void update_pwm_out_state(bool on); + + void update_params(); + + static void sensor_reset(int ms); + static void peripheral_reset(int ms); + + int capture_ioctl(file *filp, int cmd, unsigned long arg); + + PWMOut(const PWMOut &) = delete; + PWMOut operator=(const PWMOut &) = delete; + +};