Subversion Repositories LedShow

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/**
2
  ******************************************************************************
3
  * @file    usbd_cdc_if_template.c
4
  * @author  MCD Application Team
5
  * @brief   Generic media access Layer.
6
  ******************************************************************************
7
  * @attention
8
  *
9 mjames 9
  * <h2><center>&copy; Copyright (c) 2015 STMicroelectronics.
10
  * All rights reserved.</center></h2>
2 mjames 11
  *
9 mjames 12
  * This software component is licensed by ST under Ultimate Liberty license
13
  * SLA0044, the "License"; You may not use this file except in compliance with
14
  * the License. You may obtain a copy of the License at:
15
  *                      www.st.com/SLA0044
2 mjames 16
  *
17
  ******************************************************************************
9 mjames 18
  */
2 mjames 19
 
9 mjames 20
/* BSPDependencies
21
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
22
- "stm32xxxxx_{eval}{discovery}_io.c"
23
EndBSPDependencies */
24
 
2 mjames 25
/* Includes ------------------------------------------------------------------*/
26
#include "usbd_cdc_if_template.h"
27
 
28
/** @addtogroup STM32_USB_DEVICE_LIBRARY
29
  * @{
30
  */
31
 
32
 
9 mjames 33
/** @defgroup USBD_CDC
2 mjames 34
  * @brief usbd core module
35
  * @{
9 mjames 36
  */
2 mjames 37
 
38
/** @defgroup USBD_CDC_Private_TypesDefinitions
39
  * @{
9 mjames 40
  */
2 mjames 41
/**
42
  * @}
9 mjames 43
  */
2 mjames 44
 
45
 
46
/** @defgroup USBD_CDC_Private_Defines
47
  * @{
9 mjames 48
  */
2 mjames 49
/**
50
  * @}
9 mjames 51
  */
2 mjames 52
 
53
 
54
/** @defgroup USBD_CDC_Private_Macros
55
  * @{
9 mjames 56
  */
2 mjames 57
 
58
/**
59
  * @}
9 mjames 60
  */
2 mjames 61
 
62
 
63
/** @defgroup USBD_CDC_Private_FunctionPrototypes
64
  * @{
65
  */
66
 
9 mjames 67
static int8_t TEMPLATE_Init(void);
68
static int8_t TEMPLATE_DeInit(void);
69
static int8_t TEMPLATE_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length);
70
static int8_t TEMPLATE_Receive(uint8_t *pbuf, uint32_t *Len);
2 mjames 71
 
9 mjames 72
USBD_CDC_ItfTypeDef USBD_CDC_Template_fops =
2 mjames 73
{
74
  TEMPLATE_Init,
75
  TEMPLATE_DeInit,
76
  TEMPLATE_Control,
77
  TEMPLATE_Receive
78
};
79
 
80
USBD_CDC_LineCodingTypeDef linecoding =
9 mjames 81
{
82
  115200, /* baud rate*/
83
  0x00,   /* stop bits-1*/
84
  0x00,   /* parity - none*/
85
  0x08    /* nb. of bits 8*/
86
};
2 mjames 87
 
88
/* Private functions ---------------------------------------------------------*/
89
 
90
/**
91
  * @brief  TEMPLATE_Init
92
  *         Initializes the CDC media low layer
93
  * @param  None
94
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
95
  */
96
static int8_t TEMPLATE_Init(void)
97
{
98
  /*
9 mjames 99
     Add your initialization code here
100
  */
2 mjames 101
  return (0);
102
}
103
 
104
/**
105
  * @brief  TEMPLATE_DeInit
106
  *         DeInitializes the CDC media low layer
107
  * @param  None
108
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
109
  */
110
static int8_t TEMPLATE_DeInit(void)
111
{
112
  /*
9 mjames 113
     Add your deinitialization code here
114
  */
2 mjames 115
  return (0);
116
}
117
 
118
 
119
/**
120
  * @brief  TEMPLATE_Control
121
  *         Manage the CDC class requests
9 mjames 122
  * @param  Cmd: Command code
2 mjames 123
  * @param  Buf: Buffer containing command data (request parameters)
124
  * @param  Len: Number of data to be sent (in bytes)
125
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
126
  */
9 mjames 127
static int8_t TEMPLATE_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
128
{
2 mjames 129
  switch (cmd)
130
  {
9 mjames 131
    case CDC_SEND_ENCAPSULATED_COMMAND:
132
      /* Add your code here */
133
      break;
2 mjames 134
 
9 mjames 135
    case CDC_GET_ENCAPSULATED_RESPONSE:
136
      /* Add your code here */
137
      break;
2 mjames 138
 
9 mjames 139
    case CDC_SET_COMM_FEATURE:
140
      /* Add your code here */
141
      break;
2 mjames 142
 
9 mjames 143
    case CDC_GET_COMM_FEATURE:
144
      /* Add your code here */
145
      break;
2 mjames 146
 
9 mjames 147
    case CDC_CLEAR_COMM_FEATURE:
148
      /* Add your code here */
149
      break;
2 mjames 150
 
9 mjames 151
    case CDC_SET_LINE_CODING:
152
      linecoding.bitrate    = (uint32_t)(pbuf[0] | (pbuf[1] << 8) | \
153
                                         (pbuf[2] << 16) | (pbuf[3] << 24));
154
      linecoding.format     = pbuf[4];
155
      linecoding.paritytype = pbuf[5];
156
      linecoding.datatype   = pbuf[6];
2 mjames 157
 
9 mjames 158
      /* Add your code here */
159
      break;
2 mjames 160
 
9 mjames 161
    case CDC_GET_LINE_CODING:
162
      pbuf[0] = (uint8_t)(linecoding.bitrate);
163
      pbuf[1] = (uint8_t)(linecoding.bitrate >> 8);
164
      pbuf[2] = (uint8_t)(linecoding.bitrate >> 16);
165
      pbuf[3] = (uint8_t)(linecoding.bitrate >> 24);
166
      pbuf[4] = linecoding.format;
167
      pbuf[5] = linecoding.paritytype;
168
      pbuf[6] = linecoding.datatype;
2 mjames 169
 
9 mjames 170
      /* Add your code here */
171
      break;
172
 
173
    case CDC_SET_CONTROL_LINE_STATE:
174
      /* Add your code here */
175
      break;
176
 
177
    case CDC_SEND_BREAK:
178
      /* Add your code here */
179
      break;
180
 
181
    default:
182
      break;
2 mjames 183
  }
184
 
185
  return (0);
186
}
187
 
188
/**
189
  * @brief  TEMPLATE_Receive
9 mjames 190
  *         Data received over USB OUT endpoint are sent over CDC interface
2 mjames 191
  *         through this function.
9 mjames 192
  *
2 mjames 193
  *         @note
9 mjames 194
  *         This function will issue a NAK packet on any OUT packet received on
2 mjames 195
  *         USB endpoint untill exiting this function. If you exit this function
196
  *         before transfer is complete on CDC interface (ie. using DMA controller)
9 mjames 197
  *         it will result in receiving more data while previous ones are still
2 mjames 198
  *         not sent.
9 mjames 199
  *
2 mjames 200
  * @param  Buf: Buffer of data to be received
201
  * @param  Len: Number of data received (in bytes)
202
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
203
  */
9 mjames 204
static int8_t TEMPLATE_Receive(uint8_t *Buf, uint32_t *Len)
2 mjames 205
{
9 mjames 206
 
2 mjames 207
  return (0);
208
}
209
 
210
/**
211
  * @}
9 mjames 212
  */
2 mjames 213
 
214
/**
215
  * @}
9 mjames 216
  */
2 mjames 217
 
218
/**
219
  * @}
9 mjames 220
  */
2 mjames 221
 
222
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
223