#ifndef _USB_DEBUG_H_
#define _USB_DEBUG_H_

#ifdef USB_ENABLE           /* include stuff for USB debug functions */

#include <cdcdf_acm.h>
#include <string.h>
#include <stdio.h>

char debug_buf[255] __attribute((aligned(4)));
#define debug(fmt, ...) \
        do { \
                sprintf(debug_buf, "%s:%d: " fmt "\r\n", __FILE__, __LINE__, ##__VA_ARGS__); \
                cdcdf_acm_write((uint8_t*)debug_buf, strlen(debug_buf));    \
        } while (0)

#define print(fmt, ...)                         \
        do { \
                sprintf(debug_buf, fmt "\r\n", ##__VA_ARGS__); \
                cdcdf_acm_write((uint8_t*)debug_buf, strlen(debug_buf));    \
        delay_ms(2); \
        } while (0)

#define printf(fmt, ...)                         \
        do { \
                sprintf(debug_buf, fmt, ##__VA_ARGS__); \
                cdcdf_acm_write((uint8_t*)debug_buf, strlen(debug_buf));    \
        delay_ms(2); \
        } while (0)

#else  /* USB_ENABLE not defined, don't include string.h, stdio.h, etc */

#define debug(fmt, ...)

#endif  /* USB_ENABLE */

#endif  /* _USB_DEBUG_H_ */
