/* Copyright 2025 muzkr https://github.com/muzkr * * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * * 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. * */ #include "driver/vcp.h" #include "usb_config.h" #include "py32f071_ll_bus.h" uint8_t VCP_RxBuf[VCP_RX_BUF_SIZE]; volatile uint32_t VCP_RxBufPointer = 0; void VCP_Init() { LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_SYSCFG); LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA); // PA12:11 LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USBD); cdc_acm_rx_buf_t rx_buf = { .buf = VCP_RxBuf, .size = sizeof(VCP_RxBuf), .write_pointer = &VCP_RxBufPointer, }; cdc_acm_init(rx_buf); NVIC_SetPriority(USBD_IRQn, 3); NVIC_EnableIRQ(USBD_IRQn); } bool VCP_ScreenshotPing(void) { static uint32_t read_ptr = 0; uint32_t write_ptr = VCP_RxBufPointer; while (read_ptr != write_ptr) { uint8_t b = VCP_RxBuf[read_ptr]; read_ptr++; if (read_ptr >= VCP_RX_BUF_SIZE) read_ptr = 0; if (b == 0x55) { return true; } } return false; }