Esempio n. 1
0
static void renderMenu()
{
    byte i;
    byte n;
    byte page = __kernel_menu_selectedProgram / __KERNEL_MENU_MAX_PROGRAMS_PER_PAGE;
    char __lcd_buffer[17];

    halLcdClearScreen();
    halLcdPrintLineCol("BOT MK1", 0, 1, OVERWRITE_TEXT);

    {   // Write program page number X:X
        sprintf(__lcd_buffer, "%d:%d", page + 1, __kernel_menu_totalPages);
        halLcdPrintLineCol(__lcd_buffer, 0, 13, OVERWRITE_TEXT);
    }

    {   // Write programs available at current page
        for ( i = 0, n = ( page * __KERNEL_MENU_MAX_PROGRAMS_PER_PAGE ) ; i < __KERNEL_MENU_MAX_PROGRAMS_PER_PAGE && ( n + i ) < __kernel_menu_storedPrograms ; i++ )
        {
            halLcdPrintLineCol(__kernel_menu_programs[n + i].tag, i + 2, 3, OVERWRITE_TEXT);
        }
    }

    // Write currently selected program
    renderTickle();
}
Esempio n. 2
0
static void prvSetupHardware( void )
{
    /* Convert a Hz value to a KHz value, as required by the Init_FLL_Settle()
    function. */
    unsigned long ulCPU_Clock_KHz = ( configCPU_CLOCK_HZ / 1000UL );

    halBoardInit();

    LFXT_Start( XT1DRIVE_0 );
    Init_FLL_Settle( ( unsigned short ) ulCPU_Clock_KHz, 488 );

    halButtonsInit( BUTTON_ALL );
    halButtonsInterruptEnable( BUTTON_SELECT );

    /* Initialise the LCD, but note that the backlight is not used as the
    library function uses timer A0 to modulate the backlight, and this file
    defines	vApplicationSetupTimerInterrupt() to also use timer A0 to generate
    the tick interrupt.  If the backlight is required, then change either the
    halLCD library or vApplicationSetupTimerInterrupt() to use a different
    timer.  Timer A1 is used for the run time stats time base6. */
    halLcdInit();
    halLcdSetContrast( 100 );
    halLcdClearScreen();

    halLcdPrintLine( " www.FreeRTOS.org", 0,  OVERWRITE_TEXT );
}
Esempio n. 3
0
/**********************************************************************//**
 * @brief  Executes the "Voice Rec" menu option in the User Experience
 *         example code. Calls the necessary functions according to the
 *         user selection of "Record", "Play", or Exit (center D-pad btn press)
 * 
 * - Initializes the LCD to display the "Record" and "Play" selections
 * - Enters LPM3 to be awoken and continue code execution after a button press
 * - According to the user selection records audio, plays audio, or exits 
 * 
 * @param  none
 * 
 * @return none
 *************************************************************************/
void audio(void)
{
  unsigned char quit = 0;
  
  halLcdClearScreen();
  
  while (!quit)
  {
    buttonsPressed = 0;   
    halLcdPrintLineCol("Record", 8, 1,  OVERWRITE_TEXT);
    halLcdPrintLineCol("Play", 8, 12,  OVERWRITE_TEXT);
    
    __bis_SR_register(LPM3_bits + GIE);   //Returns if button pressed        
    __no_operation(); 
    
    if (buttonsPressed & BUTTON_S1)
    {
      halLcdPrintLineCol("Record", 8, 1, INVERT_TEXT | OVERWRITE_TEXT);
      audioRecord( AUDIO_DEMO_MODE );
      halLcdPrintLineCol("Record", 8, 1,  OVERWRITE_TEXT);
    }
    if (buttonsPressed & BUTTON_S2)
    {
      halLcdPrintLineCol("Play", 8, 12, INVERT_TEXT | OVERWRITE_TEXT);
      audioPlayBack( AUDIO_DEMO_MODE );
      halLcdPrintLineCol("Play", 8, 12,  OVERWRITE_TEXT);
    }
    if (buttonsPressed & BUTTON_SELECT)
      quit = 1;
  }
}
Esempio n. 4
0
static void prvSetupHardware( void )
{
	taskDISABLE_INTERRUPTS();
	
	/* Disable the watchdog. */
	WDTCTL = WDTPW + WDTHOLD;
  
	halBoardInit();

	LFXT_Start( XT1DRIVE_0 );
	hal430SetSystemClock( configCPU_CLOCK_HZ, configLFXT_CLOCK_HZ );

	hal430SetSubSystemMasterClock( );

	halButtonsInit( BUTTON_ALL );
	halButtonsInterruptEnable( BUTTON_SELECT );

	/* Initialise the LCD, but note that the backlight is not used as the
	library function uses timer A0 to modulate the backlight, and this file
	defines	vApplicationSetupTimerInterrupt() to also use timer A0 to generate
	the tick interrupt.  If the backlight is required, then change either the
	halLCD library or vApplicationSetupTimerInterrupt() to use a different
	timer.  Timer A1 is used for the run time stats time base6. */
	halLcdInit();
	halLcdSetContrast( 100 );
	halLcdClearScreen();
	
	halLcdPrintLine( " www.FreeRTOS.org", 0,  OVERWRITE_TEXT );
}
Esempio n. 5
0
void init_LCD(void)
{
    halLcdInit();                    // Programa interno para iniciar la pantalla
    halLcdBackLightInit();           // Inicio de Iluminación posterior de la pantalla
    halLcdSetBackLight(iluminacion); // Determinación de la Iluminación posterior de la pantalla
    halLcdSetContrast(contraste);    //Establecimiento del contraste
    halLcdClearScreen();             //Limpiar (borrar) la pantalla
}
Esempio n. 6
0
void initialize_lcd()
{
    halLcdInit();
    halLcdBackLightInit();
    halLcdSetBackLight(lcd_backlight);
    halLcdSetContrast(lcd_contrast);
    halLcdClearScreen();
}
Esempio n. 7
0
/*---------------------------------------------------------------------------*/
void
lcd_clear(void)
{
  if(WITH_LCD) {
    halLcdClearScreen();
    xpos = ypos = 0;
  }
}
Esempio n. 8
0
void init_LCD(void)
{
	//Inicializamos la pantallita LCD:    
  halLcdInit();       
  halLcdBackLightInit();  
  halLcdSetBackLight(iluminacion);
  halLcdSetContrast(contraste);
  halLcdClearScreen(); 
}
void render_time(uint8_t* data) {
	char time_str[] = "12:34:56";

	time_str[7] = '0' + data[0] % 10;
	time_str[6] = '0' + data[0] / 10;
	time_str[4] = '0' + data[1] % 10;
	time_str[3] = '0' + data[1] / 10;
	time_str[1] = '0' + data[2] % 10;
	time_str[0] = '0' + data[2] / 10;

    halLcdClearScreen();
	halLcdPrintXY(time_str, 40, 45, GRAYSCALE_TEXT | OVERWRITE_TEXT);
	halLcdPrintXY(status_str, 0, 98, GRAYSCALE_TEXT | OVERWRITE_TEXT | INVERT_TEXT);
}
Esempio n. 10
0
void doLCD(void){
    //Initialize LCD and backlight    
    // 138 x 110, 4-level grayscale pixels.
    halLcdInit();       
    // halLcdBackLightInit();  
    // halLcdSetBackLight(0);  // 8 for normal
    halLcdSetContrast(100);
    halLcdClearScreen(); 
    halLcdImage(TI_TINY_BUG, 4, 32, 104, 12 );

    halLcdPrintLine("BTstack on ", 0, 0);
    halLcdPrintLine("TI MSP430", 1, 0);
    halLcdPrintLine("Keyboard", 2, 0);
    halLcdPrintLine("Init...", 3, 0);
    row = 4;
}
Esempio n. 11
0
static void prvLCDTask( void *pvParameters )
{
    xQueueMessage xReceivedMessage;

    /* Buffer into which strings are formatted and placed ready for display on the
    LCD.  Note this is a static variable to prevent it being allocated on the task
    stack, which is too small to hold such a variable.  The stack size is configured
    when the task is created. */
    static char cBuffer[ 512 ];
    unsigned char ucLine = 1;


    /* This function is the only function that uses printf().  If printf() is
    used from any other function then some sort of mutual exclusion on stdout
    will be necessary.

    This is also the only function that is permitted to access the LCD.

    First print out the number of bytes that remain in the FreeRTOS heap.  This
    can be viewed in the terminal IO window within the IAR Embedded Workbench. */
    printf( "%d bytes of heap space remain unallocated\n", ( int ) xPortGetFreeHeapSize() );

    /* Just as a test of the port, and for no functional reason, check the task
    parameter contains its expected value. */
    if( pvParameters != mainTASK_PARAMETER_CHECK_VALUE )
    {
        halLcdPrintLine( "Invalid parameter", ucLine,  OVERWRITE_TEXT );
        ucLine++;
    }

    for( ;; )
    {
        /* Wait for a message to be received.  Using portMAX_DELAY as the block
        time will result in an indefinite wait provided INCLUDE_vTaskSuspend is
        set to 1 in FreeRTOSConfig.h, therefore there is no need to check the
        function return value and the function will only return when a value
        has been received. */
        xQueueReceive( xLCDQueue, &xReceivedMessage, portMAX_DELAY );

        /* Clear the LCD if no room remains for any more text output. */
        if( ucLine > mainMAX_LCD_LINES )
        {
            halLcdClearScreen();
            ucLine = 0;
        }

        /* What is this message?  What does it contain? */
        switch( xReceivedMessage.cMessageID )
        {
        case mainMESSAGE_BUTTON_UP		:	/* The button poll task has just
												informed this task that the up
												button on the joystick input has
												been pressed or released. */
            sprintf( cBuffer, "Button up = %d", ( int ) xReceivedMessage.ulMessageValue );
            break;

        case mainMESSAGE_BUTTON_SEL		:	/* The select button interrupt
												just informed this task that the
												select button was pressed.
												Generate a table of task run time
												statistics and output this to
												the terminal IO window in the IAR
												embedded workbench. */
            printf( "\nTask\t     Abs Time\t     %%Time\n*****************************************" );
            vTaskGetRunTimeStats( ( signed char * ) cBuffer );
            printf( cBuffer );

            /* Also print out a message to
            the LCD - in this case the
            pointer to the string to print
            is sent directly in the
            ulMessageValue member of the
            message.  This just demonstrates
            a different communication
            technique. */
            sprintf( cBuffer, "%s", ( char * ) xReceivedMessage.ulMessageValue );
            break;

        case mainMESSAGE_STATUS			:	/* The tick interrupt hook
												function has just informed this
												task of the system status.
												Generate a string in accordance
												with the status value. */
            prvGenerateStatusMessage( cBuffer, xReceivedMessage.ulMessageValue );
            break;

        default							:
            sprintf( cBuffer, "Unknown message" );
            break;
        }

        /* Output the message that was placed into the cBuffer array within the
        switch statement above, then move onto the next line ready for the next
        message to arrive on the queue. */
        halLcdPrintLine( cBuffer, ucLine,  OVERWRITE_TEXT );
        ucLine++;
    }
}
Esempio n. 12
0
static void onMenuShutdown()
{
    halLcdClearScreen();
}
Esempio n. 13
0
/**********************************************************************//**
 * @brief  Executes the "PMM-MCLK" menu option in the User Experience
 *         example code. This menu option allows one to change the frequency
 *         of operation for the MSP430 and the VCore setting. 
 * 
 * @param  none 
 * 
 * @return none 
 *************************************************************************/
void menuPMMMCLK( void )
{
  unsigned char menuLeftPos = 2, menuRightPos = 0, menuRightMaxAllowed = 5;
  unsigned char ledOn, quit = 0;
  volatile unsigned int i;
  
  halButtonsInterruptDisable( BUTTON_ALL );
  halButtonsInterruptEnable( BUTTON_SELECT + BUTTON_S1 +   \
                             BUTTON_S2 + BUTTON_RIGHT );
  halAccelerometerShutDown();
  halLcdClearScreen();
  
  halBoardOutputSystemClock();
  halLcdPrintLineCol(&VcoreText[0], 0, 1,  OVERWRITE_TEXT );

  for (i=0;i < MCLK_MENU_MAX+1; i++)
    halLcdPrintLineCol(&MCLKText[i*6], i, 12,  OVERWRITE_TEXT );
  
  halLcdPrintLineCol(&VcoreText[menuLeftPos*6 + 6],        \
                     menuLeftPos+1, 1, INVERT_TEXT | OVERWRITE_TEXT);
  halLcdPrintLineCol(&MCLKText[menuRightPos*6 + 6],        \
                     menuRightPos+1, 12, INVERT_TEXT | OVERWRITE_TEXT);    
  buttonsPressed = 0;  
  
  for (i = menuRightMaxAllowed; i < MCLK_MENU_MAX; i++)
  {
    halLcdLine(96, 12*(i+1)+6, 136, 12*(i+1)+6, PIXEL_ON);        
    halLcdLine(96, 12*(i+1)+7, 136, 12*(i+1)+7, PIXEL_ON);     
  }
  ledOn = 0;
  halLcdPrintLine("      LED", 6, 0);  
  halLcdPrintLine("      OFF", 7, 0);
  halLcdImage(IMG_RIGHT_FILLED, 4, 32, 10, 75);
  
  halBoardSetVCore(menuLeftPos);
  halBoardSetSystemClock(menuRightPos);  

  while (!quit)
  {
  	// The LED can be enabled to show the relative difference between
  	// frequencies of operation. 
    while (!buttonsPressed)    
      if (ledOn)
      {
        LED_PORT_OUT ^= LED_1;
        for (i=0; i < 0xFFFF; i++)
          if (buttonsPressed)
            break;
      }      
      else
      {
      	// To emulate a real application instead of continuous jumps, use nops 
        __no_operation();
        __no_operation();
        __no_operation();
        __no_operation();                           
        __no_operation();
        __no_operation();
        __no_operation();
        __no_operation();                           
        __no_operation();
      }
    if (buttonsPressed & BUTTON_S1)
    {
      /*
       * Disabled for MSP430F5438 RTM Silicon
      halLcdPrintLineCol(&VcoreText[menuLeftPos*6 + 6], menuLeftPos+1,      \
                         1,  OVERWRITE_TEXT);
      if (++ menuLeftPos >= VCORE_MENU_MAX)
      {
        menuLeftPos = 0;
        menuRightMaxAllowed = MAX_MCLK_ALLOWED[ menuLeftPos ];
        if (menuRightPos >= menuRightMaxAllowed)
        {
          halLcdPrintLineCol(&MCLKText[menuRightPos*6 + 6], menuRightPos+1, \
                             12,  OVERWRITE_TEXT);                
          menuRightPos = menuRightMaxAllowed - 1;
          halLcdPrintLineCol(&MCLKText[menuRightPos*6 + 6], menuRightPos+1, \
                             12, INVERT_TEXT | OVERWRITE_TEXT);  
        }        
        for (i = menuRightMaxAllowed; i < MCLK_MENU_MAX; i++)
        {
          halLcdLine(96, 12*(i+1)+6, 136, 12*(i+1)+6, PIXEL_ON);        
          halLcdLine(96, 12*(i+1)+7, 136, 12*(i+1)+7, PIXEL_ON);        
        }
      } 
         
      else            
      {
        for (i=menuRightMaxAllowed+1; i< MAX_MCLK_ALLOWED[menuLeftPos]+1; i ++)
          halLcdPrintLineCol(&MCLKText[i*6], i, 12,  OVERWRITE_TEXT );          
        menuRightMaxAllowed = MAX_MCLK_ALLOWED[menuLeftPos];
      }      
      halLcdPrintLineCol(&VcoreText[menuLeftPos*6 + 6], menuLeftPos+1,       \
                         1, INVERT_TEXT | OVERWRITE_TEXT);
      */
    }
    if ( buttonsPressed & BUTTON_S2 )
    {
      halLcdPrintLineCol(&MCLKText[menuRightPos*6 + 6],    \
                         menuRightPos+1, 12,  OVERWRITE_TEXT);        
      
      if ( ++menuRightPos >= menuRightMaxAllowed )      
        menuRightPos = 0;
        
      halLcdPrintLineCol(&MCLKText[menuRightPos*6 + 6],    \
                         menuRightPos+1, 12, INVERT_TEXT| OVERWRITE_TEXT);              
    }
    if ( buttonsPressed & BUTTON_RIGHT )
    {
      ledOn = 1 - ledOn;
      if ( ledOn )        
        halLcdPrintLineCol("ON ", 7, 6, OVERWRITE_TEXT);
      else
      {
      	halLcdPrintLineCol("OFF", 7, 6, OVERWRITE_TEXT);
        LED_PORT_OUT &= ~LED_1;
      }         
    }    
    
    if ( buttonsPressed & (BUTTON_S1 | BUTTON_S2) )
    {
      halBoardSetVCore(menuLeftPos);
  		halBoardSetSystemClock(menuRightPos);  
  		//halBoardDisableSVS();
    }
    if ( buttonsPressed & BUTTON_SELECT )    
      quit = 1;
    buttonsPressed = 0;
  }
  
  halBoardSetSystemClock( SYSCLK_16MHZ );
  halBoardStopOutputSystemClock();
  LED_PORT_OUT &= ~LED_1;
}
Esempio n. 14
0
static void prvLCDTask( void *pvParameters )
{
xQueueMessage xReceivedMessage;

/* Buffer into which strings are formatted and placed ready for display on the
LCD.  Note this is a static variable to prevent it being allocated on the task
stack, which is too small to hold such a variable.  The stack size is configured
when the task is created. */
static char cBuffer[ 50 ];
unsigned char ucLine = 1;

	/* Now the scheduler has been started (it must have been for this task to
	be running), start the check timer too.  The call to xTimerStart() will
	block until the command has been accepted. */
	if( xCheckTimer != NULL )
	{
		xTimerStart( xCheckTimer, portMAX_DELAY );
	}

	/* This is the only function that is permitted to access the LCD.
	
	First print out the number of bytes that remain in the FreeRTOS heap.  This
	is done after a short delay to ensure all the demo tasks have created all
	the objects they are going to use.  */
	vTaskDelay( mainTIMER_TEST_PERIOD * 10 );
	sprintf( cBuffer, "%d heap free", ( int ) xPortGetFreeHeapSize() );
	halLcdPrintLine( cBuffer, ucLine, OVERWRITE_TEXT );
	ucLine++;
	
	/* Just as a test of the port, and for no functional reason, check the task
	parameter contains its expected value. */
	if( pvParameters != mainTASK_PARAMETER_CHECK_VALUE )
	{
		halLcdPrintLine( "Invalid parameter", ucLine, OVERWRITE_TEXT );
		ucLine++;		
	}

	for( ;; )
	{
		/* Wait for a message to be received.  Using portMAX_DELAY as the block
		time will result in an indefinite wait provided INCLUDE_vTaskSuspend is
		set to 1 in FreeRTOSConfig.h, therefore there is no need to check the
		function return value and the function will only return when a value
		has been received. */
		xQueueReceive( xLCDQueue, &xReceivedMessage, portMAX_DELAY );

		/* Clear the LCD if no room remains for any more text output. */
		if( ucLine > mainMAX_LCD_LINES )
		{
			halLcdClearScreen();
			ucLine = 0;
		}
		
		/* What is this message?  What does it contain? */
		switch( xReceivedMessage.cMessageID )
		{
			case mainMESSAGE_BUTTON_UP		:	/* The button poll task has just
												informed this task that the up
												button on the joystick input has
												been pressed or released. */
												sprintf( cBuffer, "Button up = %d", ( int ) xReceivedMessage.ulMessageValue );
												break;

			case mainMESSAGE_BUTTON_SEL		:	/* The select button interrupt
												just informed this task that the
												select button has been pressed.
												In this case the pointer to the 
												string to print is sent directly 
												in the ulMessageValue member of 
												the	message.  This just 
												demonstrates a different 
												communication technique. */
												sprintf( cBuffer, "%s", ( char * ) xReceivedMessage.ulMessageValue );
												break;
												
			case mainMESSAGE_STATUS			:	/* The tick interrupt hook
												function has just informed this
												task of the system status.
												Generate a string in accordance
												with the status value. */
												prvGenerateStatusMessage( cBuffer, xReceivedMessage.ulMessageValue );
												break;
												
			default							:	sprintf( cBuffer, "Unknown message" );
												break;
		}
		
		/* Output the message that was placed into the cBuffer array within the
		switch statement above, then move onto the next line ready for the next
		message to arrive on the queue. */
		halLcdPrintLine( cBuffer, ucLine,  OVERWRITE_TEXT );
		ucLine++;
	}
}
Esempio n. 15
0
int main(void) {
    uint8_t  currState;
    uint8_t  targetState;
    uint16_t readbcLength;
    uint32_t nwkId;
    uint8_t  errorCheckInterval = 100;

    // Stop watchdog timer to prevent time out reset
    WDTCTL = WDTPW + WDTHOLD;

    // Initialize the MCU and board peripherals
    halBoardInit();
    halBoardStartXT1();	
    halBoardSetSystemClock(SYSCLK_16MHZ);
    halButtonsInit(BUTTON_ALL);
    halLcdInit();
    halLcdBackLightInit();
    halLcdSetContrast(90);
    halLcdSetBackLight(10);
    halLcdClearScreen();

    halLcdPrintLine("  CC85XX SLAVE   ", 0, OVERWRITE_TEXT );
    halLcdPrintLine("                 ", 1, OVERWRITE_TEXT );
    halLcdPrintLine("S1: Power toggle ", 2, OVERWRITE_TEXT );
    halLcdPrintLine("S2: Pairing start", 3, OVERWRITE_TEXT );
    uifLcdPrintJoystickInfo();

    // Wipe remote control information
    memset(&ehifRcSetDataParam, 0x00, sizeof(ehifRcSetDataParam));

    // Initialize EHIF IO
    ehifIoInit();

    // Reset into the application
    ehifSysResetPin(true);
    currState = CC85XX_STATE_ALONE;
    targetState = CC85XX_STATE_ACTIVE;

    // Get the last used network ID from CC85XX non-volatile storage
    initParam();
    ehifCmdParam.nvsGetData.index = 0;
    ehifCmdExecWithRead(EHIF_EXEC_ALL, EHIF_CMD_NVS_GET_DATA, 
                        sizeof(EHIF_CMD_NVS_GET_DATA_PARAM_T), &ehifCmdParam, 
                        sizeof(EHIF_CMD_NVS_GET_DATA_DATA_T), &ehifCmdData);
    nwkId = ehifCmdData.nvsGetData.data;

    // Handle illegal default network IDs that may occur first time after programming
    if ((nwkId == 0x00000000) || (nwkId == 0xFFFFFFFF)) {
        nwkId = 0xFFFFFFFE;
    }

    // Main loop
    while (1) {

        // Wait 10 ms
        EHIF_DELAY_MS(10);

        // Perform action according to edge-triggered button events (debouncing with 100 ms delay)
        switch (pollButtons()) {

        // POWER TOGGLE
        case BUTTON_S1:
            if (currState == CC85XX_STATE_OFF) {
                targetState = CC85XX_STATE_ACTIVE;
            } else {
                targetState = CC85XX_STATE_OFF;
            }
            break;

        // PAIRING TRIGGER
        case BUTTON_S2:
            if (currState != CC85XX_STATE_OFF) {
                targetState = CC85XX_STATE_PAIRING;
            }
            break;
        }

        // Run the state machine
        if (currState != targetState) {

            if (currState == CC85XX_STATE_OFF) {
                // HANDLE POWER ON

                // Ensure known state (power state 5)
                ehifSysResetPin(true);
                currState = CC85XX_STATE_ALONE;

            } else if (targetState == CC85XX_STATE_OFF) {
                // HANDLE POWER OFF

                // Ensure known state (power state 5)
                ehifSysResetPin(true);
                currState = CC85XX_STATE_ALONE;

                // Set power state 0
                ehifCmdParam.pmSetState.state = 0;
                ehifCmdExec(EHIF_CMD_PM_SET_STATE, sizeof(EHIF_CMD_PM_SET_STATE_PARAM_T), &ehifCmdParam);
                currState = CC85XX_STATE_OFF;

            } else if (targetState == CC85XX_STATE_PAIRING) {
                // HANDLE PAIRING

                // Let the last executed EHIF command complete, with 5 second timeout
                ehifWaitReadyMs(5000);

                // Disconnect if currently connected
                if (ehifGetStatus() & BV_EHIF_STAT_CONNECTED) {
                    initParam();
                    // All parameters should be zero
                    ehifCmdExec(EHIF_CMD_NWM_DO_JOIN, sizeof(EHIF_CMD_NWM_DO_JOIN_PARAM_T), &ehifCmdParam);
                }

                // Search for one protocol master with pairing signal enabled for 10 seconds
                initParam();
                ehifCmdParam.nwmDoScan.scanTo           = 1000;
                ehifCmdParam.nwmDoScan.scanMax          = 1;
                ehifCmdParam.nwmDoScan.reqPairingSignal = 1;
                ehifCmdParam.nwmDoScan.reqRssi          = -128;
                ehifCmdExecWithReadbc(EHIF_EXEC_CMD, EHIF_CMD_NWM_DO_SCAN, 
                                      sizeof(EHIF_CMD_NWM_DO_SCAN_PARAM_T), &ehifCmdParam, 
                                      NULL, NULL);

                // Fetch network information once ready
                ehifWaitReadyMs(12000);
                readbcLength = sizeof(ehifNwmDoScanData);
                ehifCmdExecWithReadbc(EHIF_EXEC_DATA, EHIF_CMD_NWM_DO_SCAN, 
                                      0, NULL, 
                                      &readbcLength, &ehifNwmDoScanData);

                // If found ...
                if (readbcLength == sizeof(EHIF_CMD_NWM_DO_SCAN_DATA_T)) {

                    // Update the network ID to be used next
                    nwkId = ehifNwmDoScanData.deviceId;

                    // Place the new network ID in CC85XX non-volatile storage
                    initParam();
                    ehifCmdParam.nvsSetData.index = 0;
                    ehifCmdParam.nvsSetData.data  = ehifNwmDoScanData.deviceId;
                    ehifCmdExec(EHIF_CMD_NVS_SET_DATA, sizeof(EHIF_CMD_NVS_SET_DATA_PARAM_T), &ehifCmdParam);
                }

                // Done
                currState = CC85XX_STATE_ALONE;
                targetState = CC85XX_STATE_ACTIVE;

            } else if (targetState == CC85XX_STATE_ACTIVE) {

                // We're disconnected. Proceed only if EHIF is ready, so that power toggle and pairing
                // buttons can still be operated
                uint16_t status = ehifGetStatus();
                if (status & BV_EHIF_STAT_CMD_REQ_RDY) {

                    // Perform join operation first and then activate audio channels. We're using remote
                    // volume control
                    if (!(status & BV_EHIF_STAT_CONNECTED)) {

                        // Enable disconnection notification to avoid unnecessary EHIF activity while active
                        initParam();
                        ehifCmdParam.ehcEvtClr.clearedEvents = BV_EHIF_EVT_NWK_CHG;
                        ehifCmdExec(EHIF_CMD_EHC_EVT_CLR, sizeof(EHIF_CMD_EHC_EVT_CLR_PARAM_T), &ehifCmdParam);
                        initParam();
                        ehifCmdParam.ehcEvtMask.irqGioLevel = 0;
                        ehifCmdParam.ehcEvtMask.eventFilter = BV_EHIF_EVT_NWK_CHG;
                        ehifCmdExec(EHIF_CMD_EHC_EVT_MASK, sizeof(EHIF_CMD_EHC_EVT_MASK_PARAM_T), &ehifCmdParam);

                        // Not connected: Start JOIN operation
                        initParam();
                        ehifCmdParam.nwmDoJoin.joinTo = 100;
                        ehifCmdParam.nwmDoJoin.deviceId = nwkId;
                        ehifCmdExec(EHIF_CMD_NWM_DO_JOIN, sizeof(EHIF_CMD_NWM_DO_JOIN_PARAM_T), &ehifCmdParam);

                    } else {
                        // Connected: Subscribe to audio channels (0xFF = unused)
                        memset(&ehifCmdParam, 0xFF, sizeof(EHIF_CMD_NWM_ACH_SET_USAGE_PARAM_T));
                        ehifCmdParam.nwmAchSetUsage.pAchUsage[0] = 0; // Front left  -> I2S LEFT
                        ehifCmdParam.nwmAchSetUsage.pAchUsage[1] = 1; // Front right -> I2S RIGHT
                        ehifCmdExec(EHIF_CMD_NWM_ACH_SET_USAGE, sizeof(EHIF_CMD_NWM_ACH_SET_USAGE_PARAM_T), &ehifCmdParam);
                        currState = CC85XX_STATE_ACTIVE;
                    }
                }
            }

        } else {

            // Only OFF and ACTIVE are permanent target states. SCAN is only a temporary target state.
            // In the OFF state we do nothing, so only need to handle the ACTIVE state.
            if (currState == CC85XX_STATE_ACTIVE) {

                // Detect network disconnection without generating noise on the SPI interface
                if (EHIF_INTERRUPT_IS_ACTIVE()) {
                    currState = CC85XX_STATE_ALONE;
                }

                // Perform error checking at 10 ms * 100 = 1 second intervals:
                // - No timeouts or SPI errors shall have occurred
                // - We should be connected unless disconnection has been signalized
                if (--errorCheckInterval == 0) {
                    errorCheckInterval = 100;
                    uint16_t status = ehifGetStatus();
                    if (ehifGetWaitReadyError() || (status & BV_EHIF_EVT_SPI_ERROR) ||
                        (!(status & BV_EHIF_STAT_CONNECTED) && !(status & BV_EHIF_EVT_NWK_CHG))) {

                        // The device is in an unknown state -> restart everything
                        ehifSysResetPin(true);
                        currState = CC85XX_STATE_ALONE;
                    }
                }

                // If the network connection is up and running...
                if (currState == CC85XX_STATE_ACTIVE) {

                    // Send remote control commands (mouse or play control, depending on which uif file
                    // is included in the build)
                    if (uifPollFunc(&ehifRcSetDataParam)) {
                        ehifCmdExec(EHIF_CMD_RC_SET_DATA, sizeof(EHIF_CMD_RC_SET_DATA_PARAM_T), &ehifRcSetDataParam);
                    }
                }
            }
        }
    }

} // main