Skip to content

Commit e234473

Browse files
valeriosettikartben
authored andcommitted
drivers: rtc: pcf8563: some fixes to the driver
- Define alarm_set_callback() only when CONFIG_RTC_ALARM is set otherwise a warning will be generated at runtime for the function not being used. - add "static" keyword to all internal functions. Signed-off-by: Valerio Setti <vsetti@baylibre.com>
1 parent 4aaf463 commit e234473

File tree

1 file changed

+34
-36
lines changed

1 file changed

+34
-36
lines changed

drivers/rtc/rtc_pcf8563.c

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ struct pcf8563_data {
103103
* the datasheet because they may contain unexpected values. Applying a mask will help us
104104
* to sanitize the read values
105105
*/
106-
int pcf8563_set_time(const struct device *dev, const struct rtc_time *timeptr)
106+
static int pcf8563_set_time(const struct device *dev, const struct rtc_time *timeptr)
107107
{
108108
const struct pcf8563_config *config = dev->config;
109109
int ret;
@@ -146,7 +146,7 @@ int pcf8563_set_time(const struct device *dev, const struct rtc_time *timeptr)
146146
return 0;
147147
}
148148

149-
int pcf8563_get_time(const struct device *dev, struct rtc_time *timeptr)
149+
static int pcf8563_get_time(const struct device *dev, struct rtc_time *timeptr)
150150
{
151151
const struct pcf8563_config *config = dev->config;
152152
int ret;
@@ -198,7 +198,34 @@ int pcf8563_get_time(const struct device *dev, struct rtc_time *timeptr)
198198
return 0;
199199
}
200200

201+
#ifdef PCF8563_INT1_GPIOS_IN_USE
202+
203+
/* The logic related to the pin interrupt logic */
204+
static void callback_work_handler(struct k_work *work)
205+
{
206+
/* This function is run as a work so the user can spend here all the necessary time */
207+
struct pcf8563_data *data = CONTAINER_OF(work, struct pcf8563_data, callback_work);
208+
209+
if (data->alarm_callback == NULL) {
210+
LOG_WRN("No PCF8563 alarm callback function provided");
211+
} else {
212+
data->alarm_callback(data->dev, 0, data->alarm_user_data);
213+
}
214+
}
215+
216+
/* The function called when the clock alarm activates the interrupt*/
217+
static void gpio_callback_function(const struct device *dev, struct gpio_callback *cb,
218+
uint32_t pins)
219+
{
220+
struct pcf8563_data *data = CONTAINER_OF(cb, struct pcf8563_data, int1_callback);
221+
222+
LOG_DBG("PCF8563 interrupt detected");
223+
/* By using a work we are able to run "heavier" code */
224+
k_work_submit(&(data->callback_work));
225+
226+
}
201227

228+
#endif /* PCF8563_INT1_GPIOS_IN_USE */
202229

203230
#ifdef CONFIG_RTC_ALARM
204231

@@ -366,37 +393,6 @@ static int pcf8563_alarm_is_pending(const struct device *dev, uint16_t id)
366393
/* No alarms */
367394
return 0;
368395
}
369-
#endif
370-
371-
#ifdef PCF8563_INT1_GPIOS_IN_USE
372-
/* The logic related to the pin interrupt logic */
373-
374-
void callback_work_handler(struct k_work *work)
375-
{
376-
/* This function is run as a work so the user can spend here all the necessary time */
377-
struct pcf8563_data *data = CONTAINER_OF(work, struct pcf8563_data, callback_work);
378-
379-
if (data->alarm_callback == NULL) {
380-
LOG_WRN("No PCF8563 alarm callback function provided");
381-
} else {
382-
data->alarm_callback(data->dev, 0, data->alarm_user_data);
383-
}
384-
}
385-
386-
387-
/* The function called when the clock alarm activates the interrupt*/
388-
void gpio_callback_function(const struct device *dev, struct gpio_callback *cb,
389-
uint32_t pins)
390-
{
391-
struct pcf8563_data *data = CONTAINER_OF(cb, struct pcf8563_data, int1_callback);
392-
393-
LOG_DBG("PCF8563 interrupt detected");
394-
/* By using a work we are able to run "heavier" code */
395-
k_work_submit(&(data->callback_work));
396-
397-
}
398-
399-
#endif
400396

401397
static int pcf8563_alarm_set_callback(const struct device *dev, uint16_t id,
402398
rtc_alarm_callback callback, void *user_data)
@@ -408,7 +404,7 @@ static int pcf8563_alarm_set_callback(const struct device *dev, uint16_t id,
408404
ARG_UNUSED(user_data);
409405

410406
return -ENOTSUP;
411-
#else
407+
#else /* PCF8563_INT1_GPIOS_IN_USE */
412408
const struct pcf8563_config *config = dev->config;
413409
struct pcf8563_data *data = dev->data;
414410
int ret;
@@ -446,9 +442,11 @@ static int pcf8563_alarm_set_callback(const struct device *dev, uint16_t id,
446442
gpio_add_callback(config->int1.port, &data->int1_callback);
447443
LOG_DBG("Alarm set");
448444
return 0;
449-
#endif
445+
#endif /* PCF8563_INT1_GPIOS_IN_USE */
450446
}
451447

448+
#endif /* CONFIG_RTC_ALARM */
449+
452450
static DEVICE_API(rtc, pcf8563_driver_api) = {
453451
.set_time = pcf8563_set_time,
454452
.get_time = pcf8563_get_time,
@@ -462,7 +460,7 @@ static DEVICE_API(rtc, pcf8563_driver_api) = {
462460
};
463461

464462

465-
int pcf8563_init(const struct device *dev)
463+
static int pcf8563_init(const struct device *dev)
466464
{
467465
const struct pcf8563_config *config = dev->config;
468466
int ret;

0 commit comments

Comments
 (0)