*/\r
\r
// TODO: Add in software SPI for lower programming speeds below 125KHz\r
-// TODO: Add in VTARGET detection\r
// TODO: Add reversed target connector checks\r
\r
#include "AVRISP.h"\r
\r
for (;;)\r
{
- Process_AVRISP_Commands();
+ Process_AVRISP_Commands();\r
+ \r
+ #if defined(ADC)\r
+ /* Update VTARGET parameter with the latest ADC conversion of VTARGET on supported AVR models */\r
+ V2Params_SetParameterValue(PARAM_VTARGET, ((5 * 10 * ADC_GetResult()) / 1024));\r
+ #endif
\r
USB_USBTask();\r
}\r
LEDs_Init();\r
USB_Init();\r
\r
+ #if defined(ADC)\r
+ /* Initialize the ADC converter for VTARGET level detection on supported AVR models */\r
+ ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_128);\r
+ ADC_SetupChannel(VTARGET_ADC_CHANNEL);\r
+ ADC_StartReading(VTARGET_ADC_CHANNEL | ADC_RIGHT_ADJUSTED | ADC_REFERENCE_AVCC);\r
+ #endif\r
+ \r
/* Millisecond timer initialization for timeout checking */\r
OCR0A = ((F_CPU / 64) / 1000);\r
TCCR0A = (1 << WGM01);\r
\r
#include <LUFA/Version.h>\r
#include <LUFA/Drivers/Board/LEDs.h>\r
- #include <LUFA/Drivers/USB/USB.h>
-
+ #include <LUFA/Drivers/USB/USB.h>\r
+ \r
+ #if defined(ADC)
+ #include <LUFA/Drivers/Peripheral/ADC.h>\r
+ #endif\r
+
#include "Lib/V2Protocol.h"\r
\r
/* Macros: */
#define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)\r
\r
/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */\r
- #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) \r
+ #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)\r
\r
/* Function Prototypes: */\r
void SetupHardware(void);\r
*\r
* Note that this design currently has several limitations:\r
* - Minimum target clock speed of 500KHz due to hardware SPI used\r
- * - No VTARGET detection and notification\r
* - No reversed/shorted target connector detection and notification\r
*\r
+ * On AVR models with an ADC converter, ACC should be tied to 5V (e.g. VBUS) and the VTARGET_ADC_CHANNEL token should be\r
+ * set to an appropriate ADC channel number in the project makefile for VTARGET detection to operate correctly. On models\r
+ * without an ADC converter, VTARGET will report at a fixed 5V level.\r
+ *\r
* \section SSec_Options Project Options\r
*\r
* The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value.\r
* <td>Makefile CDEFS</td>\r
* <td>Mask for the programmer's target RESET line on the chosen port.</td>\r
* </tr>\r
+ * <tr>\r
+ * <td>VTARGET_ADC_CHANNEL</td>\r
+ * <td>Makefile CDEFS</td>\r
+ * <td>ADC channel number (on supported AVRs) to use for VTARGET level detection.</td> \r
+ * </tr>\r
* </table>\r
*/\r
\r
\r
# MCU name\r
-MCU = at90usb647\r
+MCU = at90usb1287\r
\r
\r
# Target board (see library "Board Types" documentation, USER or blank for projects not requiring\r
CDEFS += -DRESET_LINE_PORT=PORTB\r
CDEFS += -DRESET_LINE_DDR=DDRB\r
CDEFS += -DRESET_LINE_MASK="(1 << 4)"\r
+CDEFS += -DVTARGET_ADC_CHANNEL=2\r
\r
\r
# Place -D or -U options here for ASM sources\r