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