ph_oem.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 University of Applied Sciences Emden / Leer
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 
50 #ifndef PH_OEM_H
51 #define PH_OEM_H
52 
53 #ifdef __cplusplus
54 extern "C"
55 {
56 #endif
57 
58 #include "periph/i2c.h"
59 #include "periph/gpio.h"
60 
64 typedef enum {
65  PH_OEM_OK = 0,
66  PH_OEM_NODEV = -1,
74 
78 typedef enum {
79  PH_OEM_LED_ON = 0x01,
80  PH_OEM_LED_OFF = 0x00,
82 
86 typedef enum {
93 typedef enum {
96  PH_OEM_IRQ_BOTH = 0x08,
98 
102 typedef enum {
107 
111 typedef struct ph_oem_params {
113  uint8_t addr;
114  gpio_t interrupt_pin;
118 
122 typedef void (*ph_oem_interrupt_pin_cb_t)(void *);
123 
127 typedef struct ph_oem {
130  void *arg;
131 } ph_oem_t;
132 
144 int ph_oem_init(ph_oem_t *dev, const ph_oem_params_t *params);
145 
165 int ph_oem_set_i2c_address(ph_oem_t *dev, uint8_t addr);
166 
194  void *arg);
195 
209 int ph_oem_reset_interrupt_pin(const ph_oem_t *dev);
210 
221 int ph_oem_set_led_state(const ph_oem_t *dev, ph_oem_led_state_t state);
222 
238 
253 int ph_oem_start_new_reading(const ph_oem_t *dev);
254 
264 int ph_oem_clear_calibration(const ph_oem_t *dev);
265 
288 int ph_oem_set_calibration(const ph_oem_t *dev, uint16_t calibration_value,
290 
304 int ph_oem_read_calibration_state(const ph_oem_t *dev, uint16_t *calibration_state);
305 
324 int ph_oem_set_compensation(const ph_oem_t *dev,
325  uint16_t temperature_compensation);
326 
340 int ph_oem_read_compensation(const ph_oem_t *dev,
341  uint16_t *temperature_compensation);
342 
355 int ph_oem_read_ph(const ph_oem_t *dev, uint16_t *ph_value);
356 
357 #ifdef __cplusplus
358 }
359 #endif
360 
361 #endif /* PH_OEM_H */
362 
PH_OEM_GPIO_INIT_ERR
@ PH_OEM_GPIO_INIT_ERR
Error while initializing GPIO PIN.
Definition: ph_oem.h:71
PH_OEM_LED_OFF
@ PH_OEM_LED_OFF
LED off state.
Definition: ph_oem.h:80
ph_oem_params::irq_option
ph_oem_irq_option_t irq_option
behavior of the interrupt pin, disabled by default
Definition: ph_oem.h:116
PH_OEM_OK
@ PH_OEM_OK
Everything was fine.
Definition: ph_oem.h:65
PH_OEM_TAKE_READINGS
@ PH_OEM_TAKE_READINGS
Device active state.
Definition: ph_oem.h:87
ph_oem_params::interrupt_pin
gpio_t interrupt_pin
interrupt pin (GPIO_UNDEF if not defined)
Definition: ph_oem.h:114
PH_OEM_INTERRUPT_GPIO_UNDEF
@ PH_OEM_INTERRUPT_GPIO_UNDEF
Interrupt pin is GPIO_UNDEF.
Definition: ph_oem.h:70
ph_oem_params::gpio_mode
gpio_mode_t gpio_mode
gpio mode of the interrupt pin
Definition: ph_oem.h:115
ph_oem_read_ph
int ph_oem_read_ph(const ph_oem_t *dev, uint16_t *ph_value)
Reads the PH_OEM_REG_PH_READING_BASE register to get the current pH reading.
ph_oem_enable_interrupt
int ph_oem_enable_interrupt(ph_oem_t *dev, ph_oem_interrupt_pin_cb_t cb, void *arg)
Enable the pH OEM interrupt pin if ph_oem_params_t::interrupt_pin is defined.
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
ph_oem_set_led_state
int ph_oem_set_led_state(const ph_oem_t *dev, ph_oem_led_state_t state)
Set the LED state of the pH OEM sensor by writing to the PH_OEM_REG_LED register.
ph_oem_params::addr
uint8_t addr
the slave address of the sensor on the I2C bus
Definition: ph_oem.h:113
ph_oem_calibration_option_t
ph_oem_calibration_option_t
Calibration option values.
Definition: ph_oem.h:102
ph_oem_t
struct ph_oem ph_oem_t
pH OEM device descriptor
PH_OEM_STOP_READINGS
@ PH_OEM_STOP_READINGS
Device hibernate state.
Definition: ph_oem.h:88
PH_OEM_TEMP_OUT_OF_RANGE
@ PH_OEM_TEMP_OUT_OF_RANGE
Temperature is out of range.
Definition: ph_oem.h:72
PH_OEM_IRQ_FALLING
@ PH_OEM_IRQ_FALLING
Pin low on new reading (manually reset)
Definition: ph_oem.h:95
ph_oem::arg
void * arg
interrupt pin callback param
Definition: ph_oem.h:130
PH_OEM_CALIBRATE_HIGH_POINT
@ PH_OEM_CALIBRATE_HIGH_POINT
High point calibration option.
Definition: ph_oem.h:105
PH_OEM_NOT_PH
@ PH_OEM_NOT_PH
Not an Atlas Scientific pH OEM device.
Definition: ph_oem.h:69
PH_OEM_READ_ERR
@ PH_OEM_READ_ERR
Reading to device failed.
Definition: ph_oem.h:67
ph_oem_read_calibration_state
int ph_oem_read_calibration_state(const ph_oem_t *dev, uint16_t *calibration_state)
Read the PH_OEM_REG_CALIBRATION_CONFIRM register.
ph_oem
pH OEM device descriptor
Definition: ph_oem.h:127
PH_OEM_CALIBRATE_MID_POINT
@ PH_OEM_CALIBRATE_MID_POINT
Mid point calibration option.
Definition: ph_oem.h:104
ph_oem_params_t
struct ph_oem_params ph_oem_params_t
pH OEM sensor params
ph_oem_irq_option_t
ph_oem_irq_option_t
Interrupt pin option values.
Definition: ph_oem.h:93
ph_oem_params
pH OEM sensor params
Definition: ph_oem.h:111
PH_OEM_WRITE_ERR
@ PH_OEM_WRITE_ERR
Writing to device failed.
Definition: ph_oem.h:68
ph_oem_clear_calibration
int ph_oem_clear_calibration(const ph_oem_t *dev)
Clears all calibrations previously done.
ph_oem_interrupt_pin_cb_t
void(* ph_oem_interrupt_pin_cb_t)(void *)
pH OEM interrupt pin callback
Definition: ph_oem.h:122
ph_oem_reset_interrupt_pin
int ph_oem_reset_interrupt_pin(const ph_oem_t *dev)
The interrupt pin will not auto reset on option PH_OEM_IRQ_RISING and PH_OEM_IRQ_FALLING after interr...
PH_OEM_IRQ_BOTH
@ PH_OEM_IRQ_BOTH
Invert state on new reading (automatically reset)
Definition: ph_oem.h:96
ph_oem::cb
ph_oem_interrupt_pin_cb_t cb
interrupt pin callback
Definition: ph_oem.h:129
ph_oem_set_compensation
int ph_oem_set_compensation(const ph_oem_t *dev, uint16_t temperature_compensation)
Sets the PH_OEM_REG_TEMP_COMPENSATION_BASE register to the temperature_compensation value which the p...
ph_oem_start_new_reading
int ph_oem_start_new_reading(const ph_oem_t *dev)
Starts a new reading by setting the device state to PH_OEM_TAKE_READINGS.
ph_oem::params
ph_oem_params_t params
device driver configuration
Definition: ph_oem.h:128
ph_oem_init
int ph_oem_init(ph_oem_t *dev, const ph_oem_params_t *params)
Initialize a pH OEM sensor.
ph_oem_device_state_t
ph_oem_device_state_t
Device state values.
Definition: ph_oem.h:86
gpio.h
Low-level GPIO peripheral driver interface definitions.
PH_OEM_NODEV
@ PH_OEM_NODEV
No device found on the bus.
Definition: ph_oem.h:66
gpio_mode_t
gpio_mode_t
Available pin modes.
Definition: periph_cpu.h:70
ph_oem_set_device_state
int ph_oem_set_device_state(const ph_oem_t *dev, ph_oem_device_state_t state)
Sets the device state (active/hibernate) of the pH OEM sensor by writing to the PH_OEM_REG_HIBERNATE ...
PH_OEM_CALIBRATE_LOW_POINT
@ PH_OEM_CALIBRATE_LOW_POINT
Low point calibration option.
Definition: ph_oem.h:103
ph_oem_set_i2c_address
int ph_oem_set_i2c_address(ph_oem_t *dev, uint8_t addr)
Sets a new address to the pH OEM device by unlocking the PH_OEM_REG_UNLOCK register and writing a new...
ph_oem_set_calibration
int ph_oem_set_calibration(const ph_oem_t *dev, uint16_t calibration_value, ph_oem_calibration_option_t option)
Sets the PH_OEM_REG_CALIBRATION_BASE register to the calibration_value which the pH OEM sensor will b...
ph_oem_led_state_t
ph_oem_led_state_t
LED state values.
Definition: ph_oem.h:78
PH_OEM_LED_ON
@ PH_OEM_LED_ON
LED on state.
Definition: ph_oem.h:79
PH_OEM_IRQ_RISING
@ PH_OEM_IRQ_RISING
Pin high on new reading (manually reset)
Definition: ph_oem.h:94
ph_oem_read_compensation
int ph_oem_read_compensation(const ph_oem_t *dev, uint16_t *temperature_compensation)
Reads the PH_OEM_REG_TEMP_CONFIRMATION_BASE register to verify the temperature compensation value tha...
ph_oem_params::i2c
i2c_t i2c
I2C device the sensor is connected to.
Definition: ph_oem.h:112
ph_oem_named_returns_t
ph_oem_named_returns_t
Named return values.
Definition: ph_oem.h:64
i2c.h
Low-level I2C peripheral driver interface definition.