hodcap  2.1.0.0
hodcap.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 HODCAP_H
29 #define HODCAP_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 #include "spi_specifics.h"
49 
70 #define HODCAP_REG_SENSOR_ID 0x01
71 #define HODCAP_REG_STATUS 0x02
72 #define HODCAP_REG_I_DATA 0x03
73 #define HODCAP_REG_Q_DATA 0x04
74 #define HODCAP_REG_ADC_STATUS 0x05
75 #define HODCAP_REG_EDIV 0x20
76 #define HODCAP_REG_FREQ 0x21
77 #define HODCAP_REG_TXV 0x22
78 #define HODCAP_REG_MUX_CTRL 0x23
79 #define HODCAP_REG_SDG 0x24
80 #define HODCAP_REG_CBG 0x25
81 #define HODCAP_REG_DCLK 0x26
82 #define HODCAP_REG_PGA 0x27
83 #define HODCAP_REG_PGA_OFFSET_I 0x28
84 #define HODCAP_REG_PGA_OFFSET_Q 0x29
85 #define HODCAP_REG_ADCTL 0x2A
86 #define HODCAP_REG_BLANK 0x2B
87 #define HODCAP_REG_DIAG_MUX_CTRL 0x2C
88 #define HODCAP_REG_QUICK_READ 0x90
89 
94 #define HODCAP_CMD_WRITE 0x10
95 #define HODCAP_CMD_READ 0x00
96 #define HODCAP_CMD_QUICK_READ 0x90
97  // hodcap_reg
99 
114 #define HODCAP_SENSOR_ID 0xA431u
115 
120 #define HODCAP_ADC_DATA_READY 0x0001u
121 
126 #define HODCAP_SET_EDIV_12 0x0000u
127 #define HODCAP_SET_EDIV_11 0x0001u
128 #define HODCAP_SET_EDIV_10 0x0002u
129 #define HODCAP_SET_EDIV_9 0x0003u
130 #define HODCAP_SET_EDIV_8 0x0004u
131 #define HODCAP_SET_EDIV_7 0x0005u
132 #define HODCAP_SET_EDIV_6 0x0006u
133 #define HODCAP_SET_EDIV_5 0x0007u
134 #define HODCAP_SET_EDIV_4 0x0008u
135 #define HODCAP_SET_EDIV_3 0x0009u
136 #define HODCAP_SET_EDIV_2 0x000Au
137 #define HODCAP_SET_EDIV_1 0x000Bu
138 #define HODCAP_SET_EDIV_BIT_MASK 0x000Fu
139 
144 #define HODCAP_SET_FREQ_45_45KHZ 0x0000u
145 #define HODCAP_SET_FREQ_71_4KHZ 0x0001u
146 #define HODCAP_SET_FREQ_100KHZ 0x0002u
147 #define HODCAP_SET_FREQ_125KHZ 0x0003u
148 
153 #define HODCAP_SET_TXV_0V 0x0000u
154 #define HODCAP_SET_TXV_0_5V 0x0001u
155 #define HODCAP_SET_TXV_1V 0x0002u
156 
161 #define HODCAP_SET_MUX_CTRL_MODE_OPEN 0x0000u
162 #define HODCAP_SET_MUX_CTRL_MODE_SENSOR_DRV 0x0001u
163 #define HODCAP_SET_MUX_CTRL_MODE_COMMON 0x0002u
164 #define HODCAP_SET_MUX_CTRL_MODE_NO_OP 0x0003u
165 #define HODCAP_SET_MUX_CTRL_SEL_SEN0 0x0000u
166 #define HODCAP_SET_MUX_CTRL_SEL_SEN1 0x0004u
167 #define HODCAP_SET_MUX_CTRL_SEL_SEN2 0x0008u
168 #define HODCAP_SET_MUX_CTRL_SEL_SEN3 0x000Cu
169 #define HODCAP_SET_MUX_CTRL_SEL_SEN4 0x0010u
170 #define HODCAP_SET_MUX_CTRL_SEL_SEN5 0x0014u
171 #define HODCAP_SET_MUX_CTRL_SEL_SEN6 0x0018u
172 #define HODCAP_SET_MUX_CTRL_SEL_SEN7 0x001Cu
173 #define HODCAP_SET_MUX_CTRL_SEL_SEN8 0x0020u
174 #define HODCAP_SET_MUX_CTRL_SEL_SEN9 0x0024u
175 #define HODCAP_SET_MUX_CTRL_SEL_NONE 0x0028u
176 #define HODCAP_SET_MUX_CTRL_SEL_VAR_SEN 0x002Cu
177 #define HODCAP_SET_MUX_CTRL_SEL_BIT_MASK 0x003Cu
178 
183 #define HODCAP_TOTAL_NUMBER_OF_CHANNELS 10
184 
189 #define HODCAP_SET_PGA_GAIN_36 0x0000u
190 #define HODCAP_SET_PGA_GAIN_24 0x0001u
191 #define HODCAP_SET_PGA_GAIN_16 0x0002u
192 #define HODCAP_SET_PGA_GAIN_10_67 0x0003u
193 #define HODCAP_SET_PGA_GAIN_7_11 0x0004u
194 #define HODCAP_SET_PGA_GAIN_4_74 0x0005u
195 #define HODCAP_SET_PGA_GAIN_3_16 0x0006u
196 #define HODCAP_SET_PGA_GAIN_2_11 0x0007u
197 
202 #define HODCAP_SET_DEFAULT_PGA_OFFSET_I 96
203 #define HODCAP_SET_DEFAULT_PGA_OFFSET_Q 144
204 
209 #define HODCAP_SET_ADCTL_MODE_RESET_STOP 0x0000u
210 #define HODCAP_SET_ADCTL_MODE_START_SINGLE_CONVO 0x0001u
211 #define HODCAP_SET_ADCTL_MODE_START_CONT_CONVO 0x0002u
212 #define HODCAP_SET_ADCTL_MODE_STOP_CURRENT_CONVO 0x0003u
213 #define HODCAP_SET_ADCTL_MODE_BIT_MASK 0x0003u
214 #define HODCAP_SET_ADCTL_CS_CLK_250KHZ 0x0000u
215 #define HODCAP_SET_ADCTL_CS_CLK_500KHZ 0x0004u
216 #define HODCAP_SET_ADCTL_CS_CLK_1000KHZ 0x0008u
217 #define HODCAP_SET_ADCTL_ACCU_NUMB_OF_SAMPLES_4 0x0000u
218 #define HODCAP_SET_ADCTL_ACCU_NUMB_OF_SAMPLES_8 0x0010u
219 #define HODCAP_SET_ADCTL_ACCU_NUMB_OF_SAMPLES_16 0x0020u
220 #define HODCAP_SET_ADCTL_TS_400US 0x0000u
221 #define HODCAP_SET_ADCTL_TS_576US 0x0040u
222 #define HODCAP_SET_ADCTL_TS_664US 0x0080u
223 
228 #define HODCAP_SET_MUX_CTRL_PLUS_SEN0 0x0000u
229 #define HODCAP_SET_MUX_CTRL_PLUS_SEN1 0x0001u
230 #define HODCAP_SET_MUX_CTRL_PLUS_SEN2 0x0002u
231 #define HODCAP_SET_MUX_CTRL_PLUS_SEN3 0x0003u
232 #define HODCAP_SET_MUX_CTRL_PLUS_SEN4 0x0004u
233 #define HODCAP_SET_MUX_CTRL_PLUS_SEN5 0x0005u
234 #define HODCAP_SET_MUX_CTRL_PLUS_SEN6 0x0006u
235 #define HODCAP_SET_MUX_CTRL_PLUS_SEN7 0x0007u
236 #define HODCAP_SET_MUX_CTRL_PLUS_SEN8 0x0008u
237 #define HODCAP_SET_MUX_CTRL_PLUS_SEN9 0x0009u
238 #define HODCAP_SET_MUX_CTRL_PLUS_VAR_SEN 0x000Bu
239 #define HODCAP_SET_MUX_CTRL_PLUS_NONE 0x000Fu
240 #define HODCAP_SET_MUX_CTRL_MINUS_SEN0 0x0000u
241 #define HODCAP_SET_MUX_CTRL_MINUS_SEN1 0x0010u
242 #define HODCAP_SET_MUX_CTRL_MINUS_SEN2 0x0020u
243 #define HODCAP_SET_MUX_CTRL_MINUS_SEN3 0x0030u
244 #define HODCAP_SET_MUX_CTRL_MINUS_SEN4 0x0040u
245 #define HODCAP_SET_MUX_CTRL_MINUS_SEN5 0x0050u
246 #define HODCAP_SET_MUX_CTRL_MINUS_SEN6 0x0060u
247 #define HODCAP_SET_MUX_CTRL_MINUS_SEN7 0x0070u
248 #define HODCAP_SET_MUX_CTRL_MINUS_SEN8 0x0080u
249 #define HODCAP_SET_MUX_CTRL_MINUS_SEN9 0x0090u
250 #define HODCAP_SET_MUX_CTRL_MINUS_VAR_SEN 0x00B0u
251 #define HODCAP_SET_MUX_CTRL_MINUS_NONE 0x00F0u
252 
261 #define HODCAP_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
262 #define HODCAP_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
263  // hodcap_set
265 
280 #define HODCAP_MAP_MIKROBUS( cfg, mikrobus ) \
281  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
282  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
283  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
284  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
285  cfg.clk = MIKROBUS( mikrobus, MIKROBUS_PWM )
286  // hodcap_map // hodcap
289 
294 typedef struct
295 {
296  // Output pins
297  digital_out_t clk;
299  // Modules
300  spi_master_t spi;
302  pin_name_t chip_select;
304 } hodcap_t;
305 
310 typedef struct
311 {
312  // Communication gpio pins
313  pin_name_t miso;
314  pin_name_t mosi;
315  pin_name_t sck;
316  pin_name_t cs;
318  // Additional gpio pins
319  pin_name_t clk;
321  // static variable
322  uint32_t spi_speed;
323  spi_master_mode_t spi_mode;
324  spi_master_chip_select_polarity_t cs_polarity;
326 } hodcap_cfg_t;
327 
332 typedef struct
333 {
334  uint8_t r_ediv;
335  uint8_t otpf;
336  uint8_t ppsf;
337  uint8_t bpff;
338  uint8_t regf;
339  uint8_t ocsld;
340  uint8_t ocsen;
341  uint8_t test;
342  uint8_t tx1f;
343  uint8_t tx2f;
344  uint8_t pga1f;
345  uint8_t pga2f;
346  uint8_t nclk;
347  uint8_t cbf;
350 
355 typedef enum
356 {
358  HODCAP_ERROR = -1
359 
361 
378 
392 err_t hodcap_init ( hodcap_t *ctx, hodcap_cfg_t *cfg );
393 
407 
422 err_t hodcap_generic_write ( hodcap_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
423 
438 err_t hodcap_generic_read ( hodcap_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
439 
453 err_t hodcap_write_reg ( hodcap_t *ctx, uint8_t reg, uint16_t data_in );
454 
468 err_t hodcap_read_reg ( hodcap_t *ctx, uint8_t reg, uint16_t *data_out );
469 
482 err_t hodcap_get_sensor_id ( hodcap_t *ctx, uint16_t *sensor_id );
483 
497 
510 err_t hodcap_check_adc_data_ready ( hodcap_t *ctx, uint16_t *data_ready );
511 
524 err_t hodcap_set_adc_op_mode ( hodcap_t *ctx, uint16_t adc_op_mode );
525 
538 err_t hodcap_mux_channel_selection ( hodcap_t *ctx, uint8_t sen_pos );
539 
553 err_t hodcap_get_i_q_data ( hodcap_t *ctx, uint16_t *i_data, uint16_t *q_data );
554 
567 
578 void hodcap_set_clk_state ( hodcap_t *ctx, uint8_t clk_state );
579 
580 #ifdef __cplusplus
581 }
582 #endif
583 #endif // HODCAP_H
584  // hodcap
586 
587 // ------------------------------------------------------------------------ END
hodcap_t::spi
spi_master_t spi
Definition: hodcap.h:300
hodcap_get_status
err_t hodcap_get_status(hodcap_t *ctx, hodcap_status_t *status)
HOD CAP gets sensor status function.
hodcap_write_reg
err_t hodcap_write_reg(hodcap_t *ctx, uint8_t reg, uint16_t data_in)
HOD CAP write register function.
hodcap_get_i_q_data
err_t hodcap_get_i_q_data(hodcap_t *ctx, uint16_t *i_data, uint16_t *q_data)
HOD CAP gets the I and Q data function.
hodcap_status_t::otpf
uint8_t otpf
Definition: hodcap.h:335
hodcap_cfg_t::clk
pin_name_t clk
Definition: hodcap.h:319
hodcap_cfg_t::spi_speed
uint32_t spi_speed
Definition: hodcap.h:322
hodcap_status_t::tx2f
uint8_t tx2f
Definition: hodcap.h:343
hodcap_status_t::r_ediv
uint8_t r_ediv
Definition: hodcap.h:334
spi_specifics.h
This file contains SPI specific macros, functions, etc.
hodcap_return_value_t
hodcap_return_value_t
HOD CAP Click return value data.
Definition: hodcap.h:356
hodcap_default_cfg
err_t hodcap_default_cfg(hodcap_t *ctx)
HOD CAP default configuration function.
hodcap_mux_channel_selection
err_t hodcap_mux_channel_selection(hodcap_t *ctx, uint8_t sen_pos)
HOD CAP MUX channel selection function.
hodcap_set_clk_state
void hodcap_set_clk_state(hodcap_t *ctx, uint8_t clk_state)
HOD CAP set CLK pin state function.
hodcap_status_t::pga1f
uint8_t pga1f
Definition: hodcap.h:344
hodcap_init
err_t hodcap_init(hodcap_t *ctx, hodcap_cfg_t *cfg)
HOD CAP initialization function.
hodcap_cfg_t
HOD CAP Click configuration object.
Definition: hodcap.h:311
HODCAP_OK
@ HODCAP_OK
Definition: hodcap.h:357
hodcap_status_t::bpff
uint8_t bpff
Definition: hodcap.h:337
hodcap_read_reg
err_t hodcap_read_reg(hodcap_t *ctx, uint8_t reg, uint16_t *data_out)
HOD CAP read register function.
HODCAP_ERROR
@ HODCAP_ERROR
Definition: hodcap.h:358
hodcap_status_t
HOD CAP Click status object.
Definition: hodcap.h:333
hodcap_t
HOD CAP Click context object.
Definition: hodcap.h:295
hodcap_check_adc_data_ready
err_t hodcap_check_adc_data_ready(hodcap_t *ctx, uint16_t *data_ready)
HOD CAP check ADC data ready function.
hodcap_status_t::nclk
uint8_t nclk
Definition: hodcap.h:346
hodcap_t::clk
digital_out_t clk
Definition: hodcap.h:297
hodcap_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: hodcap.h:324
hodcap_status_t::ocsen
uint8_t ocsen
Definition: hodcap.h:340
hodcap_generic_read
err_t hodcap_generic_read(hodcap_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
HOD CAP data reading function.
hodcap_status_t::ocsld
uint8_t ocsld
Definition: hodcap.h:339
hodcap_wait_adc_data_ready
err_t hodcap_wait_adc_data_ready(hodcap_t *ctx)
HOD CAP wait ADC data ready function.
hodcap_cfg_t::sck
pin_name_t sck
Definition: hodcap.h:315
hodcap_status_t::tx1f
uint8_t tx1f
Definition: hodcap.h:342
hodcap_generic_write
err_t hodcap_generic_write(hodcap_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
HOD CAP data writing function.
hodcap_cfg_t::mosi
pin_name_t mosi
Definition: hodcap.h:314
hodcap_status_t::pga2f
uint8_t pga2f
Definition: hodcap.h:345
hodcap_status_t::ppsf
uint8_t ppsf
Definition: hodcap.h:336
hodcap_status_t::cbf
uint8_t cbf
Definition: hodcap.h:347
hodcap_status_t::test
uint8_t test
Definition: hodcap.h:341
hodcap_get_sensor_id
err_t hodcap_get_sensor_id(hodcap_t *ctx, uint16_t *sensor_id)
HOD CAP gets sensor ID function.
hodcap_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: hodcap.h:323
hodcap_cfg_setup
void hodcap_cfg_setup(hodcap_cfg_t *cfg)
HOD CAP configuration object setup function.
hodcap_cfg_t::miso
pin_name_t miso
Definition: hodcap.h:313
hodcap_t::chip_select
pin_name_t chip_select
Definition: hodcap.h:302
hodcap_status_t::regf
uint8_t regf
Definition: hodcap.h:338
hodcap_cfg_t::cs
pin_name_t cs
Definition: hodcap.h:316
hodcap_set_adc_op_mode
err_t hodcap_set_adc_op_mode(hodcap_t *ctx, uint16_t adc_op_mode)
HOD CAP sets the ADC operation mode function.