Exemplo n.º 1
0
static void target_keystatus()
{
	keys_init();

	if(target_volume_down())
		keys_post_event(KEY_VOLUMEDOWN, 1);

	if(target_volume_up())
		keys_post_event(KEY_VOLUMEUP, 1);
}
static void check_output(struct gpio_kp *kp, int out, int polarity)
{
	struct gpio_keypad_info *kpinfo = kp->keypad_info;
	int key_index;
	int in;
	int gpio;
	int changed = 0;

	key_index = out * kpinfo->ninputs;
	for (in = 0; in < kpinfo->ninputs; in++, key_index++) {
		gpio = kpinfo->input_gpios[in];
		changed = 0;
		if (gpio_get(gpio) ^ !polarity) {
			if (kp->some_keys_pressed < 3)
				kp->some_keys_pressed++;
			changed = !bitmap_set(kp->keys_pressed, key_index);
		} else {
			changed = bitmap_clear(kp->keys_pressed, key_index);
		}
		if (changed) {
			int state = bitmap_test(kp->keys_pressed, key_index);
			keys_post_event(kpinfo->keymap[key_index], state);
		}
	}

	/* sets up the right state for the next poll cycle */
	gpio = kpinfo->output_gpios[out];
	if (kpinfo->flags & GPIOKPF_DRIVE_INACTIVE)
		gpio_set(gpio, !polarity);
	else
		gpio_config(gpio, GPIO_INPUT);
}
static enum handler_return
scan_qwerty_gpio_keypad(struct timer *timer, time_t now, void *arg)
{
	int i=0;
	int num =0;
	uint8_t key_status;
	struct qwerty_keypad_info *keypad = qwerty_keypad->keypad_info;

	num = keypad->mapsize;

	for(i=0; i < num; i++)
	{
		/*continue if not interested in key*/
		if(!keypad->keymap[i])
			continue;

		/*read key gpio*/
		keypad->key_gpio_get(keypad->gpiomap[i], &key_status);

		/*Post event if key pressed*/
		if(key_status)
		{
			keys_post_event(keypad->keymap[i], 1);
			goto done;
		}
	}

done:
	event_signal(&qwerty_keypad->full_scan, false);
	return INT_RESCHEDULE;
}
Exemplo n.º 4
0
static enum handler_return
scan_qwerty_keypad(struct timer *timer, time_t now, void *arg)
{
    unsigned int rows = (qwerty_keypad->keypad_info)->rows;
    unsigned int columns = (qwerty_keypad->keypad_info)->columns;
    unsigned int num_of_ssbi_reads = (qwerty_keypad->keypad_info)->num_of_reads;
    read_func rd_function = (qwerty_keypad->keypad_info)->rd_func;
    unsigned char column_new_keys = 0x00;
    unsigned char column_old_keys = 0x00;
    int shift = 0;
    static int key_detected = -1;

    if ((*rd_function)((qwerty_keypad->keypad_info)->rec_keys, num_of_ssbi_reads,
    SSBI_REG_KYPD_REC_DATA_ADDR))
        dprintf (CRITICAL, "Error in initializing SSBI_REG_KYPD_CNTL register\n");

    if ((*rd_function)((qwerty_keypad->keypad_info)->old_keys, num_of_ssbi_reads,
    SSBI_REG_KYPD_OLD_DATA_ADDR))
        dprintf (CRITICAL, "Error in initializing SSBI_REG_KYPD_CNTL register\n");

    while (rows--) {
        columns = qwerty_keypad->keypad_info->columns;
        if (((qwerty_keypad->keypad_info)->rec_keys[rows]
        != (qwerty_keypad->keypad_info)->old_keys[rows])
        && ((qwerty_keypad->keypad_info)->rec_keys[rows] != 0x00)
        && ((qwerty_keypad->keypad_info)->old_keys[rows] != 0x00)) {
            while (columns--) {
                column_new_keys = ((qwerty_keypad->keypad_info)->rec_keys[rows]);
                column_old_keys = ((qwerty_keypad->keypad_info)->old_keys[rows]);
                if (((0x01 << columns) & (~column_new_keys))
                && !((0x01 << columns) & (~column_old_keys))) {
                    shift = (rows * 8) + columns;
                    if ((qwerty_keypad->keypad_info)->keymap[shift]) {
                        if (shift != key_detected) {
                            key_detected = shift;
                            keys_post_event((qwerty_keypad->keypad_info)->keymap[shift], 1);
                            event_signal(&qwerty_keypad->full_scan, false);
                            timer_set_oneshot(timer, (qwerty_keypad->keypad_info)->poll_time,
                            scan_qwerty_keypad, NULL);
                            return INT_RESCHEDULE;

                        }
                    }
                }
            }
        }
    }
    if (qwerty_keypad->num_of_scans < 10)
    {
        (qwerty_keypad->num_of_scans)++;
        timer_set_oneshot(timer, (qwerty_keypad->keypad_info)->settle_time,
                          scan_qwerty_keypad, NULL);
        return INT_RESCHEDULE;
    }

    event_signal(&qwerty_keypad->full_scan, false);
    return INT_RESCHEDULE;

}
Exemplo n.º 5
0
static int event_source_poll(key_event_source_t* source) {
	uint16_t value = target_power_key();
	if(keys_set_report_key(source, 0, &value)){
		keys_post_event(13, value);
	}

	value = target_volume_up();
	if(keys_set_report_key(source, 1, &value)){
		keys_post_event(KEY_VOLUMEUP, value);
	}

	value = target_volume_down();
	if(keys_set_report_key(source, 2, &value)){
		keys_post_event(KEY_VOLUMEDOWN, value);
	}

	return NO_ERROR;
}
static enum handler_return
scan_qt_keypad(struct timer *timer, time_t now, void *arg)
{
    unsigned int gpio;
    unsigned int last_state=0;
    unsigned int new_state=0;
    unsigned int bits_changed;
    static int key_detected=-1;

    /* Row GPIOs 8,9,10 are used for sensing here */
    for (gpio=8;gpio<=10;gpio++)
    {
        bool status;
        status = pm8058_gpio_get(gpio);
        if (status == 0)
            new_state |= (1<<(gpio-8));
    }

    bits_changed = last_state ^ new_state;

    if (bits_changed)
    {
        int shift = 0;
        for (unsigned int rows = 0; rows < (qwerty_keypad->keypad_info)->rows; rows++)
        {
            if ((bits_changed & (1<<rows)) == 0)
                continue;
            shift = rows * 8 + 3;
        }
        if ((qwerty_keypad->keypad_info)->keymap[shift])
        {
            if (shift != key_detected)
            {
                key_detected = shift;
                keys_post_event((qwerty_keypad->keypad_info)->keymap[shift], 1);
                timer_set_oneshot(timer,(qwerty_keypad->keypad_info)->poll_time,
                                  scan_qt_keypad, NULL);
                return INT_RESCHEDULE;
            }
        }
    }
    event_signal(&qwerty_keypad->full_scan, false);
    return INT_RESCHEDULE;
}
Exemplo n.º 7
0
static enum handler_return gpio_key_irq(void *arg)
{
	struct gpio_key *key = arg;
	mdelay(25);
	int state = !!gpio_get(key->gpio);

	//some debouncing
	for (int i = 0; i < 5; i++) {
		mdelay(10);
		int state2 = !!gpio_get(key->gpio);
		if (state2 != state) {
//			printf("%s: failed to reach stable state after %d ms\n",
//					__func__, i * 10);
			return INT_RESCHEDULE;
		}
	}
	keys_post_event(key->keycode, state ^ key->active_low);
	return INT_RESCHEDULE;
}
Exemplo n.º 8
0
static enum handler_return
gpio_keys_poll_fn(struct timer *timer, time_t now, void *arg)
{
	uint32_t i = 0;
	struct gpio_key *key = pdata->gpio_key;
	
	for(; ((i < pdata->nr_keys) && (key != NULL)); i++, key++) {
		int changed = 0;

		if (gpio_get(key->gpio_nr) ^ !!key->polarity) {
			changed = !bitmap_set(&gpio_keys_bitmap, i);
		} else {
			changed = bitmap_clear(&gpio_keys_bitmap, i);
		}

		if (changed) {
			int state = bitmap_test(&gpio_keys_bitmap, i);

			keys_post_event(key->key_code, state);
			if (key->notify_fn) {
				key->notify_fn(key->key_code, state);
			}
			if(state) {
				some_key_pressed++;
			} else if(some_key_pressed) {
				some_key_pressed--;
			}
		}
	}

	if (some_key_pressed) {
		timer_set_oneshot(timer, pdata->debounce_time, gpio_keys_poll_fn, NULL);
	} else {
		timer_set_oneshot(timer, pdata->poll_time, gpio_keys_poll_fn, NULL);		
	}
	
	return 1;
}