main.h 762 B

123456789101112131415161718192021
  1. #ifndef _MAIN_H_
  2. #define _MAIN_H_
  3. // Calculate the byte offset of a field in a structure of type type.
  4. #define FIELD_OFFSET(type, field) ((uint32_t)(uint32_t*)&(((type *)0)->field))
  5. // Calculate the size of a field in a structure of type type
  6. #define FIELD_SIZE(type, field) (sizeof(((type *)0)->field))
  7. // Calculate the size from field1 to field2 (inclusive)
  8. #define FIELD_SIZE_THROUGH(type, field1, field2) \
  9. (FIELD_OFFSET(type, field2) + FIELD_SIZE(type, field2) - FIELD_OFFSET(type, field1))
  10. #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
  11. #define I2C_MAX_BUFFER 20
  12. void I2C_Write(int DeviceAddress, char RegAddress, char *Data, int Length);
  13. void I2C_Read(int DeviceAddress, char RegAddress, char *Data, int Length);
  14. #endif