pressure2  2.0.0.0
pressure2.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef PRESSURE2_H
36 #define PRESSURE2_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 PRESSURE2_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 
65 #define PRESSURE2_RETVAL uint8_t
66 #define PRESSURE2_OK 0x00
67 #define PRESSURE2_INIT_ERROR 0xFF
68 #define PRESSURE2_TRUE 1
69 #define PRESSURE2_FALSE 0
70 
76 #define PRESSURE2_CMD_RESET 0x1E // ADC reset command
77 #define PRESSURE2_CMD_ADC_READ 0x00 // ADC read command
78 #define PRESSURE2_CMD_ADC_CONV 0x40 // ADC conversion command
79 #define PRESSURE2_CMD_ADC_D1 0x00 // ADC D1 conversion
80 #define PRESSURE2_CMD_ADC_D2 0x10 // ADC D2 conversion
81 #define PRESSURE2_CMD_ADC_256 0x00 // ADC OSR=256
82 #define PRESSURE2_CMD_ADC_512 0x02 // ADC OSR=512
83 #define PRESSURE2_CMD_ADC_1024 0x04 // ADC OSR=1024
84 #define PRESSURE2_CMD_ADC_2048 0x06 // ADC OSR=2056
85 #define PRESSURE2_CMD_ADC_4096 0x08 // ADC OSR=4096
86 #define PRESSURE2_CMD_PROM_RD 0xA0 // Prom read command
87  // End group macro
89 
90 // --------------------------------------------------------------- PUBLIC TYPES
99 typedef struct
100 {
101  // Modules
102 
103  spi_master_t spi;
104 
105  uint16_t sensor_coefficients[8];
106  uint32_t pressure;
107  uint32_t temperature;
108  uint32_t delta_temp;
110  float sensitivity;
111 
112 } pressure2_t;
113 
117 typedef struct
118 {
119  // Communication gpio pins
120 
121  pin_name_t miso;
122  pin_name_t mosi;
123  pin_name_t sck;
124  pin_name_t cs;
125 
126  // static variable
127 
128  hal_spi_speed_t spi_speed;
129  hal_spi_mode_t spi_mode;
130 
132  // End types group
134 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
135 
140 #ifdef __cplusplus
141 extern "C"{
142 #endif
143 
153 
162 
171 
180 void pressure2_generic_transfer ( pressure2_t *ctx, spi_master_transfer_data_t *block );
181 
189 void pressure2_reset ( pressure2_t *ctx );
190 
201 void pressure2_read_data ( pressure2_t *ctx, uint8_t cmd, uint8_t *buffer, uint8_t n_bytes );
202 
211 void pressure2_write_bytes ( pressure2_t *ctx, uint8_t cmd );
212 
222 uint16_t pressure2_read_coefficient ( pressure2_t *ctx, uint8_t index );
223 
233 uint32_t pressure2_send_CmdADC ( pressure2_t *ctx, uint8_t cmd );
234 
244 void pressure2_read_sensor ( pressure2_t *ctx, float *P, float *T );
245 
246 
247 #ifdef __cplusplus
248 }
249 #endif
250 #endif // _PRESSURE2_H_
251  // End public_function group
254 
255 // ------------------------------------------------------------------------- END
Click ctx object definition.
Definition: pressure2.h:99
uint32_t pressure
Definition: pressure2.h:106
void pressure2_write_bytes(pressure2_t *ctx, uint8_t cmd)
Sends command.
PRESSURE2_RETVAL pressure2_init(pressure2_t *ctx, pressure2_cfg_t *cfg)
Initialization function.
uint32_t temperature
Definition: pressure2.h:107
spi_master_t spi
Definition: pressure2.h:103
void pressure2_generic_transfer(pressure2_t *ctx, spi_master_transfer_data_t *block)
Generic transfer function.
Click configuration structure definition.
Definition: pressure2.h:117
float sensitivity
Definition: pressure2.h:110
PRESSURE2_RETVAL pressure2_default_cfg(pressure2_t *ctx)
Click Default Configuration function.
uint16_t pressure2_read_coefficient(pressure2_t *ctx, uint8_t index)
Read calibration coefficients and return coefficient.
hal_spi_mode_t spi_mode
Definition: pressure2.h:129
uint32_t pressure2_send_CmdADC(pressure2_t *ctx, uint8_t cmd)
ADC conversion and return 24bit result.
void pressure2_reset(pressure2_t *ctx)
Functions for reset chip.
#define PRESSURE2_RETVAL
Definition: pressure2.h:65
pin_name_t sck
Definition: pressure2.h:123
pin_name_t cs
Definition: pressure2.h:124
void pressure2_read_sensor(pressure2_t *ctx, float *P, float *T)
Read sensor.
hal_spi_speed_t spi_speed
Definition: pressure2.h:128
pin_name_t miso
Definition: pressure2.h:121
uint32_t delta_temp
Definition: pressure2.h:108
void pressure2_read_data(pressure2_t *ctx, uint8_t cmd, uint8_t *buffer, uint8_t n_bytes)
Generic transfer function.
void pressure2_cfg_setup(pressure2_cfg_t *cfg)
Config Object Initialization function.
float sensor_offset
Definition: pressure2.h:109
pin_name_t mosi
Definition: pressure2.h:122