LUFA ships with several basic pre-made board drivers, to control hardware present on the supported board hardware - such as Dataflash ICs, LEDs, Joysticks, or other hardware peripherals. When compiling an application which makes use of one or more board drivers located in LUFA/Drivers/Board, you must also indicate which board hardware you are using in your project makefile. This is done by defining the BOARD
macro using the -D
switch passed to the compiler, with a constant of BOARD_{Name}
. For example, -DBOARD=BOARD_USBKEY
instructs the compiler to use the USBKEY board hardware drivers.
If your application does not use any board level drivers, you can omit the definition of the BOARD
macro. However, some users may wish to write their own custom board hardware drivers which are to remain compatible with the LUFA hardware API. To do this, the BOARD
macro should be defined to the value BOARD_USER
. This indicates that the board level drivers should be located in a folder named "Board" located inside the application's folder.
When used, the driver stub files located in the LUFA/CodeTemplates/DriverStubs
folder should be copied to the user application's Board/
directory, and filled out to include the values and code needed to control the custom board hardware. Once done, the existing LUFA board level APIs (accessed in the regular LUFA/Drivers/Board/
folder) will redirect to the user board drivers, maintaining code compatibility and allowing for a different board to be selected through the project makefile with no code changes.
Board Driver Templates
The templates for each board driver are reproduced below.
Template for USER <Board/Board.h>
#ifndef __BOARD_USER_H__
#define __BOARD_USER_H__
#if defined(__cplusplus)
extern "C" {
#endif
#if !defined(__INCLUDE_FROM_BOARD_H)
#error Do not include this file directly. Include LUFA/Drivers/Board/Board.h instead.
#endif
#if defined(__cplusplus)
}
#endif
#endif
Template for USER <Board/Buttons.h>
#ifndef __BUTTONS_USER_H__
#define __BUTTONS_USER_H__
#if defined(__cplusplus)
extern "C" {
#endif
#if !defined(__INCLUDE_FROM_BUTTONS_H)
#error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead.
#endif
#define BUTTONS_BUTTON1
#if !defined(__DOXYGEN__)
{
}
{
}
{
}
#endif
#if defined(__cplusplus)
}
#endif
#endif
#define ATTR_WARN_UNUSED_RESULT
Definition: Attributes.h:74
Template for USER <Board/Dataflash.h>
#ifndef __DATAFLASH_USER_H__
#define __DATAFLASH_USER_H__
#if !defined(__INCLUDE_FROM_DATAFLASH_H)
#error Do not include this file directly. Include LUFA/Drivers/Board/Dataflash.h instead.
#endif
#if !defined(__DOXYGEN__)
#define DATAFLASH_CHIPCS_MASK
#define DATAFLASH_CHIPCS_DDR
#define DATAFLASH_CHIPCS_PORT
#endif
#define DATAFLASH_TOTALCHIPS 1
#define DATAFLASH_NO_CHIP 0
#define DATAFLASH_CHIP1
#define DATAFLASH_CHIP2
#define DATAFLASH_PAGE_SIZE
#define DATAFLASH_PAGES
#if !defined(__DOXYGEN__)
{
DATAFLASH_CHIPCS_DDR |= DATAFLASH_CHIPCS_MASK;
DATAFLASH_CHIPCS_PORT |= DATAFLASH_CHIPCS_MASK;
}
{
}
{
}
{
}
{
return (~DATAFLASH_CHIPCS_PORT & DATAFLASH_CHIPCS_MASK);
}
{
DATAFLASH_CHIPCS_PORT = ((DATAFLASH_CHIPCS_PORT | DATAFLASH_CHIPCS_MASK) & ~ChipMask);
}
{
}
{
return;
#if (DATAFLASH_TOTALCHIPS == 2)
if (PageAddress & 0x01)
else
#else
#endif
}
{
}
{
}
const uint16_t BufferByte)
{
#if (DATAFLASH_TOTALCHIPS == 2)
PageAddress >>= 1;
#endif
}
#endif
#endif
#define DATAFLASH_PAGES
Definition: Dataflash.h:81
#define DATAFLASH_CHIP2
Definition: Dataflash.h:75
#define DATAFLASH_CHIP1
Definition: Dataflash.h:72
#define DATAFLASH_NO_CHIP
Definition: Dataflash.h:69
#define DATAFLASH_TOTALCHIPS
Definition: Dataflash.h:66
#define DF_CMD_GETSTATUS
Definition: AT45DB321C.h:59
#define DF_STATUS_READY
Definition: AT45DB321C.h:52
static uint8_t Dataflash_TransferByte(const uint8_t Byte) ATTR_ALWAYS_INLINE
Definition: Dataflash.h:110
static void Dataflash_DeselectChip(void) ATTR_ALWAYS_INLINE
Definition: Dataflash.h:159
static void Dataflash_SelectChip(const uint8_t ChipMask) ATTR_ALWAYS_INLINE
Definition: Dataflash.h:152
static uint8_t Dataflash_ReceiveByte(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT
Definition: Dataflash.h:130
static void Dataflash_Init(void)
Definition: Dataflash.h:95
static void Dataflash_WaitWhileBusy(void)
Definition: Dataflash.h:197
static void Dataflash_SendAddressBytes(uint16_t PageAddress, const uint16_t BufferByte)
Definition: Dataflash.h:211
static void Dataflash_SendByte(const uint8_t Byte) ATTR_ALWAYS_INLINE
Definition: Dataflash.h:120
static void Dataflash_ToggleSelectedChipCS(void)
Definition: Dataflash.h:186
static void Dataflash_SelectChipFromPage(const uint16_t PageAddress)
Definition: Dataflash.h:173
static uint8_t Dataflash_GetSelectedChip(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT
Definition: Dataflash.h:141
#define ATTR_ALWAYS_INLINE
Definition: Attributes.h:96
Template for USER <Board/Joystick.h>
#ifndef __JOYSTICK_USER_H__
#define __JOYSTICK_USER_H__
#if defined(__cplusplus)
extern "C" {
#endif
#if !defined(__INCLUDE_FROM_JOYSTICK_H)
#error Do not include this file directly. Include LUFA/Drivers/Board/Joystick.h instead.
#endif
#define JOY_LEFT
#define JOY_RIGHT
#define JOY_UP
#define JOY_DOWN
#define JOY_PRESS
#if !defined(__DOXYGEN__)
{
}
{
}
{
}
#endif
#if defined(__cplusplus)
}
#endif
#endif
static void Joystick_Disable(void)
static uint_reg_t Joystick_GetStatus(void) ATTR_WARN_UNUSED_RESULT
static void Joystick_Init(void)
Template for USER <Board/LEDs.h>
#ifndef __LEDS_USER_H__
#define __LEDS_USER_H__
#if defined(__cplusplus)
extern "C" {
#endif
#if !defined(__INCLUDE_FROM_LEDS_H)
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
#endif
#define LEDS_LED1
#define LEDS_LED2
#define LEDS_LED3
#define LEDS_LED4
#define LEDS_ALL_LEDS (LEDS_LED1 | LEDS_LED2 | LEDS_LED3 | LEDS_LED4)
#define LEDS_NO_LEDS 0
#if !defined(__DOXYGEN__)
{
}
{
}
{
}
{
}
{
}
static inline void LEDs_ChangeLEDs(
const uint8_t LEDMask,
const uint8_t ActiveMask)
{
}
{
}
{
}
#endif
#if defined(__cplusplus)
}
#endif
#endif
static void LEDs_ToggleLEDs(const uint_reg_t LEDMask)
static uint_reg_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT
static void LEDs_SetAllLEDs(const uint_reg_t LEDMask)
static void LEDs_ChangeLEDs(const uint_reg_t LEDMask, const uint_reg_t ActiveMask)
static void LEDs_Disable(void)
static void LEDs_TurnOnLEDs(const uint_reg_t LEDMask)
static void LEDs_Init(void)
static void LEDs_TurnOffLEDs(const uint_reg_t LEDMask)