I’m developing an SSD1306 I2C driver and when sending data over the bus to the device the sequence to copy directly to the device Ram starts with 0x40 and end with an I2C stop.
So for example in micropython one would have the following code snippet:
self.i2c.start() self.i2c.write(0x40) self.i2c.write(buf) self.i2c.stop()
This does not work in Zerynth because the I2C write() seems to initiate an I2C start then send the data and stop.
Results in no data being recognised as there is an I2C bus stop after sending 0x40 signalling data transmission has ended.
Without being able to control the low level I2C bus state then a simple way would be to have code like the following:
screen_buffer_length = width//8 x height # Assume 8 bits per byte wbuf=bytearray(1+screen_buffer_length) # Data write buffer sbuf=memoryview(wbuf)[1:screen_buffer_length) # Screen buffer # Do stuff in the buffer like pixels, text self.write(wbuf) # Performs I2C start, sends 0x40 then the screen buffer data, I2C stop
Alas memoryview causes a compile error with:
Can’t find name [memoryview] in …
So one has to have two buffers and just before sending perform:
wbuf[1:screen_buffer_length+1] = sbuf
Or the code has to offset by 1 byte every time it manipulates the buffer which adds complexity / slows down the code i.e. function call.
A more elegant solution would be to implement memoryview and or make I2C stop and start controllable in Python.