3838// Bit-bang implementation
3939
4040#define NS_TICKS_OVERHEAD (6)
41-
41+ #ifndef SOC_RMT_SUPPORTED
42+ #warning "INFO: machine_bitstream.c: Defining machine_bitstream_high_low_bitbang")
4243// This is a translation of the cycle counter implementation in ports/stm32/machine_bitstream.c.
4344static void IRAM_ATTR machine_bitstream_high_low_bitbang (mp_hal_pin_obj_t pin , uint32_t * timing_ns , const uint8_t * buf , size_t len ) {
4445 uint32_t pin_mask , gpio_reg_set , gpio_reg_clear ;
@@ -89,7 +90,7 @@ static void IRAM_ATTR machine_bitstream_high_low_bitbang(mp_hal_pin_obj_t pin, u
8990
9091 mp_hal_quiet_timing_exit (irq_state );
9192}
92-
93+ #endif
9394#if SOC_RMT_SUPPORTED
9495/******************************************************************************/
9596// RMT implementation
@@ -105,12 +106,24 @@ static void machine_bitstream_high_low_rmt(mp_hal_pin_obj_t pin, uint32_t *timin
105106 uint32_t clock_div = 2 ;
106107 rmt_channel_handle_t channel = NULL ;
107108 // TODO create a permanent/reserved channel outside this function? Lazy creation?
109+ // NOTE:
110+ // s3/p4 support DMA (.flags.with_dma =1), others do not
111+ // see SOC_RMT_SUPPORT_DMA
112+
108113 rmt_tx_channel_config_t tx_chan_config = {
109114 .clk_src = RMT_CLK_SRC_DEFAULT ,
110115 .gpio_num = pin ,
111- .mem_block_symbols = 64 ,
112116 .resolution_hz = APB_CLK_FREQ / clock_div ,
113- .trans_queue_depth = 1 ,
117+ .trans_queue_depth = 1 , // should this be biggert
118+ #if SOC_RMT_SUPPORT_DMA
119+ #warning "INFO: machine_bitstream rmt using DMA"
120+ .mem_block_symbols = 1024 ,
121+ .flags .with_dma = 1 ,
122+ #else
123+ #warning "INFO: machine_bitstream rmt no DMA"
124+ .mem_block_symbols = 64 ,
125+ .flags .with_dma = 0 ,
126+ #endif
114127 };
115128 check_esp_err (rmt_new_tx_channel (& tx_chan_config , & channel ));
116129 check_esp_err (rmt_enable (channel ));
@@ -173,8 +186,10 @@ static void machine_bitstream_high_low_rmt(mp_hal_pin_obj_t pin, uint32_t *timin
173186
174187void machine_bitstream_high_low (mp_hal_pin_obj_t pin , uint32_t * timing_ns , const uint8_t * buf , size_t len ) {
175188 #if SOC_RMT_SUPPORTED
189+ #warning "INFO: machine_bitstream.c Using RMT bitstream"
176190 machine_bitstream_high_low_rmt (pin , timing_ns , buf , len );
177191 #else
192+ #warning "INFO: machine_bitstream.c Using bitbang bitstream"
178193 // TODO test whether channel creation was successful?
179194 machine_bitstream_high_low_bitbang (pin , timing_ns , buf , len );
180195 #endif
0 commit comments