mirror of
https://github.com/mitxela/clock4.git
synced 2025-12-05 23:20:26 -08:00
Compare commits
1 Commits
70c04301dc
...
cdc-pps
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60fac6fd77 |
@@ -45,6 +45,7 @@
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
uint8_t delayButtonPress=0;
|
||||
_Bool CDC_Set = 0;
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
@@ -76,7 +77,7 @@ extern DAC_HandleTypeDef hdac1;
|
||||
extern ADC_HandleTypeDef hadc1;
|
||||
extern float dac_target;
|
||||
extern uint8_t uart2_tx_buffer[32];
|
||||
extern _Bool data_valid, had_pps;
|
||||
extern _Bool data_valid, had_pps, last_pps_time, currentTime;
|
||||
extern uint8_t decisec, centisec, millisec;
|
||||
extern uint8_t displayMode, countMode, nmea_cdc_level;
|
||||
|
||||
@@ -193,6 +194,12 @@ void PendSV_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN PendSV_IRQn 0 */
|
||||
|
||||
if (had_pps && last_pps_time == (uint32_t)currentTime) {
|
||||
CDC_Transmit_serial_state(CDC_SERIAL_STATE_DCD);
|
||||
CDC_Set=1;
|
||||
}
|
||||
|
||||
|
||||
// Writing to the RTC is normally very fast, but if something goes wrong
|
||||
// the HAL functions will fail to time out if it's running with the same
|
||||
// preemption priority as systick
|
||||
@@ -346,6 +353,10 @@ void USART1_IRQHandler(void)
|
||||
&& nmea[5]=='V')
|
||||
decodeGSV();
|
||||
|
||||
if (CDC_Set && (GPIOC->IDR & GPIO_PIN_7)==0){
|
||||
CDC_Transmit_serial_state(0);
|
||||
CDC_Set=0;
|
||||
}
|
||||
|
||||
HAL_UART_AbortReceive(&huart1);
|
||||
HAL_UART_Receive_DMA(&huart1, nmea, sizeof(nmea));
|
||||
|
||||
@@ -117,6 +117,7 @@ typedef struct
|
||||
|
||||
__IO uint32_t TxState;
|
||||
__IO uint32_t RxState;
|
||||
__IO uint32_t CMDState;
|
||||
}
|
||||
USBD_CDC_HandleTypeDef;
|
||||
|
||||
|
||||
@@ -501,6 +501,7 @@ uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
/* Init Xfer states */
|
||||
hcdc->TxState = 0U;
|
||||
hcdc->RxState = 0U;
|
||||
hcdc->CMDState= 0U;
|
||||
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
@@ -670,7 +671,10 @@ uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
}
|
||||
else
|
||||
{
|
||||
hcdc->TxState = 0U;
|
||||
if (epnum == (CDC_IN_EP & 0x7F))
|
||||
hcdc->TxState = 0U;
|
||||
else if (epnum == (CDC_CMD_EP & 0x7F))
|
||||
hcdc->CMDState = 0U;
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
/* USER CODE BEGIN INCLUDE */
|
||||
#include "main.h"
|
||||
#include "usbd_msc_cdc.h"
|
||||
/* USER CODE END INCLUDE */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@@ -100,6 +101,15 @@ uint8_t UserTxBufferFS[APP_TX_DATA_SIZE];
|
||||
|
||||
/* USER CODE BEGIN PRIVATE_VARIABLES */
|
||||
|
||||
static struct serial_state {
|
||||
uint8_t bmRequestType;
|
||||
uint8_t bNotification;
|
||||
uint16_t wValue;
|
||||
uint16_t wIndex;
|
||||
uint16_t wLength;
|
||||
uint16_t state;
|
||||
} serial_state_msg;
|
||||
|
||||
/* USER CODE END PRIVATE_VARIABLES */
|
||||
|
||||
/**
|
||||
@@ -133,6 +143,35 @@ static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t *Len);
|
||||
|
||||
/* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */
|
||||
|
||||
/**
|
||||
* @brief CDC_Transmit_serial_state
|
||||
* Sends the new serial state to the host
|
||||
* @param newstate: new state of CDC_SERIAL_STATE* flags
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
uint8_t CDC_Transmit_serial_state(uint16_t newstate) {
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassDataCDC;
|
||||
|
||||
if(hcdc == NULL)
|
||||
return USBD_FAIL;
|
||||
|
||||
if(hcdc->CMDState != 0)
|
||||
return USBD_BUSY;
|
||||
|
||||
/* CMD Transfer in progress */
|
||||
hcdc->CMDState = 1;
|
||||
|
||||
serial_state_msg.bmRequestType = 0xA1;
|
||||
serial_state_msg.bNotification = 0x20;
|
||||
serial_state_msg.wValue = 0;
|
||||
serial_state_msg.wIndex = 0; // interface
|
||||
serial_state_msg.wLength = 2;
|
||||
serial_state_msg.state = newstate;
|
||||
USBD_LL_Transmit(&hUsbDeviceFS, CDC_CMD_EP, (uint8_t *)&serial_state_msg, 10);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,6 +50,14 @@
|
||||
*/
|
||||
/* USER CODE BEGIN EXPORTED_DEFINES */
|
||||
|
||||
#define CDC_SERIAL_STATE_DCD 0b0000001
|
||||
#define CDC_SERIAL_STATE_DSR 0b0000010
|
||||
#define CDC_SERIAL_STATE_BREAK 0b0000100
|
||||
#define CDC_SERIAL_STATE_RING 0b0001000
|
||||
#define CDC_SERIAL_STATE_FRAME 0b0010000
|
||||
#define CDC_SERIAL_STATE_PARITY 0b0100000
|
||||
#define CDC_SERIAL_STATE_OVERRUN 0b1000000
|
||||
|
||||
/* USER CODE END EXPORTED_DEFINES */
|
||||
|
||||
/**
|
||||
@@ -108,6 +116,7 @@ uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len);
|
||||
/* USER CODE BEGIN EXPORTED_FUNCTIONS */
|
||||
|
||||
uint8_t CDC_Copy_Transmit(uint8_t* nmea, uint16_t Len);
|
||||
uint8_t CDC_Transmit_serial_state(uint16_t newstate);
|
||||
|
||||
/* USER CODE END EXPORTED_FUNCTIONS */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user