Greetings Freaks -
I am mucking around in the Arduino twi module for M4809 and friends written by Microchip. I've made a few changes to help it run well as a c module but that mostly involved interrupt handling, as I recall. twi.c contains this:
/* Master variables */ static register8_t master_slaveAddress; /*!< Slave address */ static register8_t* master_writeData; /*!< Data to write */ static register8_t* master_readData; /*!< Read data */ static register8_t master_bytesToWrite; /*!< Number of bytes to write */ static register8_t master_bytesToRead; /*!< Number of bytes to read */ static register8_t master_bytesWritten; /*!< Number of bytes written */ static register8_t master_bytesRead; /*!< Number of bytes read */ static register8_t master_sendStop; /*!< To send a stop at the end of the transaction or not */ static register8_t master_trans_status; /*!< Status of transaction */ static register8_t master_result; /*!< Result of transaction */
And in twi.h, there is
/*! Master Transaction result enumeration. */ typedef enum TWIM_RESULT_enum { TWIM_RESULT_UNKNOWN = (0x00<<0), TWIM_RESULT_OK = (0x01<<0), TWIM_RESULT_BUFFER_OVERFLOW = (0x02<<0), TWIM_RESULT_ARBITRATION_LOST = (0x03<<0), TWIM_RESULT_BUS_ERROR = (0x04<<0), TWIM_RESULT_NACK_RECEIVED = (0x05<<0), TWIM_RESULT_FAIL = (0x06<<0), } TWIM_RESULT_t;
Now, I am compiling this with our AS7/gcc and get no complaints about typedef register8_t. I am puzzled because they seem to be able to assign values from that typedef'd enum (shown above) to master_result without any casting. Can someone explain what is going on, here? In the code module, I can find no other reference to either TWIM_RESULT_enum or TWIM_RESULT_t.
And, why all the "static" declarations? These are declared globally to the module.
And, in the enum, why all the, for example, (0x06<<0) statements? If the value is left-shifted zero times, what is wrong with, for example, 0x06? Why make it more complicated than it needs to be? Oh, sorry, I forgot. This is Arduino code!
Many thanks
Jim