예제 #1
0
tBleStatus Blue_NRG_HCI_Timer_Start(uint32_t expiryTime,
                                    TIMER_HCI_TIMEOUT_NOTIFY_CALLBACK_TYPE timercb,
                                    uint8_t *timerID)
{
  TIMER_Create(eTimerModuleID_BlueNRG_HCI, timerID, eTimerMode_SingleShot,
               (pf_TIMER_TimerCallBack_t) timercb);
  TIMER_Start(*timerID, expiryTime*1000/TIMERSERVER_TICK_VALUE);
  
  return (BLE_STATUS_SUCCESS);
}
/**
 * @brief  Initializes the SPI communication with the BlueNRG Shield.
 * @param  None
 * @retval None
 */
void BNRG_SPI_Init(void)
{
  BNRG_MSP_SPI_Init(&SpiHandle);
  
  SPI_Context.hspi = &SpiHandle;  
  
  SPI_Context.Spi_Peripheral_State = SPI_AVAILABLE;
  SPI_Context.SPI_Transmit_Context.RequestPending = FALSE;
  
  __HAL_BLUENRG_SPI_ENABLE_DMAREQ(&SpiHandle, SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN);
  
  __HAL_SPI_ENABLE(&SpiHandle);

#ifdef ENABLE_SPI_FIX
  TIMER_Create(eTimerModuleID_Interrupt, &StartupTimerId, eTimerMode_SingleShot, TimerStartupCallback);
#endif
  TIMER_Create(eTimerModuleID_Interrupt, &TxRxTimerId, eTimerMode_SingleShot, TimerTxRxCallback);
  return;
}
/**
 * @brief  Resets the BlueNRG.
 * @param  None
 * @retval None
 */
void BlueNRG_RST(void)
{
  uint8_t ubnRFResetTimerID;
  
  GPIO_InitTypeDef GPIO_InitStruct;
  
  GPIO_InitStruct.Pin = BNRG_SPI_RESET_PIN;
  GPIO_InitStruct.Speed = BNRG_SPI_RESET_SPEED;
  TIMER_Create(eTimerModuleID_Interrupt, &ubnRFResetTimerID, eTimerMode_SingleShot, pf_nRFResetTimerCallBack);
  
  BNRG_SPI_RESET_CLK_ENABLE();
  
  HAL_GPIO_WritePin(BNRG_SPI_RESET_PORT, BNRG_SPI_RESET_PIN, GPIO_PIN_RESET);
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(BNRG_SPI_RESET_PORT, &GPIO_InitStruct);
  
  TIMER_Start(ubnRFResetTimerID, BLUENRG_HOLD_TIME_IN_RESET);
  ubnRFresetTimerLock = 1;
  while(ubnRFresetTimerLock == 1);
  
  HAL_GPIO_WritePin(BNRG_SPI_RESET_PORT, BNRG_SPI_RESET_PIN, GPIO_PIN_SET);
  
#if 1
  /*
   * Limitation in HAL V1.1.0
   * The HAL_GPIO_Init() is first configuring the Mode of the IO before the Pull UP configuration
   * To avoid glitch on the IO, the configuration shall go through an extra step OUTPUT/PULLUP
   * to set upfront the PULL UP configuration.
   */
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(BNRG_SPI_RESET_PORT, &GPIO_InitStruct);
#endif
  
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(BNRG_SPI_RESET_PORT, &GPIO_InitStruct);
  
  TIMER_Start(ubnRFResetTimerID, BLUENRG_HOLD_TIME_AFTER_RESET);
  ubnRFresetTimerLock = 1;
  while(ubnRFresetTimerLock == 1);
  TIMER_Delete(ubnRFResetTimerID);
  
  return;
}
예제 #4
0
Boolean TInitForm::_OnWinInitEvent(TApplication * pApp, EventType * pEvent)
{
	for(int i=0; i<LOADING_FORM_DOT_NUM; i++)
	{
		TImage* pTImage = new TImage;
		if(pTImage->Create(this))
		{
			TRectangle obBtnRec(DOT_X+((SCR_W - DOT_X*2)/LOADING_FORM_DOT_NUM)*i, DOT_Y, DOT_W, DOT_H);
			nDotID[i] = pTImage->GetId();//save button ID
			pTImage->SetBounds(&obBtnRec); 	
			pTImage->SetBitmapByResId (APP_KA_ID_BITMAP_Loading_dot); 
		}
	}

	_DrawDot(pApp, nLoadStep);
	m_nTimerId = TIMER_Create(1000, TIMER_MODE_AUTORUN | TIMER_MODE_PERIOD, NULL, 0, 0);	
	return TRUE;
}
예제 #5
0
파일: main.c 프로젝트: icelittle/hid_ble
/**
 * @brief  Main function to show how to use BlueNRG Bluetooth Low Energy
 *         stack.
 *         To test this application you need:
 *         - an STM32 Nucleo board with its BlueNRG STM32 expansion board
 *         - a Smartphone with Bluetooth Low Energy (BLE) chip and Android
 *           OS >= v4.3.
 *         On the Android smartphone the STM32_BLE_Toolbox App must be installed
 *         and running.
 *         The STM32_BLE_Toolbox App can be found in this package at:
 *         $PATH_TO_THIS_PACKAGE$\Utilities\Android_Software\Profiles_Central
 *         This sample application configures the board as Server-Peripheral,
 *         while the smartphone plays the Client-Central role.
 *         To set/change the BLE Profile to test, change the value of the macro
 *         BLE_CURRENT_PROFILE_ROLES (in the "active profile" section) in file:
 *         $PATH_TO_THIS_PACKAGE$\Middlewares\ST\STM32_BlueNRG\Profile_Framework
 *         \includes\host_config.h
 *         For example, if the HEART_RATE profile is set, after the connection
 *         between the board and the smartphone has been established, the
 *         STM32_BLE_Toolbox App will show the Heart Rate values in bpm (beats
 *         per minute) coming from the STM32 Nucleo board.
 *         The communication is done using a vendor specific profile.
 *
 * @param  None
 * @retval None
 */
int main(void)
{
#if (JTAG_SUPPORTED == 1) 
  /*
  * Keep debugger enabled while in any low power mode
  */
#ifdef STM32L053xx
  __DBGMCU_CLK_ENABLE();
  HAL_DBG_LowPowerConfig(DBGMCU_SLEEP | DBGMCU_STOP | DBGMCU_STANDBY, ENABLE);
#endif /* STM32L053xx */
  
#ifdef STM32L476xx
  HAL_DBGMCU_EnableDBGSleepMode();
  HAL_DBGMCU_EnableDBGStopMode();
  HAL_DBGMCU_EnableDBGStandbyMode();
#endif /* STM32L476xx */

#ifdef STM32F401xE 
  HAL_EnableDBGSleepMode();
  HAL_EnableDBGStopMode();
  HAL_EnableDBGStandbyMode();
#endif /* STM32F401xE */

#endif /* (JTAG_SUPPORTED == 1) */
 
  /* STM32Cube HAL library initialization:
   *  - Configure the Flash prefetch, Flash preread and Buffer caches
   *  - Systick timer is configured by default as source of time base, but user 
   *    can eventually implement his proper time base source (a general purpose 
   *    timer for example or other time source), keeping in mind that Time base 
   *    duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
   *    handled in milliseconds basis.
   *  - Low Level Initialization
   */
  HAL_Init();
  
  /* Configure the system clock */
  SystemClock_Config();
  
  /* Configure the system Power */
  SystemPower_Config();
    
  /* Initialize the Profile Application Context's Data Structures */
  Osal_MemSet(&profileApplContext,0,sizeof(tProfileApplContext));
  
  /* Configure the RTC */
  Init_RTC();
  TIMER_Init(&hrtc);
  TIMER_Create(eTimerModuleID_BlueNRG_Profile_App, &(profileApplContext.profileTimer_Id), eTimerMode_Repeated, 0);
  
  LPM_Mode_Request(eLPM_MAIN_LOOP_PROCESSES, eLPM_Mode_LP_Stop);  
  
  /* Initialize the BlueNRG SPI driver */
  BNRG_SPI_Init();
  
  /* Set current BlueNRG profile (HRM, HTM, GS, ...) */
  BNRG_Set_Current_profile();
  
  /* Initialize the BlueNRG Profile */
  /* set tx power and security parameters (common to all profiles) */
  BNRG_Profiles_Init();  
  /* low level profile initialization (profile specific) */
  profileApplContext.initProfileFunc();
  
  /* Start the main processes */
  while(1)
  {
    Background();
    
  } /* end while(1) */  
}