pressure2 2.0.0.0
pressure2.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 PRESSURE2_H
36#define PRESSURE2_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_spi_master.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
68#define PRESSURE2_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
79#define PRESSURE2_OK 0
80#define PRESSURE2_ERROR -1
87#define PRESSURE2_CMD_RESET 0x1E // ADC reset command
88#define PRESSURE2_CMD_ADC_READ 0x00 // ADC read command
89#define PRESSURE2_CMD_ADC_CONV 0x40 // ADC conversion command
90#define PRESSURE2_CMD_ADC_D1 0x00 // ADC D1 conversion
91#define PRESSURE2_CMD_ADC_D2 0x10 // ADC D2 conversion
92#define PRESSURE2_CMD_ADC_256 0x00 // ADC OSR=256
93#define PRESSURE2_CMD_ADC_512 0x02 // ADC OSR=512
94#define PRESSURE2_CMD_ADC_1024 0x04 // ADC OSR=1024
95#define PRESSURE2_CMD_ADC_2048 0x06 // ADC OSR=2056
96#define PRESSURE2_CMD_ADC_4096 0x08 // ADC OSR=4096
97#define PRESSURE2_CMD_PROM_RD 0xA0 // Prom read command
99 // End group macro
100
101// --------------------------------------------------------------- PUBLIC TYPES
110typedef struct
111{
112 digital_out_t cs;
113
114 // Modules
115 spi_master_t spi;
116 pin_name_t chip_select;
117
118 uint16_t sensor_coefficients[ 8 ];
119 uint32_t pressure;
120 uint32_t temperature;
121 uint32_t delta_temp;
124
126
130typedef struct
131{
132 // Communication gpio pins
133 pin_name_t miso;
134 pin_name_t mosi;
135 pin_name_t sck;
136 pin_name_t cs;
137
138 // Static variable
139 uint32_t spi_speed;
140 spi_master_mode_t spi_mode;
141 spi_master_chip_select_polarity_t cs_polarity;
142
144
145 // End types group
146// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
147
152#ifdef __cplusplus
153extern "C"{
154#endif
155
165
174
183
192
203void pressure2_read_data ( pressure2_t *ctx, uint8_t cmd, uint8_t *buffer, uint8_t n_bytes );
204
213void pressure2_write_bytes ( pressure2_t *ctx, uint8_t cmd );
214
224uint16_t pressure2_read_coefficient ( pressure2_t *ctx, uint8_t index );
225
235uint32_t pressure2_send_cmd_adc ( pressure2_t *ctx, uint8_t cmd );
236
246void pressure2_read_sensor ( pressure2_t *ctx, float *press, float *temp );
247
248#ifdef __cplusplus
249}
250#endif
251#endif // _PRESSURE2_H_
252
253 // End public_function group
255
256// ------------------------------------------------------------------------- END
err_t pressure2_init(pressure2_t *ctx, pressure2_cfg_t *cfg)
Initialization function.
void pressure2_read_sensor(pressure2_t *ctx, float *press, float *temp)
Read sensor.
void pressure2_read_data(pressure2_t *ctx, uint8_t cmd, uint8_t *buffer, uint8_t n_bytes)
Generic transfer function.
err_t 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.
void pressure2_cfg_setup(pressure2_cfg_t *cfg)
Config Object Initialization function.
void pressure2_write_bytes(pressure2_t *ctx, uint8_t cmd)
Sends command.
uint32_t pressure2_send_cmd_adc(pressure2_t *ctx, uint8_t cmd)
ADC conversion and return 24bit result.
void pressure2_reset(pressure2_t *ctx)
Functions for reset chip.
Click configuration structure definition.
Definition pressure2.h:131
spi_master_chip_select_polarity_t cs_polarity
Definition pressure2.h:141
pin_name_t sck
Definition pressure2.h:135
spi_master_mode_t spi_mode
Definition pressure2.h:140
pin_name_t mosi
Definition pressure2.h:134
uint32_t spi_speed
Definition pressure2.h:139
pin_name_t miso
Definition pressure2.h:133
pin_name_t cs
Definition pressure2.h:136
Click ctx object definition.
Definition pressure2.h:111
digital_out_t cs
Definition pressure2.h:112
spi_master_t spi
Definition pressure2.h:115
uint32_t delta_temp
Definition pressure2.h:121
uint32_t pressure
Definition pressure2.h:119
float sensor_offset
Definition pressure2.h:122
uint32_t temperature
Definition pressure2.h:120
float sensitivity
Definition pressure2.h:123
pin_name_t chip_select
Definition pressure2.h:116