Previous changes to USB connection state management to fix behavior on Windows was broken. This appears to work on Windows, Linux and MacOS.

fsk9600
Rob Riggs 2019-06-08 23:05:03 -05:00
rodzic b7791ab536
commit d82e198d59
3 zmienionych plików z 27 dodań i 28 usunięć

Wyświetl plik

@ -55,7 +55,7 @@
#include "UsbPort.h" #include "UsbPort.h"
#include "main.h" #include "main.h"
#include "cmsis_os.h" #include "cmsis_os.h"
extern osMessageQId ioEventQueueHandle; #include "IOEventTask.h"
/* USER CODE END INCLUDE */ /* USER CODE END INCLUDE */
@ -65,7 +65,6 @@ extern osMessageQId ioEventQueueHandle;
/* USER CODE BEGIN PV */ /* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/
static int connected = 0;
/* USER CODE END PV */ /* USER CODE END PV */
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
@ -262,10 +261,6 @@ static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
/* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */ /* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */
/*******************************************************************************/ /*******************************************************************************/
case CDC_SET_LINE_CODING: case CDC_SET_LINE_CODING:
if (!connected) {
connected = 1;
osMessagePut(ioEventQueueHandle, CMD_USB_CDC_CONNECT, 0);
}
LineCoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) | (pbuf[2] << 16) | (pbuf[3] << 24)); LineCoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) | (pbuf[2] << 16) | (pbuf[3] << 24));
LineCoding.format = pbuf[4]; LineCoding.format = pbuf[4];
LineCoding.paritytype = pbuf[5]; LineCoding.paritytype = pbuf[5];
@ -285,11 +280,9 @@ static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
case CDC_SET_CONTROL_LINE_STATE: case CDC_SET_CONTROL_LINE_STATE:
if (length == 0) { if (length == 0) {
USBD_SetupReqTypedef* req = (USBD_SetupReqTypedef*) pbuf; USBD_SetupReqTypedef* req = (USBD_SetupReqTypedef*) pbuf;
if ((req->wValue & 1) && (!connected)) { if ((req->wValue & 1)) {
connected = 1;
osMessagePut(ioEventQueueHandle, CMD_USB_CDC_CONNECT, 0); osMessagePut(ioEventQueueHandle, CMD_USB_CDC_CONNECT, 0);
} else if (connected) { } else {
connected = 0;
osMessagePut(ioEventQueueHandle, CMD_USB_CDC_DISCONNECT, 0); osMessagePut(ioEventQueueHandle, CMD_USB_CDC_DISCONNECT, 0);
} }
} }
@ -313,7 +306,7 @@ static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
* *
* @note * @note
* This function will block any OUT packet reception on USB endpoint * This function will block any OUT packet reception on USB endpoint
* untill exiting this function. If you exit this function before transfer * until exiting this function. If you exit this function before transfer
* is complete on CDC interface (ie. using DMA controller) it will result * is complete on CDC interface (ie. using DMA controller) it will result
* in receiving more data while previous ones are still not sent. * in receiving more data while previous ones are still not sent.
* *
@ -324,8 +317,7 @@ static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len) static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
{ {
/* USER CODE BEGIN 6 */ /* USER CODE BEGIN 6 */
if (!connected) { if (!cdc_connected) {
connected = 1;
osMessagePut(ioEventQueueHandle, CMD_USB_CDC_CONNECT, 0); osMessagePut(ioEventQueueHandle, CMD_USB_CDC_CONNECT, 0);
} }
cdc_receive(Buf, *Len); cdc_receive(Buf, *Len);

Wyświetl plik

@ -32,6 +32,8 @@ extern "C" void stop2(void);
extern "C" void shutdown(void const * argument); extern "C" void shutdown(void const * argument);
extern "C" void startLedBlinkerTask(void const*); extern "C" void startLedBlinkerTask(void const*);
volatile int cdc_connected{0};
static PTT getPttStyle(const mobilinkd::tnc::kiss::Hardware& hardware) static PTT getPttStyle(const mobilinkd::tnc::kiss::Hardware& hardware)
{ {
return hardware.options & KISS_OPTION_PTT_SIMPLEX ? PTT::SIMPLEX : PTT::MULTIPLEX; return hardware.options & KISS_OPTION_PTT_SIMPLEX ? PTT::SIMPLEX : PTT::MULTIPLEX;
@ -123,8 +125,9 @@ void startIOEventTask(void const*)
{ {
switch (cmd) { switch (cmd) {
case CMD_USB_CDC_CONNECT: case CMD_USB_CDC_CONNECT:
if (openCDC()) if (!cdc_connected && openCDC())
{ {
cdc_connected = true;
// Disable Bluetooth Module // Disable Bluetooth Module
HAL_NVIC_DisableIRQ(EXTI4_IRQn); HAL_NVIC_DisableIRQ(EXTI4_IRQn);
HAL_NVIC_DisableIRQ(EXTI9_5_IRQn); HAL_NVIC_DisableIRQ(EXTI9_5_IRQn);
@ -152,21 +155,24 @@ void startIOEventTask(void const*)
} }
[[ fallthrough ]]; // when the CDC part was connected. [[ fallthrough ]]; // when the CDC part was connected.
case CMD_USB_CDC_DISCONNECT: case CMD_USB_CDC_DISCONNECT:
osMessagePut(audioInputQueueHandle, audio::IDLE, if (cdc_connected) {
osWaitForever); cdc_connected = false;
kiss::getAFSKTestTone().stop(); osMessagePut(audioInputQueueHandle, audio::IDLE,
closeCDC(); osWaitForever);
INFO("CDC Closed"); kiss::getAFSKTestTone().stop();
closeCDC();
INFO("CDC Closed");
// Enable Bluetooth Module // Enable Bluetooth Module
HAL_GPIO_WritePin(BT_SLEEP_GPIO_Port, BT_SLEEP_Pin, HAL_GPIO_WritePin(BT_SLEEP_GPIO_Port, BT_SLEEP_Pin,
GPIO_PIN_SET); GPIO_PIN_SET);
bm78_wait_until_ready(); bm78_wait_until_ready();
HAL_NVIC_EnableIRQ(EXTI4_IRQn); HAL_NVIC_EnableIRQ(EXTI4_IRQn);
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn); HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
indicate_waiting_to_connect(); indicate_waiting_to_connect();
}
break; break;
case CMD_POWER_BUTTON_DOWN: case CMD_POWER_BUTTON_DOWN:
INFO("Power Down"); INFO("Power Down");

Wyświetl plik

@ -13,11 +13,12 @@ extern "C" {
void startIOEventTask(void const* argument); void startIOEventTask(void const* argument);
void startCdcBlinker(void const* argument); void startCdcBlinker(void const* argument);
extern osMessageQId ioEventQueueHandle;
extern volatile int cdc_connected;
#ifdef __cplusplus #ifdef __cplusplus
} }
extern osMessageQId ioEventQueueHandle;
namespace mobilinkd { namespace tnc { namespace mobilinkd { namespace tnc {
void print_startup_banner() __attribute__((noinline)); void print_startup_banner() __attribute__((noinline));