1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
24
25
26
30
33
34
35
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
70
72
73
74
75
80
85
86
91
92
93
94
95
96
97
98
99
100
101
113
118
119
120
121
126
127
132
133
/* ... */
#include "main.h"
Includes
#define RX_BUFF_SIZE 0x400
Private define
uint16_t xPos, yLinePos;
uint8_t CDC_RX_Buffer[RX_BUFF_SIZE];
Private variables
static void DumpReceivedData(void);
Private function prototypes
/* ... */
void CDC_Handle_Receive_Menu(void)
{
switch(CdcDemo.Receive_state)
{
case CDC_RECEIVE_IDLE:
LCD_LOG_ClearTextZone();
CdcDemo.Receive_state = CDC_RECEIVE_WAIT;
USBH_CDC_Stop(&hUSBHost);
LCD_DbgLog("Receiving data ...\n");
xPos = 0;
yLinePos = 5;
memset(CDC_RX_Buffer, 0, RX_BUFF_SIZE);
USBH_CDC_Receive(&hUSBHost, CDC_RX_Buffer, RX_BUFF_SIZE);
BSP_LCD_ClearStringLine(19);
BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"Press User button to start sending data ");
break;
case CDC_RECEIVE_IDLE:
case CDC_RECEIVE_WAIT:
if((BSP_PB_GetState(BUTTON_WAKEUP) == SET) && (Appli_state != APPLICATION_DISCONNECT))
{
CdcDemo.state = CDC_DEMO_WAIT;
CdcDemo.Receive_state = CDC_RECEIVE_IDLE;
}if ((BSP_PB_GetState(BUTTON_WAKEUP) == SET) && (Appli_state != APPLICATION_DISCONNECT)) { ... }
break;
case CDC_RECEIVE_WAIT:
default:
break;default
}switch (CdcDemo.Receive_state) { ... }
}{ ... }
/* ... */
void USBH_CDC_ReceiveCallback(USBH_HandleTypeDef *phost)
{
DumpReceivedData();
USBH_CDC_Receive(&hUSBHost, CDC_RX_Buffer, RX_BUFF_SIZE);
}{ ... }
/* ... */
static void DumpReceivedData(void)
{
uint16_t size;
uint8_t *ptr = CDC_RX_Buffer;
size = USBH_CDC_GetLastReceivedDataSize(&hUSBHost);
BSP_LCD_SetTextColor(LCD_COLOR_YELLOW);
while(size--)
{
if((*ptr != '\n') && (*ptr != '\r'))
{
if(*ptr == '\t')
{
BSP_LCD_DisplayChar(xPos, LINE(yLinePos), ' ');
}if (*ptr == '\t') { ... }
else
{
BSP_LCD_DisplayChar(xPos, LINE(yLinePos), *ptr);
}else { ... }
xPos += 10;
}if ((*ptr != '\n') && (*ptr != '\r')) { ... }
else if(*ptr == '\n')
{
yLinePos++;
xPos = 0;
}else if (*ptr == '\n') { ... }
ptr++;
if(xPos > (BSP_LCD_GetXSize() - 7))
{
xPos = 0;
yLinePos++;
}if (xPos > (BSP_LCD_GetXSize() - 7)) { ... }
if(yLinePos > 13)
{
xPos = 0;
yLinePos = 5;
}if (yLinePos > 13) { ... }
}while (size--) { ... }
}{ ... }