38
38
#include "shared-bindings/util.h"
39
39
40
40
//| class BufferedInput:
41
- //| """Input analog voltage level to supplied buffer using DMA Capture """
41
+ //| """Capture multiple analog voltage levels to the supplied buffer"""
42
42
//|
43
43
//| def __init__(self, pin: microcontroller.Pin, buffer: WriteableBuffer, *, sample_rate: int = 500000) -> None:
44
- //| """Use the BufferedInput on the given pin. Fill the given buffer from ADC read values at the supplied
45
- //| sample_rate.
44
+ //| """Create a `BufferedInput` on the given pin. ADC values will be read
45
+ //| into the given buffer at the supplied sample_rate. Depending on the
46
+ //| buffer typecode, 'b', 'B', 'h', 'H', samples are 8-bit byte-arrays or
47
+ //| 16-bit half-words and are signed or unsigned.
48
+ //| The ADC most significant bits of the ADC are kept. Please see:
49
+ //| `https://docs.circuitpython.org/en/latest/docs/library/array.html`
46
50
//|
47
51
//| :param ~microcontroller.Pin pin: the pin to read from
48
52
//| :param ~circuitpython_typing.WriteableBuffer buffer: buffer: A buffer for samples
49
- //| :param ~int sample_rate: rate: The desired playback sample rate
53
+ //| :param ~int sample_rate: rate: sampling frequency, in samples per second
50
54
//|
51
55
//| Usage::
52
56
//|
58
62
//| mybuffer = array.array("H", [0] * length)
59
63
//| rate = 500000
60
64
//| adcbuf = adcbuffer.BufferedInput(board.GP26, mybuffer, rate)
61
- //| adcbuf.readmultiple ()
65
+ //| adcbuf.read ()
62
66
//| adcbuf.deinit()
63
67
//| for i in range(length):
64
68
//| print(i, mybuffer[i])
@@ -93,7 +97,7 @@ STATIC mp_obj_t adcbuffer_bufferedinput_make_new(const mp_obj_type_t *type, size
93
97
if (bufinfo .typecode == 'h' || bufinfo .typecode == 'H' ) {
94
98
bytes_per_sample = 2 ;
95
99
} else if (bufinfo .typecode != 'b' && bufinfo .typecode != 'B' && bufinfo .typecode != BYTEARRAY_TYPECODE ) {
96
- mp_raise_ValueError (translate ("sample_source buffer must be a bytearray or array of type 'h', 'H', 'b' or 'B'" ));
100
+ mp_raise_ValueError_varg (translate ("%q must`` be a bytearray or array of type 'h', 'H', 'b' or 'B'" ), MP_QSTR_buffer );
97
101
}
98
102
99
103
// Validate sample rate here
@@ -117,7 +121,7 @@ STATIC mp_obj_t adcbuffer_bufferedinput_make_new(const mp_obj_type_t *type, size
117
121
}
118
122
119
123
//| def deinit(self) -> None:
120
- //| """Turn off the BufferedInput and release the pin for other use."""
124
+ //| """Shut down the ` BufferedInput` and release the pin for other use."""
121
125
//| ...
122
126
//|
123
127
STATIC mp_obj_t adcbuffer_bufferedinput_deinit (mp_obj_t self_in ) {
@@ -147,26 +151,23 @@ STATIC mp_obj_t adcbuffer_bufferedinput___exit__(size_t n_args, const mp_obj_t *
147
151
}
148
152
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (adcbuffer_bufferedinput___exit___obj , 4 , 4 , adcbuffer_bufferedinput___exit__ );
149
153
150
- //| value: None
151
- //| """Fills the supplied buffer with ADC values using DMA transfer.
152
- //| If the buffer is 8-bit, then values are 8-bit shifted and error bit is off.
153
- //| If buffer is 16-bit, then values are not shifted and error bit is present.
154
- //| Number of transfers is always the number of samples which is the array
155
- //| byte length divided by the bytes_per_sample."""
154
+ //|
155
+ //| def read(self) -> None:
156
+ //| """Fills the provided buffer with ADC voltage values."""
156
157
//|
157
- STATIC mp_obj_t adcbuffer_bufferedinput_obj_readmultiple (mp_obj_t self_in ) {
158
+ STATIC mp_obj_t adcbuffer_bufferedinput_obj_read (mp_obj_t self_in ) {
158
159
adcbuffer_bufferedinput_obj_t * self = MP_OBJ_TO_PTR (self_in );
159
160
check_for_deinit (self );
160
- common_hal_adcbuffer_bufferedinput_readmultiple (self );
161
+ common_hal_adcbuffer_bufferedinput_read (self );
161
162
return mp_const_none ;
162
163
}
163
- MP_DEFINE_CONST_FUN_OBJ_1 (adcbuffer_bufferedinput_readmultiple_obj , adcbuffer_bufferedinput_obj_readmultiple );
164
+ MP_DEFINE_CONST_FUN_OBJ_1 (adcbuffer_bufferedinput_read_obj , adcbuffer_bufferedinput_obj_read );
164
165
165
166
STATIC const mp_rom_map_elem_t adcbuffer_bufferedinput_locals_dict_table [] = {
166
- { MP_ROM_QSTR (MP_QSTR_deinit ), MP_ROM_PTR (& adcbuffer_bufferedinput_deinit_obj ) },
167
- { MP_ROM_QSTR (MP_QSTR___enter__ ), MP_ROM_PTR (& default___enter___obj ) },
168
- { MP_ROM_QSTR (MP_QSTR___exit__ ), MP_ROM_PTR (& adcbuffer_bufferedinput___exit___obj ) },
169
- { MP_ROM_QSTR (MP_QSTR_readmultiple ), MP_ROM_PTR (& adcbuffer_bufferedinput_readmultiple_obj )},
167
+ { MP_ROM_QSTR (MP_QSTR_deinit ), MP_ROM_PTR (& adcbuffer_bufferedinput_deinit_obj ) },
168
+ { MP_ROM_QSTR (MP_QSTR___enter__ ), MP_ROM_PTR (& default___enter___obj ) },
169
+ { MP_ROM_QSTR (MP_QSTR___exit__ ), MP_ROM_PTR (& adcbuffer_bufferedinput___exit___obj ) },
170
+ { MP_ROM_QSTR (MP_QSTR_read ), MP_ROM_PTR (& adcbuffer_bufferedinput_read_obj )},
170
171
171
172
};
172
173
0 commit comments