Skip to content

Commit

Permalink
Add ENUM for DSHOT commands (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
stylesuxx authored Jun 15, 2023
1 parent 2f58078 commit 0b286d9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
18 changes: 9 additions & 9 deletions src/Modules/DShot.asm
Original file line number Diff line number Diff line change
Expand Up @@ -83,39 +83,39 @@ dshot_cmd_check_count:

dshot_cmd_direction_normal:
; Set motor spinning direction to normal
cjne Temp1, #7, dshot_cmd_direction_reverse
cjne Temp1, #CMD_DIRECTION_NORMAL, dshot_cmd_direction_reverse

clr Flag_Pgm_Dir_Rev

sjmp dshot_cmd_exit

dshot_cmd_direction_reverse:
; Set motor spinning direction to reversed
cjne Temp1, #8, dshot_cmd_direction_bidir_off
cjne Temp1, #CMD_DIRECTION_REVERSE, dshot_cmd_direction_bidir_off

setb Flag_Pgm_Dir_Rev

sjmp dshot_cmd_exit

dshot_cmd_direction_bidir_off:
; Set motor control mode to normal (not bidirectional)
cjne Temp1, #9, dshot_cmd_direction_bidir_on
cjne Temp1, #CMD_BIDIR_OFF, dshot_cmd_direction_bidir_on

clr Flag_Pgm_Bidir

sjmp dshot_cmd_exit

dshot_cmd_direction_bidir_on:
; Set motor control mode to bidirectional
cjne Temp1, #10, dshot_cmd_extended_telemetry_enable
cjne Temp1, #CMD_BIDIR_ON, dshot_cmd_extended_telemetry_enable

setb Flag_Pgm_Bidir

sjmp dshot_cmd_exit

dshot_cmd_extended_telemetry_enable:
; Enable extended telemetry
cjne Temp1, #13, dshot_cmd_extended_telemetry_disable
cjne Temp1, #CMD_EXTENDED_TELEMETRY_ENABLE, dshot_cmd_extended_telemetry_disable

mov Ext_Telemetry_L, #00h
mov Ext_Telemetry_H, #0Eh ; Send state/event 0 frame to signal telemetry enable
Expand All @@ -126,7 +126,7 @@ dshot_cmd_extended_telemetry_enable:

dshot_cmd_extended_telemetry_disable:
; Disable extended telemetry
cjne Temp1, #14, dshot_cmd_direction_user_normal
cjne Temp1, #CMD_EXTENDED_TELEMETRY_DISABLE, dshot_cmd_direction_user_normal

mov Ext_Telemetry_L, #0FFh
mov Ext_Telemetry_H, #0Eh ; Send state/event 0xff frame to signal telemetry disable
Expand All @@ -137,7 +137,7 @@ dshot_cmd_extended_telemetry_disable:

dshot_cmd_direction_user_normal:
; Set motor spinning direction to user programmed direction
cjne Temp1, #20, dshot_cmd_direction_user_reverse
cjne Temp1, #CMD_DIRECTION_USER_NORMAL, dshot_cmd_direction_user_reverse

mov Temp2, #Pgm_Direction ; Read programmed direction
mov A, @Temp2
Expand All @@ -152,7 +152,7 @@ dshot_cmd_direction_user_normal:

dshot_cmd_direction_user_reverse: ; Temporary reverse
; Set motor spinning direction to reverse of user programmed direction
cjne Temp1, #21, dshot_cmd_save_settings
cjne Temp1, #CMD_DIRECTION_USER_REVERSE, dshot_cmd_save_settings

mov Temp2, #Pgm_Direction ; Read programmed direction
mov A, @Temp2
Expand All @@ -167,7 +167,7 @@ dshot_cmd_direction_user_reverse: ; Temporary reverse
sjmp dshot_cmd_exit

dshot_cmd_save_settings:
cjne Temp1, #12, dshot_cmd_exit
cjne Temp1, #CMD_SAVE_SETTINGS, dshot_cmd_exit

clr A ; Set programmed direction from flags
mov C, Flag_Pgm_Dir_Rev
Expand Down
19 changes: 19 additions & 0 deletions src/Modules/Enums.asm
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,22 @@
PWM_10_BIT EQU 2
PWM_9_BIT EQU 1
PWM_8_BIT EQU 0

;**** **** **** **** **** **** **** **** **** **** **** **** ****
; DSHOT Commands
;**** **** **** **** **** **** **** **** **** **** **** **** ****
CMD_DIRECTION_USER_REVERSE EQU 21
CMD_DIRECTION_USER_NORMAL EQU 20
CMD_EXTENDED_TELEMETRY_DISABLE EQU 14
CMD_EXTENDED_TELEMETRY_ENABLE EQU 13
CMD_SAVE_SETTINGS EQU 12
CMD_BIDIR_ON EQU 10
CMD_BIDIR_OFF EQU 9
CMD_DIRECTION_REVERSE EQU 8
CMD_DIRECTION_NORMAL EQU 7
CMD_ESC_INFO EQU 6
CMD_BEEP_5 EQU 5
CMD_BEEP_4 EQU 4
CMD_BEEP_3 EQU 3
CMD_BEEP_2 EQU 2
CMD_BEEP_1 EQU 1
8 changes: 4 additions & 4 deletions src/Modules/Fx.asm
Original file line number Diff line number Diff line change
Expand Up @@ -220,22 +220,22 @@ beacon_beep:
mov Temp2, #Pgm_Beacon_Strength ; Set beacon beep strength
mov Beep_Strength, @Temp2

cjne Temp1, #1, beacon_beep2
cjne Temp1, #CMD_BEEP_1, beacon_beep2
call beep_f1
sjmp beacon_beep_exit

beacon_beep2:
cjne Temp1, #2, beacon_beep3
cjne Temp1, #CMD_BEEP_2, beacon_beep3
call beep_f2
sjmp beacon_beep_exit

beacon_beep3:
cjne Temp1, #3, beacon_beep4
cjne Temp1, #CMD_BEEP_3, beacon_beep4
call beep_f3
sjmp beacon_beep_exit

beacon_beep4:
cjne Temp1, #4, beacon_beep5
cjne Temp1, #CMD_BEEP_4, beacon_beep5
call beep_f4
sjmp beacon_beep_exit

Expand Down

0 comments on commit 0b286d9

Please sign in to comment.