no-OS
max31827.h
Go to the documentation of this file.
1 /***************************************************************************/
34 #ifndef __MAX31827_H__
35 #define __MAX31827_H__
36 
37 #include "no_os_i2c.h"
38 #include "no_os_util.h"
39 
40 #define MAX31827_T_REG 0x0
41 #define MAX31827_CONF_REG 0x2
42 #define MAX31827_TH_REG 0x4
43 #define MAX31827_TL_REG 0x6
44 #define MAX31827_TH_HYST_REG 0x8
45 #define MAX31827_TL_HYST_REG 0xA
46 
47 #define MAX31827_CONF_1SHOT_MASK NO_OS_BIT(0)
48 #define MAX31827_CONF_CNV_RATE_MASK NO_OS_GENMASK(3, 1)
49 #define MAX31827_CONF_PEC_EN_MASK NO_OS_BIT(4)
50 #define MAX31827_CONF_TIMEOUT_MASK NO_OS_BIT(5)
51 #define MAX31827_CONF_RESO_MASK NO_OS_GENMASK(7, 6)
52 #define MAX31827_CONF_ALRM_POL_MASK NO_OS_BIT(8)
53 #define MAX31827_CONF_COMP_INT_MASK NO_OS_BIT(9)
54 #define MAX31827_CONF_FLT_Q_MASK NO_OS_GENMASK(11, 10)
55 #define MAX31827_CONF_U_TEMP_STAT_MASK NO_OS_BIT(14)
56 #define MAX31827_CONF_O_TEMP_STAT_MASK NO_OS_BIT(15)
57 
58 #define MAX31827_CONF_CNV_RATE(x) \
59  no_os_field_get(MAX31827_CONF_CNV_RATE_MASK, x)
60 #define MAX31827_CONF_RESO(x) \
61  no_os_field_get(MAX31827_CONF_RESO_MASK, x)
62 #define MAX31827_CONF_U_TEMP_STAT(x) \
63  no_os_field_get(MAX31827_CONF_U_TEMP_STAT_MASK, x)
64 #define MAX31827_CONF_O_TEMP_STAT(x) \
65  no_os_field_get(MAX31827_CONF_O_TEMP_STAT_MASK, x)
66 
67 #define MAX31827_ALRM_POL_LOW 0x0
68 #define MAX31827_ALRM_POL_HIGH 0x1
69 #define MAX31827_FLT_Q_1 0x0
70 #define MAX31827_FLT_Q_4 0x2
71 
72 #define MAX31827_M_DGR_TO_16_BIT(x) (((x) << 4) / 1000)
73 #define MAX31827_DEVICE_ENABLE(x) ((x) ? 0xA : 0x0)
74 
86 };
87 
96 };
97 
101 extern const uint16_t max31827_conversions[8];
102 
106 extern const uint16_t max31827_resolutions[4];
107 
111 extern const int max31827_conv_times[4];
112 
120  bool enable;
122  unsigned int resolution;
124  unsigned int update_interval;
125 };
126 
134  bool comp_int;
136  bool alarm_pol;
138  uint8_t fault_q;
141 };
142 
144 int max31827_reg_read(struct max31827_device *dev, uint8_t addr, uint16_t *val);
145 
147 int max31827_reg_write(struct max31827_device *dev, uint8_t addr, uint16_t val);
148 
150 int max31827_reg_update_bits(struct max31827_device *dev, uint8_t addr,
151  uint16_t mask, uint16_t val);
152 
154 int max31827_init(struct max31827_device **dev,
156 
158 int max31827_remove(struct max31827_device *dev);
159 
161 int max31827_init_client(struct max31827_device *dev,
163 
165 int max31827_read_temp(struct max31827_device *dev, uint8_t addr, int32_t *val);
166 
168 int max31827_read_temp_input(struct max31827_device *dev, int32_t *val);
169 
171 int max31827_shutdown_write(struct max31827_device *dev, uint8_t reg,
172  uint16_t mask, uint16_t val);
173 
175 int max31827_write_alarm_val(struct max31827_device *dev, unsigned int reg,
176  int32_t val);
177 
178 #endif /* __MAX31827_H__ */
max31827_conv_times
const int max31827_conv_times[4]
MAX31827 temperature conversion times in us.
Definition: max31827.c:77
MILLI
#define MILLI
Definition: no_os_units.h:48
max31827_init_param
MAX31827 init param.
Definition: max31827.h:130
no_os_alloc.h
max31827_init_param::alarm_pol
bool alarm_pol
Definition: max31827.h:136
MAX31827_RES_12_BIT
@ MAX31827_RES_12_BIT
Definition: max31827.h:95
MAX31827_RES_10_BIT
@ MAX31827_RES_10_BIT
Definition: max31827.h:94
no_os_i2c_write
int32_t no_os_i2c_write(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Write data to slave device.
Definition: no_os_i2c.c:159
no_os_i2c_init
int32_t no_os_i2c_init(struct no_os_i2c_desc **desc, const struct no_os_i2c_init_param *param)
Initialize the I2C communication peripheral.
Definition: no_os_i2c.c:52
max31827_remove
int max31827_remove(struct max31827_device *dev)
Free resources allocated by the init function.
Definition: max31827.c:200
max31827_init_param::i2c_init_param
struct no_os_i2c_init_param i2c_init_param
Definition: max31827.h:132
max31827_device::resolution
unsigned int resolution
Definition: max31827.h:122
max31827_shutdown_write
int max31827_shutdown_write(struct max31827_device *dev, uint8_t reg, uint16_t mask, uint16_t val)
Shutdown then write register value.
Definition: max31827.c:317
max31827_init_client
int max31827_init_client(struct max31827_device *dev, struct max31827_init_param *init_param)
Initialize MAX31827 device setup.
Definition: max31827.c:222
max31827_device::update_interval
unsigned int update_interval
Definition: max31827.h:124
MAX31827_RES_9_BIT
@ MAX31827_RES_9_BIT
Definition: max31827.h:93
max31827_reg_write
int max31827_reg_write(struct max31827_device *dev, uint8_t addr, uint16_t val)
Write a register value.
Definition: max31827.c:121
max31827_reg_read
int max31827_reg_read(struct max31827_device *dev, uint8_t addr, uint16_t *val)
Read a register value.
Definition: max31827.c:96
no_os_i2c_remove
int32_t no_os_i2c_remove(struct no_os_i2c_desc *desc)
Free the resources allocated by no_os_i2c_init().
Definition: no_os_i2c.c:113
max31827_reg_write
int max31827_reg_write(struct max31827_device *dev, uint8_t addr, uint16_t val)
Write a register value.
Definition: max31827.c:121
no_os_units.h
Header file of Units.
max31827_read_temp_input
int max31827_read_temp_input(struct max31827_device *dev, int32_t *val)
Read input temperature.
Definition: max31827.c:284
pr_err
#define pr_err(fmt, args...)
Definition: no_os_print_log.h:88
no_os_delay.h
Header file of Delay functions.
MAX31827_DEVICE_ENABLE
#define MAX31827_DEVICE_ENABLE(x)
Definition: max31827.h:73
max31827_init_param::comp_int
bool comp_int
Definition: max31827.h:134
MAX31827_CONF_1SHOT_MASK
#define MAX31827_CONF_1SHOT_MASK
Definition: max31827.h:47
no_os_print_log.h
Print messages helpers.
max31827_conv_times
const int max31827_conv_times[]
MAX31827 temperature conversion times in us.
Definition: max31827.c:77
max31827_conversions
const uint16_t max31827_conversions[8]
MAX31827 conversion period in ms.
Definition: max31827.c:54
no_os_calloc
void * no_os_calloc(size_t nitems, size_t size)
Allocate memory and return a pointer to it, set memory to 0.
Definition: chibios_alloc.c:54
NO_OS_ARRAY_SIZE
#define NO_OS_ARRAY_SIZE(x)
Definition: no_os_util.h:49
max31827_remove
int max31827_remove(struct max31827_device *dev)
Free resources allocated by the init function.
Definition: max31827.c:200
MAX31827_CONF_FLT_Q_MASK
#define MAX31827_CONF_FLT_Q_MASK
Definition: max31827.h:54
max31827_shutdown_write
int max31827_shutdown_write(struct max31827_device *dev, uint8_t reg, uint16_t mask, uint16_t val)
Shutdown then write register value.
Definition: max31827.c:317
max31827_reg_update_bits
int max31827_reg_update_bits(struct max31827_device *dev, uint8_t addr, uint16_t mask, uint16_t val)
Read-modify-write operation.
Definition: max31827.c:136
max31827.h
Implementation of MAX31827 Driver.
max31827_reg_update_bits
int max31827_reg_update_bits(struct max31827_device *dev, uint8_t addr, uint16_t mask, uint16_t val)
Read-modify-write operation.
Definition: max31827.c:136
MAX31827_CNV_1_DIV_16_HZ
@ MAX31827_CNV_1_DIV_16_HZ
Definition: max31827.h:81
no_os_field_prep
uint32_t no_os_field_prep(uint32_t mask, uint32_t val)
MAX31827_CONF_CNV_RATE_MASK
#define MAX31827_CONF_CNV_RATE_MASK
Definition: max31827.h:48
MAX31827_CONF_COMP_INT_MASK
#define MAX31827_CONF_COMP_INT_MASK
Definition: max31827.h:53
no_os_error.h
Error codes definition.
MAX31827_CNV_1_DIV_64_HZ
@ MAX31827_CNV_1_DIV_64_HZ
Definition: max31827.h:79
max31827_init_client
int max31827_init_client(struct max31827_device *dev, struct max31827_init_param *init_param)
Initialize MAX31827 device setup.
Definition: max31827.c:222
max31827_read_temp
int max31827_read_temp(struct max31827_device *dev, uint8_t addr, int32_t *val)
Read a temperature from a register.
Definition: max31827.c:261
MAX31827_CONF_RESO_MASK
#define MAX31827_CONF_RESO_MASK
Definition: max31827.h:51
max31827_write_alarm_val
int max31827_write_alarm_val(struct max31827_device *dev, unsigned int reg, int32_t val)
Write the alarm value to the specified register.
Definition: max31827.c:364
max31827_reg_read
int max31827_reg_read(struct max31827_device *dev, uint8_t addr, uint16_t *val)
Read a register value.
Definition: max31827.c:96
MAX31827_CNV_1_HZ
@ MAX31827_CNV_1_HZ
Definition: max31827.h:83
MAX31827_CNV_4_HZ
@ MAX31827_CNV_4_HZ
Definition: max31827.h:84
max31827_read_temp_input
int max31827_read_temp_input(struct max31827_device *dev, int32_t *val)
Read input temperature.
Definition: max31827.c:284
MAX31827_RES_8_BIT
@ MAX31827_RES_8_BIT
Definition: max31827.h:92
max31827_device::enable
bool enable
Definition: max31827.h:120
MAX31827_CONF_ALRM_POL_MASK
#define MAX31827_CONF_ALRM_POL_MASK
Definition: max31827.h:52
MAX31827_CNV_1_DIV_32_HZ
@ MAX31827_CNV_1_DIV_32_HZ
Definition: max31827.h:80
max31827_resolution
max31827_resolution
MAX31827 temperature resolution.
Definition: max31827.h:91
max31827_init
int max31827_init(struct max31827_device **dev, struct max31827_init_param *init_param)
Device and comm init function.
Definition: max31827.c:158
max31827_conversions
const uint16_t max31827_conversions[]
MAX31827 conversion period in ms.
Definition: max31827.c:54
MAX31827_CONF_TIMEOUT_MASK
#define MAX31827_CONF_TIMEOUT_MASK
Definition: max31827.h:50
no_os_i2c_desc
Structure holding I2C address descriptor.
Definition: no_os_i2c.h:101
max31827_resolutions
const uint16_t max31827_resolutions[4]
MAX31827 temperature resolution.
Definition: max31827.c:67
no_os_i2c_read
int32_t no_os_i2c_read(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Read data from slave device.
Definition: no_os_i2c.c:190
no_os_i2c.h
Header file of I2C Interface.
max31827_device::i2c_desc
struct no_os_i2c_desc * i2c_desc
Definition: max31827.h:118
max31827_device
MAX31827 descriptor.
Definition: max31827.h:116
no_os_free
void no_os_free(void *ptr)
Deallocate memory previously allocated by a call to no_os_calloc or no_os_malloc.
Definition: chibios_alloc.c:69
max31827_init_param::timeout_enable
bool timeout_enable
Definition: max31827.h:140
MAX31827_CNV_8_HZ
@ MAX31827_CNV_8_HZ
Definition: max31827.h:85
max31827_init
int max31827_init(struct max31827_device **dev, struct max31827_init_param *init_param)
Device and comm init function.
Definition: max31827.c:158
no_os_udelay
void no_os_udelay(uint32_t usecs)
Wait until usecs microseconds passed.
Definition: aducm3029_delay.c:114
no_os_i2c_init_param
Structure holding the parameters for I2C initialization.
Definition: no_os_i2c.h:64
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:113
max31827_read_temp
int max31827_read_temp(struct max31827_device *dev, uint8_t addr, int32_t *val)
Read a temperature from a register.
Definition: max31827.c:261
MAX31827_CONF_REG
#define MAX31827_CONF_REG
Definition: max31827.h:41
no_os_get_unaligned_be16
uint16_t no_os_get_unaligned_be16(uint8_t *buf)
MAX31827_CNV_1_DIV_4_HZ
@ MAX31827_CNV_1_DIV_4_HZ
Definition: max31827.h:82
no_os_util.h
Header file of utility functions.
no_os_find_first_set_bit
uint32_t no_os_find_first_set_bit(uint32_t word)
no_os_hweight32
unsigned int no_os_hweight32(uint32_t word)
no_os_sign_extend32
int32_t no_os_sign_extend32(uint32_t value, int index)
max31827_write_alarm_val
int max31827_write_alarm_val(struct max31827_device *dev, unsigned int reg, int32_t val)
Write the alarm value to the specified register.
Definition: max31827.c:364
MAX31827_T_REG
#define MAX31827_T_REG
Definition: max31827.h:40
max31827_init_param::fault_q
uint8_t fault_q
Definition: max31827.h:138
max31827_cnv
max31827_cnv
MAX31827 conversion rate.
Definition: max31827.h:78
max31827_resolutions
const uint16_t max31827_resolutions[]
MAX31827 temperature resolution.
Definition: max31827.c:67