2013-05-02 11:06:15 +00:00
|
|
|
#pragma once
|
|
|
|
#include "ac_cfg.h"
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2013-05-16 17:11:35 +00:00
|
|
|
#if defined(HAVE_LIBFTDI1) && defined(HAVE_LIBUSB_1_0)
|
|
|
|
# if defined(HAVE_LIBUSB_1_0_LIBUSB_H)
|
|
|
|
# include <libusb-1.0/libusb.h>
|
|
|
|
# else
|
|
|
|
# include <libusb.h>
|
|
|
|
# endif
|
|
|
|
# include <libftdi1/ftdi.h>
|
|
|
|
# undef HAVE_LIBFTDI_TYPE_232H
|
|
|
|
# define HAVE_LIBFTDI_TYPE_232H 1
|
|
|
|
#elif defined(HAVE_LIBFTDI) && defined(HAVE_USB_H)
|
|
|
|
/* ftdi.h includes usb.h */
|
2013-05-15 18:55:19 +00:00
|
|
|
#include <ftdi.h>
|
2013-05-16 17:11:35 +00:00
|
|
|
#else
|
|
|
|
#warning No libftdi or libusb support. Install libftdi1/libusb-1.0 or libftdi/libusb and run configure/make again.
|
|
|
|
#define DO_NOT_BUILD_AVRFTDI
|
2013-05-15 18:55:19 +00:00
|
|
|
#endif
|
2013-05-02 11:06:15 +00:00
|
|
|
|
2013-05-16 17:11:35 +00:00
|
|
|
#ifndef DO_NOT_BUILD_AVRFTDI
|
|
|
|
|
2013-05-02 11:06:15 +00:00
|
|
|
#include "pgm.h"
|
2013-05-06 11:48:15 +00:00
|
|
|
#include "pindefs.h"
|
2013-05-02 11:06:15 +00:00
|
|
|
|
2013-05-02 11:07:37 +00:00
|
|
|
enum { ERR, WARN, INFO, DEBUG, TRACE };
|
|
|
|
|
|
|
|
#define __log(lvl, fmt, ...) \
|
|
|
|
do { \
|
|
|
|
avrftdi_log(lvl, __func__, __LINE__, fmt, ##__VA_ARGS__); \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
|
|
#define log_err(fmt, ...) __log(ERR, fmt, ##__VA_ARGS__)
|
|
|
|
#define log_warn(fmt, ...) __log(WARN, fmt, ##__VA_ARGS__)
|
|
|
|
#define log_info(fmt, ...) __log(INFO, fmt, ##__VA_ARGS__)
|
|
|
|
#define log_debug(fmt, ...) __log(DEBUG, fmt, ##__VA_ARGS__)
|
|
|
|
#define log_trace(fmt, ...) __log(TRACE, fmt, ##__VA_ARGS__)
|
|
|
|
|
2013-05-02 11:06:15 +00:00
|
|
|
#define E(x, ftdi) \
|
|
|
|
do { \
|
|
|
|
if ((x)) \
|
|
|
|
{ \
|
|
|
|
fprintf(stderr, "%s:%d %s() %s: %s (%d)\n\t%s\n", \
|
|
|
|
__FILE__, __LINE__, __FUNCTION__, \
|
|
|
|
#x, strerror(errno), errno, ftdi_get_error_string(ftdi)); \
|
|
|
|
return -1; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define E_VOID(x, ftdi) \
|
|
|
|
do { \
|
|
|
|
if ((x)) \
|
|
|
|
{ \
|
|
|
|
fprintf(stderr, "%s:%d %s() %s: %s (%d)\n\t%s\n", \
|
|
|
|
__FILE__, __LINE__, __FUNCTION__, \
|
|
|
|
#x, strerror(errno), errno, ftdi_get_error_string(ftdi)); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
|
|
#define to_pdata(pgm) \
|
|
|
|
((avrftdi_t *)((pgm)->cookie))
|
|
|
|
|
|
|
|
typedef struct avrftdi_s {
|
|
|
|
/* pointer to struct maintained by libftdi to identify the device */
|
|
|
|
struct ftdi_context* ftdic;
|
|
|
|
/* bitmask of values for pins. bit 0 represents pin 0 ([A|B]DBUS0) */
|
|
|
|
uint16_t pin_value;
|
|
|
|
/* bitmask of pin direction. a '1' make a pin an output.
|
|
|
|
* bit 0 corresponds to pin 0. */
|
|
|
|
uint16_t pin_direction;
|
|
|
|
/* don't know. not useful. someone put it in. */
|
|
|
|
uint16_t led_mask;
|
|
|
|
/* total number of pins supported by a programmer. varies with FTDI chips */
|
|
|
|
int pin_limit;
|
|
|
|
/* internal RX buffer of the device. needed for INOUT transfers */
|
|
|
|
int rx_buffer_size;
|
2013-06-19 17:40:32 +00:00
|
|
|
/* use bitbanging instead of mpsse spi */
|
|
|
|
bool use_bitbanging;
|
2013-05-02 11:06:15 +00:00
|
|
|
} avrftdi_t;
|
|
|
|
|
2013-05-03 12:55:24 +00:00
|
|
|
void avrftdi_log(int level, const char * func, int line, const char * fmt, ...);
|
2013-05-02 11:06:15 +00:00
|
|
|
|
2013-05-16 17:11:35 +00:00
|
|
|
#endif /* DO_NOT_BUILD_AVRFDTI */
|
2013-05-02 11:07:16 +00:00
|
|
|
|