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 "drv_digital_out.h"
36 #include "drv_i2c_master.h"
37 
58 #define DCMOTOR25_WRITE_TO_RDAC 0x00
59 #define DCMOTOR25_ONE_TIME_PROG 0x80
60  // dcmotor25_inst
62 
77 #define DCMOTOR25_OTP_V_READY 0x00
78 #define DCMOTOR25_OTP_V_TEST_OK 0x40
79 #define DCMOTOR25_OTP_V_ERROR 0x80
80 #define DCMOTOR25_OTP_V_PROG_SUCCESS 0xC0
81 
87 #define DCMOTOR25_RESISTANCE_MIN 17000
88 #define DCMOTOR25_RES_DEFAULT_20_kOhm 20000
89 #define DCMOTOR25_FULL_SCALE_RES_50_kOhm 50000
90 #define DCMOTOR25_WIPER_POS_MAX 0x3F
91 
92 
98 #define DCMOTOR25_DEVICE_ADDRESS 0x2C
99  // dcmotor25_set
101 
116 #define DCMOTOR25_MAP_MIKROBUS( cfg, mikrobus ) \
117  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
118  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
119  cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
120  cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_PWM )
121  // dcmotor25_map // dcmotor25
124 
129 typedef struct
130 {
131  // Output pins
132  digital_out_t in1;
133  digital_out_t in2;
135  // Modules
136  i2c_master_t i2c;
138  // I2C slave address
139  uint8_t slave_address;
141 } dcmotor25_t;
142 
147 typedef struct
148 {
149  pin_name_t scl;
150  pin_name_t sda;
152  pin_name_t in1;
153  pin_name_t in2;
155  uint32_t i2c_speed;
156  uint8_t i2c_address;
159 
164 typedef enum
165 {
167  DCMOTOR25_ERROR = -1
168 
170 
187 
202 
216 
230 err_t dcmotor25_write_byte ( dcmotor25_t *ctx, uint8_t inst, uint8_t data_in );
231 
243 err_t dcmotor25_read_byte ( dcmotor25_t *ctx, uint8_t *data_out );
244 
258 err_t dcmotor25_write_rdac ( dcmotor25_t *ctx, uint8_t rdac_data );
259 
273 err_t dcmotor25_read_rdac ( dcmotor25_t *ctx, uint8_t *rdac_data );
274 
288 err_t dcmotor25_set_digi_pot ( dcmotor25_t *ctx, uint8_t wiper_pos );
289 
304 err_t dcmotor25_set_resistance ( dcmotor25_t *ctx, uint16_t res_ohm );
305 
317 
329 
341 
353 
354 #ifdef __cplusplus
355 }
356 #endif
357 #endif // DCMOTOR25_H
358  // dcmotor25
360 
361 // ------------------------------------------------------------------------ END
dcmotor25_cfg_t::sda
pin_name_t sda
Definition: dcmotor25.h:150
dcmotor25_cfg_t::scl
pin_name_t scl
Definition: dcmotor25.h:149
DCMOTOR25_ERROR
@ DCMOTOR25_ERROR
Definition: dcmotor25.h:167
dcmotor25_t::in2
digital_out_t in2
Definition: dcmotor25.h:133
dcmotor25_t::in1
digital_out_t in1
Definition: dcmotor25.h:132
dcmotor25_return_value_t
dcmotor25_return_value_t
DC Motor 25 Click return value data.
Definition: dcmotor25.h:165
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:155
dcmotor25_t
DC Motor 25 Click context object.
Definition: dcmotor25.h:130
dcmotor25_cfg_t::in2
pin_name_t in2
Definition: dcmotor25.h:153
dcmotor25_t::slave_address
uint8_t slave_address
Definition: dcmotor25.h:139
dcmotor25_cfg_t::i2c_address
uint8_t i2c_address
Definition: dcmotor25.h:156
DCMOTOR25_OK
@ DCMOTOR25_OK
Definition: dcmotor25.h:166
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:152
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:136
dcmotor25_cfg_t
DC Motor 25 Click configuration object.
Definition: dcmotor25.h:148
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.