#ifndef __AVRUTIL_H__
#define __AVRUTIL_H__

#include <stdint.h>

#ifndef NULL
#define NULL ((void*) 0)
#endif

/* On a attiny861 this was found to be valid:
  t8[0] == (t32     & 0xff) == (t16[0]    & 0xff)
  t8[1] == (t32>> 8 & 0xff) == (t16[0]>>8 & 0xff)
  t8[2] == (t32>>16 & 0xff) == (t16[1]    & 0xff)
  t8[4] == (t32>>24 & 0xff) == (t16[1]>>8 & 0xff)
 */
union lwb { // union of Long Word Byte
  uint32_t t32;
  uint16_t t16[2];
  uint8_t  t8[4];
};

/*
// for debugging only?
int8_t util_sizes(void);

int8_t util_sizes(void) {
  const char s1[] = "sizeof(unsigned int ) = ";
  const char s2[] = "sizeof(unsigned long) = ";
  buff_write(s1, strlen(s1));
  buff_uint8(sizeof(unsigned int)); // = 2, last time I checked
  buff_nl();
  buff_write(s2, strlen(s2));
  buff_uint8(sizeof(unsigned long int)); // = 4
  return buff_nl();
}
*/

#endif
