Function with variable parameters in viper emitter

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
kak
Posts: 22
Joined: Fri Oct 05, 2018 11:35 am

Function with variable parameters in viper emitter

Post by kak » Thu Oct 18, 2018 1:36 pm

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.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Function with variable parameters in viper emitter

Post by Roberthh » Thu Oct 18, 2018 1:52 pm

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.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

You don't need Viper

Post by pythoncoder » Fri Oct 19, 2018 8:52 am

You can address memory directly without using Viper. See recent discussions of the uctypes module, for example this thread.
Peter Hinch
Index to my micropython libraries.

Post Reply