cdc  2.1.0.0
cdc.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 CDC_H
29 #define CDC_H
30 
31 #ifdef __cplusplus
32 extern "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_i2c_master.h"
52 #include "drv_spi_master.h"
53 #include "spi_specifics.h"
54 
75 #define CDC_OPCODE_WR_MEM 0xA0
76 #define CDC_OPCODE_RD_MEM 0x20
77 #define CDC_OPCODE_RD_RES 0x40
78 #define CDC_OPCODE_POR 0x88
79 #define CDC_OPCODE_INITIALIZE 0x8A
80 #define CDC_OPCODE_CDC_START 0x8C
81 #define CDC_OPCODE_RDC_START 0x8E
82 #define CDC_OPCODE_DSP_TRIG 0x8D
83 #define CDC_OPCODE_NV_STORE 0x96
84 #define CDC_OPCODE_NV_RECALL 0x99
85 #define CDC_OPCODE_NV_ERASE 0x9C
86 #define CDC_OPCODE_TEST_READ 0x7E
87 
91 #define CDC_REG_CFG0 0x00
92 #define CDC_REG_CFG1 0x01
93 #define CDC_REG_CFG2 0x02
94 #define CDC_REG_CFG3 0x03
95 #define CDC_REG_CFG4 0x04
96 #define CDC_REG_CFG5 0x05
97 #define CDC_REG_CFG6 0x06
98 #define CDC_REG_CFG7 0x07
99 #define CDC_REG_CFG8 0x08
100 #define CDC_REG_CFG9 0x09
101 #define CDC_REG_CFG10 0x0A
102 #define CDC_REG_CFG11 0x0B
103 #define CDC_REG_CFG12 0x0C
104 #define CDC_REG_CFG13 0x0D
105 #define CDC_REG_CFG14 0x0E
106 #define CDC_REG_CFG15 0x0F
107 #define CDC_REG_CFG16 0x10
108 #define CDC_REG_CFG17 0x11
109 #define CDC_REG_CFG18 0x12
110 #define CDC_REG_CFG19 0x13
111 #define CDC_REG_CFG20 0x14
112 #define CDC_REG_CFG21 0x15
113 #define CDC_REG_CFG22 0x16
114 #define CDC_REG_CFG23 0x17
115 #define CDC_REG_CFG24 0x18
116 #define CDC_REG_CFG25 0x19
117 #define CDC_REG_CFG26 0x1A
118 #define CDC_REG_CFG27 0x1B
119 #define CDC_REG_CFG28 0x1C
120 #define CDC_REG_CFG29 0x1D
121 #define CDC_REG_CFG30 0x1E
122 #define CDC_REG_CFG31 0x1F
123 #define CDC_REG_CFG32 0x20
124 #define CDC_REG_CFG33 0x21
125 #define CDC_REG_CFG34 0x22
126 #define CDC_REG_CFG35 0x23
127 #define CDC_REG_CFG38 0x26
128 #define CDC_REG_CFG39 0x27
129 #define CDC_REG_CFG40 0x28
130 #define CDC_REG_CFG41 0x29
131 #define CDC_REG_CFG42 0x2A
132 #define CDC_REG_CFG47 0x2F
133 #define CDC_REG_CFG48 0x30
134 #define CDC_REG_CFG49 0x31
135 #define CDC_REG_CFG50 0x32
136 #define CDC_REG_CFG54 0x36
137 #define CDC_REG_CFG62 0x3E
138 #define CDC_REG_CFG63 0x3F
139 
144 #define CDC_REG_RES0 0x00
145 #define CDC_REG_RES1 0x04
146 #define CDC_REG_RES2 0x08
147 #define CDC_REG_RES3 0x0C
148 #define CDC_REG_RES4 0x10
149 #define CDC_REG_RES5 0x14
150 #define CDC_REG_RES6 0x18
151 #define CDC_REG_RES7 0x1C
152 #define CDC_REG_STATUS_0 0x20
153 #define CDC_REG_STATUS_1 0x21
154 #define CDC_REG_STATUS_2 0x22
155  // cdc_reg
157 
172 #define CDC_MEM_ADDRESS_START 0x0000u
173 #define CDC_MEM_ADDRESS_END 0x03FFu
174 #define CDC_MEM_ADDRESS_CFG_OFFSET 0x03C0u
175 #define CDC_MEM_ADDRESS_WR_BLOCK_SIZE 64
176 
181 #define CDC_FIXED_POINT_NUM_FRACTIONAL 27
182 
187 #define CDC_TEST_READ_RES 0x11
188 
194 #define CDC_DEVICE_ADDRESS 0x28
195 
204 #define CDC_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
205 #define CDC_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
206  // cdc_set
208 
223 #define CDC_MAP_MIKROBUS( cfg, mikrobus ) \
224  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
225  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
226  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
227  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
228  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
229  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
230  cfg.sis = MIKROBUS( mikrobus, MIKROBUS_AN );
231  // cdc_map // cdc
234 
239 typedef enum
240 {
245 
250 typedef struct cdc_s
251 {
252  digital_out_t sis;
254  i2c_master_t i2c;
255  spi_master_t spi;
257  uint8_t slave_address;
258  pin_name_t chip_select;
262 
267 typedef struct
268 {
269  pin_name_t scl;
270  pin_name_t sda;
271  pin_name_t miso;
272  pin_name_t mosi;
273  pin_name_t sck;
274  pin_name_t cs;
275  pin_name_t sis;
277  uint32_t i2c_speed;
278  uint8_t i2c_address;
280  uint32_t spi_speed;
281  spi_master_mode_t spi_mode;
282  spi_master_chip_select_polarity_t cs_polarity;
286 } cdc_cfg_t;
287 
292 typedef struct
293 {
294  float res_0;
295  float res_1;
296  float res_2;
297  float res_3;
298  float res_4;
299  float res_5;
300  float res_6;
301  float res_7;
302  uint8_t status_0;
303  uint8_t status_1;
304  uint8_t status_2;
306 } cdc_results_t;
307 
312 typedef enum
313 {
314  CDC_OK = 0,
315  CDC_ERROR = -1
316 
318 
334 void cdc_cfg_setup ( cdc_cfg_t *cfg );
335 
351 
365 err_t cdc_init ( cdc_t *ctx, cdc_cfg_t *cfg );
366 
379 err_t cdc_default_cfg ( cdc_t *ctx );
380 
394 err_t cdc_write_memory ( cdc_t *ctx, uint16_t address, const uint8_t *data_in, uint16_t len );
395 
410 err_t cdc_read_memory ( cdc_t *ctx, uint16_t address, uint8_t *data_out, uint16_t len );
411 
425 err_t cdc_write_config ( cdc_t *ctx, uint8_t address, const uint8_t *data_in, uint8_t len );
426 
441 err_t cdc_read_config ( cdc_t *ctx, uint8_t address, uint8_t *data_out, uint8_t len );
442 
457 err_t cdc_read_result ( cdc_t *ctx, uint8_t address, uint8_t *data_out, uint8_t len );
458 
470 err_t cdc_send_opcode ( cdc_t *ctx, uint8_t opcode );
471 
483 
496 err_t cdc_read_results ( cdc_t *ctx, cdc_results_t *results );
497 
498 #ifdef __cplusplus
499 }
500 #endif
501 #endif // CDC_H
502  // cdc
504 
505 // ------------------------------------------------------------------------ END
cdc_t
struct cdc_s cdc_t
CDC Click context object.
cdc_results_t::status_0
uint8_t status_0
Definition: cdc.h:302
cdc_s::sis
digital_out_t sis
Definition: cdc.h:252
cdc_read_config
err_t cdc_read_config(cdc_t *ctx, uint8_t address, uint8_t *data_out, uint8_t len)
CDC read config function.
cdc_cfg_t::scl
pin_name_t scl
Definition: cdc.h:269
cdc_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: cdc.h:277
cdc_cfg_t::sda
pin_name_t sda
Definition: cdc.h:270
cdc_send_opcode
err_t cdc_send_opcode(cdc_t *ctx, uint8_t opcode)
CDC send opcode function.
CDC_DRV_SEL_I2C
@ CDC_DRV_SEL_I2C
Definition: cdc.h:242
spi_specifics.h
This file contains SPI specific macros, functions, etc.
cdc_results_t::res_7
float res_7
Definition: cdc.h:301
cdc_results_t::res_4
float res_4
Definition: cdc.h:298
CDC_DRV_SEL_SPI
@ CDC_DRV_SEL_SPI
Definition: cdc.h:241
cdc_return_value_t
cdc_return_value_t
CDC Click return value data.
Definition: cdc.h:313
cdc_results_t
CDC Click results object.
Definition: cdc.h:293
cdc_write_memory
err_t cdc_write_memory(cdc_t *ctx, uint16_t address, const uint8_t *data_in, uint16_t len)
CDC write memory function.
cdc_cfg_t::cs
pin_name_t cs
Definition: cdc.h:274
cdc_cfg_t::sck
pin_name_t sck
Definition: cdc.h:273
cdc_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: cdc.h:282
cdc_cfg_t::sis
pin_name_t sis
Definition: cdc.h:275
cdc_s
CDC Click context object.
Definition: cdc.h:251
cdc_default_cfg
err_t cdc_default_cfg(cdc_t *ctx)
CDC default configuration function.
cdc_read_results
err_t cdc_read_results(cdc_t *ctx, cdc_results_t *results)
CDC read results function.
cdc_results_t::res_3
float res_3
Definition: cdc.h:297
cdc_cfg_t::mosi
pin_name_t mosi
Definition: cdc.h:272
CDC_ERROR
@ CDC_ERROR
Definition: cdc.h:315
cdc_s::chip_select
pin_name_t chip_select
Definition: cdc.h:258
cdc_s::drv_sel
cdc_drv_t drv_sel
Definition: cdc.h:259
cdc_s::i2c
i2c_master_t i2c
Definition: cdc.h:254
CDC_OK
@ CDC_OK
Definition: cdc.h:314
cdc_cfg_t::i2c_address
uint8_t i2c_address
Definition: cdc.h:278
cdc_drv_interface_sel
void cdc_drv_interface_sel(cdc_cfg_t *cfg, cdc_drv_t drv_sel)
CDC driver interface setup function.
cdc_results_t::res_1
float res_1
Definition: cdc.h:295
cdc_results_t::res_5
float res_5
Definition: cdc.h:299
cdc_cfg_t::miso
pin_name_t miso
Definition: cdc.h:271
cdc_s::spi
spi_master_t spi
Definition: cdc.h:255
cdc_results_t::status_2
uint8_t status_2
Definition: cdc.h:304
cdc_init
err_t cdc_init(cdc_t *ctx, cdc_cfg_t *cfg)
CDC initialization function.
cdc_results_t::status_1
uint8_t status_1
Definition: cdc.h:303
cdc_check_communication
err_t cdc_check_communication(cdc_t *ctx)
CDC check communication function.
cdc_drv_t
cdc_drv_t
CDC Click driver selector.
Definition: cdc.h:240
cdc_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: cdc.h:281
cdc_read_result
err_t cdc_read_result(cdc_t *ctx, uint8_t address, uint8_t *data_out, uint8_t len)
CDC read result function.
cdc_s::slave_address
uint8_t slave_address
Definition: cdc.h:257
cdc_cfg_t::drv_sel
cdc_drv_t drv_sel
Definition: cdc.h:284
cdc_results_t::res_6
float res_6
Definition: cdc.h:300
cdc_results_t::res_2
float res_2
Definition: cdc.h:296
cdc_read_memory
err_t cdc_read_memory(cdc_t *ctx, uint16_t address, uint8_t *data_out, uint16_t len)
CDC read memory function.
cdc_results_t::res_0
float res_0
Definition: cdc.h:294
cdc_cfg_t
CDC Click configuration object.
Definition: cdc.h:268
cdc_write_config
err_t cdc_write_config(cdc_t *ctx, uint8_t address, const uint8_t *data_in, uint8_t len)
CDC write config function.
cdc_cfg_t::spi_speed
uint32_t spi_speed
Definition: cdc.h:280
cdc_cfg_setup
void cdc_cfg_setup(cdc_cfg_t *cfg)
CDC configuration object setup function.