#include "util.h"
#include "app.h"
+#undef TEST_VECTOR
+
+#if 0
+#define bmp_debug debug_printf
+#else
+static inline void bmp_debug(char *msg, ...)
+{ }
+#endif
+
static byte bmp_i2c_buf[4];
volatile byte *bmp_i2c_ptr;
volatile byte bmp_i2c_len;
}
// Formulae from BMP085 specs
-static void bmp_recalc(uint UT, uint UP, uint oss, u16 cc[11], s16 *tt, s16 *pp)
+static void bmp_recalc(uint UT, uint UP, uint oss, u16 cc[11], int *tt, int *pp)
{
s16 AC1 = cc[0];
s16 AC2 = cc[1];
u16 AC6 = cc[5];
s16 B1 = cc[6];
s16 B2 = cc[7];
- // FIXME: Why is this unused?
// s16 MB = cc[8];
s16 MC = cc[9];
s16 MD = cc[10];
*pp = p;
}
+#ifdef TEST_VECTOR
+
+#define BMP_OSS 0
+static u16 bmp_constants[11] = {
+ 408,
+ -72,
+ -14383,
+ 32741,
+ 32757,
+ 23153,
+ 6190,
+ 4,
+ 32768,
+ -8711,
+ 2868,
+};
+
+void bmp_init(void)
+{
+ bmp_debug("BMP: Test constants\n");
+}
+
+#else
+
+#define BMP_OSS 3
static u16 bmp_constants[11];
void bmp_init(void)
{
+ bmp_debug("BMP: Reading constants\n");
for (uint i=0; i<11; i++)
{
bmp_constants[i] = bmp_read(0xaa + 2*i, 2);
- debug_printf("BMP: const[%d] = %u\n", i, bmp_constants[i]);
+ bmp_debug("BMP: const[%d] = %04x\n", i, bmp_constants[i]);
}
}
+#endif
+
enum bmp_state {
BMP_IDLE,
BMP_TEMP,
static byte bmp_state = BMP_IDLE;
static u16 raw_temp;
static u32 raw_press;
-#define BMP_OSS 3
-s16 adjusted_temp;
-s16 adjusted_press;
+int adjusted_temp;
+int adjusted_press;
void bmp_step(void)
{
switch (bmp_state)
{
case BMP_IDLE:
- debug_puts("BMP: Start measure\n");
+ bmp_debug("BMP: Start measure\n");
bmp_start_measure(0x2e);
bmp_state++;
break;
case BMP_TEMP:
if (!LL_GPIO_IsInputPinSet(BMP_DONE_GPIO_Port, BMP_DONE_Pin))
return;
- debug_puts("BMP: Temperature measured\n");
+ bmp_debug("BMP: Temperature measured\n");
+#ifdef TEST_VECTOR
+ raw_temp = 27898;
+#else
raw_temp = bmp_read(0xf6, 2);
- debug_printf("BMP: Temperature read: %u\n", raw_temp);
+#endif
+ bmp_debug("BMP: Raw temperature: %04x\n", raw_temp);
bmp_start_measure(0xf4 | (BMP_OSS<<6));
bmp_state++;
break;
case BMP_PRESSURE:
if (!LL_GPIO_IsInputPinSet(BMP_DONE_GPIO_Port, BMP_DONE_Pin))
return;
- debug_puts("BMP: Pressure measured\n");
+ bmp_debug("BMP: Pressure measured\n");
+#ifdef TEST_VECTOR
+ raw_press = 23843 << 8;
+#else
raw_press = bmp_read(0xf6, 3);
- debug_printf("BMP: Pressure read: %u\n", raw_press);
+#endif
+ bmp_debug("BMP: Raw pressure: %06x\n", raw_press);
bmp_recalc(raw_temp, raw_press, BMP_OSS, bmp_constants, &adjusted_temp, &adjusted_press);
- debug_printf("BMP: Adjusted temp %u, press %u\n", adjusted_temp, adjusted_press);
+ bmp_debug("BMP: Adjusted temp %d, press %d\n", adjusted_temp, adjusted_press);
bmp_state = BMP_IDLE;
break;
}