saul.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Freie Universität Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
50 #include <errno.h>
51 #include <stdint.h>
52 #include <sys/types.h>
53 
54 #include "phydat.h"
55 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
88 enum {
89  SAUL_CAT_UNDEF = 0x00,
90  SAUL_CAT_ACT = 0x40,
91  SAUL_CAT_SENSE = 0x80,
92 };
93 
97 enum {
105  /* Extend this list as needed, but keep SAUL_ACT_ID_ANY the first and
106  * SAUL_ACT_NUMOF the last entry
107  */
108 };
109 
113 enum {
145  /* Extend this list as needed, but keep SAUL_SENSE_ID_ANY the first and
146  * SAUL_SENSE_NUMOF the last entry
147  */
148 };
149 
156 enum {
230  SAUL_CLASS_ANY = 0xff
231  /* extend this list as needed... */
232 };
233 
238 enum {
239  SAUL_CAT_MASK = 0xc0,
240  SAUL_ID_MASK = 0x3f,
241 };
261 typedef int(*saul_read_t)(const void *dev, phydat_t *res);
262 
281 typedef int(*saul_write_t)(const void *dev, const phydat_t *data);
282 
286 typedef struct {
289  uint8_t type;
290 } saul_driver_t;
291 
300 void saul_init_devs(void);
301 
307 int saul_write_notsup(const void *dev, const phydat_t *dat);
308 
314 int saul_read_notsup(const void *dev, phydat_t *dat);
315 
330 const char *saul_class_to_str(const uint8_t class_id);
331 
337 void saul_class_print(uint8_t class_id);
338 
355 ssize_t saul_class_write(char *dest, size_t max_size, uint8_t class_id);
356 
357 #ifdef __cplusplus
358 }
359 #endif
360 
int saul_write_notsup(const void *dev, const phydat_t *dat)
Fallback function when write is not supported.
void saul_class_print(uint8_t class_id)
Prints the class string of the given class ID.
ssize_t saul_class_write(char *dest, size_t max_size, uint8_t class_id)
Write the string representation of the given device class to the given buffer.
void saul_init_devs(void)
Initialize all available SAUL drivers.
int saul_read_notsup(const void *dev, phydat_t *dat)
Fallback function when read is not supported.
const char * saul_class_to_str(const uint8_t class_id)
Helper function converts a class ID to a string.
int(* saul_read_t)(const void *dev, phydat_t *res)
Read a value (a set of values) from a device.
Definition: saul.h:261
int(* saul_write_t)(const void *dev, const phydat_t *data)
Write a value (a set of values) to a device.
Definition: saul.h:281
@ SAUL_SENSE_CO2
sensor: CO2 Gas
Definition: saul.h:200
@ SAUL_ACT_MOTOR
actuator: motor
Definition: saul.h:164
@ SAUL_SENSE_GAS
sensor: Gas common
Definition: saul.h:204
@ SAUL_SENSE_ACCEL
sensor: accelerometer
Definition: saul.h:180
@ SAUL_SENSE_LIGHT
sensor: light
Definition: saul.h:178
@ SAUL_SENSE_ANALOG
sensor: raw analog value
Definition: saul.h:190
@ SAUL_SENSE_PH
sensor: pH
Definition: saul.h:222
@ SAUL_SENSE_CHARGE
sensor: coulomb counter
Definition: saul.h:212
@ SAUL_SENSE_RSSI
sensor: RSSI
Definition: saul.h:210
@ SAUL_SENSE_SPEED
sensor: speed
Definition: saul.h:228
@ SAUL_SENSE_TEMP
sensor: temperature
Definition: saul.h:174
@ SAUL_SENSE_CURRENT
sensor: ammeter
Definition: saul.h:214
@ SAUL_SENSE_TVOC
sensor: TVOC Gas
Definition: saul.h:202
@ SAUL_ACT_ANY
any actuator - wildcard
Definition: saul.h:158
@ SAUL_SENSE_UV
sensor: UV index
Definition: saul.h:192
@ SAUL_SENSE_MAG
sensor: magnetometer
Definition: saul.h:182
@ SAUL_SENSE_DISTANCE
sensor: distance
Definition: saul.h:198
@ SAUL_SENSE_CAPACITANCE
sensor: capacitance
Definition: saul.h:218
@ SAUL_ACT_DIMMER
actuator: dimmable switch
Definition: saul.h:168
@ SAUL_ACT_LED_RGB
actuator: RGB LED
Definition: saul.h:160
@ SAUL_SENSE_OCCUP
sensor: occupancy
Definition: saul.h:206
@ SAUL_SENSE_HUM
sensor: humidity
Definition: saul.h:176
@ SAUL_ACT_SERVO
actuator: servo motor
Definition: saul.h:162
@ SAUL_SENSE_OBJTEMP
sensor: object temperature
Definition: saul.h:194
@ SAUL_CLASS_ANY
any device - wildcard
Definition: saul.h:230
@ SAUL_SENSE_BTN
sensor: simple button
Definition: saul.h:172
@ SAUL_SENSE_COUNT
sensor: pulse counter
Definition: saul.h:196
@ SAUL_SENSE_ANY
any sensor - wildcard
Definition: saul.h:170
@ SAUL_SENSE_GYRO
sensor: gyroscope
Definition: saul.h:184
@ SAUL_ACT_SWITCH
actuator: simple on/off switch
Definition: saul.h:166
@ SAUL_SENSE_VOLTAGE
sensor: voltage
Definition: saul.h:220
@ SAUL_SENSE_PROXIMITY
sensor: proximity
Definition: saul.h:208
@ SAUL_SENSE_COLOR
sensor: (light) color
Definition: saul.h:186
@ SAUL_SENSE_POWER
sensor: power
Definition: saul.h:224
@ SAUL_SENSE_PRESS
sensor: pressure
Definition: saul.h:188
@ SAUL_SENSE_SIZE
sensor: size
Definition: saul.h:226
@ SAUL_SENSE_PM
sensor: particulate matter
Definition: saul.h:216
@ SAUL_ACT_ID_SERVO
actuator: servo motor
Definition: saul.h:100
@ SAUL_ACT_ID_DIMMER
actuator: dimmable switch
Definition: saul.h:103
@ SAUL_ACT_ID_SWITCH
actuator: simple on/off switch
Definition: saul.h:102
@ SAUL_ACT_NUMOF
Number of actuators supported.
Definition: saul.h:104
@ SAUL_ACT_ID_ANY
any actuator - wildcard
Definition: saul.h:98
@ SAUL_ACT_ID_MOTOR
actuator: motor
Definition: saul.h:101
@ SAUL_ACT_ID_LED_RGB
actuator: RGB LED
Definition: saul.h:99
@ SAUL_ID_MASK
Bitmask to obtain the intra-category ID.
Definition: saul.h:240
@ SAUL_CAT_MASK
Bitmask to obtain the category ID.
Definition: saul.h:239
@ SAUL_SENSE_ID_PH
sensor: pH
Definition: saul.h:140
@ SAUL_SENSE_ID_PROXIMITY
sensor: proximity
Definition: saul.h:133
@ SAUL_SENSE_ID_ANY
any sensor - wildcard
Definition: saul.h:114
@ SAUL_SENSE_ID_GAS
sensor: Gas common
Definition: saul.h:131
@ SAUL_SENSE_ID_OCCUP
sensor: occupancy
Definition: saul.h:132
@ SAUL_SENSE_ID_SIZE
sensor: size
Definition: saul.h:142
@ SAUL_SENSE_ID_UV
sensor: UV index
Definition: saul.h:125
@ SAUL_SENSE_ID_ACCEL
sensor: accelerometer
Definition: saul.h:119
@ SAUL_SENSE_ID_TEMP
sensor: temperature
Definition: saul.h:116
@ SAUL_SENSE_ID_TVOC
sensor: TVOC Gas
Definition: saul.h:130
@ SAUL_SENSE_ID_HUM
sensor: humidity
Definition: saul.h:117
@ SAUL_SENSE_ID_POWER
sensor: power
Definition: saul.h:141
@ SAUL_SENSE_ID_SPEED
sensor: speed
Definition: saul.h:143
@ SAUL_SENSE_ID_COLOR
sensor: (light) color
Definition: saul.h:122
@ SAUL_SENSE_ID_GYRO
sensor: gyroscope
Definition: saul.h:121
@ SAUL_SENSE_ID_VOLTAGE
sensor: voltage
Definition: saul.h:139
@ SAUL_SENSE_ID_OBJTEMP
sensor: object temperature
Definition: saul.h:126
@ SAUL_SENSE_ID_CURRENT
sensor: ammeter
Definition: saul.h:136
@ SAUL_SENSE_ID_PM
sensor: particulate matter
Definition: saul.h:137
@ SAUL_SENSE_ID_CHARGE
sensor: coulomb counter
Definition: saul.h:135
@ SAUL_SENSE_ID_CAPACITANCE
sensor: capacitance
Definition: saul.h:138
@ SAUL_SENSE_ID_MAG
sensor: magnetometer
Definition: saul.h:120
@ SAUL_SENSE_ID_CO2
sensor: CO2 Gas
Definition: saul.h:129
@ SAUL_SENSE_ID_DISTANCE
sensor: distance
Definition: saul.h:128
@ SAUL_SENSE_NUMOF
Number of actuators supported.
Definition: saul.h:144
@ SAUL_SENSE_ID_LIGHT
sensor: light
Definition: saul.h:118
@ SAUL_SENSE_ID_PRESS
sensor: pressure
Definition: saul.h:123
@ SAUL_SENSE_ID_COUNT
sensor: pulse counter
Definition: saul.h:127
@ SAUL_SENSE_ID_RSSI
sensor: RSSI
Definition: saul.h:134
@ SAUL_SENSE_ID_ANALOG
sensor: raw analog value
Definition: saul.h:124
@ SAUL_SENSE_ID_BTN
sensor: simple button
Definition: saul.h:115
@ SAUL_CAT_SENSE
Sensor device class.
Definition: saul.h:91
@ SAUL_CAT_ACT
Actuator device class.
Definition: saul.h:90
@ SAUL_CAT_UNDEF
device class undefined
Definition: saul.h:89
Generic data structure for expressing physical values.
Definition: phydat.h:155
Definition of the RIOT actuator/sensor interface.
Definition: saul.h:286
saul_write_t write
write function pointer
Definition: saul.h:288
uint8_t type
device class the device belongs to
Definition: saul.h:289
saul_read_t read
read function pointer
Definition: saul.h:287