@@ -80,9 +80,8 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self, const mcu
80
80
}
81
81
// We add one to the maxlen version to ensure that two symbols at lease are
82
82
// captured because we may skip the first portion of a symbol.
83
- self -> raw_symbols_size = (maxlen / 2 + 1 ) * sizeof (rmt_symbol_word_t );
84
- // RMT DMA mode cannot access PSRAM -> ensure raw_symbols is in internal ram
85
- self -> raw_symbols = (rmt_symbol_word_t * )port_malloc (self -> raw_symbols_size , true);
83
+ self -> raw_symbols_size = MIN (64 , maxlen / 2 + 1 ) * sizeof (rmt_symbol_word_t );
84
+ self -> raw_symbols = (rmt_symbol_word_t * )m_malloc_without_collect (self -> raw_symbols_size );
86
85
if (self -> raw_symbols == NULL ) {
87
86
m_free (self -> buffer );
88
87
m_malloc_fail (self -> raw_symbols_size );
@@ -110,26 +109,17 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self, const mcu
110
109
.clk_src = RMT_CLK_SRC_DEFAULT ,
111
110
// 2 us resolution so we can capture 65ms pulses. The RMT period is only 15 bits.
112
111
.resolution_hz = 1000000 / 2 ,
113
- .mem_block_symbols = self -> raw_symbols_size ,
114
- .flags .with_dma = 1
112
+ .mem_block_symbols = SOC_RMT_MEM_WORDS_PER_CHANNEL ,
115
113
};
116
- // If we fail here, the self->buffer will be garbage collected.
117
- esp_err_t result = rmt_new_rx_channel (& config , & self -> channel );
118
- if (result != ESP_OK ) {
119
- port_free (self -> raw_symbols );
120
- raise_esp_error (result );
121
- }
114
+ // If we fail here, the buffers allocated above will be garbage collected.
115
+ CHECK_ESP_RESULT (rmt_new_rx_channel (& config , & self -> channel ));
122
116
123
117
rmt_rx_event_callbacks_t rx_callback = {
124
118
.on_recv_done = _done_callback
125
119
};
126
120
rmt_rx_register_event_callbacks (self -> channel , & rx_callback , self );
127
121
rmt_enable (self -> channel );
128
- result = rmt_receive (self -> channel , self -> raw_symbols , self -> raw_symbols_size , & rx_config );
129
- if (result != ESP_OK ) {
130
- port_free (self -> raw_symbols );
131
- raise_esp_error (result );
132
- }
122
+ rmt_receive (self -> channel , self -> raw_symbols , self -> raw_symbols_size , & rx_config );
133
123
}
134
124
135
125
bool common_hal_pulseio_pulsein_deinited (pulseio_pulsein_obj_t * self ) {
0 commit comments