FurHal: synchronise subghz hal between targets. (#904)

* furi-hal-subghz: target fixes
* FuriHal: remove unused include from subghz

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
gornekich 2021-12-15 20:58:42 +03:00 committed by GitHub
parent f0d4584b40
commit 757ea073a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 6 deletions

View File

@ -808,6 +808,8 @@ typedef struct {
bool flip_flop; bool flip_flop;
FuriHalSubGhzAsyncTxCallback callback; FuriHalSubGhzAsyncTxCallback callback;
void* callback_context; void* callback_context;
uint64_t duty_high;
uint64_t duty_low;
} FuriHalSubGhzAsyncTx; } FuriHalSubGhzAsyncTx;
static FuriHalSubGhzAsyncTx furi_hal_subghz_async_tx = {0}; static FuriHalSubGhzAsyncTx furi_hal_subghz_async_tx = {0};
@ -817,21 +819,30 @@ static void furi_hal_subghz_async_tx_refill(uint32_t* buffer, size_t samples) {
bool is_odd = samples % 2; bool is_odd = samples % 2;
LevelDuration ld = LevelDuration ld =
furi_hal_subghz_async_tx.callback(furi_hal_subghz_async_tx.callback_context); furi_hal_subghz_async_tx.callback(furi_hal_subghz_async_tx.callback_context);
if(level_duration_is_wait(ld)) return;
if(level_duration_is_reset(ld)) { if(level_duration_is_wait(ld)) {
return;
} else if(level_duration_is_reset(ld)) {
// One more even sample required to end at low level // One more even sample required to end at low level
if(is_odd) { if(is_odd) {
*buffer = API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME; *buffer = API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME;
buffer++; buffer++;
samples--; samples--;
furi_hal_subghz_async_tx.duty_low += API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME;
} }
break; break;
} else { } else {
// Inject guard time if level is incorrect // Inject guard time if level is incorrect
if(is_odd == level_duration_get_level(ld)) { bool level = level_duration_get_level(ld);
if(is_odd == level) {
*buffer = API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME; *buffer = API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME;
buffer++; buffer++;
samples--; samples--;
if (!level) {
furi_hal_subghz_async_tx.duty_high += API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME;
} else {
furi_hal_subghz_async_tx.duty_low += API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME;
}
} }
uint32_t duration = level_duration_get_duration(ld); uint32_t duration = level_duration_get_duration(ld);
@ -839,6 +850,12 @@ static void furi_hal_subghz_async_tx_refill(uint32_t* buffer, size_t samples) {
*buffer = duration; *buffer = duration;
buffer++; buffer++;
samples--; samples--;
if (level) {
furi_hal_subghz_async_tx.duty_high += duration;
} else {
furi_hal_subghz_async_tx.duty_low += duration;
}
} }
} }
@ -888,6 +905,9 @@ bool furi_hal_subghz_start_async_tx(FuriHalSubGhzAsyncTxCallback callback, void*
furi_hal_subghz_state = SubGhzStateAsyncTx; furi_hal_subghz_state = SubGhzStateAsyncTx;
furi_hal_subghz_async_tx.duty_low = 0;
furi_hal_subghz_async_tx.duty_high = 0;
furi_hal_subghz_async_tx.buffer = furi_hal_subghz_async_tx.buffer =
furi_alloc(API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL * sizeof(uint32_t)); furi_alloc(API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL * sizeof(uint32_t));
furi_hal_subghz_async_tx_refill( furi_hal_subghz_async_tx_refill(
@ -994,5 +1014,8 @@ void furi_hal_subghz_stop_async_tx() {
free(furi_hal_subghz_async_tx.buffer); free(furi_hal_subghz_async_tx.buffer);
float duty_cycle = 100.0f * (float)furi_hal_subghz_async_tx.duty_high / ((float)furi_hal_subghz_async_tx.duty_low + (float)furi_hal_subghz_async_tx.duty_high);
FURI_LOG_D(TAG, "Async TX Radio stats: on %0.0fus, off %0.0fus, DutyCycle: %0.0f%%", (float)furi_hal_subghz_async_tx.duty_high, (float)furi_hal_subghz_async_tx.duty_low, duty_cycle);
furi_hal_subghz_state = SubGhzStateIdle; furi_hal_subghz_state = SubGhzStateIdle;
} }

View File

@ -10,9 +10,6 @@
#include <cc1101.h> #include <cc1101.h>
#include <stdio.h> #include <stdio.h>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#define TAG "FuriHalSubGhz" #define TAG "FuriHalSubGhz"
static volatile SubGhzState furi_hal_subghz_state = SubGhzStateInit; static volatile SubGhzState furi_hal_subghz_state = SubGhzStateInit;