Lines Matching +full:threshold +full:- +full:mv
3 * SPDX-License-Identifier: Apache-2.0
49 const struct adc_keys_config *cfg = dev->config; in adc_keys_read()
50 struct adc_keys_data *data = dev->data; in adc_keys_read()
55 data->seq.buffer = &sample_raw; in adc_keys_read()
56 data->seq.buffer_size = sizeof(sample_raw); in adc_keys_read()
58 ret = adc_read(cfg->channel.dev, &data->seq); in adc_keys_read()
61 return cfg->keyup_mv; in adc_keys_read()
65 adc_raw_to_millivolts_dt(&cfg->channel, &sample_mv); in adc_keys_read()
72 const struct adc_keys_config *cfg = dev->config; in adc_keys_process()
82 * Find the closest key press threshold to the sample value. in adc_keys_process()
85 for (uint8_t i = 0; i < cfg->code_cnt; i++) { in adc_keys_process()
86 diff = abs(sample_mv - cfg->code_cfg[i].press_mv); in adc_keys_process()
89 closest_mv = cfg->code_cfg[i].press_mv; in adc_keys_process()
93 diff = abs(sample_mv - cfg->keyup_mv); in adc_keys_process()
96 closest_mv = cfg->keyup_mv; in adc_keys_process()
99 LOG_DBG("sample=%d mV, closest=%d mV, diff=%d mV", sample_mv, closest_mv, closest_diff); in adc_keys_process()
102 * Update cached key states according to the closest key press threshold. in adc_keys_process()
104 * Note that multiple keys may have the same press threshold, which is in adc_keys_process()
108 for (uint8_t i = 0; i < cfg->code_cnt; i++) { in adc_keys_process()
109 code_cfg = &cfg->code_cfg[i]; in adc_keys_process()
110 key_state = &cfg->key_state[code_cfg->key_index]; in adc_keys_process()
114 * being overwritten by another threshold configuration. in adc_keys_process()
116 if (closest_mv == code_cfg->press_mv) { in adc_keys_process()
117 key_state->curr_state = true; in adc_keys_process()
125 for (uint8_t i = 0; i < cfg->key_cnt; i++) { in adc_keys_process()
126 key_state = &cfg->key_state[i]; in adc_keys_process()
127 key_code = cfg->key_code[i]; in adc_keys_process()
129 if (key_state->last_state != key_state->curr_state) { in adc_keys_process()
130 LOG_DBG("Report event %s %d, code=%d", dev->name, key_state->curr_state, in adc_keys_process()
132 input_report_key(dev, key_code, key_state->curr_state, true, K_FOREVER); in adc_keys_process()
133 key_state->last_state = key_state->curr_state; in adc_keys_process()
140 key_state->curr_state = false; in adc_keys_process()
148 const struct device *dev = data->self; in adc_keys_work_handler()
149 const struct adc_keys_config *cfg = dev->config; in adc_keys_work_handler()
153 k_work_schedule(&data->dwork, K_MSEC(cfg->sample_period_ms)); in adc_keys_work_handler()
158 const struct adc_keys_config *cfg = dev->config; in adc_keys_init()
159 struct adc_keys_data *data = dev->data; in adc_keys_init()
162 if (!adc_is_ready_dt(&cfg->channel)) { in adc_keys_init()
163 LOG_ERR("ADC controller device %s not ready", cfg->channel.dev->name); in adc_keys_init()
164 return -ENODEV; in adc_keys_init()
167 ret = adc_channel_setup_dt(&cfg->channel); in adc_keys_init()
173 ret = adc_sequence_init_dt(&cfg->channel, &data->seq); in adc_keys_init()
179 data->self = dev; in adc_keys_init()
180 k_work_init_delayable(&data->dwork, adc_keys_work_handler); in adc_keys_init()
183 for (uint8_t i = 0; i < cfg->code_cnt; i++) { in adc_keys_init()
184 LOG_DBG("* code %d: key_index=%d threshold=%d mV code=%d", i, in adc_keys_init()
185 cfg->code_cfg[i].key_index, cfg->code_cfg[i].press_mv, in adc_keys_init()
186 cfg->key_code[cfg->code_cfg[i].key_index]); in adc_keys_init()
190 k_work_schedule(&data->dwork, K_MSEC(cfg->sample_period_ms)); in adc_keys_init()