File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -445,6 +445,8 @@ class UioIf:
445445 ...
446446 def read_bulk (self , arg0 : typing .SupportsInt , arg1 : typing .SupportsInt ) -> numpy .typing .NDArray [numpy .uint8 ]:
447447 ...
448+ def write_bulk (self , arg0 : typing .SupportsInt , arg1 : bytes ) -> None :
449+ ...
448450 def wait_for_interrupt (self ) -> int :
449451 ...
450452class UioMemSgdma (UioIf ):
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ class UioIf_PyPublishHelper : public udmaio::UioIf {
3232 using udmaio::UioIf::_wr32;
3333 using udmaio::UioIf::arm_interrupt;
3434 using udmaio::UioIf::read_bulk;
35+ using udmaio::UioIf::write_bulk;
3536 using udmaio::UioIf::UioIf;
3637 using udmaio::UioIf::wait_for_interrupt;
3738};
@@ -119,7 +120,19 @@ PYBIND11_MODULE(binding, m) {
119120 {sizeof (uint8_t )}, // stride
120121 reinterpret_cast <uint8_t *>(vec->data ()), // data pointer
121122 gc_callback);
122- });
123+ })
124+ .def (" write_bulk" ,
125+ [](UioIf_PyPublishHelper& self, uint32_t offs, py::buffer b) {
126+ py::buffer_info info = b.request ();
127+ // Accept only contiguous 1-D buffers
128+ if (info.ndim != 1 ) {
129+ throw std::runtime_error (" write_bulk expects a 1-D bytes-like object" );
130+ }
131+ auto ptr = static_cast <uint8_t *>(info.ptr );
132+ std::vector<uint8_t > data (ptr, ptr + info.size * info.itemsize );
133+ self.write_bulk (offs, std::move (data));
134+ },
135+ " Write a contiguous bytes-like object to the mapped device memory at the given offset" );
123136
124137 py::class_<udmaio::DmaBufferAbstract, std::shared_ptr<udmaio::DmaBufferAbstract>>(
125138 m,
You can’t perform that action at this time.
0 commit comments