PebbleOS v4.47.0
Loading...
Searching...
No Matches
Temperature sensor

Temperature sensor class. More...

Modules

 nRF5
 Nordic nRF5 die temperature sensor (TEMP).
 
 SF32LB
 SiFli SF32LB die temperature sensor (TSEN).
 
 Simulator
 Simulated temperature sensor, reading what pbl_temp_sim_set() sets, 25 degrees Celsius by default.
 

Data Structures

struct  pbl_temp_ops
 Temperature sensor driver operations, called with the device lock held. More...
 
struct  pbl_temp_state
 Temperature sensor runtime state. More...
 
struct  pbl_temp
 Temperature sensor. More...
 

Macros

#define PBL_TEMP_STATE_DEFINE(sym)
 Define the class state of a temperature sensor.
 
#define PBL_TEMP_INIT(sym, _name, _parent, _deps, _ops)
 Initialize a struct pbl_temp.
 

Functions

int pbl_temp_read (const struct pbl_temp *temp, int32_t *millicelsius)
 Read the temperature.
 

Variables

const struct pbl_temp *const DIE_TEMP
 The board's die temperature sensor.
 

Detailed Description

Temperature sensor class.

A temperature sensor is a struct pbl_temp device. Every call into the driver runs with the device lock held, a recursive mutex.

int32_t temp;
if (pbl_temp_read(DIE_TEMP, &temp) == 0) {
// temp is in millidegrees Celsius
}
const struct pbl_temp *const DIE_TEMP
The board's die temperature sensor.
int pbl_temp_read(const struct pbl_temp *temp, int32_t *millicelsius)
Read the temperature.

Data Structure Documentation

◆ pbl_temp_state

struct pbl_temp_state

Temperature sensor runtime state.

Data Fields
struct pbl_mutex lock Device lock.

◆ pbl_temp

struct pbl_temp

Temperature sensor.

Data Fields
struct pbl_device dev Device.
const struct pbl_temp_ops * ops Driver operations.
struct pbl_temp_state * state Runtime state.

Macro Definition Documentation

◆ PBL_TEMP_INIT

#define PBL_TEMP_INIT (   sym,
  _name,
  _parent,
  _deps,
  _ops 
)
Value:
{ \
.dev = PBL_DEVICE_INIT_CLASS(sym, _name, pbl_temp_dev_init, _parent, _deps, &pbl_temp_class), \
.ops = (_ops), \
.state = &sym##_temp_state, \
}
#define PBL_DEVICE_INIT_CLASS(sym, _name, _init, _parent, _deps, _cls)
Initializer for the struct pbl_device of device instance sym, in class _cls.
Definition device.h:145

Initialize a struct pbl_temp.

Parameters
symSymbol of the instance, as passed to PBL_TEMP_STATE_DEFINE().
_nameDevice name.
_parentParent device, or NULL.
_depsDependencies from PBL_DEVICE_DEPS(), or NULL.
_opsDriver operations.

◆ PBL_TEMP_STATE_DEFINE

#define PBL_TEMP_STATE_DEFINE (   sym)
Value:
static struct pbl_temp_state sym##_temp_state = {.lock = PBL_MUTEX_INITIALIZER}
#define PBL_DEVICE_STATE_DEFINE(sym)
Define the runtime state of device instance sym.
Definition device.h:131
struct pbl_mutex lock
Device lock.
Definition temp.h:42
Temperature sensor runtime state.
Definition temp.h:40
#define PBL_MUTEX_INITIALIZER
Static initializer for an unlocked mutex.
Definition mutex.h:50

Define the class state of a temperature sensor.

Parameters
symSymbol of the instance.

Function Documentation

◆ pbl_temp_read()

int pbl_temp_read ( const struct pbl_temp *  temp,
int32_t *  millicelsius 
)

Read the temperature.

Warning
The sensor may not be calibrated: do not rely on the reading as an accurate absolute temperature.
Parameters
tempTemperature sensor.
[out]millicelsiusTemperature in millidegrees Celsius.
Returns
0, -ENODEV if the sensor is not ready, -ETIMEDOUT if the conversion timed out, or a negative errno.

Variable Documentation

◆ DIE_TEMP

const struct pbl_temp* const DIE_TEMP
extern

The board's die temperature sensor.