dcmotor25  2.1.0.0
dcmotor25.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 DCMOTOR25_H
29 #define DCMOTOR25_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_i2c_master.h"
51 
72 #define DCMOTOR25_WRITE_TO_RDAC 0x00
73 #define DCMOTOR25_ONE_TIME_PROG 0x80
74  // dcmotor25_inst
76 
91 #define DCMOTOR25_OTP_V_READY 0x00
92 #define DCMOTOR25_OTP_V_TEST_OK 0x40
93 #define DCMOTOR25_OTP_V_ERROR 0x80
94 #define DCMOTOR25_OTP_V_PROG_SUCCESS 0xC0
95 
101 #define DCMOTOR25_RESISTANCE_MIN 17000
102 #define DCMOTOR25_RES_DEFAULT_20_kOhm 20000
103 #define DCMOTOR25_FULL_SCALE_RES_50_kOhm 50000
104 #define DCMOTOR25_WIPER_POS_MAX 0x3F
105 
106 
112 #define DCMOTOR25_DEVICE_ADDRESS 0x2C
113  // dcmotor25_set
115 
130 #define DCMOTOR25_MAP_MIKROBUS( cfg, mikrobus ) \
131  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
132  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
133  cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
134  cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_PWM )
135  // dcmotor25_map // dcmotor25
138 
143 typedef struct
144 {
145  // Output pins
146  digital_out_t in1;
147  digital_out_t in2;
149  // Modules
150  i2c_master_t i2c;
152  // I2C slave address
153  uint8_t slave_address;
155 } dcmotor25_t;
156 
161 typedef struct
162 {
163  pin_name_t scl;
164  pin_name_t sda;
166  pin_name_t in1;
167  pin_name_t in2;
169  uint32_t i2c_speed;
170  uint8_t i2c_address;
173 
178 typedef enum
179 {
181  DCMOTOR25_ERROR = -1
182 
184 
201 
216 
230 
244 err_t dcmotor25_write_byte ( dcmotor25_t *ctx, uint8_t inst, uint8_t data_in );
245 
257 err_t dcmotor25_read_byte ( dcmotor25_t *ctx, uint8_t *data_out );
258 
272 err_t dcmotor25_write_rdac ( dcmotor25_t *ctx, uint8_t rdac_data );
273 
287 err_t dcmotor25_read_rdac ( dcmotor25_t *ctx, uint8_t *rdac_data );
288 
302 err_t dcmotor25_set_digi_pot ( dcmotor25_t *ctx, uint8_t wiper_pos );
303 
318 err_t dcmotor25_set_resistance ( dcmotor25_t *ctx, uint16_t res_ohm );
319 
331 
343 
355 
367 
368 #ifdef __cplusplus
369 }
370 #endif
371 #endif // DCMOTOR25_H
372  // dcmotor25
374 
375 // ------------------------------------------------------------------------ END
dcmotor25_cfg_t::sda
pin_name_t sda
Definition: dcmotor25.h:164
dcmotor25_cfg_t::scl
pin_name_t scl
Definition: dcmotor25.h:163
DCMOTOR25_ERROR
@ DCMOTOR25_ERROR
Definition: dcmotor25.h:181
dcmotor25_t::in2
digital_out_t in2
Definition: dcmotor25.h:147
dcmotor25_t::in1
digital_out_t in1
Definition: dcmotor25.h:146
dcmotor25_return_value_t
dcmotor25_return_value_t
DC Motor 25 Click return value data.
Definition: dcmotor25.h:179
dcmotor25_forward
void dcmotor25_forward(dcmotor25_t *ctx)
DC Motor 25 set forward mode function.
dcmotor25_default_cfg
err_t dcmotor25_default_cfg(dcmotor25_t *ctx)
DC Motor 25 default configuration function.
dcmotor25_init
err_t dcmotor25_init(dcmotor25_t *ctx, dcmotor25_cfg_t *cfg)
DC Motor 25 initialization function.
dcmotor25_write_rdac
err_t dcmotor25_write_rdac(dcmotor25_t *ctx, uint8_t rdac_data)
DC Motor 25 write RDAC function.
dcmotor25_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: dcmotor25.h:169
dcmotor25_t
DC Motor 25 Click context object.
Definition: dcmotor25.h:144
dcmotor25_cfg_t::in2
pin_name_t in2
Definition: dcmotor25.h:167
dcmotor25_t::slave_address
uint8_t slave_address
Definition: dcmotor25.h:153
dcmotor25_cfg_t::i2c_address
uint8_t i2c_address
Definition: dcmotor25.h:170
DCMOTOR25_OK
@ DCMOTOR25_OK
Definition: dcmotor25.h:180
dcmotor25_brake
void dcmotor25_brake(dcmotor25_t *ctx)
DC Motor 25 set brake mode function.
dcmotor25_cfg_t::in1
pin_name_t in1
Definition: dcmotor25.h:166
dcmotor25_standby
void dcmotor25_standby(dcmotor25_t *ctx)
DC Motor 25 set standby mode function.
dcmotor25_cfg_setup
void dcmotor25_cfg_setup(dcmotor25_cfg_t *cfg)
DC Motor 25 configuration object setup function.
dcmotor25_read_rdac
err_t dcmotor25_read_rdac(dcmotor25_t *ctx, uint8_t *rdac_data)
DC Motor 25 read RDAC function.
dcmotor25_reverse
void dcmotor25_reverse(dcmotor25_t *ctx)
DC Motor 25 set reverse mode function.
dcmotor25_read_byte
err_t dcmotor25_read_byte(dcmotor25_t *ctx, uint8_t *data_out)
DC Motor 25 I2C reading function.
dcmotor25_t::i2c
i2c_master_t i2c
Definition: dcmotor25.h:150
dcmotor25_cfg_t
DC Motor 25 Click configuration object.
Definition: dcmotor25.h:162
dcmotor25_write_byte
err_t dcmotor25_write_byte(dcmotor25_t *ctx, uint8_t inst, uint8_t data_in)
DC Motor 25 I2C writing function.
dcmotor25_set_resistance
err_t dcmotor25_set_resistance(dcmotor25_t *ctx, uint16_t res_ohm)
DC Motor 25 set the resistance function.
dcmotor25_set_digi_pot
err_t dcmotor25_set_digi_pot(dcmotor25_t *ctx, uint8_t wiper_pos)
DC Motor 25 set the digital potentiometer function.