piezoaccel 2.0.0.0
piezoaccel.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 PIEZOACCEL_H
29#define PIEZOACCEL_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52#include "drv_analog_in.h"
53
70#define PIEZOACCEL_MEAS_MODE_AN_PIN 0x00
71#define PIEZOACCEL_MEAS_MODE_ADC 0x01
72
73 // measurement_mode
74
85#define PIEZOACCEL_SENSOR_VOLTAGE_5V 0x00
86#define PIEZOACCEL_SENSOR_VOLTAGE_3V3 0x01
87
88 // sensor_voltage
89
104#define PIEZOACCEL_MAP_MIKROBUS( cfg, mikrobus ) \
105 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
106 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
107 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
108 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
109 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN )
110
111 // piezoaccel_map
112 // piezoaccel
113
118typedef struct
119{
120 // Modules
121
122 analog_in_t adc;
124 spi_master_t spi;
126 pin_name_t chip_select;
129
134typedef struct
135{
136 // Communication gpio pins
137
138 pin_name_t miso;
139 pin_name_t mosi;
140 pin_name_t sck;
141 pin_name_t cs;
143 // Additional gpio pins
144
145 pin_name_t an;
147 // static variable
148
149 uint32_t spi_speed;
150 spi_master_mode_t spi_mode;
151 spi_master_chip_select_polarity_t cs_polarity;
153 analog_in_resolution_t resolution;
154 float vref;
157
162typedef struct
163{
169
186
202
215
226
237
250err_t piezoaccel_read_an_pin_value ( piezoaccel_t *ctx, uint16_t *data_out );
251
266err_t piezoaccel_read_an_pin_voltage ( piezoaccel_t *ctx, float *data_out );
267
281
294
295#ifdef __cplusplus
296}
297#endif
298#endif // PIEZOACCEL_H
299
300 // piezoaccel
301
302// ------------------------------------------------------------------------ END
void piezoaccel_default_cfg(piezoaccel_t *ctx, piezoaccel_setup_t *setup_cfg_data)
Piezo Accel default configuration function.
float piezoaccel_adc_voltage_read(piezoaccel_t *ctx)
Piezo Accel read adc converted to voltage function.
void piezoaccel_calibration(piezoaccel_t *ctx, piezoaccel_setup_t *cfg_data)
Piezo Accel calibration function.
err_t piezoaccel_read_an_pin_voltage(piezoaccel_t *ctx, float *data_out)
Piezo Accel read AN pin voltage level function.
void piezoaccel_cfg_setup(piezoaccel_cfg_t *cfg)
Piezo Accel configuration object setup function.
float piezoaccel_g_unit_read(piezoaccel_t *ctx, piezoaccel_setup_t *cfg_data)
Piezo Accel read force of acceleration function.
err_t piezoaccel_read_an_pin_value(piezoaccel_t *ctx, uint16_t *data_out)
Piezo Accel read AN pin value function.
uint16_t piezoaccel_adc_raw_read(piezoaccel_t *ctx)
Piezo Accel read raw adc function.
err_t piezoaccel_init(piezoaccel_t *ctx, piezoaccel_cfg_t *cfg)
Piezo Accel initialization function.
Piezo Accel Click configuration object.
Definition piezoaccel.h:135
analog_in_resolution_t resolution
Definition piezoaccel.h:153
float vref
Definition piezoaccel.h:154
spi_master_chip_select_polarity_t cs_polarity
Definition piezoaccel.h:151
pin_name_t sck
Definition piezoaccel.h:140
spi_master_mode_t spi_mode
Definition piezoaccel.h:150
pin_name_t mosi
Definition piezoaccel.h:139
uint32_t spi_speed
Definition piezoaccel.h:149
pin_name_t miso
Definition piezoaccel.h:138
pin_name_t an
Definition piezoaccel.h:145
pin_name_t cs
Definition piezoaccel.h:141
Piezo Accel Click Configuration setup structure.
Definition piezoaccel.h:163
float offset_data
Definition piezoaccel.h:166
uint8_t measurement_mode
Definition piezoaccel.h:164
uint8_t sensor_voltage
Definition piezoaccel.h:165
Piezo Accel Click context object.
Definition piezoaccel.h:119
spi_master_t spi
Definition piezoaccel.h:124
pin_name_t chip_select
Definition piezoaccel.h:126
analog_in_t adc
Definition piezoaccel.h:122