ammonia  2.0.0.0
ammonia.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 AMMONIA_H
36 #define AMMONIA_H
37 
38 #include "drv_analog_in.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define AMMONIA_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
54  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
55  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
56  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN )
58 
64 #define AMMONIA_OK 0
65 #define AMMONIA_INIT_ERROR (-1)
66  // End group macro
69 // --------------------------------------------------------------- PUBLIC TYPES
78 typedef enum
79 {
82 
84 
88 typedef struct
89 {
90  // Input pins objects
91 
92  analog_in_t an;
93  digital_in_t miso;
94 
95  // Module object
96 
97  spi_master_t spi;
98  pin_name_t chip_select;
99 
100  // ADC selection
101 
103 
104 } ammonia_t;
105 
109 typedef struct
110 {
111  // Communication gpio pins
112 
113  pin_name_t miso;
114  pin_name_t mosi;
115  pin_name_t sck;
116  pin_name_t cs;
117 
118  // Additional gpio pins
119 
120  pin_name_t an;
121 
122  // SPI settings
123 
124  uint32_t spi_speed;
125  spi_master_mode_t spi_mode;
126  spi_master_chip_select_polarity_t cs_polarity;
127 
128  // ADC settings
129 
130  analog_in_resolution_t resolution;
131  float vref;
132 
133  // ADC selection
134 
136 
137 } ammonia_cfg_t;
138 
139 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
145 #ifdef __cplusplus
146 extern "C"{
147 #endif
148 
159 
171 err_t ammonia_init ( ammonia_t *ctx, ammonia_cfg_t *cfg );
172 
183 err_t ammonia_read_signal_voltage ( ammonia_t *ctx, float *data_out );
184 
196 err_t ammonia_read_measurement ( ammonia_t *ctx, uint16_t *data_out );
197 
198 #ifdef __cplusplus
199 }
200 #endif
201 #endif // AMMONIA_H
202  // End public_function group // End click Driver group
205 
206 // ------------------------------------------------------------------------ END
ammonia_adc_sel_t
ammonia_adc_sel_t
Click AD conversion type selectors.
Definition: ammonia.h:79
ammonia_cfg_t
Click configuration structure definition.
Definition: ammonia.h:110
ammonia_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: ammonia.h:125
AMMONIA_ADC_SEL_AN
@ AMMONIA_ADC_SEL_AN
Definition: ammonia.h:80
ammonia_cfg_t::sck
pin_name_t sck
Definition: ammonia.h:115
ammonia_cfg_t::cs
pin_name_t cs
Definition: ammonia.h:116
ammonia_t::spi
spi_master_t spi
Definition: ammonia.h:97
ammonia_init
err_t ammonia_init(ammonia_t *ctx, ammonia_cfg_t *cfg)
Initialization function.
ammonia_cfg_setup
void ammonia_cfg_setup(ammonia_cfg_t *cfg)
Config Object Initialization function.
ammonia_cfg_t::mosi
pin_name_t mosi
Definition: ammonia.h:114
ammonia_read_measurement
err_t ammonia_read_measurement(ammonia_t *ctx, uint16_t *data_out)
Measurement Read function.
ammonia_cfg_t::an
pin_name_t an
Definition: ammonia.h:120
ammonia_cfg_t::vref
float vref
Definition: ammonia.h:131
ammonia_cfg_t::resolution
analog_in_resolution_t resolution
Definition: ammonia.h:130
ammonia_t
Click ctx object definition.
Definition: ammonia.h:89
ammonia_cfg_t::miso
pin_name_t miso
Definition: ammonia.h:113
ammonia_cfg_t::spi_speed
uint32_t spi_speed
Definition: ammonia.h:124
ammonia_t::adc_sel
ammonia_adc_sel_t adc_sel
Definition: ammonia.h:102
ammonia_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: ammonia.h:126
AMMONIA_ADC_SEL_SPI
@ AMMONIA_ADC_SEL_SPI
Definition: ammonia.h:81
ammonia_t::an
analog_in_t an
Definition: ammonia.h:92
ammonia_read_signal_voltage
err_t ammonia_read_signal_voltage(ammonia_t *ctx, float *data_out)
Measurement Voltage Read function.
ammonia_t::chip_select
pin_name_t chip_select
Definition: ammonia.h:98
ammonia_t::miso
digital_in_t miso
Definition: ammonia.h:93