Skip to content
Snippets Groups Projects
Commit 9c802777 authored by Erik Strand's avatar Erik Strand
Browse files

Echo my board's address over virtual serial

parent 804e80a2
No related branches found
No related tags found
No related merge requests found
......@@ -79,10 +79,13 @@ int main(void)
{
SetupHardware();
PORTC.DIRSET = (1 << 5) | (1u << 6) | (1u << 7);
PORTC.OUTSET = (1 << 5) | (1u << 6) | (1u << 7);
/* Create a regular character stream for the interface so that it can be used with the stdio.h functions */
CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
//LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
GlobalInterruptEnable();
for (;;)
......@@ -120,18 +123,30 @@ void SetupHardware(void)
#endif
/* Hardware Initialization */
Joystick_Init();
LEDs_Init();
//Joystick_Init();
//LEDs_Init();
USB_Init();
}
/** Checks for changes in the position of the board joystick, sending strings to the host upon each change. */
void CheckJoystickMovement(void)
{
uint8_t JoyStatus_LCL = Joystick_GetStatus();
//uint8_t JoyStatus_LCL = Joystick_GetStatus();
char* ReportString = NULL;
static bool ActionSent = false;
//static bool ActionSent = false;
ReportString = "00000000";
unsigned address = USB.ADDR;
if (address & (1u < 0)) { ReportString[0] = '1'; }
if (address & (1u < 1)) { ReportString[1] = '1'; }
if (address & (1u < 2)) { ReportString[2] = '1'; }
if (address & (1u < 3)) { ReportString[3] = '1'; }
if (address & (1u < 4)) { ReportString[4] = '1'; }
if (address & (1u < 5)) { ReportString[5] = '1'; }
if (address & (1u < 6)) { ReportString[6] = '1'; }
if (address & (1u < 7)) { ReportString[7] = '1'; }
/*
if (JoyStatus_LCL & JOY_UP)
ReportString = "Joystick Up\r\n";
else if (JoyStatus_LCL & JOY_DOWN)
......@@ -144,29 +159,36 @@ void CheckJoystickMovement(void)
ReportString = "Joystick Pressed\r\n";
else
ActionSent = false;
*/
fputs(ReportString, &USBSerialStream);
/*
if ((ReportString != NULL) && (ActionSent == false))
{
ActionSent = true;
/* Write the string to the virtual COM port via the created character stream */
// Write the string to the virtual COM port via the created character stream
fputs(ReportString, &USBSerialStream);
/* Alternatively, without the stream: */
// Alternatively, without the stream:
// CDC_Device_SendString(&VirtualSerial_CDC_Interface, ReportString);
}
*/
}
/** Event handler for the library USB Connection event. */
void EVENT_USB_Device_Connect(void)
{
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
//LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
PORTC.OUTCLR = (1 << 5);
}
/** Event handler for the library USB Disconnection event. */
void EVENT_USB_Device_Disconnect(void)
{
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
//LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
PORTC.OUTSET = (1 << 5);
}
/** Event handler for the library USB Configuration Changed event. */
......@@ -175,14 +197,16 @@ void EVENT_USB_Device_ConfigurationChanged(void)
bool ConfigSuccess = true;
ConfigSuccess &= CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface);
PORTC.OUTTGL = (1 << 6);
LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
//LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
}
/** Event handler for the library USB Control Request reception event. */
void EVENT_USB_Device_ControlRequest(void)
{
CDC_Device_ProcessControlRequest(&VirtualSerial_CDC_Interface);
PORTC.OUTTGL = (1 << 7);
}
/** CDC class driver callback function the processing of changes to the virtual
......
......@@ -46,8 +46,8 @@
#include "Descriptors.h"
#include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Drivers/Board/Joystick.h>
//#include <LUFA/Drivers/Board/LEDs.h>
//#include <LUFA/Drivers/Board/Joystick.h>
#include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Platform/Platform.h>
......
......@@ -11,10 +11,10 @@
# Run "make help" for target help.
MCU = at90usb1287
ARCH = AVR8
BOARD = USBKEY
F_CPU = 8000000
MCU = atxmega128a4u
ARCH = XMEGA
BOARD = BOARD_USER
F_CPU = 48000000
F_USB = $(F_CPU)
OPTIMIZATION = s
TARGET = VirtualSerial
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment