forked from mfulz_github/qmk_firmware
Add VTARGET level detection to the AVRISP project on supported AVR models.
This commit is contained in:
parent
244bba2097
commit
17d06b8494
|
@ -35,7 +35,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// TODO: Add in software SPI for lower programming speeds below 125KHz
|
// TODO: Add in software SPI for lower programming speeds below 125KHz
|
||||||
// TODO: Add in VTARGET detection
|
|
||||||
// TODO: Add reversed target connector checks
|
// TODO: Add reversed target connector checks
|
||||||
|
|
||||||
#include "AVRISP.h"
|
#include "AVRISP.h"
|
||||||
|
@ -53,7 +52,12 @@ int main(void)
|
||||||
|
|
||||||
for (;;)
|
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();
|
USB_USBTask();
|
||||||
}
|
}
|
||||||
|
@ -73,6 +77,13 @@ void SetupHardware(void)
|
||||||
LEDs_Init();
|
LEDs_Init();
|
||||||
USB_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 */
|
/* Millisecond timer initialization for timeout checking */
|
||||||
OCR0A = ((F_CPU / 64) / 1000);
|
OCR0A = ((F_CPU / 64) / 1000);
|
||||||
TCCR0A = (1 << WGM01);
|
TCCR0A = (1 << WGM01);
|
||||||
|
|
|
@ -46,8 +46,12 @@
|
||||||
|
|
||||||
#include <LUFA/Version.h>
|
#include <LUFA/Version.h>
|
||||||
#include <LUFA/Drivers/Board/LEDs.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"
|
#include "Lib/V2Protocol.h"
|
||||||
|
|
||||||
/* Macros: */
|
/* Macros: */
|
||||||
|
@ -61,7 +65,7 @@
|
||||||
#define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
|
#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. */
|
/** 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: */
|
/* Function Prototypes: */
|
||||||
void SetupHardware(void);
|
void SetupHardware(void);
|
||||||
|
|
|
@ -60,9 +60,12 @@
|
||||||
*
|
*
|
||||||
* Note that this design currently has several limitations:
|
* Note that this design currently has several limitations:
|
||||||
* - Minimum target clock speed of 500KHz due to hardware SPI used
|
* - Minimum target clock speed of 500KHz due to hardware SPI used
|
||||||
* - No VTARGET detection and notification
|
|
||||||
* - No reversed/shorted target connector 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
|
* \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.
|
* 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>Makefile CDEFS</td>
|
||||||
* <td>Mask for the programmer's target RESET line on the chosen port.</td>
|
* <td>Mask for the programmer's target RESET line on the chosen port.</td>
|
||||||
* </tr>
|
* </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>
|
* </table>
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -60,7 +60,7 @@
|
||||||
|
|
||||||
|
|
||||||
# MCU name
|
# MCU name
|
||||||
MCU = at90usb647
|
MCU = at90usb1287
|
||||||
|
|
||||||
|
|
||||||
# Target board (see library "Board Types" documentation, USER or blank for projects not requiring
|
# 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_PORT=PORTB
|
||||||
CDEFS += -DRESET_LINE_DDR=DDRB
|
CDEFS += -DRESET_LINE_DDR=DDRB
|
||||||
CDEFS += -DRESET_LINE_MASK="(1 << 4)"
|
CDEFS += -DRESET_LINE_MASK="(1 << 4)"
|
||||||
|
CDEFS += -DVTARGET_ADC_CHANNEL=2
|
||||||
|
|
||||||
|
|
||||||
# Place -D or -U options here for ASM sources
|
# Place -D or -U options here for ASM sources
|
||||||
|
|
Loading…
Reference in New Issue