void PPMin_Init() { UART_Stop(); // disable USART1 for GPIO PA9 & PA10 (Trainer Tx(PA9) & Rx(PA10)) /* Enable GPIOA clock. */ rcc_periph_clock_enable(RCC_GPIOA); /* Enable EXTI interrupt. */ nvic_enable_irq(NVIC_EXTI0_1_IRQ); /* Set GPIO0 (in GPIO port A) to 'input float'. */ PORT_mode_setup(PPM, GPIO_MODE_INPUT, GPIO_PUPD_NONE); /* Configure the EXTI subsystem. */ exti_select_source(EXTI0, GPIOA); exti_set_trigger(EXTI0, EXTI_TRIGGER_RISING); exti_disable_request(EXTI0); }
void PPMin_Init() { #if _PWM_PIN == GPIO_USART1_TX UART_Stop(); // disable USART1 for GPIO PA9 & PA10 (Trainer Tx(PA9) & Rx(PA10)) #endif /* Enable GPIOA clock. */ rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); /* Enable AFIO clock. */ rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN); /* Enable EXTI interrupt. */ nvic_enable_irq(NVIC_EXTI9_5_IRQ); /* Set GPIO0 (in GPIO port A) to 'input float'. */ gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, _PWM_PIN); /* Configure the EXTI subsystem. */ exti_select_source(_PWM_EXTI, GPIOA); exti_set_trigger(_PWM_EXTI, EXTI_TRIGGER_RISING); exti_disable_request(_PWM_EXTI); }
void PROTO_Stubs(int idx) { if (! idx) return; CLOCK_StartTimer(); spi_disable(); spi_set_bidirectional_receive_only_mode(); spi_read(); spi_set_unidirectional_mode(); TELEMETRY_SetUpdated(); TELEMETRY_SetType(); UART_Stop(); rcc_peripheral_disable_clock(); _usleep(); MCU_SerialNumber(); USB_Disable(); PROTO_CS_HI(); PROTO_CS_LO(); MUSIC_Beep(); rand32(); }
/******************************************************************************* * Function Name: UART_Sleep ******************************************************************************** * * Summary: * Calls SaveConfig function fucntion for selected mode. * * Parameters: * None * * Return: * None * *******************************************************************************/ void UART_Sleep(void) { #if(UART_SCB_MODE_UNCONFIG_CONST_CFG) if(0u != UART_scbEnableWake) { if(UART_SCB_MODE_I2C_RUNTM_CFG) { UART_I2CSaveConfig(); } else if(UART_SCB_MODE_SPI_RUNTM_CFG) { UART_SpiSaveConfig(); } else if(UART_SCB_MODE_UART_RUNTM_CFG) { UART_UartSaveConfig(); } else if(UART_SCB_MODE_EZI2C_RUNTM_CFG) { UART_EzI2CSaveConfig(); } else { /* Unknown mode: do nothing */ } } else { UART_backup.enableState = (uint8) UART_GET_CTRL_ENABLED; if(0u != UART_backup.enableState) { UART_Stop(); } } UART_DisableTxPinsInputBuffer(); #else #if defined (UART_I2C_WAKE_ENABLE_CONST) && (UART_I2C_WAKE_ENABLE_CONST) UART_I2CSaveConfig(); #elif defined (UART_SPI_WAKE_ENABLE_CONST) && (UART_SPI_WAKE_ENABLE_CONST) UART_SpiSaveConfig(); #elif defined (UART_UART_WAKE_ENABLE_CONST) && (UART_UART_WAKE_ENABLE_CONST) UART_UartSaveConfig(); #elif defined (UART_EZI2C_WAKE_ENABLE_CONST) && (UART_EZI2C_WAKE_ENABLE_CONST) UART_EzI2CSaveConfig(); #else UART_backup.enableState = (uint8) UART_GET_CTRL_ENABLED; /* Check enable state */ if(0u != UART_backup.enableState) { UART_Stop(); } #endif /* defined (UART_SCB_MODE_I2C_CONST_CFG) && (UART_I2C_WAKE_ENABLE_CONST) */ UART_DisableTxPinsInputBuffer(); #endif /* (UART_SCB_MODE_UNCONFIG_CONST_CFG) */ }
void CyBtldrCommStop (void) { UART_Stop(); }
/******************************************************************************* * Function Name: UART_Sleep ******************************************************************************** * * Summary: * Prepares the component to enter Deep Sleep. * The “Enable wakeup from Sleep Mode” selection has an influence on * this function implementation. * * Parameters: * None * * Return: * None * *******************************************************************************/ void UART_Sleep(void) { #if(UART_SCB_MODE_UNCONFIG_CONST_CFG) if(UART_SCB_WAKE_ENABLE_CHECK) { if(UART_SCB_MODE_I2C_RUNTM_CFG) { UART_I2CSaveConfig(); } else if(UART_SCB_MODE_EZI2C_RUNTM_CFG) { UART_EzI2CSaveConfig(); } #if(!UART_CY_SCBIP_V1_I2C_ONLY) else if(UART_SCB_MODE_SPI_RUNTM_CFG) { UART_SpiSaveConfig(); } else if(UART_SCB_MODE_UART_RUNTM_CFG) { UART_UartSaveConfig(); } #endif /* (!UART_CY_SCBIP_V1_I2C_ONLY) */ else { /* Unknown mode: do nothing */ } } else { UART_backup.enableState = (uint8) UART_GET_CTRL_ENABLED; if(0u != UART_backup.enableState) { UART_Stop(); } } #else #if (UART_SCB_MODE_I2C_CONST_CFG && UART_I2C_WAKE_ENABLE_CONST) UART_I2CSaveConfig(); #elif (UART_SCB_MODE_EZI2C_CONST_CFG && UART_EZI2C_WAKE_ENABLE_CONST) UART_EzI2CSaveConfig(); #elif (UART_SCB_MODE_SPI_CONST_CFG && UART_SPI_WAKE_ENABLE_CONST) UART_SpiSaveConfig(); #elif (UART_SCB_MODE_UART_CONST_CFG && UART_UART_WAKE_ENABLE_CONST) UART_UartSaveConfig(); #else UART_backup.enableState = (uint8) UART_GET_CTRL_ENABLED; if(0u != UART_backup.enableState) { UART_Stop(); } #endif /* defined (UART_SCB_MODE_I2C_CONST_CFG) && (UART_I2C_WAKE_ENABLE_CONST) */ #endif /* (UART_SCB_MODE_UNCONFIG_CONST_CFG) */ }
/******************************************************************************* * Function Name: CyBtldrCommStop ******************************************************************************** * * Summary: * Disable the component. * * Parameters: * void * * Return: * void * *******************************************************************************/ void CyBtldrCommStop(void) { /* Stop UART */ UART_Stop(); }
/******************************************************************************* * Function Name: AppCallBack ******************************************************************************** * * Summary: * Call back function for BLE stack to handle BLESS events * * Parameters: * event - the event generated by stack * eventParam - the parameters related to the corresponding event * * Return: * None. * *******************************************************************************/ void AppCallBack(uint32 event, void *eventParam) { CYBLE_GATTC_READ_BY_TYPE_RSP_PARAM_T *readResponse; CYBLE_GAPC_ADV_REPORT_T *advReport; CYBLE_GATTC_FIND_BY_TYPE_RSP_PARAM_T *findResponse; CYBLE_GATTC_FIND_INFO_RSP_PARAM_T *findInfoResponse; switch (event) { case CYBLE_EVT_STACK_ON: break; case CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT: advReport = (CYBLE_GAPC_ADV_REPORT_T *) eventParam; /* check if report has manfacturing data corresponding to the intended matching peer */ if((advReport->eventType == CYBLE_GAPC_SCAN_RSP) && (advReport->dataLen == 0x06) \ && (advReport->data[1] == 0xff) && (advReport->data[2] == 0x31) \ && (advReport->data[3] == 0x01) && (advReport->data[4] == 0x3b) \ && (advReport->data[5] == 0x04)) { peerDeviceFound = true; memcpy(peerAddr.bdAddr, advReport->peerBdAddr, sizeof(peerAddr.bdAddr)); peerAddr.type = advReport->peerAddrType; #ifdef PRINT_MESSAGE_LOG UART_UartPutString("\n\r\n\rServer with matching custom service discovered..."); #endif } break; case CYBLE_EVT_GAP_DEVICE_DISCONNECTED: /* RESET all flags */ peerDeviceFound = false; notificationEnabled = false; infoExchangeState = INFO_EXCHANGE_START; #ifdef PRINT_MESSAGE_LOG UART_UartPutString("\n\r DISCONNECTED!!! \n\r "); while(0 != (UART_SpiUartGetTxBufferSize() + UART_GET_TX_FIFO_SR_VALID)); #endif /* RESET Uart and flush all buffers */ UART_Stop(); UART_SpiUartClearTxBuffer(); UART_SpiUartClearRxBuffer(); UART_Start(); break; case CYBLE_EVT_GATTC_READ_BY_TYPE_RSP: readResponse = (CYBLE_GATTC_READ_BY_TYPE_RSP_PARAM_T *) eventParam; if(0 == memcmp((uint8 *)&(readResponse->attrData.attrValue[5]), (uint8 *)uartTxAttrUuid, 16)) { txCharHandle = readResponse->attrData.attrValue[3]; txCharHandle |= (readResponse->attrData.attrValue[4] << 8); infoExchangeState |= TX_ATTR_HANDLE_FOUND; } else if(0 == memcmp((uint8 *)&(readResponse->attrData.attrValue[5]), (uint8 *)uartRxAttrUuid, 16)) { rxCharHandle = readResponse->attrData.attrValue[3]; rxCharHandle |= (readResponse->attrData.attrValue[4] << 8); infoExchangeState |= RX_ATTR_HANDLE_FOUND; } break; case CYBLE_EVT_GATTC_FIND_INFO_RSP: findInfoResponse = (CYBLE_GATTC_FIND_INFO_RSP_PARAM_T *) eventParam; if((0x29 == findInfoResponse->handleValueList.list[3]) && \ (0x02 == findInfoResponse->handleValueList.list[2])) { txCharDescHandle = findInfoResponse->handleValueList.list[0]; txCharDescHandle |= findInfoResponse->handleValueList.list[1] << 8; infoExchangeState |= TX_CCCD_HANDLE_FOUND; } break; case CYBLE_EVT_GATTC_XCHNG_MTU_RSP: /*set the 'mtuSize' variable based on the minimum MTU supported by both devices */ if(CYBLE_GATT_MTU > ((CYBLE_GATT_XCHG_MTU_PARAM_T *)eventParam)->mtu) { mtuSize = ((CYBLE_GATT_XCHG_MTU_PARAM_T *)eventParam)->mtu; } else { mtuSize = CYBLE_GATT_MTU; } infoExchangeState |= MTU_XCHNG_COMPLETE; break; case CYBLE_EVT_GATTC_HANDLE_VALUE_NTF: HandleUartRxTraffic((CYBLE_GATTC_HANDLE_VALUE_NTF_PARAM_T *)eventParam); break; case CYBLE_EVT_GATTC_FIND_BY_TYPE_VALUE_RSP: findResponse = (CYBLE_GATTC_FIND_BY_TYPE_RSP_PARAM_T *) eventParam; bleUartServiceHandle = findResponse->range->startHandle; bleUartServiceEndHandle = findResponse->range->endHandle; infoExchangeState |= BLE_UART_SERVICE_HANDLE_FOUND; break; case CYBLE_EVT_GATTS_XCNHG_MTU_REQ: /*set the 'mtuSize' variable based on the minimum MTU supported by both devices */ if(CYBLE_GATT_MTU > ((CYBLE_GATT_XCHG_MTU_PARAM_T *)eventParam)->mtu) { mtuSize = ((CYBLE_GATT_XCHG_MTU_PARAM_T *)eventParam)->mtu; } else { mtuSize = CYBLE_GATT_MTU; } break; case CYBLE_EVT_GATTC_WRITE_RSP: notificationEnabled = true; #ifdef PRINT_MESSAGE_LOG UART_UartPutString("\n\rNotifications enabled\n\r"); UART_UartPutString("\n\rStart entering data:\n\r"); #endif break; case CYBLE_EVT_GATT_CONNECT_IND: #ifdef PRINT_MESSAGE_LOG UART_UartPutString("\n\rConnection established"); #endif break; default: break; } }
/******************************************************************************* * Function Name: UART_UartCyBtldrCommStop ******************************************************************************** * * Summary: * Disables the UART component. * * Parameters: * None * * Return: * None * *******************************************************************************/ void UART_UartCyBtldrCommStop(void) { UART_Stop(); }
void UART_CustomPortDisable(void) { UART_Stop(); pinMode(D0, INPUT); pinMode(D1, INPUT); }