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 
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_i2c_master.h"
48 
69 #define ANTOPWM2_OTP_BIT 0x80
70 #define ANTOPWM2_STATUS_READY 0x00
71 #define ANTOPWM2_STATUS_TEST_FUSE 0x40
72 #define ANTOPWM2_STATUS_FATAL_ERROR 0x80
73 #define ANTOPWM2_STATUS_OTP_SUCCESS 0xC0
74 #define ANTOPWM2_STATUS_MASK 0xC0
75 
80 #define ANTOPWM2_DIGIPOT_WIPER_MAX 0x3F
81 #define ANTOPWM2_DIGIPOT_R6 49900u
82 #define ANTOPWM2_DIGIPOT_WIPER_RES 60
83 #define ANTOPWM2_DIGIPOT_MAX_RES 50000u
84 
89 #define ANTOPWM2_FREQ_MAX 1000000ul
90 #define ANTOPWM2_FREQ_MIN 500000ul
91 #define ANTOPWM2_RSET_REF 50000u
92 #define ANTOPWM2_NDIV 1
93 
99 #define ANTOPWM2_DEVICE_ADDRESS 0x2C
100  // antopwm2_set
102 
117 #define ANTOPWM2_MAP_MIKROBUS( cfg, mikrobus ) \
118  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
119  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
120  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
121  // antopwm2_map // antopwm2
124 
129 typedef struct
130 {
131  // Input pins
132  digital_in_t int_pin;
134  // Modules
135  i2c_master_t i2c;
137  // I2C slave address
138  uint8_t slave_address;
140 } antopwm2_t;
141 
146 typedef struct
147 {
148  pin_name_t scl;
149  pin_name_t sda;
151  pin_name_t int_pin;
153  uint32_t i2c_speed;
154  uint8_t i2c_address;
157 
162 typedef enum
163 {
165  ANTOPWM2_ERROR = -1
166 
168 
185 
200 
212 err_t antopwm2_set_digipot ( antopwm2_t *ctx, uint8_t wiper );
213 
225 err_t antopwm2_read_digipot ( antopwm2_t *ctx, uint8_t *data_out );
226 
238 err_t antopwm2_set_digipot_otp ( antopwm2_t *ctx, uint8_t wiper );
239 
252 err_t antopwm2_set_frequency ( antopwm2_t *ctx, uint32_t freq );
253 
266 err_t antopwm2_set_frequency_otp ( antopwm2_t *ctx, uint32_t freq );
267 
277 
278 #ifdef __cplusplus
279 }
280 #endif
281 #endif // ANTOPWM2_H
282  // antopwm2
284 
285 // ------------------------------------------------------------------------ END
ANTOPWM2_ERROR
@ ANTOPWM2_ERROR
Definition: antopwm2.h:165
antopwm2_cfg_t::i2c_address
uint8_t i2c_address
Definition: antopwm2.h:154
antopwm2_return_value_t
antopwm2_return_value_t
AN to PWM 2 Click return value data.
Definition: antopwm2.h:163
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:148
antopwm2_t::slave_address
uint8_t slave_address
Definition: antopwm2.h:138
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:164
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:132
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:151
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:153
antopwm2_t::i2c
i2c_master_t i2c
Definition: antopwm2.h:135
antopwm2_cfg_t
AN to PWM 2 Click configuration object.
Definition: antopwm2.h:147
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:130
antopwm2_cfg_t::sda
pin_name_t sda
Definition: antopwm2.h:149