Fixing Build errors/ DMA Xfer Rate
This commit is contained in:
parent
61591ac136
commit
f5655dd48c
@ -43,7 +43,7 @@
|
||||
#define ADC_FIRST_PIN_NUMBER 26
|
||||
#define ADC_PIN_COUNT 4
|
||||
|
||||
void common_hal_adcbuffer_bufferedinput_construct(adcbuffer_bufferedinput_obj_t *self, const mcu_pin_obj_t *pin, uint8_t *buffer, uint32_t len, uint8_t bytes_per_sample, bool samples_signed, mp_float_t sample_rate) {
|
||||
void common_hal_adcbuffer_bufferedinput_construct(adcbuffer_bufferedinput_obj_t *self, const mcu_pin_obj_t *pin, uint8_t *buffer, uint32_t len, uint8_t bytes_per_sample, bool samples_signed, uint32_t sample_rate) {
|
||||
|
||||
// Set pin and channel
|
||||
self->pin = pin;
|
||||
@ -65,9 +65,10 @@ void common_hal_adcbuffer_bufferedinput_construct(adcbuffer_bufferedinput_obj_t
|
||||
|
||||
// TODO: checks on length here
|
||||
|
||||
// uint8_t bytes_per_sample
|
||||
// Set sample rate
|
||||
// self->bits_per_sample = bytes_per_sample * 8;
|
||||
// NOTE: bits_per_sample = bytes_per_sample * 8;
|
||||
self->bytes_per_sample = bytes_per_sample;
|
||||
|
||||
// TODO: Possibly check Rate values here, already u_int
|
||||
// NOTE: Anything over 500000 for RP2040 will not
|
||||
// exceed DMA conversion sampling rate.
|
||||
@ -86,8 +87,8 @@ void common_hal_adcbuffer_bufferedinput_construct(adcbuffer_bufferedinput_obj_t
|
||||
true, // Write each completed conversion to the sample FIFO
|
||||
true, // Enable DMA data request (DREQ)
|
||||
1, // DREQ (and IRQ) asserted when at least 1 sample present
|
||||
false, // We won't see the ERR bit because of 8 bit reads; disable. // ??
|
||||
false // Shift each sample to 8 bits when pushing to FIFO // ??
|
||||
true, // We will see the ERR bit because of 12 bit reads; enabled.
|
||||
false // Do not shift each sample to 8 bits when pushing to FIFO
|
||||
);
|
||||
|
||||
// Divisor of 0 -> full speed. Free-running capture with the divider is
|
||||
@ -98,7 +99,7 @@ void common_hal_adcbuffer_bufferedinput_construct(adcbuffer_bufferedinput_obj_t
|
||||
// intervals). This is all timed by the 48 MHz ADC clock.
|
||||
// sample rate determines divisor, not zero.
|
||||
|
||||
adc_set_clkdiv(48000000.0 / self->sample_rate);
|
||||
adc_set_clkdiv((float)48000000.0 / (float)self->sample_rate);
|
||||
|
||||
// sleep_ms(1000);
|
||||
// Set up the DMA to start transferring data as soon as it appears in FIFO
|
||||
@ -109,7 +110,11 @@ void common_hal_adcbuffer_bufferedinput_construct(adcbuffer_bufferedinput_obj_t
|
||||
self->cfg = dma_channel_get_default_config(dma_chan);
|
||||
|
||||
// Reading from constant address, writing to incrementing byte addresses
|
||||
channel_config_set_transfer_data_size(&(self->cfg), DMA_SIZE_16);
|
||||
if (self->bytes_per_sample == 1) {
|
||||
channel_config_set_transfer_data_size(&(self->cfg), DMA_SIZE_8);
|
||||
} else if (self->bytes_per_sample == 2) {
|
||||
channel_config_set_transfer_data_size(&(self->cfg), DMA_SIZE_16);
|
||||
}
|
||||
channel_config_set_read_increment(&(self->cfg), false);
|
||||
channel_config_set_write_increment(&(self->cfg), true);
|
||||
|
||||
@ -141,13 +146,14 @@ void common_hal_adcbuffer_bufferedinput_deinit(adcbuffer_bufferedinput_obj_t *se
|
||||
|
||||
bool common_hal_adcbuffer_bufferedinput_readmultiple(adcbuffer_bufferedinput_obj_t *self) {
|
||||
|
||||
// uint32_t cdl = self->len / 2 - 1;
|
||||
uint32_t cdl = self->len;
|
||||
// uint32_t cdl = self->len/2 + 1;
|
||||
// uint32_t cdl = 3*self->len/4; //BAD
|
||||
uint32_t cdl = self->len * self->bytes_per_sample;
|
||||
|
||||
dma_channel_configure(self->dma_chan, &(self->cfg),
|
||||
self->buffer, // dst
|
||||
&adc_hw->fifo, // src
|
||||
cdl, // CAPTURE_DEPTH, // transfer count
|
||||
cdl, // transfer count
|
||||
true // start immediately
|
||||
);
|
||||
|
||||
|
@ -47,7 +47,7 @@ typedef struct {
|
||||
uint32_t len;
|
||||
uint8_t bytes_per_sample;
|
||||
bool samples_signed;
|
||||
mp_float_t sample_rate;
|
||||
uint32_t sample_rate;
|
||||
uint8_t chan;
|
||||
uint dma_chan;
|
||||
dma_channel_config cfg;
|
||||
|
@ -65,7 +65,7 @@ CFLAGS += -DCIRCUITPY_ALARM=$(CIRCUITPY_ALARM)
|
||||
CIRCUITPY_ANALOGIO ?= 1
|
||||
CFLAGS += -DCIRCUITPY_ANALOGIO=$(CIRCUITPY_ANALOGIO)
|
||||
|
||||
CIRCUITPY_ADCBUFFER ?= 1
|
||||
CIRCUITPY_ADCBUFFER ?= 0
|
||||
CFLAGS += -DCIRCUITPY_ADCBUFFER=$(CIRCUITPY_ADCBUFFER)
|
||||
|
||||
CIRCUITPY_ATEXIT ?= $(CIRCUITPY_FULL_BUILD)
|
||||
|
@ -68,18 +68,12 @@
|
||||
/// """
|
||||
/// ...
|
||||
///
|
||||
STATIC void validate_rate(mp_float_t rate) {
|
||||
if (rate < (mp_float_t)1.0f || rate > (mp_float_t)500000.0f) {
|
||||
mp_raise_ValueError(translate("sample rate must be 1.0-500000.0 per second"));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t adcbuffer_bufferedinput_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
enum { ARG_pin, ARG_buffer, ARG_sample_rate };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_pin, MP_ARG_OBJ | MP_ARG_REQUIRED },
|
||||
{ MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED },
|
||||
{ MP_QSTR_sample_rate, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_int = 500000} },
|
||||
{ MP_QSTR_sample_rate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 500000} },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
@ -103,8 +97,7 @@ STATIC mp_obj_t adcbuffer_bufferedinput_make_new(const mp_obj_type_t *type, size
|
||||
}
|
||||
|
||||
// Validate sample rate here
|
||||
mp_float_t sample_rate = mp_obj_get_float(args[ARG_sample_rate].u_obj);
|
||||
validate_rate(sample_rate);
|
||||
uint32_t sample_rate = (uint32_t)mp_arg_validate_int_range(args[ARG_sample_rate].u_int, 1, 500000, MP_QSTR_sample_rate);
|
||||
|
||||
// Create local object
|
||||
adcbuffer_bufferedinput_obj_t *self = m_new_obj(adcbuffer_bufferedinput_obj_t);
|
||||
|
@ -34,7 +34,7 @@
|
||||
|
||||
extern const mp_obj_type_t adcbuffer_bufferedinput_type;
|
||||
|
||||
void common_hal_adcbuffer_bufferedinput_construct(adcbuffer_bufferedinput_obj_t *self, const mcu_pin_obj_t *pin, uint8_t *buffer, uint32_t len, uint8_t bytes_per_sample, bool samples_signed, mp_float_t sample_rate);
|
||||
void common_hal_adcbuffer_bufferedinput_construct(adcbuffer_bufferedinput_obj_t *self, const mcu_pin_obj_t *pin, uint8_t *buffer, uint32_t len, uint8_t bytes_per_sample, bool samples_signed, uint32_t sample_rate);
|
||||
void common_hal_adcbuffer_bufferedinput_deinit(adcbuffer_bufferedinput_obj_t *self);
|
||||
bool common_hal_adcbuffer_bufferedinput_deinited(adcbuffer_bufferedinput_obj_t *self);
|
||||
bool common_hal_adcbuffer_bufferedinput_readmultiple(adcbuffer_bufferedinput_obj_t *self);
|
||||
|
Loading…
x
Reference in New Issue
Block a user