rtd  2.0.0.0
rtd.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef RTD_H
36 #define RTD_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define RTD_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
56  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
57  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
58  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
59  cfg.drdy = MIKROBUS( mikrobus, MIKROBUS_INT );
60 
66 #define RTD_RETVAL uint8_t
67 
68 #define RTD_OK 0x00
69 #define RTD_INIT_ERROR 0xFF
70 #define RTD_ERR 1
71 
77 #define RTD_REF_RESISTANCE_470 470
78 
84 #define RTD_CONFIGURATION 0x00
85 #define RTD_RTD_MSB 0x01
86 #define RTD_RTD_LSB 0x02
87 #define RTD_HI_FLT_THRHLD_MSB 0x03
88 #define RTD_HI_FLT_THRHLD_LSB 0x04
89 #define RTD_LO_FLT_THRHLD_MSB 0x05
90 #define RTD_LO_FLT_THRHLD_LSB 0x06
91 #define RTD_FLT_STATUS 0x07
92  // End group macro
95 // --------------------------------------------------------------- PUBLIC TYPES
104 typedef struct
105 {
106  digital_out_t cs;
107 
108  // Input pins
109 
110  digital_in_t drdy;
111 
112  // Modules
113 
114  spi_master_t spi;
115  pin_name_t chip_select;
116 
117 } rtd_t;
118 
122 typedef struct
123 {
124  // Communication gpio pins
125 
126  pin_name_t miso;
127  pin_name_t mosi;
128  pin_name_t sck;
129  pin_name_t cs;
130 
131  // Additional gpio pins
132 
133  pin_name_t drdy;
134 
135  // static variable
136 
137  uint32_t spi_speed;
138  uint8_t spi_mode;
139  spi_master_chip_select_polarity_t cs_polarity;
140 
141 } rtd_cfg_t;
142  // End types group
144 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
145 
150 #ifdef __cplusplus
151 extern "C"{
152 #endif
153 
162 void rtd_cfg_setup ( rtd_cfg_t *cfg );
163 
172 RTD_RETVAL rtd_init ( rtd_t *ctx, rtd_cfg_t *cfg );
173 
186 (
187  rtd_t *ctx,
188  uint8_t *wr_buf,
189  uint16_t wr_len,
190  uint8_t *rd_buf,
191  uint16_t rd_len
192 );
193 
206 void rtd_write_register ( rtd_t *ctx, uint8_t reg_address, uint8_t write_data );
207 
216 uint8_t rtd_read_register ( rtd_t *ctx, uint8_t reg_address );
217 
225 uint16_t rtd_read_temperature ( rtd_t *ctx );
226 
241 float rtd_convert_temperature ( rtd_t *ctx, uint16_t input_data, uint16_t referent_resistance );
242 
243 #ifdef __cplusplus
244 }
245 #endif
246 #endif // _RTD_H_
247  // End public_function group
250 
251 // ------------------------------------------------------------------------- END
rtd_t::drdy
digital_in_t drdy
Definition: rtd.h:110
rtd_t::chip_select
pin_name_t chip_select
Definition: rtd.h:115
rtd_write_register
void rtd_write_register(rtd_t *ctx, uint8_t reg_address, uint8_t write_data)
Write to Register function.
rtd_t::spi
spi_master_t spi
Definition: rtd.h:114
rtd_cfg_setup
void rtd_cfg_setup(rtd_cfg_t *cfg)
Config Object Initialization function.
rtd_generic_transfer
void rtd_generic_transfer(rtd_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
rtd_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: rtd.h:139
rtd_cfg_t::cs
pin_name_t cs
Definition: rtd.h:129
rtd_cfg_t::spi_mode
uint8_t spi_mode
Definition: rtd.h:138
rtd_cfg_t::drdy
pin_name_t drdy
Definition: rtd.h:133
rtd_read_temperature
uint16_t rtd_read_temperature(rtd_t *ctx)
Read Temperature function.
rtd_convert_temperature
float rtd_convert_temperature(rtd_t *ctx, uint16_t input_data, uint16_t referent_resistance)
Convert Temperature function.
rtd_t
Click ctx object definition.
Definition: rtd.h:104
rtd_cfg_t::spi_speed
uint32_t spi_speed
Definition: rtd.h:137
rtd_cfg_t
Click configuration structure definition.
Definition: rtd.h:122
rtd_read_register
uint8_t rtd_read_register(rtd_t *ctx, uint8_t reg_address)
Read from Register function.
rtd_t::cs
digital_out_t cs
Definition: rtd.h:106
RTD_RETVAL
#define RTD_RETVAL
Definition: rtd.h:66
rtd_cfg_t::miso
pin_name_t miso
Definition: rtd.h:126
rtd_cfg_t::sck
pin_name_t sck
Definition: rtd.h:128
rtd_init
RTD_RETVAL rtd_init(rtd_t *ctx, rtd_cfg_t *cfg)
Initialization function.
rtd_cfg_t::mosi
pin_name_t mosi
Definition: rtd.h:127