コード例 #1
0
wiced_result_t wiced_rtos_register_timed_event( wiced_timed_event_t* event_object, wiced_worker_thread_t* worker_thread, event_handler_t function, uint32_t time_ms, void* arg )
{
    if ( wiced_rtos_init_timer( &event_object->timer, time_ms, timed_event_handler, (void*) event_object ) != WICED_SUCCESS )
    {
        return WICED_ERROR;
    }

    event_object->function = function;
    event_object->thread = worker_thread;
    event_object->arg = arg;

    if ( wiced_rtos_start_timer( &event_object->timer ) != WICED_SUCCESS )
    {
        wiced_rtos_deinit_timer( &event_object->timer );
        return WICED_ERROR;
    }

    return WICED_SUCCESS;
}
コード例 #2
0
ファイル: gpio_keypad.c プロジェクト: gicho/wiced-emw3165
wiced_result_t gpio_keypad_enable( gpio_keypad_t* keypad, wiced_worker_thread_t* thread, gpio_keypad_handler_t function, uint32_t held_event_interval_ms, uint32_t total_keys, const gpio_key_t* key_list )
{
    gpio_key_internal_t* key_internal;
    uint32_t malloc_size;
    uint32_t i;

    if ( !keypad || !thread || !function || !total_keys || !key_list )
    {
        return WICED_BADARG;
    }

    malloc_size      = sizeof(gpio_keypad_internal_t) + total_keys * sizeof(gpio_key_internal_t);
    keypad->internal = (gpio_keypad_internal_t*) malloc_named("key internal", malloc_size);
    if ( !keypad->internal )
    {
        return WICED_ERROR;
    }

    memset( keypad->internal, 0, sizeof( *( keypad->internal ) ) );

    key_internal = (gpio_key_internal_t*)((uint8_t*)keypad->internal + sizeof(gpio_keypad_internal_t));

    keypad->internal->function   = function;
    keypad->internal->thread     = thread;
    keypad->internal->total_keys = total_keys;
    keypad->internal->key_list   = (gpio_key_t*)key_list;

    wiced_rtos_init_timer( &keypad->internal->check_state_timer, held_event_interval_ms, check_state_timer_handler, (void*) keypad->internal );

    for ( i = 0; i < total_keys; i++ )
    {
        wiced_gpio_irq_trigger_t trigger = ( key_list[i].polarity == KEY_POLARITY_HIGH ) ? IRQ_TRIGGER_FALLING_EDGE : IRQ_TRIGGER_RISING_EDGE;

        key_internal[i].key   = (gpio_key_t*)&key_list[i];
        key_internal[i].owner = keypad->internal;
        key_internal[i].last_irq_timestamp = 0;

        wiced_gpio_init( key_list[i].gpio, ( ( key_list[i].polarity == KEY_POLARITY_HIGH ) ? INPUT_PULL_UP : INPUT_PULL_DOWN ) );
        wiced_gpio_input_irq_enable( key_list[i].gpio, trigger, gpio_interrupt_key_handler, (void*)&key_internal[i] );
    }

    return WICED_SUCCESS;
}