antopwm2  2.1.0.0
antopwm2.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 ANTOPWM2_H
29 #define ANTOPWM2_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 
73 #define ANTOPWM2_OTP_BIT 0x80
74 #define ANTOPWM2_STATUS_READY 0x00
75 #define ANTOPWM2_STATUS_TEST_FUSE 0x40
76 #define ANTOPWM2_STATUS_FATAL_ERROR 0x80
77 #define ANTOPWM2_STATUS_OTP_SUCCESS 0xC0
78 #define ANTOPWM2_STATUS_MASK 0xC0
79 
84 #define ANTOPWM2_DIGIPOT_WIPER_MAX 0x3F
85 #define ANTOPWM2_DIGIPOT_R6 49900u
86 #define ANTOPWM2_DIGIPOT_WIPER_RES 60
87 #define ANTOPWM2_DIGIPOT_MAX_RES 50000u
88 
93 #define ANTOPWM2_FREQ_MAX 1000000ul
94 #define ANTOPWM2_FREQ_MIN 500000ul
95 #define ANTOPWM2_RSET_REF 50000u
96 #define ANTOPWM2_NDIV 1
97 
103 #define ANTOPWM2_DEVICE_ADDRESS 0x2C
104  // antopwm2_set
106 
121 #define ANTOPWM2_MAP_MIKROBUS( cfg, mikrobus ) \
122  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
123  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
124  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
125  // antopwm2_map // antopwm2
128 
133 typedef struct
134 {
135  // Input pins
136  digital_in_t int_pin;
138  // Modules
139  i2c_master_t i2c;
141  // I2C slave address
142  uint8_t slave_address;
144 } antopwm2_t;
145 
150 typedef struct
151 {
152  pin_name_t scl;
153  pin_name_t sda;
155  pin_name_t int_pin;
157  uint32_t i2c_speed;
158  uint8_t i2c_address;
161 
166 typedef enum
167 {
169  ANTOPWM2_ERROR = -1
170 
172 
189 
204 
216 err_t antopwm2_set_digipot ( antopwm2_t *ctx, uint8_t wiper );
217 
229 err_t antopwm2_read_digipot ( antopwm2_t *ctx, uint8_t *data_out );
230 
242 err_t antopwm2_set_digipot_otp ( antopwm2_t *ctx, uint8_t wiper );
243 
256 err_t antopwm2_set_frequency ( antopwm2_t *ctx, uint32_t freq );
257 
270 err_t antopwm2_set_frequency_otp ( antopwm2_t *ctx, uint32_t freq );
271 
281 
282 #ifdef __cplusplus
283 }
284 #endif
285 #endif // ANTOPWM2_H
286  // antopwm2
288 
289 // ------------------------------------------------------------------------ END
ANTOPWM2_ERROR
@ ANTOPWM2_ERROR
Definition: antopwm2.h:169
antopwm2_cfg_t::i2c_address
uint8_t i2c_address
Definition: antopwm2.h:158
antopwm2_return_value_t
antopwm2_return_value_t
AN to PWM 2 Click return value data.
Definition: antopwm2.h:167
antopwm2_read_digipot
err_t antopwm2_read_digipot(antopwm2_t *ctx, uint8_t *data_out)
AN to PWM 2 read digipot function.
antopwm2_set_digipot_otp
err_t antopwm2_set_digipot_otp(antopwm2_t *ctx, uint8_t wiper)
AN to PWM 2 set digipot otp function.
antopwm2_cfg_t::scl
pin_name_t scl
Definition: antopwm2.h:152
antopwm2_t::slave_address
uint8_t slave_address
Definition: antopwm2.h:142
antopwm2_cfg_setup
void antopwm2_cfg_setup(antopwm2_cfg_t *cfg)
AN to PWM 2 configuration object setup function.
ANTOPWM2_OK
@ ANTOPWM2_OK
Definition: antopwm2.h:168
antopwm2_set_digipot
err_t antopwm2_set_digipot(antopwm2_t *ctx, uint8_t wiper)
AN to PWM 2 set digipot function.
antopwm2_t::int_pin
digital_in_t int_pin
Definition: antopwm2.h:136
antopwm2_set_frequency_otp
err_t antopwm2_set_frequency_otp(antopwm2_t *ctx, uint32_t freq)
AN to PWM 2 set frequency otp function.
antopwm2_get_int_pin
uint8_t antopwm2_get_int_pin(antopwm2_t *ctx)
AN to PWM 2 get int pin function.
antopwm2_cfg_t::int_pin
pin_name_t int_pin
Definition: antopwm2.h:155
antopwm2_set_frequency
err_t antopwm2_set_frequency(antopwm2_t *ctx, uint32_t freq)
AN to PWM 2 set frequency function.
antopwm2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: antopwm2.h:157
antopwm2_t::i2c
i2c_master_t i2c
Definition: antopwm2.h:139
antopwm2_cfg_t
AN to PWM 2 Click configuration object.
Definition: antopwm2.h:151
antopwm2_init
err_t antopwm2_init(antopwm2_t *ctx, antopwm2_cfg_t *cfg)
AN to PWM 2 initialization function.
antopwm2_t
AN to PWM 2 Click context object.
Definition: antopwm2.h:134
antopwm2_cfg_t::sda
pin_name_t sda
Definition: antopwm2.h:153