Exemple #1
0
static void check_state_timer_handler( void* arg )
{
    gpio_keypad_internal_t* keypad = (gpio_keypad_internal_t*)arg;

    if ( keypad != NULL )
    {
        gpio_key_internal_t* key = keypad->current_key_pressed;

        if ( key != NULL )
        {
            if ( key->key->polarity == KEY_POLARITY_HIGH )
            {
                if ( wiced_gpio_input_get( key->key->gpio ) == 0 )
                {
                    wiced_rtos_send_asynchronous_event( keypad->thread, key_held_event_handler, (void*)key );
                }
                else
                {
                    wiced_rtos_send_asynchronous_event( keypad->thread, key_released_event_handler, (void*)key );
                }
            }
            else
            {
                if ( wiced_gpio_input_get( key->key->gpio ) == 1 )
                {
                    wiced_rtos_send_asynchronous_event( keypad->thread, key_held_event_handler, (void*)key );
                }
                else
                {
                    wiced_rtos_send_asynchronous_event( keypad->thread, key_released_event_handler, (void*)key );
                }
            }
        }
    }
}
Exemple #2
0
void application_start( )
{
    uint8_t      led_state = 0;
    wiced_bool_t button_pressed;

    /* Initialise the WICED device */
    wiced_init();

    // The RGB and setup button are initialized in platform.c

    WPRINT_APP_INFO( ( "The RGB are flashing R-G-B alternately. Holding the setup button will force it flashing white.\n" ) );

    while ( 1 )
    {
        /* Read the state of setup button */
        button_pressed = wiced_gpio_input_get( SETUP_BUTTON ) ? WICED_FALSE : WICED_TRUE;  /* The button has inverse logic */

        if ( button_pressed == WICED_TRUE )
        {
            /* Flashing white */
            if( (led_state%2) == 0 )
            {
                wiced_gpio_output_low( RGB_R );
                wiced_gpio_output_low( RGB_G );
                wiced_gpio_output_low( RGB_B );
            }
            else
            {
                wiced_gpio_output_high( RGB_R );
                wiced_gpio_output_high( RGB_G );
                wiced_gpio_output_high( RGB_B );
            }
        }
        else
        {
            /* Flashing R-G-B alternately */
            if ( (led_state%3) == 0 )
            {
                wiced_gpio_output_low( RGB_R );
                wiced_gpio_output_high( RGB_G );
                wiced_gpio_output_high( RGB_B );
            }
            else if ( (led_state%3) == 1 )
            {
                wiced_gpio_output_high( RGB_R );
                wiced_gpio_output_low( RGB_G );
                wiced_gpio_output_high( RGB_B );
            }
            else
            {
                wiced_gpio_output_high( RGB_R );
                wiced_gpio_output_high( RGB_G );
                wiced_gpio_output_low( RGB_B );
            }
        }

        wiced_rtos_delay_milliseconds( 300 );
        led_state++;
    }
}
Exemple #3
0
void platform_init_external_devices( void )
{
    //wiced_bool_t button1_pressed;

    /* Initialise buttons to input by default */
    platform_gpio_init( &platform_gpio_pins[BTN1], INPUT_PULL_UP );
#if 0
    button1_pressed = wiced_gpio_input_get( BTN1 ) ? WICED_FALSE : WICED_TRUE;  /* The button has inverse logic */
    if ( button1_pressed != WICED_TRUE )
    {
        platform_gpio_init( &platform_gpio_pins[LED], OUTPUT_PUSH_PULL );
        platform_gpio_output_high( &platform_gpio_pins[LED] );
    }
#endif

    /* Initialise LEDs and turn off by default */
    platform_gpio_init( &platform_gpio_pins[LED_R], OUTPUT_PUSH_PULL );
    platform_gpio_init( &platform_gpio_pins[LED_G], OUTPUT_PUSH_PULL );
    platform_gpio_init( &platform_gpio_pins[LED_B], OUTPUT_PUSH_PULL );
    platform_gpio_output_high( &platform_gpio_pins[LED_R] );
    platform_gpio_output_high( &platform_gpio_pins[LED_G] );
    platform_gpio_output_high( &platform_gpio_pins[LED_B] );

#ifndef WICED_DISABLE_STDIO
    /* Initialise UART standard I/O */
    platform_stdio_init( &platform_uart_drivers[STDIO_UART], &platform_uart_peripherals[STDIO_UART], &stdio_config );
#endif
}
/******************************************************
 *               Function Definitions
 ******************************************************/
wiced_result_t aws_app_init( aws_app_info_t *app_info )
{
    wiced_result_t ret = WICED_SUCCESS;
    aws_config_dct_t *aws_app_dct = NULL;

    aws_app_info = app_info;

    wiced_init( );

    /* Disable roaming to other access points */
    wiced_wifi_set_roam_trigger( -99 ); /* -99dBm ie. extremely low signal level */

    WPRINT_APP_INFO((" Please wait, connecting to network...\n"));
    WPRINT_APP_INFO(("(To return to SSID console screen, hold USER switch for 5 seconds during RESET to clear DCT configuration)\n"));
    wiced_rtos_delay_milliseconds( 1000 );

    for ( int i = 0; i < 25; i++ )
    {
        wiced_gpio_output_high( WICED_LED2 );
        wiced_rtos_delay_milliseconds( 100 );
        wiced_gpio_output_low( WICED_LED2 );
        wiced_rtos_delay_milliseconds( 100 );

        if ( !wiced_gpio_input_get( WICED_BUTTON1 ) )
        {
            wiced_rtos_delay_milliseconds( 5000 );

            if ( !wiced_gpio_input_get( WICED_BUTTON1 ) )
            {
                aws_config_dct_t aws_dct =
                {
                    .is_configured = WICED_FALSE,
                    .thing_name = AWS_DEFAULT_THING_NAME
                };

                wiced_gpio_output_high( WICED_LED1 );
                WPRINT_APP_INFO(( "DCT clearing start\n" ));
                wiced_dct_write( &aws_dct, DCT_APP_SECTION, 0, sizeof( aws_config_dct_t ) );
                wiced_rtos_delay_milliseconds( 1000 );
                wiced_gpio_output_low( WICED_LED1 );
                WPRINT_APP_INFO(( "DCT clearing end\n" ));

                break;
            }
        }
Exemple #5
0
wiced_result_t spi_master_write_register( spi_master_t* master, uint16_t address, uint16_t size, uint8_t* data_out )
{
    wiced_result_t                    result;
    wiced_spi_slave_command_t         command;
    wiced_spi_message_segment_t       message;
    wiced_spi_slave_transfer_status_t status;

    memset( &command, 0x00, sizeof( command ) );

    /* Indicate that master is currently in transaction */
    master->in_transaction = WICED_TRUE;

    /* Send command */
    command.direction   = SPI_SLAVE_TRANSFER_WRITE;
    command.address     = address;
    command.data_length = size;
    message.length      = sizeof(command);
    message.tx_buffer   = &command;
    message.rx_buffer   = NULL;

    /* Wait until data ready pin is set to low logic level( falling edge is detected ) */
    /* Slave is ready to receive a command only when it sets its ready pin to low logic level */
    if( wiced_gpio_input_get( master->data_ready_pin ) == WICED_TRUE )
    {
        while(1)
        {
            result = wiced_rtos_get_semaphore( &master->data_ready_semaphore, DATA_READY_TIMEOUT_MS );
            if( result != WICED_SUCCESS )
            {
                master->in_transaction = WICED_FALSE;
                return result;
            }

            /* Check whether the ready ping is set to high logic level, if not wait on a semaphore again */
            if( wiced_gpio_input_get( master->data_ready_pin ) == WICED_FALSE )
            {
                break;
            }
            else
            {
                //wiced_assert("Unexpected condition", 0!=0);
            }
        }
    }

    /* Send the command */
    result = wiced_spi_transfer( master->device, &message, 1 );
    if( result != WICED_SUCCESS )
    {
        master->in_transaction = WICED_FALSE;
        return result;
    }

    /* Wait until data ready pin is set to high logic level( rising edge is detected ) */
    if( wiced_gpio_input_get( master->data_ready_pin ) == WICED_FALSE )
    {
        while(1)
        {
            result = wiced_rtos_get_semaphore( &master->data_ready_semaphore, DATA_READY_TIMEOUT_MS );
            if( result != WICED_SUCCESS )
            {
                master->in_transaction = WICED_FALSE;
                return result;
            }
            /* Check whether the ready ping is set to high logic level, if not wait on a semaphore again */
            if( wiced_gpio_input_get( master->data_ready_pin ) == WICED_TRUE )
            {
                break;
            }
            else
            {
                //wiced_assert("Unexpected condition", 0!=0);
            }
        }
    }

    /* Read status byte */
    message.length    = 1;
    message.tx_buffer = NULL;
    message.rx_buffer = &status;
    result = wiced_spi_transfer( master->device, &message, 1 );
    if ( result != WICED_SUCCESS )
    {
        master->in_transaction = WICED_FALSE;
        return result;
    }
    if ( status != SPI_SLAVE_TRANSFER_SUCCESS )
    {
        master->in_transaction = WICED_FALSE;
        return spi_slave_convert_status_to_result( status );
    }

    /* Write data value */
    message.length      = size;
    message.tx_buffer   = data_out;
    message.rx_buffer   = NULL;
    result = wiced_spi_transfer( master->device, &message, 1 );
    if ( result != WICED_SUCCESS )
    {
        master->in_transaction = WICED_FALSE;
        return result;
    }

    return WICED_SUCCESS;
}
Exemple #6
0
wiced_bool_t bt_bus_is_ready( void )
{
    return ( bus_initialised == WICED_FALSE ) ? WICED_FALSE : ( ( wiced_gpio_input_get( BLUETOOTH_GPIO_CTS_PIN ) == WICED_TRUE ) ? WICED_FALSE : WICED_TRUE );
}