summaryrefslogtreecommitdiffstatshomepage
path: root/stmhal/usbd_cdc_interface.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-03-22 13:21:58 +0000
committerDamien George <damien.p.george@gmail.com>2014-03-22 13:21:58 +0000
commit2fb37847a712127543c879cd4c925ac4ee3c8554 (patch)
treebe37434ed42c984ff8c916669752b131c4715192 /stmhal/usbd_cdc_interface.c
parentfb1d6d097e0528e5b5b5f7890101c0709ca21fd2 (diff)
downloadmicropython-2fb37847a712127543c879cd4c925ac4ee3c8554.tar.gz
micropython-2fb37847a712127543c879cd4c925ac4ee3c8554.zip
stmhal: Tidy up USB CDC+MSC device some more.
Diffstat (limited to 'stmhal/usbd_cdc_interface.c')
-rw-r--r--stmhal/usbd_cdc_interface.c143
1 files changed, 73 insertions, 70 deletions
diff --git a/stmhal/usbd_cdc_interface.c b/stmhal/usbd_cdc_interface.c
index 6316439356..5116ce860e 100644
--- a/stmhal/usbd_cdc_interface.c
+++ b/stmhal/usbd_cdc_interface.c
@@ -52,6 +52,8 @@
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
+static uint8_t dev_is_connected = 0; // indicates if we are connected
+
static uint8_t UserRxBuffer[APP_RX_DATA_SIZE]; // received data from USB OUT endpoint is stored in this buffer
static uint16_t UserRxBufCur = 0; // points to next available character in UserRxBuffer
static uint16_t UserRxBufLen = 0; // counts number of valid characters in UserRxBuffer
@@ -174,76 +176,73 @@ static int8_t CDC_Itf_DeInit(void)
* @param Len: Number of data to be sent (in bytes)
* @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
*/
-static int8_t CDC_Itf_Control (uint8_t cmd, uint8_t* pbuf, uint16_t length)
-{
- switch (cmd)
- {
- case CDC_SEND_ENCAPSULATED_COMMAND:
- /* Add your code here */
- break;
-
- case CDC_GET_ENCAPSULATED_RESPONSE:
- /* Add your code here */
- break;
-
- case CDC_SET_COMM_FEATURE:
- /* Add your code here */
- break;
-
- case CDC_GET_COMM_FEATURE:
- /* Add your code here */
- break;
-
- case CDC_CLEAR_COMM_FEATURE:
- /* Add your code here */
- break;
-
- case CDC_SET_LINE_CODING:
- #if 0
- LineCoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) |\
- (pbuf[2] << 16) | (pbuf[3] << 24));
- LineCoding.format = pbuf[4];
- LineCoding.paritytype = pbuf[5];
- LineCoding.datatype = pbuf[6];
-
- /* Set the new configuration */
- #endif
- break;
-
- case CDC_GET_LINE_CODING:
- #if 0
- pbuf[0] = (uint8_t)(LineCoding.bitrate);
- pbuf[1] = (uint8_t)(LineCoding.bitrate >> 8);
- pbuf[2] = (uint8_t)(LineCoding.bitrate >> 16);
- pbuf[3] = (uint8_t)(LineCoding.bitrate >> 24);
- pbuf[4] = LineCoding.format;
- pbuf[5] = LineCoding.paritytype;
- pbuf[6] = LineCoding.datatype;
- #endif
-
- /* Add your code here */
- pbuf[0] = (uint8_t)(115200);
- pbuf[1] = (uint8_t)(115200 >> 8);
- pbuf[2] = (uint8_t)(115200 >> 16);
- pbuf[3] = (uint8_t)(115200 >> 24);
- pbuf[4] = 0; // stop bits (1)
- pbuf[5] = 0; // parity (none)
- pbuf[6] = 8; // number of bits (8)
- break;
-
- case CDC_SET_CONTROL_LINE_STATE:
- /* Add your code here */
- break;
-
- case CDC_SEND_BREAK:
- /* Add your code here */
- break;
-
- default:
- break;
- }
-
- return (USBD_OK);
+static int8_t CDC_Itf_Control(uint8_t cmd, uint8_t* pbuf, uint16_t length) {
+ switch (cmd) {
+ case CDC_SEND_ENCAPSULATED_COMMAND:
+ /* Add your code here */
+ break;
+
+ case CDC_GET_ENCAPSULATED_RESPONSE:
+ /* Add your code here */
+ break;
+
+ case CDC_SET_COMM_FEATURE:
+ /* Add your code here */
+ break;
+
+ case CDC_GET_COMM_FEATURE:
+ /* Add your code here */
+ break;
+
+ case CDC_CLEAR_COMM_FEATURE:
+ /* Add your code here */
+ break;
+
+ case CDC_SET_LINE_CODING:
+ #if 0
+ LineCoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) |\
+ (pbuf[2] << 16) | (pbuf[3] << 24));
+ LineCoding.format = pbuf[4];
+ LineCoding.paritytype = pbuf[5];
+ LineCoding.datatype = pbuf[6];
+ /* Set the new configuration */
+ #endif
+ break;
+
+ case CDC_GET_LINE_CODING:
+ #if 0
+ pbuf[0] = (uint8_t)(LineCoding.bitrate);
+ pbuf[1] = (uint8_t)(LineCoding.bitrate >> 8);
+ pbuf[2] = (uint8_t)(LineCoding.bitrate >> 16);
+ pbuf[3] = (uint8_t)(LineCoding.bitrate >> 24);
+ pbuf[4] = LineCoding.format;
+ pbuf[5] = LineCoding.paritytype;
+ pbuf[6] = LineCoding.datatype;
+ #endif
+
+ /* Add your code here */
+ pbuf[0] = (uint8_t)(115200);
+ pbuf[1] = (uint8_t)(115200 >> 8);
+ pbuf[2] = (uint8_t)(115200 >> 16);
+ pbuf[3] = (uint8_t)(115200 >> 24);
+ pbuf[4] = 0; // stop bits (1)
+ pbuf[5] = 0; // parity (none)
+ pbuf[6] = 8; // number of bits (8)
+ break;
+
+ case CDC_SET_CONTROL_LINE_STATE:
+ dev_is_connected = length & 1; // wValue is passed in Len (bit of a hack)
+ break;
+
+ case CDC_SEND_BREAK:
+ /* Add your code here */
+ break;
+
+ default:
+ break;
+ }
+
+ return USBD_OK;
}
/**
@@ -339,6 +338,10 @@ static int8_t CDC_Itf_Receive(uint8_t* Buf, uint32_t *Len) {
return (USBD_OK);
}
+int USBD_CDC_IsConnected(void) {
+ return dev_is_connected;
+}
+
void USBD_CDC_SetInterrupt(int chr, void *data) {
user_interrupt_char = chr;
user_interrupt_data = data;