コード例 #1
0
ファイル: hal_key.c プロジェクト: ndksys01/FinalProject
/**************************************************************************************************
* @fn      HalKeyConfig
*
* @brief   Configure the Key serivce
*
* @param   interruptEnable - TRUE/FALSE, enable/disable interrupt
*          cback - pointer to the CallBack function
*
* @return  None
**************************************************************************************************/
void HalKeyConfig( bool interruptEnable, halKeyCBack_t cback)
{
#if (HAL_KEY == TRUE)
  /* Enable/Disable Interrupt or */
  Hal_KeyIntEnable = interruptEnable;
  
  /* Register the callback fucntion */
  pHal_KeyProcessFunction = cback;  
  
  /* Determine if interrupt is enable or not */
  if ( Hal_KeyIntEnable )
  {
    
    /* Initialize key handler to use interrupts */
    bspKeyInit(BSP_KEY_MODE_ISR);
    
    /* Map function dirKeyIsr to UP, LEFT, RIGHT and DOWN keys */
    bspKeyIntRegister((BSP_KEY_UP|BSP_KEY_LEFT|BSP_KEY_RIGHT|BSP_KEY_DOWN),
                      &interrupt_keybd);
    
    /* Map function selectKeyIsr to SELECT key */
    bspKeyIntRegister(BSP_KEY_SELECT, &interrupt_keybd);
    
    /* Enable interrupts on all keys */
    bspKeyIntEnable(BSP_KEY_ALL);
    
    IntPrioritySet(INT_GPIOC, HAL_INT_PRIOR_KEY);              
    IntPrioritySet(INT_GPIOA, HAL_INT_PRIOR_KEY);     
    
    /* Cancel polling if there is one active */
    osal_stop_timerEx(Hal_TaskID, HAL_KEY_EVENT);
  }
  else
  {
    bspKeyInit(BSP_KEY_MODE_POLL);
    
    if( cback != NULL)
    {
      /* Start polling if callback function is setup*/
      osal_set_event(Hal_TaskID, HAL_KEY_EVENT);
    }
  }
#endif /* HAL_KEY */
}
コード例 #2
0
ファイル: uart_example.c プロジェクト: lab11/cc2538-base
/**************************************************************************//**
* @brief    Main function of example.
******************************************************************************/
void main(void)
{
    uint8_t ui8KeyBm = 0;
    uint_fast16_t ui16Cnt = 0;
    uint8_t ui8Byte = APP_TX_BYTE;

    //
    // Initialize clocks and board I/O
    //
    bspInit(BSP_SYS_CLK_SPD);

    //
    // Set LED1 to indicate life
    //
    bspLedSet(BSP_LED_1);

    //
    // Initialize key driver
    //
    bspKeyInit(BSP_KEY_MODE_ISR);
    bspKeyIntEnable(BSP_KEY_SELECT|BSP_KEY_UP);

    //
    // Initialize UART to USB MCU
    //
    bspUartBufInit(pui8TxBuf, sizeof(pui8TxBuf), pui8RxBuf, sizeof(pui8RxBuf));

    //
    // Application must register the UART interrupt handler
    //
    UARTIntRegister(BSP_UART_BASE, &appUartIsr);

    //
    // Open UART connection
    //
    if(bspUartOpen(eBaudRate115200) != BSP_UART_SUCCESS)
    {
        //
        // Failed to initialize UART handler
        //
        bspAssert();
    }

    //
    // Initialize SPI interface to LCD, configure LCD, and display information.
    //
    bspSpiInit(BSP_SPI_CLK_SPD);
    lcdInit();
    lcdBufferPrintStringAligned(0, "UART example", eLcdAlignCenter, eLcdPage0);
    lcdBufferInvertPage(0, 0,127, eLcdPage0);
    lcdBufferPrintString(0, "Baud rate   :", 6, eLcdPage2);
    lcdBufferPrintIntAligned(0, bspUartBaudRateGet(), eLcdAlignRight, eLcdPage2);
    lcdBufferPrintString(0, "Format      :", 6, eLcdPage3);
    lcdBufferPrintStringAligned(0, "8-N-1", eLcdAlignRight, eLcdPage3);
    lcdBufferPrintString(0, "Flow control:", 6, eLcdPage4);
    lcdBufferPrintStringAligned(0, "No", eLcdAlignRight, eLcdPage4);
    lcdBufferPrintStringAligned(0, "Transmit: UP key", eLcdAlignRight, eLcdPage6);
    lcdBufferPrintStringAligned(0, "SELECT to toggle mode", eLcdAlignCenter, eLcdPage7);
    lcdBufferInvertPage(0, 0,127, eLcdPage7);
    lcdSendBuffer(0);

    //
    // Enable global interrupts
    //
    IntMasterEnable();

    while(1)
    {
        ui8KeyBm = bspKeyPushed(BSP_KEY_ALL);

        if(BSP_KEY_SELECT & ui8KeyBm)
        {
            //
            // Change mode
            //
            bRepeaterMode ^= 1;
            bspLedToggle(BSP_LED_3);

            //
            // Update LCD for the new mode
            //
            lcdBufferClearPart(0, 0,127, eLcdPage6, eLcdPage6);
            if(bRepeaterMode)
            {
                lcdBufferPrintStringAligned(0, "Repeater mode",
                                            eLcdAlignCenter, eLcdPage6);
            }
            else
            {
                lcdBufferPrintStringAligned(0, "Transmit: UP key",
                                            eLcdAlignCenter, eLcdPage6);
            }
            lcdSendBufferPart(0, 0,127, eLcdPage6, eLcdPage6);
        }

        //
        // Read data from UART RX buffer to application buffer
        //
        ui16Cnt = bspUartDataGet(pui8AppBuf, bspUartRxCharsAvail());

        if(bRepeaterMode)
        {
            //
            // Repeater mode
            //

            if(ui16Cnt)
            {
                //
                // Send data from application buffer to UART TX buffer
                //
                bspUartDataPut(pui8AppBuf, ui16Cnt);
            }
        }
        else
        {
            //
            // Transmit mode
            //

            if(BSP_KEY_UP & ui8KeyBm)
            {
                //
                // Transmit a single character
                //
                bspUartDataPut(&ui8Byte, 1);
            }
        }
    }
}
コード例 #3
0
ファイル: main.c プロジェクト: tqkhcmut/LightTimerForMyTree
/******************************************************************************
 * @fn          main
 *
 * @brief       Main handles all applications attached to the menu system
 *
 * input parameters
 *
 * output parameters
 *
 *@return
 */
void main( void )
{
   
  // Init clocks and I/O 
  bspInit(BSP_SYS_CLK_16MHZ);
  
  // Init leds 
  bspLedInit(); 

  // Init Buttons
  bspKeyInit(BSP_KEY_MODE_POLL);
  
  // Initialize SPI interface to LCD (shared with SPI flash)
  bspIoSpiInit(BSP_FLASH_LCD_SPI, BSP_FLASH_LCD_SPI_SPD);  

  /* Init Buttons */
  bspKeyInit(BSP_KEY_MODE_ISR);
  bspKeyIntEnable(BSP_KEY_ALL);
  /* Init LCD and issue a welcome */
  lcdInit();
  lcdClear();
  // Instantiate tranceiver RF spi interface to SCLK ~ 4 MHz */
  //input clockDivider - SMCLK/clockDivider gives SCLK frequency
  trxRfSpiInterfaceInit(0x10);
  
  /* Welcome Screen Part */
  lcdSendBuffer(trxebWelcomeScreen);
  lcdBufferPrintString(lcdDefaultBuffer,"TEXAS",60,eLcdPage6);
  lcdBufferPrintString(lcdDefaultBuffer,"INSTRUMENTS",60,eLcdPage7);
  lcdSendBufferPart(lcdDefaultBuffer, 60,127,eLcdPage6, eLcdPage7);
  /* MCU will stay in sleep until button is pressed */
  __low_power_mode_3();
  bspKeyPushed(BSP_KEY_ALL);
  //Clear screen
  lcdBufferClear(0);

  /* Menu Driver */
  menu_t *pCurrentMenu = &mainMenu;
  uint8 menuButtonsPressed;
  menuDisplay(pCurrentMenu);
  __low_power_mode_3();
  while(1)
  {
    menuButtonsPressed = bspKeyPushed(BSP_KEY_ALL);
    switch(menuButtonsPressed)
    {
      case BSP_KEY_LEFT:
        pCurrentMenu = menuBack(pCurrentMenu);
        break;
      case BSP_KEY_RIGHT:
        pCurrentMenu = menuEnter(pCurrentMenu);
        break;
      case BSP_KEY_DOWN:
        menuDown(pCurrentMenu);
        break;
      case BSP_KEY_UP:
        menuUp(pCurrentMenu);
        break;
      default:
        break;
    }
    menuDisplay(pCurrentMenu);
    /* Enter low power mode while menu driver waits on user input */
    __low_power_mode_3();
  }
}