/** * @brief USBD_CDC_DataIn * Data sent on non-control IN endpoint * @param pdev: device instance * @param epnum: endpoint number * @retval status */ static uint8_t USBD_CDC_DataIn (void *pdev, uint8_t epnum) { uint16_t i; if (USBD_CDC_InFlight != 0) { USBD_CDC_InFlight = 0; } if (ringbuffer_isempty(&USBD_CDC_D2H_FIFO) == 0) { for (i = 0; i < CDC_DATA_IN_PACKET_SIZE && ringbuffer_isempty(&USBD_CDC_D2H_FIFO) == 0; i++) { USBD_CDC_D2H_Buff[i] = ringbuffer_pop(&USBD_CDC_D2H_FIFO); } dbgwdg_feed(); DCD_EP_Tx (pdev, USBD_Dev_CDC_D2H_EP, (uint8_t*)USBD_CDC_D2H_Buff, i); USBD_CDC_InFlight = 1; } if (USBD_CDC_InFlight == 0) { DCD_EP_Flush(pdev, epnum); } return USBD_OK; }
void USART1_IRQHandler(void) { if (USART_GetITStatus(CEREAL_USARTx, USART_IT_RXNE) != RESET) { uint8_t c = cereal_rx_raw(); if (!ringbuffer_isfull(&cereal_incoming)) { ringbuffer_push(&cereal_incoming, c); if (c == 0 || c == '\r' || c == '\n') { cereal_incoming.flag = 1; } } else { cereal_incoming.flag = 1; } } if (USART_GetITStatus(CEREAL_USARTx, USART_IT_TXE) != RESET ) { #ifdef ENABLE_CEREAL_BUFFERED_TX if (!ringbuffer_isempty(&cereal_outgoing)) { cereal_tx_raw(ringbuffer_pop(&cereal_outgoing)); } else { cereal_outgoing.flag = 0; USART_ITConfig(CEREAL_USARTx, USART_IT_TXE, DISABLE); } #endif } }
int16_t cereal_peek() { if (!ringbuffer_isempty(&cereal_incoming)) { return ringbuffer_peek(&cereal_incoming); } else { return -1; } }
static uint8_t USBD_CDC_SOF (void *pdev) { if (CdcFrameCount >= CDC_IN_FRAME_INTERVAL) { if (USBD_CDC_InFlight == 0) { if (USBD_CDC_D2H_FIFO.ready == 0xAB) { USBD_CDC_IsReady = 1; if (ringbuffer_isempty(&USBD_CDC_D2H_FIFO) == 0) { uint16_t i; for (i = 0; i < CDC_DATA_IN_PACKET_SIZE && ringbuffer_isempty(&USBD_CDC_D2H_FIFO) == 0; i++) { USBD_CDC_D2H_Buff[i] = ringbuffer_pop(&USBD_CDC_D2H_FIFO); } DCD_EP_Tx (pdev, USBD_Dev_CDC_D2H_EP, (uint8_t*)USBD_CDC_D2H_Buff, i); USBD_CDC_InFlight = 1; CdcFrameCount = 0; } } } else if (CdcFrameCount > 100) // timeout on waiting { led_1_tog(); CdcFrameCount = 0; USBD_CDC_InFlight = 0; DCD_EP_Flush(pdev, USBD_Dev_CDC_D2H_EP); } } CdcFrameCount++; return USBD_OK; }
static void soundcard_sdlcallback(void* userdata, Uint8* stream, int len) { ringbuffer* buff = (ringbuffer*) userdata; if (ringbuffer_isempty(buff)) { //log_println(LEVEL_INFO, TAG, "audio buffer empty"); return; } len /= sizeof(int16_t); unsigned int available = ringbuffer_samplesavailable(buff); if (len > available) { //log_println(LEVEL_INFO, TAG, "available buffer is smaller than what is needed, want %d have %u", len, // available); len = available; } for (int i = 0; i < len; i++) { int16_t value = ringbuffer_get(buff); *((int16_t*) stream) = value; stream += sizeof(value); } }
uint8_t cereal_wait_rx() { while (ringbuffer_isempty(&cereal_incoming)) ; return ringbuffer_pop(&cereal_incoming); }