Lines Matching +full:has +full:- +full:interrupt +full:- +full:mask +full:- +full:reg

4  * SPDX-License-Identifier: Apache-2.0
29 * include all the interrupt code if the user configured it in the dts
43 * https://www.nxp.com/docs/en/data-sheet/PCF8563.pdf
91 * https://www.nxp.com/docs/en/data-sheet/PCF8563.pdf page 10 starting
100 * byte is 0 (ignored bit) 100 (the 4) 0011 (the 3) -> 0100001
103 * the datasheet because they may contain unexpected values. Applying a mask will help us
108 const struct pcf8563_config *config = dev->config; in pcf8563_set_time()
114 return -EINVAL; in pcf8563_set_time()
118 raw_time[0] = bin2bcd(timeptr->tm_sec); in pcf8563_set_time()
121 raw_time[1] = bin2bcd(timeptr->tm_min); in pcf8563_set_time()
124 raw_time[2] = bin2bcd(timeptr->tm_hour); in pcf8563_set_time()
127 raw_time[3] = bin2bcd(timeptr->tm_mday); in pcf8563_set_time()
130 raw_time[4] = timeptr->tm_wday; in pcf8563_set_time()
133 raw_time[5] = bin2bcd(timeptr->tm_mon); in pcf8563_set_time()
136 raw_time[6] = bin2bcd(timeptr->tm_year); in pcf8563_set_time()
139 ret = i2c_burst_write_dt(&config->i2c, PCF8563_TIME_DATE_REGISTER, in pcf8563_set_time()
151 const struct pcf8563_config *config = dev->config; in pcf8563_get_time()
155 ret = i2c_burst_read_dt(&config->i2c, PCF8563_TIME_DATE_REGISTER, in pcf8563_get_time()
165 return -ENODATA; in pcf8563_get_time()
169 timeptr->tm_nsec = 0; in pcf8563_get_time()
172 timeptr->tm_sec = bcd2bin(raw_time[0] & PCF8563_SECONDS_MASK); in pcf8563_get_time()
175 timeptr->tm_min = bcd2bin(raw_time[1] & PCF8563_MINUTES_MASK); in pcf8563_get_time()
178 timeptr->tm_hour = bcd2bin(raw_time[2] & PCF8563_HOURS_MASK); in pcf8563_get_time()
181 timeptr->tm_mday = bcd2bin(raw_time[3] & PCF8563_DAYS_MASK); in pcf8563_get_time()
184 timeptr->tm_wday = raw_time[4] & PCF8563_WEEKDAYS_MASK; in pcf8563_get_time()
187 timeptr->tm_mon = bcd2bin(raw_time[5] & PCF8563_MONTHS_MASK); in pcf8563_get_time()
190 timeptr->tm_year = bcd2bin(raw_time[6]); in pcf8563_get_time()
193 timeptr->tm_yday = -1; in pcf8563_get_time()
196 timeptr->tm_isdst = -1; in pcf8563_get_time()
206 uint16_t *mask) in pcf8563_alarm_get_supported_fields() argument
210 /* This device only has one channel*/ in pcf8563_alarm_get_supported_fields()
213 return -EINVAL; in pcf8563_alarm_get_supported_fields()
216 *mask = PCF8563_RTC_ALARM_TIME_MASK; in pcf8563_alarm_get_supported_fields()
221 static int pcf8563_alarm_set_time(const struct device *dev, uint16_t id, uint16_t mask, in pcf8563_alarm_set_time() argument
224 const struct pcf8563_config *config = dev->config; in pcf8563_alarm_set_time()
230 return -EINVAL; in pcf8563_alarm_set_time()
233 if ((mask & ~(PCF8563_RTC_ALARM_TIME_MASK)) != 0) { in pcf8563_alarm_set_time()
234 LOG_ERR("invalid alarm field mask 0x%04x", mask); in pcf8563_alarm_set_time()
235 return -EINVAL; in pcf8563_alarm_set_time()
238 if (!rtc_utils_validate_rtc_time(timeptr, mask)) { in pcf8563_alarm_set_time()
240 return -EINVAL; in pcf8563_alarm_set_time()
245 * The mask will clean it and also the unused bits in pcf8563_alarm_set_time()
247 if ((mask & RTC_ALARM_TIME_MASK_MINUTE) != 0) { in pcf8563_alarm_set_time()
248 regs[0] = bin2bcd(timeptr->tm_min) & PCF8563_MINUTES_MASK; in pcf8563_alarm_set_time()
254 if ((mask & RTC_ALARM_TIME_MASK_HOUR) != 0) { in pcf8563_alarm_set_time()
255 regs[1] = bin2bcd(timeptr->tm_hour) & PCF8563_HOURS_MASK; in pcf8563_alarm_set_time()
260 if ((mask & RTC_ALARM_TIME_MASK_MONTHDAY) != 0) { in pcf8563_alarm_set_time()
261 regs[2] = bin2bcd(timeptr->tm_mday) & PCF8563_DAYS_MASK; in pcf8563_alarm_set_time()
266 if ((mask & RTC_ALARM_TIME_MASK_WEEKDAY) != 0) { in pcf8563_alarm_set_time()
267 regs[3] = bin2bcd(timeptr->tm_wday) & PCF8563_WEEKDAYS_MASK; in pcf8563_alarm_set_time()
272 ret = i2c_burst_write_dt(&config->i2c, PCF8563_ALARM_REGISTER, regs, sizeof(regs)); in pcf8563_alarm_set_time()
280 &config->i2c, in pcf8563_alarm_set_time()
288 static int pcf8563_alarm_get_time(const struct device *dev, uint16_t id, uint16_t *mask, in pcf8563_alarm_get_time() argument
291 const struct pcf8563_config *config = dev->config; in pcf8563_alarm_get_time()
297 return -EINVAL; in pcf8563_alarm_get_time()
300 err = i2c_burst_read_dt(&config->i2c, PCF8563_ALARM_REGISTER, regs, sizeof(regs)); in pcf8563_alarm_get_time()
306 /* Initialize data structure and mask */ in pcf8563_alarm_get_time()
308 *mask = 0U; in pcf8563_alarm_get_time()
312 timeptr->tm_min = bcd2bin(regs[0] & GENMASK(6, 0)); in pcf8563_alarm_get_time()
313 *mask |= RTC_ALARM_TIME_MASK_MINUTE; in pcf8563_alarm_get_time()
317 timeptr->tm_hour = bcd2bin(regs[1] & GENMASK(5, 0)); in pcf8563_alarm_get_time()
318 *mask |= RTC_ALARM_TIME_MASK_HOUR; in pcf8563_alarm_get_time()
322 timeptr->tm_mday = bcd2bin(regs[2] & GENMASK(5, 0)); in pcf8563_alarm_get_time()
323 *mask |= RTC_ALARM_TIME_MASK_MONTHDAY; in pcf8563_alarm_get_time()
327 timeptr->tm_wday = bcd2bin(regs[3] & GENMASK(2, 0)); in pcf8563_alarm_get_time()
328 *mask |= RTC_ALARM_TIME_MASK_WEEKDAY; in pcf8563_alarm_get_time()
340 const struct pcf8563_config *config = dev->config; in pcf8563_alarm_is_pending()
341 uint8_t reg; in pcf8563_alarm_is_pending() local
346 return -EINVAL; in pcf8563_alarm_is_pending()
349 err = i2c_reg_read_byte_dt(&config->i2c, PCF8563_CONTROL2_REGISTER, &reg); in pcf8563_alarm_is_pending()
356 if (reg & GENMASK(3, 2)) { in pcf8563_alarm_is_pending()
358 err = i2c_reg_write_byte_dt(&config->i2c, PCF8563_CONTROL2_REGISTER, GENMASK(1, 0)); in pcf8563_alarm_is_pending()
372 /* The logic related to the pin interrupt logic */
379 if (data->alarm_callback == NULL) { in callback_work_handler()
382 data->alarm_callback(data->dev, 0, data->alarm_user_data); in callback_work_handler()
387 /* The function called when the clock alarm activates the interrupt*/
393 LOG_DBG("PCF8563 interrupt detected"); in gpio_callback_function()
395 k_work_submit(&(data->callback_work)); in gpio_callback_function()
410 return -ENOTSUP; in pcf8563_alarm_set_callback()
412 const struct pcf8563_config *config = dev->config; in pcf8563_alarm_set_callback()
413 struct pcf8563_data *data = dev->data; in pcf8563_alarm_set_callback()
416 if (config->int1.port == NULL) { in pcf8563_alarm_set_callback()
417 return -ENOTSUP; in pcf8563_alarm_set_callback()
422 return -EINVAL; in pcf8563_alarm_set_callback()
425 data->alarm_callback = callback; in pcf8563_alarm_set_callback()
426 data->alarm_user_data = user_data; in pcf8563_alarm_set_callback()
427 data->dev = dev; in pcf8563_alarm_set_callback()
430 ret = gpio_pin_configure_dt(&config->int1, GPIO_INPUT | GPIO_PULL_UP); in pcf8563_alarm_set_callback()
433 ret, config->int1.port->name, config->int1.pin); in pcf8563_alarm_set_callback()
437 ret = gpio_pin_interrupt_configure_dt(&config->int1, GPIO_INT_EDGE_FALLING); in pcf8563_alarm_set_callback()
439 LOG_ERR("Error %d: failed to configure interrupt on %s pin %d", in pcf8563_alarm_set_callback()
440 ret, config->int1.port->name, config->int1.pin); in pcf8563_alarm_set_callback()
445 gpio_init_callback(&data->int1_callback, gpio_callback_function, BIT(config->int1.pin)); in pcf8563_alarm_set_callback()
446 gpio_add_callback(config->int1.port, &data->int1_callback); in pcf8563_alarm_set_callback()
467 const struct pcf8563_config *config = dev->config; in pcf8563_init()
469 uint8_t reg; in pcf8563_init() local
471 struct pcf8563_data *data = dev->data; in pcf8563_init()
473 data->callback_work = callback_work; in pcf8563_init()
476 if (!device_is_ready(config->i2c.bus)) { in pcf8563_init()
477 LOG_ERR("Failed to get pointer to %s device!", config->i2c.bus->name); in pcf8563_init()
478 return -ENODEV; in pcf8563_init()
482 ret = i2c_reg_read_byte_dt(&config->i2c, PCF8563_CONTROL1_REGISTER, &reg); in pcf8563_init()
485 return -ENODEV; in pcf8563_init()
488 LOG_INF("%s is initialized!", dev->name); in pcf8563_init()