-
Hi guys, I am currently working on a tft display driver. The tft panel is huge, 536*240. For 16bits-color, a whole frame will take roughly 250KB of ram. By doing this, I learned, that using a framebuffer in C modules can be very dangerous. Since the C modules have no idea about if either a section of RAM has been used or not, it could cause data corruption. In my case, the device just triggered a reset. Half of the amount RAM I needed is quite stable, but again, I have no idea if it is guaranteed, not to use the section that has meaningful data. If I use the bytearray, I could not find a way to modify it in the C module, hence I have to use a Frambuffer in the framebuf module. This cost me 22% performance. (Simply filling the whole screen with one color dropped down to 54 fps from 66 fps) So... ye... I really do not want to do complicated drawing in python, since they will be done very slowly. Since I am also new to C and python and tft drivers, please do assume that I haven't thought through some very simple and effective solutions and please do let me know about those! Thank you very much in advance! ps. chunking is not preferred, unless there is a way to guarantee that the buffer for the chunks are safe to use. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 15 replies
-
You can pass a readable and writable bytearray to a C module quite easily, in fact the following example function in a C module will accept a bytearray, memoryview or array (or any r/w python object which supports the "buffer protocol") (I'm not sure if that actually will help with your application): STATIC mp_obj_t my_function(mp_obj_t buf_obj) {
// Get a pointer to the data of the supplied buffer (eg. bytearray)
mp_buffer_info_t buf;
mp_get_buffer_raise(buf_obj, &buf, MP_BUFFER_RW);
// buf.len is length of the supplied data buffer.
// buf.buf is a void * ptr to the contiguous data underlying the bytearray or array
// Process the bytearray underlying data....
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mymod_my_function, my_function); I assume you know how to add that function to your module. |
Beta Was this translation helpful? Give feedback.
You can pass a readable and writable bytearray to a C module quite easily, in fact the following example function in a C module will accept a bytearray, memoryview or array (or any r/w python object which supports the "buffer protocol") (I'm not sure if that actually will help with your application):