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 
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_i2c_master.h"
47 
68 #define DCMOTOR25_WRITE_TO_RDAC 0x00
69 #define DCMOTOR25_ONE_TIME_PROG 0x80
70  // dcmotor25_inst
72 
87 #define DCMOTOR25_OTP_V_READY 0x00
88 #define DCMOTOR25_OTP_V_TEST_OK 0x40
89 #define DCMOTOR25_OTP_V_ERROR 0x80
90 #define DCMOTOR25_OTP_V_PROG_SUCCESS 0xC0
91 
97 #define DCMOTOR25_RESISTANCE_MIN 17000
98 #define DCMOTOR25_RES_DEFAULT_20_kOhm 20000
99 #define DCMOTOR25_FULL_SCALE_RES_50_kOhm 50000
100 #define DCMOTOR25_WIPER_POS_MAX 0x3F
101 
102 
108 #define DCMOTOR25_DEVICE_ADDRESS 0x2C
109  // dcmotor25_set
111 
126 #define DCMOTOR25_MAP_MIKROBUS( cfg, mikrobus ) \
127  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
128  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
129  cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
130  cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_PWM )
131  // dcmotor25_map // dcmotor25
134 
139 typedef struct
140 {
141  // Output pins
142  digital_out_t in1;
143  digital_out_t in2;
145  // Modules
146  i2c_master_t i2c;
148  // I2C slave address
149  uint8_t slave_address;
151 } dcmotor25_t;
152 
157 typedef struct
158 {
159  pin_name_t scl;
160  pin_name_t sda;
162  pin_name_t in1;
163  pin_name_t in2;
165  uint32_t i2c_speed;
166  uint8_t i2c_address;
169 
174 typedef enum
175 {
177  DCMOTOR25_ERROR = -1
178 
180 
197 
212 
226 
240 err_t dcmotor25_write_byte ( dcmotor25_t *ctx, uint8_t inst, uint8_t data_in );
241 
253 err_t dcmotor25_read_byte ( dcmotor25_t *ctx, uint8_t *data_out );
254 
268 err_t dcmotor25_write_rdac ( dcmotor25_t *ctx, uint8_t rdac_data );
269 
283 err_t dcmotor25_read_rdac ( dcmotor25_t *ctx, uint8_t *rdac_data );
284 
298 err_t dcmotor25_set_digi_pot ( dcmotor25_t *ctx, uint8_t wiper_pos );
299 
314 err_t dcmotor25_set_resistance ( dcmotor25_t *ctx, uint16_t res_ohm );
315 
327 
339 
351 
363 
364 #ifdef __cplusplus
365 }
366 #endif
367 #endif // DCMOTOR25_H
368  // dcmotor25
370 
371 // ------------------------------------------------------------------------ END
dcmotor25_cfg_t::sda
pin_name_t sda
Definition: dcmotor25.h:160
dcmotor25_cfg_t::scl
pin_name_t scl
Definition: dcmotor25.h:159
DCMOTOR25_ERROR
@ DCMOTOR25_ERROR
Definition: dcmotor25.h:177
dcmotor25_t::in2
digital_out_t in2
Definition: dcmotor25.h:143
dcmotor25_t::in1
digital_out_t in1
Definition: dcmotor25.h:142
dcmotor25_return_value_t
dcmotor25_return_value_t
DC Motor 25 Click return value data.
Definition: dcmotor25.h:175
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:165
dcmotor25_t
DC Motor 25 Click context object.
Definition: dcmotor25.h:140
dcmotor25_cfg_t::in2
pin_name_t in2
Definition: dcmotor25.h:163
dcmotor25_t::slave_address
uint8_t slave_address
Definition: dcmotor25.h:149
dcmotor25_cfg_t::i2c_address
uint8_t i2c_address
Definition: dcmotor25.h:166
DCMOTOR25_OK
@ DCMOTOR25_OK
Definition: dcmotor25.h:176
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:162
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:146
dcmotor25_cfg_t
DC Motor 25 Click configuration object.
Definition: dcmotor25.h:158
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.