Get rid of the macros; inline them. Cast some values to uint8_t.