thermo21  2.0.0.0
thermo21.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef THERMO21_H
29 #define THERMO21_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 #include "spi_specifics.h"
49 
74 #define THERMO21_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
75 #define THERMO21_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
76  // thermo21_set
78 
93 #define THERMO21_MAP_MIKROBUS( cfg, mikrobus ) \
94  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
95  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
96  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
97  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
98  // thermo21_map // thermo21
101 
106 typedef struct
107 {
108  // Modules
109  spi_master_t spi;
110  pin_name_t chip_select;
112 } thermo21_t;
113 
118 typedef struct
119 {
120  // Communication gpio pins
121  pin_name_t miso;
122  pin_name_t mosi;
123  pin_name_t sck;
124  pin_name_t cs;
126  // static variable
127  uint32_t spi_speed;
128  spi_master_mode_t spi_mode;
129  spi_master_chip_select_polarity_t cs_polarity;
132 
137 typedef enum
138 {
140  THERMO21_ERROR = -1
141 
143 
160 
176 
191 err_t thermo21_generic_read ( thermo21_t *ctx, uint8_t *data_out, uint8_t len );
192 
205 err_t thermo21_temperature_read ( thermo21_t *ctx, float *data_out );
206 
207 #ifdef __cplusplus
208 }
209 #endif
210 #endif // THERMO21_H
211  // thermo21
213 
214 // ------------------------------------------------------------------------ END
thermo21_t
Thermo 21 Click context object.
Definition: thermo21.h:107
spi_specifics.h
This file contains SPI specific macros, functions, etc.
thermo21_t::chip_select
pin_name_t chip_select
Definition: thermo21.h:110
thermo21_generic_read
err_t thermo21_generic_read(thermo21_t *ctx, uint8_t *data_out, uint8_t len)
Data reading function.
thermo21_cfg_t::cs
pin_name_t cs
Definition: thermo21.h:124
thermo21_cfg_setup
void thermo21_cfg_setup(thermo21_cfg_t *cfg)
Thermo 21 configuration object setup function.
thermo21_cfg_t
Thermo 21 Click configuration object.
Definition: thermo21.h:119
thermo21_return_value_t
thermo21_return_value_t
Thermo 21 Click return value data.
Definition: thermo21.h:138
thermo21_cfg_t::sck
pin_name_t sck
Definition: thermo21.h:123
thermo21_cfg_t::spi_speed
uint32_t spi_speed
Definition: thermo21.h:127
thermo21_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: thermo21.h:129
thermo21_cfg_t::miso
pin_name_t miso
Definition: thermo21.h:121
thermo21_init
err_t thermo21_init(thermo21_t *ctx, thermo21_cfg_t *cfg)
Thermo 21 initialization function.
thermo21_temperature_read
err_t thermo21_temperature_read(thermo21_t *ctx, float *data_out)
Temperature reading function.
thermo21_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: thermo21.h:128
THERMO21_OK
@ THERMO21_OK
Definition: thermo21.h:139
thermo21_cfg_t::mosi
pin_name_t mosi
Definition: thermo21.h:122
THERMO21_ERROR
@ THERMO21_ERROR
Definition: thermo21.h:140
thermo21_t::spi
spi_master_t spi
Definition: thermo21.h:109