mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-12 21:58:36 -07:00
Protoview: new ext_cc1101 driver
This commit is contained in:
64
applications/external/protoview/app_subghz.c
vendored
64
applications/external/protoview/app_subghz.c
vendored
@@ -37,22 +37,23 @@ ProtoViewModulation ProtoViewModulations[] = {
|
||||
* subghz system and put it into idle state. */
|
||||
void radio_begin(ProtoViewApp* app) {
|
||||
furi_assert(app);
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_idle();
|
||||
|
||||
/* Power circuits are noisy. Suppressing the charge while we use
|
||||
* ProtoView will improve the RF performances. */
|
||||
furi_hal_power_suppress_charge_enter();
|
||||
subghz_devices_reset(app->radio_device);
|
||||
subghz_devices_idle(app->radio_device);
|
||||
|
||||
/* The CC1101 preset can be either one of the standard presets, if
|
||||
* the modulation "custom" field is NULL, or a custom preset we
|
||||
* defined in custom_presets.h. */
|
||||
if(ProtoViewModulations[app->modulation].custom == NULL) {
|
||||
furi_hal_subghz_load_preset(ProtoViewModulations[app->modulation].preset);
|
||||
subghz_devices_load_preset(
|
||||
app->radio_device, ProtoViewModulations[app->modulation].preset, NULL);
|
||||
} else {
|
||||
furi_hal_subghz_load_custom_preset(ProtoViewModulations[app->modulation].custom);
|
||||
subghz_devices_load_preset(
|
||||
app->radio_device,
|
||||
FuriHalSubGhzPresetCustom,
|
||||
ProtoViewModulations[app->modulation].custom);
|
||||
}
|
||||
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_init(
|
||||
subghz_devices_get_data_gpio(app->radio_device), GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
app->txrx->txrx_state = TxRxStateIDLE;
|
||||
}
|
||||
|
||||
@@ -71,21 +72,28 @@ void protoview_rx_callback(bool level, uint32_t duration, void* context) {
|
||||
/* Setup the CC1101 to start receiving using a background worker. */
|
||||
uint32_t radio_rx(ProtoViewApp* app) {
|
||||
furi_assert(app);
|
||||
if(!furi_hal_subghz_is_frequency_valid(app->frequency)) {
|
||||
|
||||
if(!subghz_devices_is_frequency_valid(app->radio_device, app->frequency)) {
|
||||
furi_crash(TAG " Incorrect RX frequency.");
|
||||
}
|
||||
|
||||
if(app->txrx->txrx_state == TxRxStateRx) return app->frequency;
|
||||
|
||||
furi_hal_subghz_idle(); /* Put it into idle state in case it is sleeping. */
|
||||
uint32_t value = furi_hal_subghz_set_frequency_and_path(app->frequency);
|
||||
subghz_devices_idle(app->radio_device); /* Put it into idle state in case it is sleeping. */
|
||||
uint32_t value = subghz_devices_set_frequency(app->radio_device, app->frequency);
|
||||
FURI_LOG_E(TAG, "Switched to frequency: %lu", value);
|
||||
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_subghz_flush_rx();
|
||||
furi_hal_subghz_rx();
|
||||
|
||||
subghz_devices_flush_rx(app->radio_device);
|
||||
subghz_devices_set_rx(app->radio_device);
|
||||
|
||||
if(!app->txrx->debug_timer_sampling) {
|
||||
furi_hal_subghz_start_async_rx(protoview_rx_callback, NULL);
|
||||
subghz_devices_start_async_rx(app->radio_device, protoview_rx_callback, NULL);
|
||||
} else {
|
||||
furi_hal_gpio_init(
|
||||
subghz_devices_get_data_gpio(app->radio_device),
|
||||
GpioModeInput,
|
||||
GpioPullNo,
|
||||
GpioSpeedLow);
|
||||
raw_sampling_worker_start(app);
|
||||
}
|
||||
app->txrx->txrx_state = TxRxStateRx;
|
||||
@@ -98,12 +106,12 @@ void radio_rx_end(ProtoViewApp* app) {
|
||||
|
||||
if(app->txrx->txrx_state == TxRxStateRx) {
|
||||
if(!app->txrx->debug_timer_sampling) {
|
||||
furi_hal_subghz_stop_async_rx();
|
||||
subghz_devices_stop_async_rx(app->radio_device);
|
||||
} else {
|
||||
raw_sampling_worker_stop(app);
|
||||
}
|
||||
}
|
||||
furi_hal_subghz_idle();
|
||||
subghz_devices_idle(app->radio_device);
|
||||
app->txrx->txrx_state = TxRxStateIDLE;
|
||||
}
|
||||
|
||||
@@ -115,9 +123,8 @@ void radio_sleep(ProtoViewApp* app) {
|
||||
* chip into sleep. */
|
||||
radio_rx_end(app);
|
||||
}
|
||||
furi_hal_subghz_sleep();
|
||||
subghz_devices_sleep(app->radio_device);
|
||||
app->txrx->txrx_state = TxRxStateSleep;
|
||||
furi_hal_power_suppress_charge_exit();
|
||||
}
|
||||
|
||||
/* =============================== Transmission ============================= */
|
||||
@@ -131,17 +138,14 @@ void radio_tx_signal(ProtoViewApp* app, FuriHalSubGhzAsyncTxCallback data_feeder
|
||||
if(oldstate == TxRxStateRx) radio_rx_end(app);
|
||||
radio_begin(app);
|
||||
|
||||
furi_hal_subghz_idle();
|
||||
uint32_t value = furi_hal_subghz_set_frequency_and_path(app->frequency);
|
||||
subghz_devices_idle(app->radio_device);
|
||||
uint32_t value = subghz_devices_set_frequency(app->radio_device, app->frequency);
|
||||
FURI_LOG_E(TAG, "Switched to frequency: %lu", value);
|
||||
furi_hal_gpio_write(furi_hal_subghz.cc1101_g0_pin, false);
|
||||
furi_hal_gpio_init(
|
||||
furi_hal_subghz.cc1101_g0_pin, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
furi_hal_subghz_start_async_tx(data_feeder, ctx);
|
||||
while(!furi_hal_subghz_is_async_tx_complete()) furi_delay_ms(10);
|
||||
furi_hal_subghz_stop_async_tx();
|
||||
furi_hal_subghz_idle();
|
||||
subghz_devices_start_async_tx(app->radio_device, data_feeder, ctx);
|
||||
while(!subghz_devices_is_async_complete_tx(app->radio_device)) furi_delay_ms(10);
|
||||
subghz_devices_stop_async_tx(app->radio_device);
|
||||
subghz_devices_idle(app->radio_device);
|
||||
|
||||
radio_begin(app);
|
||||
if(oldstate == TxRxStateRx) radio_rx(app);
|
||||
@@ -157,7 +161,7 @@ void radio_tx_signal(ProtoViewApp* app, FuriHalSubGhzAsyncTxCallback data_feeder
|
||||
void protoview_timer_isr(void* ctx) {
|
||||
ProtoViewApp* app = ctx;
|
||||
|
||||
bool level = furi_hal_gpio_read(furi_hal_subghz.cc1101_g0_pin);
|
||||
bool level = furi_hal_gpio_read(subghz_devices_get_data_gpio(app->radio_device));
|
||||
if(app->txrx->last_g0_value != level) {
|
||||
uint32_t now = DWT->CYCCNT;
|
||||
uint32_t dur = now - app->txrx->last_g0_change_time;
|
||||
|
||||
Reference in New Issue
Block a user