Greetings Freaks -
Here is a situation that has been nagging at me for some time. This happens to be a function in the MC-written TWI module for Mega0/1 AVRs:
uint8_t TWI_MasterWrite(uint8_t slave_address, uint8_t *write_data, uint8_t bytes_to_write, uint8_t send_stop)
Now, suppose that I want to write two bytes. And those two bytes are #def'd constants. The first just happens to be a register address and the second is the data that goes into that register. My first inclination is to do:
uint8_t DataBuf[] = {CONTROL_REG, CONTROL_BYTE}; uint8_t RetVal = TWI_MasterWrite(DEVADDR,DataBuf,2,TRUE);
But, that seems wasteful with a lot of "just shuffling bytes around". IS this the preferred way to do it?
Its even worse when you do a 1 byte write (register address) and a 1 byte read (register contents). Then, you have pointers to 1 byte variables and it would seem that you have to create local variables to hold those #def'd constants rather than use the constants directly in the parameter list. Anything better when you are starting with a function that someone else has created?
Collateral question: I have seen this style of parameter listing in FatFS and now this library. I am not sure that I like it but I guess that I could get used to it. I can see a few advantages. Thoughts?
Thanks
Jim