rkompass / RPi2040_mPy

7 stars 1 forks source link

I wrote my own dma class for RPI2040, inspired by https://github.com/robert-hh/RP2040-Examples/tree/master/rp2_util.

The idea was to minimize configuration arguments by writing helper functions that check the type of source and destination and deliver these. For example:

def par_bytearray(obj, src):
    return (addressof(obj), 1, len(obj), 0, None) if isinstance(obj, bytearray) else None

checks, if an argument (source, if src==1, else destination) is of type bytearray. If so, it returns a tuple containing

Usage:

from rp2_dma import RP2_Dma

src_arr = array('i', (i for i in range(-10, 9_990)))
dst_arr = array('L', (0 for _ in range(11_000)))   # may be longer than the source; dma takes the minimum of both counts

dma = RP2_Dma(sarr,  darr)
dma.start()

Dma becomes as simple as putting in the two objects. Of course the configuration parameters may be specified explicitly, thus overriding the extracted ones.

init(self, source, dest, rw_incr=None, cycle=None, count=None, dsize=None, dreq=None, chan=None)

At present there are helper functions for objects of type:

I plan to add I2C and SPI helpers too.

Once a dma object is instantiated you can use the following member functions:

There are 5 examples: