-
Notifications
You must be signed in to change notification settings - Fork 32
/
rx.h
105 lines (90 loc) · 2.18 KB
/
rx.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef RX__
#define RX__
#include <stdio.h>
#include <math.h>
#include <ctime>
#include "nco.pio.h"
#include "pico/stdlib.h"
#include "pico/sem.h"
#include "hardware/pio.h"
#include "hardware/adc.h"
#include "hardware/pwm.h"
#include "hardware/dma.h"
#include "rx_definitions.h"
#include "rx_dsp.h"
struct rx_settings
{
double tuned_frequency_Hz;
int step_Hz;
uint8_t agc_speed;
uint8_t mode;
uint8_t volume;
uint8_t squelch;
uint8_t bandwidth;
uint16_t cw_sidetone_Hz;
uint16_t gain_cal;
bool suspend;
bool swap_iq;
bool enable_auto_notch;
};
struct rx_status
{
int32_t signal_strength_dBm;
uint32_t busy_time;
uint16_t temp;
uint16_t battery;
};
class rx
{
private:
//receiver configuration
double tuned_frequency_Hz;
double nco_frequency_Hz;
double offset_frequency_Hz;
semaphore_t settings_semaphore;
bool settings_changed;
bool suspend;
uint16_t temp;
uint16_t battery;
// Choose which PIO instance to use (there are two instances)
PIO pio;
uint offset;
uint sm;
//capture buffer DMA
static int capture_dma;
static dma_channel_config capture_cfg;
//buffers and dma for adc
static int adc_dma_ping;
static int adc_dma_pong;
static dma_channel_config ping_cfg;
static dma_channel_config pong_cfg;
static uint16_t ping_samples[adc_block_size];
static uint16_t pong_samples[adc_block_size];
static uint16_t num_ping_samples;
static uint16_t num_pong_samples;
//buffers and dma for PWM audio output
static int audio_pwm_slice_num;
static int pwm_dma_ping;
static int pwm_dma_pong;
static dma_channel_config audio_ping_cfg;
static dma_channel_config audio_pong_cfg;
static int16_t ping_audio[adc_block_size];
static int16_t pong_audio[adc_block_size];
static bool audio_running;
static void dma_handler();
uint32_t pwm_max;
//store busy time for performance monitoring
uint32_t busy_time;
public:
rx(rx_settings & settings_to_apply, rx_status & status);
void apply_settings();
void run();
void get_spectrum(float spectrum[]);
rx_settings &settings_to_apply;
rx_status &status;
rx_dsp rx_dsp_inst;
void read_batt_temp();
void access(bool settings_changed);
void release();
};
#endif