aboutsummaryrefslogtreecommitdiff
path: root/barometer_sim.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 /barometer_sim.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 'barometer_sim.c')
-rw-r--r--barometer_sim.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/barometer_sim.c b/barometer_sim.c
index c695590..5c5b7d4 100644
--- a/barometer_sim.c
+++ b/barometer_sim.c
@@ -1,3 +1,5 @@
+#include "barometer.h"
+
/* Dummy pressures to return in sequence, each call to barometer_read */
static const float pressures[] = {
1019.5,
@@ -15,13 +17,21 @@ static const float pressures[] = {
};
static int cursor = 0;
-void barometer_init(void)
+static void barometer_init(void)
{
cursor = 0;
}
-float barometer_read(void)
+static float barometer_read(void)
{
cursor %= sizeof(pressures)/sizeof(pressures[0]);
return pressures[cursor++];
}
+
+/**/
+
+void get_system_barometer(struct barometer *barometer)
+{
+ barometer->init = barometer_init;
+ barometer->read_pressure = barometer_read;
+}