Selaa lähdekoodia

Signal detection in DS.

antirez 3 vuotta sitten
vanhempi
commit
13fdeb10e7
3 muutettua tiedostoa jossa 24 lisäystä ja 9 poistoa
  1. 2 0
      app.c
  2. 10 4
      app.h
  3. 12 5
      app_subghz.c

+ 2 - 0
app.c

@@ -132,6 +132,8 @@ ProtoViewApp* protoview_app_alloc() {
     app->txrx->freq_mod_changed = false;
     app->txrx->debug_direct_sampling = true;
     app->txrx->ds_thread = NULL;
+    app->txrx->last_g0_change_time = DWT->CYCCNT;
+    app->txrx->last_g0_value = false;
     app->txrx->worker = subghz_worker_alloc();
 #ifdef PROTOVIEW_DISABLE_SUBGHZ_FILTER
     app->txrx->worker->filter_running = 0;

+ 10 - 4
app.h

@@ -68,14 +68,20 @@ struct ProtoViewTxRx {
     bool freq_mod_changed;      /* The user changed frequency and/or modulation
                                    from the interface. There is to restart the
                                    radio with the right parameters. */
-    bool debug_direct_sampling; /* Read data from GDO0 in a busy loop. Only
-                                   for testing. */
     SubGhzWorker* worker;       /* Our background worker. */
-    FuriThread *ds_thread;      /* Direct sampling thread. */
-    bool ds_thread_running;     /* Exit condition for the thread. */
     SubGhzEnvironment* environment;
     SubGhzReceiver* receiver;
     TxRxState txrx_state; /* Receiving, idle or sleeping? */
+
+    /* Direct sampling mode state. */
+    bool debug_direct_sampling; /* Read data from GDO0 in a busy loop. Only
+                                   for testing. */
+    FuriThread *ds_thread;      /* Direct sampling thread. */
+    bool ds_thread_running;     /* Exit condition for the thread. */
+    uint32_t last_g0_change_time; /* Last high->low (or reverse) switch. */
+    bool last_g0_value;           /* Current value (high or low): we are
+                                     checking the duration in the timer
+                                     handler. */
 };
 
 typedef struct ProtoViewTxRx ProtoViewTxRx;

+ 12 - 5
app_subghz.c

@@ -175,9 +175,16 @@ void raw_sampling_worker_stop(ProtoViewApp *app) {
 
 void protoview_timer_isr(void *ctx) {
     ProtoViewApp *app = ctx;
-    UNUSED(app);
-    raw_samples_add(RawSamples, true, 500);
-    raw_samples_add(RawSamples, false, 500);
+
+    bool level = furi_hal_gpio_read(&gpio_cc1101_g0);
+    if (app->txrx->last_g0_value != level) {
+        uint32_t now = DWT->CYCCNT;
+        uint32_t dur = now - app->txrx->last_g0_change_time;
+        if (dur > 15000) dur = 15000;
+        raw_samples_add(RawSamples, app->txrx->last_g0_value, dur);
+        app->txrx->last_g0_value = level;
+        app->txrx->last_g0_change_time = now;
+    }
     LL_TIM_ClearFlag_UPDATE(TIM2);
 }
 
@@ -185,9 +192,9 @@ void raw_sampling_worker_start(ProtoViewApp *app) {
     UNUSED(app);
 
     LL_TIM_InitTypeDef tim_init = {
-        .Prescaler = 63999,
+        .Prescaler = 63,
         .CounterMode = LL_TIM_COUNTERMODE_UP,
-        .Autoreload = 30,
+        .Autoreload = 10,
     };
 
     LL_TIM_Init(TIM2, &tim_init);