ldc  2.0.0.0
ldc.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 LDC_H
29 #define LDC_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define LDC_REG_DATA_CH0 0x00
60 #define LDC_REG_DATA_CH1 0x02
61 #define LDC_REG_RCOUNT_CH0 0x08
62 #define LDC_REG_RCOUNT_CH1 0x09
63 #define LDC_REG_OFFSET_CH0 0x0C
64 #define LDC_REG_OFFSET_CH1 0x0D
65 #define LDC_REG_SETTLECOUNT_CH0 0x10
66 #define LDC_REG_SETTLECOUNT_CH1 0x11
67 #define LDC_REG_CLOCK_DIVIDERS_CH0 0x14
68 #define LDC_REG_CLOCK_DIVIDERS_CH1 0x15
69 #define LDC_REG_STATUS 0x18
70 #define LDC_REG_ERROR_CONFIG 0x19
71 #define LDC_REG_CONFIG 0x1A
72 #define LDC_REG_MUX_CONFIG 0x1B
73 #define LDC_REG_RESET_DEV 0x1C
74 #define LDC_REG_DRIVE_CURRENT_CH0 0x1E
75 #define LDC_REG_DRIVE_CURRENT_CH1 0x1F
76 #define LDC_REG_MANUFACTURER_ID 0x7E
77 #define LDC_REG_DEVICE_ID 0x7F
78  // ldc_reg
80 
95 #define LDC_MANUFACTURER_ID 0x5449
96 #define LDC_DEVICE_ID 0x3054
97 
103 #define LDC_SET_DEV_ADDR 0x2B
104  // ldc_set
106 
121 #define LDC_MAP_MIKROBUS( cfg, mikrobus ) \
122  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
123  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
124  cfg.sd = MIKROBUS( mikrobus, MIKROBUS_RST ); \
125  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
126  // ldc_map // ldc
129 
134 typedef struct
135 {
136  // Output pins
137  digital_out_t sd;
139  // Input pins
140  digital_in_t int_pin;
142  // Modules
143  i2c_master_t i2c;
145  // I2C slave address
146  uint8_t slave_address;
148 } ldc_t;
149 
154 typedef struct
155 {
156  pin_name_t scl;
157  pin_name_t sda;
159  pin_name_t sd;
160  pin_name_t int_pin;
162  uint32_t i2c_speed;
163  uint8_t i2c_address;
165 } ldc_cfg_t;
166 
171 typedef enum
172 {
173  LDC_OK = 0,
174  LDC_ERROR = -1
175 
177 
193 void ldc_cfg_setup ( ldc_cfg_t *cfg );
194 
208 err_t ldc_init ( ldc_t *ctx, ldc_cfg_t *cfg );
209 
223 err_t ldc_default_cfg ( ldc_t *ctx );
224 
239 err_t ldc_generic_write ( ldc_t *ctx, uint8_t reg, uint16_t tx_data );
240 
255 err_t ldc_generic_read ( ldc_t *ctx, uint8_t reg, uint16_t *rx_data );
256 
264 uint8_t ldc_get_interrupt ( ldc_t *ctx );
265 
274 void ldc_set_shut_down ( ldc_t *ctx, uint8_t state );
275 
276 #ifdef __cplusplus
277 }
278 #endif
279 #endif // LDC_H
280  // ldc
282 
283 // ------------------------------------------------------------------------ END
ldc_generic_write
err_t ldc_generic_write(ldc_t *ctx, uint8_t reg, uint16_t tx_data)
LDC I2C writing function.
ldc_t
LDC Click context object.
Definition: ldc.h:133
ldc_default_cfg
err_t ldc_default_cfg(ldc_t *ctx)
LDC default configuration function.
ldc_init
err_t ldc_init(ldc_t *ctx, ldc_cfg_t *cfg)
LDC initialization function.
ldc_cfg_setup
void ldc_cfg_setup(ldc_cfg_t *cfg)
LDC configuration object setup function.
ldc_get_interrupt
uint8_t ldc_get_interrupt(ldc_t *ctx)
Get interrupt pin status.
LDC_OK
Definition: ldc.h:172
ldc_return_value_t
ldc_return_value_t
LDC Click return value data.
Definition: ldc.h:170
LDC_ERROR
Definition: ldc.h:173
ldc_set_shut_down
void ldc_set_shut_down(ldc_t *ctx, uint8_t state)
Set shut down pin status.
ldc_generic_read
err_t ldc_generic_read(ldc_t *ctx, uint8_t reg, uint16_t *rx_data)
LDC I2C reading function.
ldc_cfg_t
LDC Click configuration object.
Definition: ldc.h:153