Prepared to use UART.
This commit is contained in:
parent
27f015ea00
commit
f0eeb38c49
2 changed files with 48 additions and 25 deletions
|
@ -70,6 +70,9 @@ int main(void)
|
|||
{
|
||||
SetupHardware();
|
||||
|
||||
|
||||
uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) );
|
||||
|
||||
SET_ERR_MASK(ERRMASK_USB_NOTREADY);
|
||||
GlobalInterruptEnable();
|
||||
|
||||
|
@ -77,6 +80,7 @@ int main(void)
|
|||
{
|
||||
CDC1_Task();
|
||||
CDC2_Task();
|
||||
|
||||
USB_USBTask();
|
||||
}
|
||||
}
|
||||
|
@ -220,8 +224,6 @@ void CDC1_Task(void)
|
|||
// TODO disable this line if data should be received
|
||||
Endpoint_ClearOUT(); // Throw away any received data from the host at this point
|
||||
|
||||
// TODO Read the data from the host
|
||||
|
||||
/* Create a temp buffer big enough to hold the incoming endpoint packet */
|
||||
uint8_t Buffer[Endpoint_BytesInEndpoint()];
|
||||
|
||||
|
@ -234,7 +236,8 @@ void CDC1_Task(void)
|
|||
/* Finalize the stream transfer to send the last packet */
|
||||
Endpoint_ClearOUT();
|
||||
|
||||
// TODO process the received data and descide to do an action
|
||||
// TODO Read the data from the host
|
||||
// process the received data and descide to do an action
|
||||
// uint8_t cmd = processReceivedControlData(&Buffer, DataLength);
|
||||
// if (cmd != NULL)
|
||||
// {
|
||||
|
@ -300,23 +303,42 @@ void CDC2_Task(void)
|
|||
|
||||
// TODO at this point send the data to the USART
|
||||
// Send USART &Buffer
|
||||
|
||||
// TODO read the USART data and send them to the host
|
||||
// Fill &Buffer with USART data or send the USART input buffer direct
|
||||
|
||||
/* Select the Serial Tx Endpoint */
|
||||
Endpoint_SelectEndpoint(CDC2_TX_EPADDR);
|
||||
|
||||
/* Write the received data to the endpoint */
|
||||
Endpoint_Write_Stream_LE(&Buffer, DataLength, NULL);
|
||||
|
||||
/* Finalize the stream transfer to send the last packet */
|
||||
Endpoint_ClearIN();
|
||||
|
||||
/* Wait until the endpoint is ready for the next packet */
|
||||
Endpoint_WaitUntilReady();
|
||||
|
||||
/* Send an empty packet to prevent host buffering */
|
||||
Endpoint_ClearIN();
|
||||
for (uint16_t i = 0; i < DataLength; i++)
|
||||
{
|
||||
uart_putc(Buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
uint8_t outBuffer[OUTPUT_BUFFER_SIZE];
|
||||
// TODO read the USART data and send them to the host
|
||||
// Fill &Buffer with USART data or send the USART input buffer direct
|
||||
uint16_t cnt = 0;
|
||||
uint8_t c = uart_getc();
|
||||
while (c != UART_NO_DATA && cnt < OUTPUT_BUFFER_SIZE)
|
||||
{
|
||||
outBuffer[cnt] = c;
|
||||
c = uart_getc();
|
||||
cnt++;
|
||||
}
|
||||
|
||||
// send the data which was received from the uart connection
|
||||
if (cnt > 0)
|
||||
{
|
||||
/* Select the Serial Tx Endpoint */
|
||||
Endpoint_SelectEndpoint(CDC2_TX_EPADDR);
|
||||
|
||||
/* Write the received data to the endpoint */
|
||||
Endpoint_Write_Stream_LE(&outBuffer, cnt, NULL);
|
||||
|
||||
/* Finalize the stream transfer to send the last packet */
|
||||
Endpoint_ClearIN();
|
||||
|
||||
/* Wait until the endpoint is ready for the next packet */
|
||||
Endpoint_WaitUntilReady();
|
||||
|
||||
/* Send an empty packet to prevent host buffering */
|
||||
Endpoint_ClearIN();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,13 +49,14 @@
|
|||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Platform/Platform.h>
|
||||
|
||||
#include "uart/uart.h"
|
||||
|
||||
uint8_t error_mask = 0x00;
|
||||
uint8_t error_mask = 0x00;
|
||||
|
||||
/* UART definitions: */
|
||||
|
||||
#define UART_BAUD_RATE 115200
|
||||
#define UART_BAUD_RATE 115200
|
||||
#define OUTPUT_BUFFER_SIZE 100
|
||||
|
||||
#include "uart/uart.h" // include after the definition
|
||||
|
||||
/* Macros: */
|
||||
|
||||
|
|
Loading…
Reference in a new issue