Skip to content
Snippets Groups Projects
Select Git revision
  • bf733c27bbfe40c2f35407a031a2900bc4eaeaba
  • master default protected
2 results

usbd_cdc_interface.c

Blame
  • usbd_cdc_interface.c 15.01 KiB
    /*
     * This file is part of the MicroPython project, http://micropython.org/
     *
     * Taken from ST Cube library and heavily modified.  See below for original
     * copyright header.
     */
    
    /**
      ******************************************************************************
      * @file    USB_Device/CDC_Standalone/Src/usbd_cdc_interface.c
      * @author  MCD Application Team
      * @version V1.0.1
      * @date    26-February-2014
      * @brief   Source file for USBD CDC interface
      ******************************************************************************
      * @attention
      *
      * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
      *
      * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
      * You may not use this file except in compliance with the License.
      * You may obtain a copy of the License at:
      *
      *        http://www.st.com/software_license_agreement_liberty_v2
      *
      * Unless required by applicable law or agreed to in writing, software
      * distributed under the License is distributed on an "AS IS" BASIS,
      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      * See the License for the specific language governing permissions and
      * limitations under the License.
      *
      ******************************************************************************
      */
    
    /* Includes ------------------------------------------------------------------*/
    
    #include <stdbool.h>
    #include <stdint.h>
    
    #include "usbd_cdc_msc_hid.h"
    #include "usbd_cdc_interface.h"
    #include "pendsv.h"
    
    #include "py/obj.h"
    #include "lib/utils/interrupt_char.h"
    #include "irq.h"
    
    #if MICROPY_HW_ENABLE_USB
    
    // CDC control commands
    #define CDC_SEND_ENCAPSULATED_COMMAND               0x00
    #define CDC_GET_ENCAPSULATED_RESPONSE               0x01
    #define CDC_SET_COMM_FEATURE                        0x02
    #define CDC_GET_COMM_FEATURE                        0x03
    #define CDC_CLEAR_COMM_FEATURE                      0x04
    #define CDC_SET_LINE_CODING                         0x20
    #define CDC_GET_LINE_CODING                         0x21
    #define CDC_SET_CONTROL_LINE_STATE                  0x22
    #define CDC_SEND_BREAK                              0x23
    
    // Used to control the connect_state variable when USB host opens the serial port
    static uint8_t usbd_cdc_connect_tx_timer;
    
    uint8_t *usbd_cdc_init(usbd_cdc_state_t *cdc_in) {
        usbd_cdc_itf_t *cdc = (usbd_cdc_itf_t*)cdc_in;
    
        // Reset the CDC state due to a new USB host connection
        // Note: we don't reset tx_buf_ptr_* in order to allow the output buffer to
        // be filled (by usbd_cdc_tx_always) before the USB device is connected, and
        // to retain transmit buffer state across multiple USB connections (they will