From 3d42e06d8af546338759e5cb31638d7adc3c977c Mon Sep 17 00:00:00 2001 From: Mathias Rasmussen Date: Tue, 24 Nov 2020 02:26:09 +0100 Subject: [PATCH] refactor: Move DShot decode macro to main file --- Bluejay.asm | 30 ++++++++++++++++++++++++++++++ Common.inc | 30 ------------------------------ 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Bluejay.asm b/Bluejay.asm index 1cfe9e6..3377361 100644 --- a/Bluejay.asm +++ b/Bluejay.asm @@ -388,6 +388,36 @@ IF MCU_48MHZ < 2 AND PWM_FREQ < 3 PWM_BITS_H EQU (2 + MCU_48MHZ - PWM_CENTERED - PWM_FREQ) ENDIF +Decode_DShot_2Bit MACRO dest, decode_fail + movx A, @Temp1 + mov Temp7, A + clr C + subb A, Temp6 ; Subtract previous timestamp + clr C + subb A, Temp2 + jc decode_fail ; Check that bit is longer than minimum + + subb A, Temp2 ; Check if bit is zero or one + mov A, dest ; Shift bit into data byte + rlc A + mov dest, A + inc Temp1 ; Next bit + + movx A, @Temp1 + mov Temp6, A + clr C + subb A, Temp7 + clr C + subb A, Temp2 + jc decode_fail + + subb A, Temp2 + mov A, dest + rlc A + mov dest, A + inc Temp1 +ENDM + ;**** **** **** **** **** Interrupt_Table_Definition ; SiLabs interrupts CSEG AT 80h ; Code segment after interrupt vectors diff --git a/Common.inc b/Common.inc index d4b8494..7393d75 100644 --- a/Common.inc +++ b/Common.inc @@ -154,36 +154,6 @@ CSEG AT 73h ; Timer3 overflow/compare interrupt jmp t3_int ENDM -Decode_DShot_2Bit MACRO dest, decode_fail - movx A, @Temp1 - mov Temp7, A - clr C - subb A, Temp6 ; Subtract previous timestamp - clr C - subb A, Temp2 - jc decode_fail ; Check that bit is longer than minimum - - subb A, Temp2 ; Check if bit is zero or one - mov A, dest ; Shift bit into data byte - rlc A - mov dest, A - inc Temp1 ; Next bit - - movx A, @Temp1 - mov Temp6, A - clr C - subb A, Temp7 - clr C - subb A, Temp2 - jc decode_fail - - subb A, Temp2 - mov A, dest - rlc A - mov dest, A - inc Temp1 -ENDM - Initialize_PCA MACRO mov PCA0CN0, #40h ; PCA enabled mov PCA0MD, #08h ; PCA clock is system clock