Page 1 of 1

Function with variable parameters in viper emitter

Posted: Thu Oct 18, 2018 1:36 pm
by kak
Hi.

I want to write a function, that can either read or write directly to memory.

It should have variable parameters, so that:

Code: Select all

mem32(address, data)
Writes to memory, while

Code: Select all

result = mem32(address)
reads from memory.
The problem is, to be able to access the memory directly, I have to use @micropython.viper, to be able to use pointers.

Does anybody know how to write such a function? As I'm in viper, I obviously can't check a parameter for being 'none', and I've got no idea how to do it in another way.

Thanks in advance.

Re: Function with variable parameters in viper emitter

Posted: Thu Oct 18, 2018 1:52 pm
by Roberthh
I do not know the answer, unless you have a special "out of band" value for data. If data is a byte value, e.g. 256. Otherwise I would make two functions for reading and writing.

You don't need Viper

Posted: Fri Oct 19, 2018 8:52 am
by pythoncoder
You can address memory directly without using Viper. See recent discussions of the uctypes module, for example this thread.