Lines Matching +full:col +full:- +full:size

4  * SPDX-License-Identifier: Apache-2.0
54 /* HT16K33 size definitions */
97 const struct ht16k33_cfg *config = dev->config; in ht16k33_led_blink()
98 struct ht16k33_data *data = dev->data; in ht16k33_led_blink()
99 struct led_data *dev_data = &data->dev_data; in ht16k33_led_blink()
104 if (period < dev_data->min_period || period > dev_data->max_period) { in ht16k33_led_blink()
105 return -EINVAL; in ht16k33_led_blink()
119 if (i2c_write_dt(&config->i2c, &cmd, sizeof(cmd))) { in ht16k33_led_blink()
121 return -EIO; in ht16k33_led_blink()
132 const struct ht16k33_cfg *config = dev->config; in ht16k33_led_set_brightness()
133 struct ht16k33_data *data = dev->data; in ht16k33_led_set_brightness()
134 struct led_data *dev_data = &data->dev_data; in ht16k33_led_set_brightness()
138 if (value < dev_data->min_brightness || in ht16k33_led_set_brightness()
139 value > dev_data->max_brightness) { in ht16k33_led_set_brightness()
140 return -EINVAL; in ht16k33_led_set_brightness()
143 dim = (value * (HT16K33_DIMMING_LEVELS - 1)) / dev_data->max_brightness; in ht16k33_led_set_brightness()
146 if (i2c_write_dt(&config->i2c, &cmd, sizeof(cmd))) { in ht16k33_led_set_brightness()
148 return -EIO; in ht16k33_led_set_brightness()
157 const struct ht16k33_cfg *config = dev->config; in ht16k33_led_set_state()
158 struct ht16k33_data *data = dev->data; in ht16k33_led_set_state()
164 return -EINVAL; in ht16k33_led_set_state()
172 cmd[1] = data->buffer[addr] | BIT(bit); in ht16k33_led_set_state()
174 cmd[1] = data->buffer[addr] & ~BIT(bit); in ht16k33_led_set_state()
177 if (data->buffer[addr] == cmd[1]) { in ht16k33_led_set_state()
181 if (i2c_write_dt(&config->i2c, cmd, sizeof(cmd))) { in ht16k33_led_set_state()
183 return -EIO; in ht16k33_led_set_state()
186 data->buffer[addr] = cmd[1]; in ht16k33_led_set_state()
204 const struct ht16k33_cfg *config = dev->config; in ht16k33_process_keyscan_data()
205 struct ht16k33_data *data = dev->data; in ht16k33_process_keyscan_data()
211 int col; in ht16k33_process_keyscan_data() local
214 err = i2c_burst_read_dt(&config->i2c, HT16K33_CMD_KEY_DATA_ADDR, keys, sizeof(keys)); in ht16k33_process_keyscan_data()
221 k_mutex_lock(&data->lock, K_FOREVER); in ht16k33_process_keyscan_data()
225 changed = data->key_state[row] ^ state; in ht16k33_process_keyscan_data()
226 data->key_state[row] = state; in ht16k33_process_keyscan_data()
232 for (col = 0; col < HT16K33_KEYSCAN_COLS; col++) { in ht16k33_process_keyscan_data()
233 if ((changed & BIT(col)) == 0) { in ht16k33_process_keyscan_data()
236 input_report_abs(dev, INPUT_ABS_X, col, false, K_FOREVER); in ht16k33_process_keyscan_data()
238 input_report_key(dev, INPUT_BTN_TOUCH, state & BIT(col), true, K_FOREVER); in ht16k33_process_keyscan_data()
242 k_mutex_unlock(&data->lock); in ht16k33_process_keyscan_data()
256 k_sem_take(&data->irq_sem, K_FOREVER); in ht16k33_irq_thread()
259 k_sem_reset(&data->irq_sem); in ht16k33_irq_thread()
260 pressed = ht16k33_process_keyscan_data(data->dev); in ht16k33_irq_thread()
275 k_sem_give(&data->irq_sem); in ht16k33_irq_callback()
283 k_sem_give(&data->irq_sem); in ht16k33_timer_callback()
289 const struct ht16k33_cfg *config = dev->config; in ht16k33_init()
290 struct ht16k33_data *data = dev->data; in ht16k33_init()
291 struct led_data *dev_data = &data->dev_data; in ht16k33_init()
295 data->dev = dev; in ht16k33_init()
297 if (!device_is_ready(config->i2c.bus)) { in ht16k33_init()
299 return -EINVAL; in ht16k33_init()
302 memset(&data->buffer, 0, sizeof(data->buffer)); in ht16k33_init()
305 dev_data->min_period = 0U; in ht16k33_init()
306 dev_data->max_period = 2000U; in ht16k33_init()
307 dev_data->min_brightness = 0U; in ht16k33_init()
308 dev_data->max_brightness = 100U; in ht16k33_init()
312 err = i2c_write_dt(&config->i2c, cmd, 1); in ht16k33_init()
316 return -EIO; in ht16k33_init()
322 err = i2c_write_dt(&config->i2c, cmd, sizeof(cmd)); in ht16k33_init()
325 return -EIO; in ht16k33_init()
330 err = i2c_write_dt(&config->i2c, cmd, 1); in ht16k33_init()
333 return -EIO; in ht16k33_init()
338 err = i2c_write_dt(&config->i2c, cmd, 1); in ht16k33_init()
341 return -EIO; in ht16k33_init()
345 k_mutex_init(&data->lock); in ht16k33_init()
346 k_sem_init(&data->irq_sem, 0, 1); in ht16k33_init()
349 if (config->irq_enabled) { in ht16k33_init()
352 if (!gpio_is_ready_dt(&config->irq)) { in ht16k33_init()
354 return -EINVAL; in ht16k33_init()
357 err = gpio_pin_configure_dt(&config->irq, GPIO_INPUT); in ht16k33_init()
360 return -EINVAL; in ht16k33_init()
363 gpio_init_callback(&data->irq_cb, &ht16k33_irq_callback, in ht16k33_init()
364 BIT(config->irq.pin)); in ht16k33_init()
366 err = gpio_add_callback(config->irq.port, &data->irq_cb); in ht16k33_init()
369 return -EINVAL; in ht16k33_init()
374 if (i2c_write_dt(&config->i2c, cmd, 1)) { in ht16k33_init()
376 return -EIO; in ht16k33_init()
380 err = i2c_burst_read_dt(&config->i2c, HT16K33_CMD_KEY_DATA_ADDR, keys, in ht16k33_init()
384 return -EIO; in ht16k33_init()
387 err = gpio_pin_interrupt_configure_dt(&config->irq, in ht16k33_init()
392 return -EINVAL; in ht16k33_init()
397 if (i2c_write_dt(&config->i2c, cmd, 1)) { in ht16k33_init()
399 return -EIO; in ht16k33_init()
403 k_timer_init(&data->timer, ht16k33_timer_callback, NULL); in ht16k33_init()
404 k_timer_start(&data->timer, K_NO_WAIT, in ht16k33_init()
408 k_thread_create(&data->irq_thread, data->irq_thread_stack, in ht16k33_init()