Skip to content

Commit

Permalink
Improved const correctness of rtc functions (#1460)
Browse files Browse the repository at this point in the history
  • Loading branch information
tornupnegatives authored May 19, 2024
1 parent ac8f277 commit 5941969
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/rp2_common/hardware_rtc/include/hardware/rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void rtc_init(void);
* \param t Pointer to a \ref datetime_t structure contains time to set
* \return true if set, false if the passed in datetime was invalid.
*/
bool rtc_set_datetime(datetime_t *t);
bool rtc_set_datetime(const datetime_t *t);

/*! \brief Get the current time from the RTC
* \ingroup hardware_rtc
Expand All @@ -76,7 +76,7 @@ bool rtc_running(void);
* \param t Pointer to a \ref datetime_t structure containing a time in the future to fire the alarm. Any values set to -1 will not be matched on.
* \param user_callback pointer to a \ref rtc_callback_t to call when the alarm fires
*/
void rtc_set_alarm(datetime_t *t, rtc_callback_t user_callback);
void rtc_set_alarm(const datetime_t *t, rtc_callback_t user_callback);

/*! \brief Enable the RTC alarm (if inactive)
* \ingroup hardware_rtc
Expand Down
8 changes: 4 additions & 4 deletions src/rp2_common/hardware_rtc/rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void rtc_init(void) {
rtc_hw->clkdiv_m1 = rtc_freq;
}

static bool valid_datetime(datetime_t *t) {
static bool valid_datetime(const datetime_t *t) {
// Valid ranges taken from RTC doc. Note when setting an RTC alarm
// these values are allowed to be -1 to say "don't match this value"
if (!(t->year >= 0 && t->year <= 4095)) return false;
Expand All @@ -52,7 +52,7 @@ static bool valid_datetime(datetime_t *t) {
return true;
}

bool rtc_set_datetime(datetime_t *t) {
bool rtc_set_datetime(const datetime_t *t) {
if (!valid_datetime(t)) {
return false;
}
Expand Down Expand Up @@ -131,7 +131,7 @@ static void rtc_irq_handler(void) {
}
}

static bool rtc_alarm_repeats(datetime_t *t) {
static bool rtc_alarm_repeats(const datetime_t *t) {
// If any value is set to -1 then we don't match on that value
// hence the alarm will eventually repeat
if (t->year < 0) return true;
Expand All @@ -144,7 +144,7 @@ static bool rtc_alarm_repeats(datetime_t *t) {
return false;
}

void rtc_set_alarm(datetime_t *t, rtc_callback_t user_callback) {
void rtc_set_alarm(const datetime_t *t, rtc_callback_t user_callback) {
rtc_disable_alarm();

// Only add to setup if it isn't -1
Expand Down

0 comments on commit 5941969

Please sign in to comment.