MCUdude / MegaCore

Arduino hardware package for ATmega64, ATmega128, ATmega165, ATmega169, ATmega325, ATmega329, ATmega640, ATmega645, ATmega649, ATmega1280, ATmega1281, ATmega2560, ATmega2561, ATmega3250, ATmega3290, ATmega6450, ATmega6490, AT90CAN32, AT90CAN64 and AT90CAN128
Other
384 stars 118 forks source link

Don't waste RAM in the low-level TWI Wire drivers. #196

Closed dewhisna closed 1 year ago

dewhisna commented 1 year ago

Apply MCUdude/MiniCore#245 to this MegaCore repo.

Since twi_readFrom() and twi_writeTo() are both blocking functions, there is no need to allocate a special twi_masterBuffer. Doing so wastes valuable RAM, uses extra time to copy the data to the secondary buffer, and limits the transfer size to TWI_BUFFER_SIZE. Instead, it only needs a pointer to the buffer for the IRQ to use for the transfer. And, if asynchronous non-blocking functions are ever added, which will require a different API and callbacks, etc., then the existing txBuffer and rxBuffer for slave mode can just be used there too, since master mode and slave mode can't both be active at the same time.

MCUdude commented 1 year ago

Perfect, thanks!