automatically detect temperature sensor
This commit is contained in:
parent
9fd174e453
commit
80cbb0fe30
7
Makefile
7
Makefile
@ -12,9 +12,6 @@ GOSSAMER_PATH=gossamer
|
|||||||
# If you need to force a specific display, set this to the type you want, CLASSIC or CUSTOM
|
# If you need to force a specific display, set this to the type you want, CLASSIC or CUSTOM
|
||||||
FORCE_DISPLAY_TYPE=CLASSIC
|
FORCE_DISPLAY_TYPE=CLASSIC
|
||||||
|
|
||||||
# Which sensor board?
|
|
||||||
SENSOR=NONE
|
|
||||||
|
|
||||||
# End of user configurable options.
|
# End of user configurable options.
|
||||||
|
|
||||||
# Support USB features?
|
# Support USB features?
|
||||||
@ -32,10 +29,6 @@ ifndef BOARD
|
|||||||
$(error Build failed: BOARD not defined. Use one of the four options below, depending on your hardware:$n$n make BOARD=sensorwatch_red$n make BOARD=sensorwatch_green$n make BOARD=sensorwatch_blue$n make BOARD=sensorwatch_pro$n$n)
|
$(error Build failed: BOARD not defined. Use one of the four options below, depending on your hardware:$n$n make BOARD=sensorwatch_red$n make BOARD=sensorwatch_green$n make BOARD=sensorwatch_blue$n make BOARD=sensorwatch_pro$n$n)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(SENSOR), TEMPERATURE)
|
|
||||||
DEFINES += -DTEMPERATURE_BOARD_INSTALLED
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifdef FORCE_DISPLAY_TYPE
|
ifdef FORCE_DISPLAY_TYPE
|
||||||
ifeq ($(FORCE_DISPLAY_TYPE), CUSTOM)
|
ifeq ($(FORCE_DISPLAY_TYPE), CUSTOM)
|
||||||
DEFINES += -DFORCE_CUSTOM_LCD_TYPE
|
DEFINES += -DFORCE_CUSTOM_LCD_TYPE
|
||||||
|
|||||||
2
gossamer
2
gossamer
@ -1 +1 @@
|
|||||||
Subproject commit 6657eb097bcb83ac19b3509e0296ee151fb310d9
|
Subproject commit 2d79f337c7a6d928830ded91f5d998582f8ea58a
|
||||||
@ -45,6 +45,7 @@
|
|||||||
#include "evsys.h"
|
#include "evsys.h"
|
||||||
#include "delay.h"
|
#include "delay.h"
|
||||||
#include "movement_activity.h"
|
#include "movement_activity.h"
|
||||||
|
#include "thermistor_driver.h"
|
||||||
|
|
||||||
#include "movement_config.h"
|
#include "movement_config.h"
|
||||||
|
|
||||||
@ -564,6 +565,8 @@ void app_init(void) {
|
|||||||
|
|
||||||
filesystem_init();
|
filesystem_init();
|
||||||
|
|
||||||
|
movement_state.has_thermistor = thermistor_driver_init();
|
||||||
|
|
||||||
// check if we are plugged into USB power.
|
// check if we are plugged into USB power.
|
||||||
HAL_GPIO_VBUS_DET_in();
|
HAL_GPIO_VBUS_DET_in();
|
||||||
HAL_GPIO_VBUS_DET_pulldown();
|
HAL_GPIO_VBUS_DET_pulldown();
|
||||||
|
|||||||
@ -287,6 +287,9 @@ typedef struct {
|
|||||||
// temporary alarm enabled boolean, until we implement this in advisories
|
// temporary alarm enabled boolean, until we implement this in advisories
|
||||||
bool alarm_enabled;
|
bool alarm_enabled;
|
||||||
|
|
||||||
|
// boolean set if thermistor is detected
|
||||||
|
bool has_thermistor;
|
||||||
|
|
||||||
// boolean set if accelerometer is detected
|
// boolean set if accelerometer is detected
|
||||||
bool has_lis2dw;
|
bool has_lis2dw;
|
||||||
} movement_state_t;
|
} movement_state_t;
|
||||||
|
|||||||
@ -27,9 +27,53 @@
|
|||||||
#include "watch.h"
|
#include "watch.h"
|
||||||
#include "watch_utility.h"
|
#include "watch_utility.h"
|
||||||
|
|
||||||
|
// assume we have no thermistor until thermistor_driver_init is called.
|
||||||
|
static bool has_thermistor = false;
|
||||||
|
|
||||||
|
bool thermistor_driver_init(void) {
|
||||||
|
// once called, assume we have a thermistor unless proven otherwise
|
||||||
|
has_thermistor = true;
|
||||||
|
uint16_t value;
|
||||||
|
#if THERMISTOR_ENABLE_VALUE == false
|
||||||
|
const uint16_t threshold_value = 60000;
|
||||||
|
#else
|
||||||
|
const uint16_t threshold_value = 5000;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
watch_enable_adc();
|
||||||
|
// Enable analog circuitry on the sense pin, which is tied to the thermistor resistor divider.
|
||||||
|
HAL_GPIO_TEMPSENSE_in();
|
||||||
|
HAL_GPIO_TEMPSENSE_pmuxen(HAL_GPIO_PMUX_ADC);
|
||||||
|
|
||||||
|
// Enable digital output on the enable pin, which is the power to the thermistor circuit.
|
||||||
|
HAL_GPIO_TS_ENABLE_out();
|
||||||
|
// and make sure it's DISABLED.
|
||||||
|
HAL_GPIO_TS_ENABLE_write(!THERMISTOR_ENABLE_VALUE);
|
||||||
|
|
||||||
|
// If the temperature sensor is connected, pulling the TS_ENABLE line to its disabled value
|
||||||
|
// connects both sides of the voltage divider to the same potential. If enable value is false,
|
||||||
|
// this will be high, if enable value is true it will be low, and TEMPSENSE should read the same.
|
||||||
|
value = watch_get_analog_pin_level(HAL_GPIO_TEMPSENSE_pin());
|
||||||
|
|
||||||
|
// If setting TS_ENABLE has no effect, there is no thermistor circuit connected to TEMPSENSE.
|
||||||
|
if (value < threshold_value) has_thermistor = false;
|
||||||
|
|
||||||
|
// now flip it to enable the temperature sensor
|
||||||
|
HAL_GPIO_TS_ENABLE_write(THERMISTOR_ENABLE_VALUE);
|
||||||
|
|
||||||
|
// If the temperature sensor is connected, pulling the TS_ENABLE line to its ENABLED value
|
||||||
|
// means we should get a reasonable temperature at this point.
|
||||||
|
value = watch_get_analog_pin_level(HAL_GPIO_TEMPSENSE_pin());
|
||||||
|
|
||||||
|
// value should be >15000 and <55000 and (between -4° and 76° C)
|
||||||
|
if (value < 15000 || value > 55000) has_thermistor = false;
|
||||||
|
|
||||||
|
return has_thermistor;
|
||||||
|
}
|
||||||
|
|
||||||
void thermistor_driver_enable(void) {
|
void thermistor_driver_enable(void) {
|
||||||
#ifdef HAS_TEMPERATURE_SENSOR
|
if (!has_thermistor) return;
|
||||||
|
|
||||||
// Enable the ADC peripheral, which we'll use to read the thermistor value.
|
// Enable the ADC peripheral, which we'll use to read the thermistor value.
|
||||||
watch_enable_adc();
|
watch_enable_adc();
|
||||||
// Enable analog circuitry on the sense pin, which is tied to the thermistor resistor divider.
|
// Enable analog circuitry on the sense pin, which is tied to the thermistor resistor divider.
|
||||||
@ -39,11 +83,11 @@ void thermistor_driver_enable(void) {
|
|||||||
HAL_GPIO_TS_ENABLE_out();
|
HAL_GPIO_TS_ENABLE_out();
|
||||||
// and make sure it's off.
|
// and make sure it's off.
|
||||||
HAL_GPIO_TS_ENABLE_write(!THERMISTOR_ENABLE_VALUE);
|
HAL_GPIO_TS_ENABLE_write(!THERMISTOR_ENABLE_VALUE);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void thermistor_driver_disable(void) {
|
void thermistor_driver_disable(void) {
|
||||||
#ifdef HAS_TEMPERATURE_SENSOR
|
if (!has_thermistor) return;
|
||||||
|
|
||||||
// Disable the ADC peripheral.
|
// Disable the ADC peripheral.
|
||||||
watch_disable_adc();
|
watch_disable_adc();
|
||||||
// Disable analog circuitry on the sense pin to save power.
|
// Disable analog circuitry on the sense pin to save power.
|
||||||
@ -51,11 +95,11 @@ void thermistor_driver_disable(void) {
|
|||||||
HAL_GPIO_TEMPSENSE_off();
|
HAL_GPIO_TEMPSENSE_off();
|
||||||
// Disable the enable pin's output circuitry.
|
// Disable the enable pin's output circuitry.
|
||||||
HAL_GPIO_TS_ENABLE_off();
|
HAL_GPIO_TS_ENABLE_off();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float thermistor_driver_get_temperature(void) {
|
float thermistor_driver_get_temperature(void) {
|
||||||
#ifdef HAS_TEMPERATURE_SENSOR
|
if (!has_thermistor) return (float) 0xFFFFFFFF;
|
||||||
|
|
||||||
// set the enable pin to the level that powers the thermistor circuit.
|
// set the enable pin to the level that powers the thermistor circuit.
|
||||||
HAL_GPIO_TS_ENABLE_write(THERMISTOR_ENABLE_VALUE);
|
HAL_GPIO_TS_ENABLE_write(THERMISTOR_ENABLE_VALUE);
|
||||||
// get the sense pin level
|
// get the sense pin level
|
||||||
@ -64,7 +108,4 @@ float thermistor_driver_get_temperature(void) {
|
|||||||
HAL_GPIO_TS_ENABLE_write(!THERMISTOR_ENABLE_VALUE);
|
HAL_GPIO_TS_ENABLE_write(!THERMISTOR_ENABLE_VALUE);
|
||||||
|
|
||||||
return watch_utility_thermistor_temperature(value, THERMISTOR_HIGH_SIDE, THERMISTOR_B_COEFFICIENT, THERMISTOR_NOMINAL_TEMPERATURE, THERMISTOR_NOMINAL_RESISTANCE, THERMISTOR_SERIES_RESISTANCE);
|
return watch_utility_thermistor_temperature(value, THERMISTOR_HIGH_SIDE, THERMISTOR_B_COEFFICIENT, THERMISTOR_NOMINAL_TEMPERATURE, THERMISTOR_NOMINAL_RESISTANCE, THERMISTOR_SERIES_RESISTANCE);
|
||||||
#else
|
|
||||||
return (float) 0xFFFFFFFF;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,6 +35,7 @@
|
|||||||
#define THERMISTOR_NOMINAL_RESISTANCE (10000.0)
|
#define THERMISTOR_NOMINAL_RESISTANCE (10000.0)
|
||||||
#define THERMISTOR_SERIES_RESISTANCE (10000.0)
|
#define THERMISTOR_SERIES_RESISTANCE (10000.0)
|
||||||
|
|
||||||
|
bool thermistor_driver_init(void);
|
||||||
void thermistor_driver_enable(void);
|
void thermistor_driver_enable(void);
|
||||||
void thermistor_driver_disable(void);
|
void thermistor_driver_disable(void);
|
||||||
float thermistor_driver_get_temperature(void);
|
float thermistor_driver_get_temperature(void);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user