aboutsummaryrefslogtreecommitdiff
path: root/altimeter.c
diff options
context:
space:
mode:
authorDavid Phillips <david@yeah.nah.nz>2021-02-20 17:43:24 +1300
committerDavid Phillips <david@yeah.nah.nz>2021-02-27 21:54:56 +1300
commit27d6d2fc5a1647395a7a9074faf8362d6d0c358a (patch)
tree81f81c6b4a5a835e01968e0059271bb90c3768ab /altimeter.c
parente843e9da835f058e09810cfeba7c60d0b270e7b3 (diff)
downloadaltimeter-27d6d2fc5a1647395a7a9074faf8362d6d0c358a.tar.xz
Use more generic interface for barometer and timer
This patch abstracts the global symbols for getting barometer readings behind a "struct of function pointers" interface as popular in Linux Kernel, U-Boot and others. This means that unit testing can take place with mocked hardware peripherals. The old "global" drivers are still available, behind explicit function calls required to access the now-static functions. This patch also introduces a timer peripheral software module with the same model, to support future unit testing of altitude rate etc.
Diffstat (limited to 'altimeter.c')
-rw-r--r--altimeter.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/altimeter.c b/altimeter.c
index 861b054..db45eb7 100644
--- a/altimeter.c
+++ b/altimeter.c
@@ -10,6 +10,8 @@
#include "data_manager.h"
#include "display.h"
+#include "timer.h"
+#include "barometer.h"
#ifdef WDT_DISABLE
# warning "WDT disabled in this build"
@@ -47,17 +49,23 @@ ISR(TIMER1_COMPA_vect)
int main(void)
{
+ struct barometer barometer;
+ struct timer timer;
+
/* Initialise display before enabling interrupts */
display_init();
display_clear();
- data_manager_init(&dctx);
- DEBUG_INIT;
+ /* get descriptors for system default peripherals */
+ get_system_barometer(&barometer);
+ get_system_timer(&timer);
+
+ timer.init();
+ barometer.init();
- /* Initialise timers for /1024 prescaler, 1 Hz comparator val */
- TCCR1B |= (1 << CS10) | (1 << CS12) | (1 << WGM12);
- TIMSK1 |= (1 << OCIE1A);
- OCR1A = F_CPU / 1024;
+ data_manager_init(&dctx, &timer, &barometer);
+
+ DEBUG_INIT;
#ifdef USBCON
/* Disable USB controller if one is present - this spams (latches?) USB_GEN