Skip to content

Commit 907191a

Browse files
committed
Some changes to the comments
1 parent 9ba2c96 commit 907191a

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

pio/uart_pio_dma/uart_pio_dma.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ int main()
104104
uart_init(HARD_UART_INST, SERIAL_BAUD);
105105
#endif
106106

107-
// setup pio for rx
108107
#if USE_PIO_FOR_RX
108+
// setup pio for rx
109109
if (!pio_claim_free_sm_and_add_program_for_gpio_range(&uart_rx_mini_program, &pio_hw_rx, &pio_sm_rx, &offset_rx, GPIO_RX, 1, true)) {
110110
panic("failed to allocate pio for rx");
111111
}
@@ -114,8 +114,8 @@ int main()
114114
gpio_set_function(GPIO_RX, GPIO_FUNC_UART);
115115
#endif
116116

117-
// setup pio for tx
118117
#if USE_PIO_FOR_TX
118+
// setup pio for tx
119119
if (!pio_claim_free_sm_and_add_program_for_gpio_range(&uart_tx_program, &pio_hw_tx, &pio_sm_tx, &offset_tx, GPIO_TX, 1, true)) {
120120
panic("failed to allocate pio for tx");
121121
}
@@ -124,8 +124,8 @@ int main()
124124
gpio_set_function(GPIO_TX, GPIO_FUNC_UART);
125125
#endif
126126

127-
// setup pio interrupt
128127
#if USE_PIO_FOR_RX
128+
// setup pio interrupt
129129
if (irq_get_exclusive_handler(pio_get_irq_num(pio_hw_rx, PIO_IRQ_TO_USE))) {
130130
panic("PIO IRQ in use");
131131
}
@@ -136,17 +136,17 @@ int main()
136136
#endif
137137
#endif
138138

139-
// add dma handler
140139
#if USE_DMA_FOR_RX || USE_DMA_FOR_TX
140+
// add dma handler
141141
if (irq_get_exclusive_handler(dma_get_irq_num(DMA_IRQ_TO_USE))) {
142142
panic("DMA IRQ in use");
143143
}
144144
irq_add_shared_handler(dma_get_irq_num(DMA_IRQ_TO_USE), dma_irq_handler, DMA_IRQ_PRIORITY);
145145
irq_set_enabled(dma_get_irq_num(DMA_IRQ_TO_USE), true);
146146
#endif
147147

148-
// Setup dma for read
149148
#if USE_DMA_FOR_RX
149+
// Setup dma for read
150150
dma_channel_rx = dma_claim_unused_channel(false);
151151
if (dma_channel_rx < 0) {
152152
panic("No free dma channels");
@@ -159,19 +159,19 @@ int main()
159159
// enable irq for rx
160160
dma_irqn_set_channel_enabled(DMA_IRQ_TO_USE, dma_channel_rx, true);
161161
#if USE_PIO_FOR_RX
162-
// read from pio fifo
162+
// setup dma to read from pio fifo
163163
channel_config_set_dreq(&config_rx, pio_get_dreq(pio_hw_rx, pio_sm_rx, false));
164164
// 8-bit read from the uppermost byte of the FIFO, as data is left-justified so need to add 3. Don't forget the cast!
165165
dma_channel_configure(dma_channel_rx, &config_rx, buffer_rx, (io_rw_8*)&pio_hw_rx->rxf[pio_sm_rx] + 3, read_size, true); // dma started
166166
#else
167-
// read from uart hardware
167+
// setup dma to read from uart hardware
168168
channel_config_set_dreq(&config_rx, uart_get_dreq(HARD_UART_INST, false));
169169
dma_channel_configure(dma_channel_rx, &config_rx, buffer_rx, &uart_get_hw(HARD_UART_INST)->dr, read_size, true); // dma started
170170
#endif
171171
#endif
172172

173-
// setup dma for write
174173
#if USE_DMA_FOR_TX
174+
// setup dma for write
175175
dma_channel_tx = dma_claim_unused_channel(false);
176176
if (dma_channel_tx < 0) {
177177
panic("No free dma channels");
@@ -183,32 +183,32 @@ int main()
183183
// enable irq for tx
184184
dma_irqn_set_channel_enabled(DMA_IRQ_TO_USE, dma_channel_tx, true);
185185
#if USE_PIO_FOR_RX
186-
// write to pio fifo
186+
// setup dma to write to pio fifo
187187
channel_config_set_dreq(&config_tx, pio_get_dreq(pio_hw_tx, pio_sm_tx, true));
188188
dma_channel_configure(dma_channel_tx, &config_tx, &pio_hw_rx->txf[pio_sm_tx], buffer_tx, sizeof(buffer_tx) - 1, true); // dma started
189189
#else
190-
// write to uart hardware
190+
// setup dma to write to uart hardware
191191
channel_config_set_dreq(&config_tx, uart_get_dreq(HARD_UART_INST, true));
192192
dma_channel_configure(dma_channel_tx, &config_tx, &uart_get_hw(HARD_UART_INST)->dr, buffer_tx, sizeof(buffer_tx) - 1, true); // dma started
193193
#endif
194194
#endif
195195

196-
// send data
197196
#if USE_DMA_FOR_TX
198-
dma_channel_wait_for_finish_blocking(dma_channel_tx); // wait for tx
197+
// Just wait for dma tx to finish
198+
dma_channel_wait_for_finish_blocking(dma_channel_tx);
199199
#elif USE_PIO_FOR_TX
200200
// write to the pio fifo
201201
int count_pio_tx = 0;
202202
while(count_pio_tx < sizeof(buffer_tx) - 1) {
203203
uart_tx_program_putc(pio_hw_tx, pio_sm_tx, buffer_tx[count_pio_tx++]);
204204
}
205205
#else
206+
// write to the uart
206207
uart_puts(HARD_UART_INST, buffer_tx);
207208
#endif
208209

209-
// Receive the data
210210
#if USE_DMA_FOR_RX
211-
// wait for dma rx
211+
// Just wait for dma rx to finish
212212
dma_channel_wait_for_finish_blocking(dma_channel_rx);
213213
#elif USE_PIO_FOR_RX
214214
// read from the pio fifo
@@ -217,7 +217,7 @@ int main()
217217
buffer_rx[count_pio_rx++] = uart_rx_program_getc(pio_hw_rx, pio_sm_rx);
218218
}
219219
#else
220-
// use the uart hardware
220+
// read from the uart
221221
int count_uart_rx = 0;
222222
while(count_uart_rx < sizeof(buffer_tx) - 1) {
223223
buffer_rx[count_uart_rx++] = uart_getc(HARD_UART_INST);

0 commit comments

Comments
 (0)