arduino - efficient prepending to array -


i porting 1 of known libraries arduino called i2cdevlib embedded system. , meet problem, time far being first one, when function interface looks like:

void function(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint8_t len); 

and need firstly write dev_addr i2c bus reg_addr , data. i2c driver(i use 1 keil mdk packs) function used send data i2c bus has definition this:

void send_i2c(uint8_t dev_addr, uint8_t *data, uint8_t len); 

and because of i2c properties can not call sequentially. every time when function called have create new array, set first item reg_addr , memcpy data looks awful , seems not efficient(to honest there little data flow when working these sensors nevertheless...). can not see solution except modifying i2c driver or writing new 1 don't feel rewriting sustainable , tested driver because of 1 function.

so there way improve solution without doing this?

the problem how i2cdevlib implemented. should not force user specify register address, because i2c protocol not mandate having 8-bit register address write to. devices do, might not.

what need send register address payload without sending stop bit. should if keil mdk has i2c function allows send data byte per byte without interrupting transmission. way function send register address each byte of payload separately.

this introduces overhead of multiple function calls, unless calls inlined compiler. if calls simple should inlined, there no guarantee be.

the other thing dig deep manual mcu, find i2c registers, how work , implement own i2c routines. requires lot more work on end.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -