Subversion Repositories LedShow

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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