diffpressure  2.0.0.0
diffpressure.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 DIFFPRESSURE_H
36 #define DIFFPRESSURE_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
53 #define DIFFPRESSURE_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
55  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
56  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
57  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
58 
65 #define DIFFPRESSURE_RETVAL uint8_t
66 
67 #define DIFFPRESSURE_OK 0x01
68 #define DIFFPRESSURE_INIT_ERROR 0xFF
69 
75 #define DIFFPRESSURE_NOT_RDY 0
76 #define DIFFPRESSURE_OK_RDY 1
77 #define DIFFPRESSURE_OVH 2
78 #define DIFFPRESSURE_OVL 3
79  // End group macro
82 // --------------------------------------------------------------- PUBLIC TYPES
91 typedef struct
92 {
93  // Modules
94 
95  spi_master_t spi;
96 
97  // ctx variable
98 
99  uint8_t slave_address;
100  pin_name_t chip_select;
101 
103 
107 typedef struct
108 {
109  // Communication gpio pins
110 
111  pin_name_t miso;
112  pin_name_t mosi;
113  pin_name_t sck;
114  pin_name_t cs;
115 
116  // static variable
117 
118  uint32_t spi_speed;
119  spi_master_mode_t spi_mode;
120  spi_master_chip_select_polarity_t cs_polarity;
121 
123 
124 typedef enum
125 {
126  NOT_RDY = 0,
127  OVH = 2,
128  OVL = 3,
129  OK = 1
130 } status_t;
131  // End types group
133 
134 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
135 
140 #ifdef __cplusplus
141 extern "C"{
142 #endif
143 
153 
163 
175 void diffpressure_generic_transfer ( diffpressure_t *ctx, uint8_t *wr_buf,
176  uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
177 
185 int32_t diffpressure_read_data ( diffpressure_t *ctx );
186 
195 int32_t diffpressure_get_kpa_difference ( diffpressure_t *ctx, int32_t difference );
196 
205 status_t diffpressure_status_check ( diffpressure_t *ctx, int32_t result );
206 
207 #ifdef __cplusplus
208 }
209 #endif
210 #endif // _DIFFPRESSURE_H_
211  // End public_function group
214 
215 // ------------------------------------------------------------------------- END
diffpressure_cfg_t::spi_speed
uint32_t spi_speed
Definition: diffpressure.h:118
diffpressure_init
DIFFPRESSURE_RETVAL diffpressure_init(diffpressure_t *ctx, diffpressure_cfg_t *cfg)
Initialization function.
diffpressure_cfg_t::mosi
pin_name_t mosi
Definition: diffpressure.h:112
diffpressure_t
Click ctx object definition.
Definition: diffpressure.h:91
diffpressure_cfg_t::cs
pin_name_t cs
Definition: diffpressure.h:114
DIFFPRESSURE_RETVAL
#define DIFFPRESSURE_RETVAL
Definition: diffpressure.h:65
diffpressure_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: diffpressure.h:119
diffpressure_cfg_setup
void diffpressure_cfg_setup(diffpressure_cfg_t *cfg)
Config Object Initialization function.
OVL
Definition: diffpressure.h:128
OVH
Definition: diffpressure.h:127
diffpressure_t::spi
spi_master_t spi
Definition: diffpressure.h:95
diffpressure_read_data
int32_t diffpressure_read_data(diffpressure_t *ctx)
Generic read data function.
diffpressure_cfg_t::sck
pin_name_t sck
Definition: diffpressure.h:113
diffpressure_status_check
status_t diffpressure_status_check(diffpressure_t *ctx, int32_t result)
Check status of measurement.
diffpressure_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: diffpressure.h:120
diffpressure_cfg_t::miso
pin_name_t miso
Definition: diffpressure.h:111
diffpressure_get_kpa_difference
int32_t diffpressure_get_kpa_difference(diffpressure_t *ctx, int32_t difference)
Get kPa Difference function.
status_t
status_t
Definition: diffpressure.h:124
diffpressure_cfg_t
Click configuration structure definition.
Definition: diffpressure.h:107
diffpressure_t::chip_select
pin_name_t chip_select
Definition: diffpressure.h:100
NOT_RDY
Definition: diffpressure.h:126
OK
Definition: diffpressure.h:129
diffpressure_t::slave_address
uint8_t slave_address
Definition: diffpressure.h:99
diffpressure_generic_transfer
void diffpressure_generic_transfer(diffpressure_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.