Minor tweaks

This commit is contained in:
Jan Hamal Dvořák 2025-06-20 21:41:17 +02:00
parent 7727826b34
commit 7b9efd8c59

View file

@ -20,8 +20,11 @@
#define IRP_SM 0
#define IRN_SM 1
// Actually one less, but this is also for timing.
#define SAMPLE_DEPTH 128
#define NUM_SAMPLES_BITS 10
#define NUM_SAMPLES (1 << NUM_SAMPLES_BITS)
#define NUM_SAMPLES (1 << NUM_SAMPLES_BITS)
static uint16_t irp_buffer[NUM_SAMPLES] __aligned(2 * NUM_SAMPLES);
static int dma_ch_irp_rx;
@ -68,7 +71,7 @@ static void init_pio_sm(pio_hw_t *pio, int sm, int rx_pin, int fb_pin)
pio_sm_restart(pio, sm);
pio_sm_clear_fifos(pio, sm);
pio->txf[sm] = 126;
pio->txf[sm] = SAMPLE_DEPTH - 2;
pio_sm_exec_wait_blocking(pio, sm, pio_encode_pull(false, false));
pio_sm_exec_wait_blocking(pio, sm, pio_encode_mov(pio_x, pio_osr));
@ -98,11 +101,11 @@ static bool read_sample(int *sample)
int neg = irn_buffer[tail] << 16;
tail = (tail + 1) % NUM_SAMPLES;
int s = pos - neg;
int s = neg - pos;
static int dc;
dc += (s - dc) >> 16;
s -= dc;
dc += s >> 16;
*sample = s >> 16;
return true;