Exemple #1
0
bool cdc_send_data(const uint8_t* data, size_t len) {
    if (!cmp_usb_configured()) {
        return false;
    }
    uint16_t sent = usbd_ep_write_packet(cdc_usbd_dev, ENDP_CDC_DATA_IN,
                                         (const void*)data,
                                         (uint16_t)len);
    return (sent != 0);
}
Exemple #2
0
bool cdc_uart_app_update(void) {
    bool active = false;
    static uint16_t packet_len = 0;
    static uint8_t packet_buffer[USB_CDC_MAX_PACKET_SIZE];

    if (packet_len < USB_CDC_MAX_PACKET_SIZE) {
        uint16_t max_bytes = (USB_CDC_MAX_PACKET_SIZE- packet_len);
        packet_len += console_recv_buffered(&packet_buffer[packet_len], max_bytes);
    }

    if (packet_len > 0 && cmp_usb_configured()) {
        if (cdc_send_data(packet_buffer, packet_len)) {
            active = true;
            packet_len = 0;
            if (cdc_uart_tx_callback) {
                cdc_uart_tx_callback();
            }
        }
    }

    return active;
}
Exemple #3
0
bool vcdc_app_update(void) {
    bool active = false;

    while (packet_len < USB_VCDC_MAX_PACKET_SIZE && !vcdc_tx_buffer_empty()) {
        packet_buffer[packet_len] = vcdc_tx_buffer_get();
        packet_len++;
    }

    if (packet_len > 0 && cmp_usb_configured()) {
        uint16_t sent = usbd_ep_write_packet(vcdc_usbd_dev, ENDP_VCDC_DATA_IN,
                                             (const void*)packet_buffer,
                                             packet_len);
        
        if (sent != 0) {
            packet_len = 0;
            active = true;
            if (vcdc_tx_callback != NULL) {
                vcdc_tx_callback();
            }
        }
    }
    
    return active;
}