Add utility function for determining the AVR model

This is needed in order to handle slightly different functionality
between the AT90USB64x and AT90USB128x.
This commit is contained in:
Doug Brown 2023-05-28 11:16:28 -07:00 committed by Doug Brown
parent 14cf8505f7
commit a7fe6d9b39

View File

@ -25,6 +25,7 @@
#ifndef HAL_AT90USB646_HARDWARE_H_
#define HAL_AT90USB646_HARDWARE_H_
#include <avr/boot.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
@ -63,4 +64,15 @@ static inline void DelayUS(uint16_t us)
_delay_us(us);
}
/** Determines if this code is running on an AT90USB128x or AT90USB64x
*
* @return True if it's an AT90USB128x, false if AT90USB64x
*/
static inline bool IsAT90USB128x(void)
{
// Read the device signature byte 2 to determine whether this is an
// AT90USB128x or AT90USB64x.
return boot_signature_byte_get(0x0002) == 0x97;
}
#endif /* HAL_AT90USB646_HARDWARE_H_ */