jakkra / ZSWatch

ZSWatch - the Open Source Zephyr™ based Smartwatch, including both HW and FW.
https://forms.gle/G48Sm5zDe9aCaYtT9
GNU General Public License v3.0
2.26k stars 191 forks source link

Using the RTC update for the 1s periodic event #309

Open Kampi opened 1 month ago

Kampi commented 1 month ago

Replace the timer for the 1s periodic callback with the RTC update function when using rev 5

image

Kampi commented 1 month ago

@jakkra maybe we can replace the 10 seconds timer too?

jakkra commented 1 month ago

@Kampi make sure both 1s and 10s are still executed in the system workqueue context. i.e. switch the delayed work to just a k_work when the RTC ISR happens.

Drawback of using it also for 10s, is that we still need to wake up every 1s, even if there are none listening on 1s. Lower accuracy on 10s is fine IMO.

Kampi commented 1 month ago

@jakkra good point. We also can't use the alarm for this because we need the alarm for something like a stopwatch. So let's start with 1s first. I want to use a worker scheduling in the update callback to make sure that there is no difference. So it's the same scenario for all listeners as now.

Btw. the RTC callbacks are already handled in the worker context :)

Kampi commented 1 month ago

@jakkra the question how to add this to the code. We can add only one update callback to the driver. So we need a bit of gluecode to handle more than one callback or I move the code from zsw_periodic_event to zsw_clock but I don´t like this solution because it splits up the code.

jakkra commented 1 month ago

@jakkra the question how to add this to the code. We can add only one update callback to the driver. So we need a bit of gluecode to handle more than one callback or I move the code from zsw_periodic_event to zsw_clock but I don´t like this solution because it splits up the code.

Just from the top of my head how about register the rtc callback in zsw_clock and then add a way to register a tick callback to zsw_clock? Which then zsw_periodic_event uses?

Kampi commented 1 month ago

@jakkra the question how to add this to the code. We can add only one update callback to the driver. So we need a bit of gluecode to handle more than one callback or I move the code from zsw_periodic_event to zsw_clock but I don´t like this solution because it splits up the code.

Just from the top of my head how about register the rtc callback in zsw_clock and then add a way to register a tick callback to zsw_clock? Which then zsw_periodic_event uses?

That´s what I mean with gluecode to add more than one callback :)

jakkra commented 1 month ago

@jakkra the question how to add this to the code. We can add only one update callback to the driver. So we need a bit of gluecode to handle more than one callback or I move the code from zsw_periodic_event to zsw_clock but I don´t like this solution because it splits up the code.

Just from the top of my head how about register the rtc callback in zsw_clock and then add a way to register a tick callback to zsw_clock? Which then zsw_periodic_event uses?

That´s what I mean with gluecode to add more than one callback :)

Don't have a better suggestion :/