2 #include "hardware/dma.h"
24 if (channel_no == -1) {
35 dma_channel_unclaim(channel_no);
54 void copy(T* dst, T* src,
int len,
boolean start =
true){
57 irq_set_enabled(DMA_IRQ_0,
true);
62 dma_channel_config c = dma_channel_get_default_config(channel_no);
63 channel_config_set_transfer_data_size(&c, DMA_SIZE_8);
64 channel_config_set_read_increment(&c,
true);
65 channel_config_set_write_increment(&c,
true);
66 dma_channel_configure(
85 void copy(T* dst, T* src,
int len,
void (*completion_handler)(),
bool startCopy=
true){
86 copy(dst, src, len,
false);
89 dma_channel_set_irq0_enabled(channel_no,
true);
92 irq_set_exclusive_handler(DMA_IRQ_0, completion_handler);
93 irq_set_enabled(DMA_IRQ_0,
true);
96 if (startCopy)
start(channel_no);
110 bool set(T* dst, T src,
int len,
boolean start =
true){
112 Logger.
error(
"Only data up to 32 bytes is supported by DMA");
119 irq_set_enabled(DMA_IRQ_0,
true);
124 dma_channel_config c = dma_channel_get_default_config(channel_no);
125 channel_config_set_transfer_data_size(&c, transferSize());
126 channel_config_set_read_increment(&c,
false);
127 channel_config_set_write_increment(&c,
true);
128 dma_channel_configure(
148 void set(T* dst, T src,
int len,
void (*completion_handler)(),
bool startCopy=
true){
150 set(dst, src, len,
false);
153 dma_channel_set_irq0_enabled(channel_no,
true);
156 irq_set_exclusive_handler(DMA_IRQ_0, completion_handler);
157 irq_set_enabled(DMA_IRQ_0,
true);
160 if (startCopy)
start(channel_no);
166 if (channel_no!=-1) dma_channel_start(channel_no);
171 if (channel_no!=-1) dma_channel_abort(channel_no);
176 if (channel_no!=-1) dma_channel_wait_for_finish_blocking(channel_no);
181 return channel_no==-1 ? true : dma_channel_is_busy(channel_no);
193 dma_channel_transfer_size transferSize() {
206 if (channel_no == -1){
207 channel_no = dma_claim_unused_channel(
true);
We can use the Pico DMA to copy data "in the background" while the processor is doing some other work...
Definition: PicoDMA.h:12
PicoDMA()
Default constructor.
Definition: PicoDMA.h:15
bool set(T *dst, T src, int len, boolean start=true)
Sets a destination array with a fixed value We support only data of the size of uint_8,...
Definition: PicoDMA.h:110
int channel()
provides the used DMA channel - returns -1 if no channel has been set up so far
Definition: PicoDMA.h:41
bool isBusy()
checks if the copy is still in process
Definition: PicoDMA.h:180
void start()
starts the copy
Definition: PicoDMA.h:165
void copy(T *dst, T *src, int len, boolean start=true)
Copies the values of num bytes from the location pointed to by source directly to the memory block po...
Definition: PicoDMA.h:54
void copy(T *dst, T *src, int len, void(*completion_handler)(), bool startCopy=true)
Copies the values of num bytes from the location pointed to by source directly to the memory block po...
Definition: PicoDMA.h:85
void abort()
aborts the copy
Definition: PicoDMA.h:170
~PicoDMA()
Destructor: releases the DMA channel if necessary - if some processing is still going on,...
Definition: PicoDMA.h:18
bool releaseChannel(bool abortProcessing=false)
Releases the DMA channel and makes it available again.
Definition: PicoDMA.h:23
void set(T *dst, T src, int len, void(*completion_handler)(), bool startCopy=true)
Sets a destination array with a fixed value.
Definition: PicoDMA.h:148
void setupChannel()
Provides the next available DMA channel.
Definition: PicoDMA.h:205
void wait()
a blocking wait for the copy to complete
Definition: PicoDMA.h:175
void clearInterrupt()
You need to call this method in the completion handler.
Definition: PicoDMA.h:185
virtual void error(const char *str, const char *str1=nullptr, const char *str2=nullptr)
logs an error
Definition: PicoLogger.h:45
Pico Arduino Framework.
Definition: Arduino.cpp:26