dcmotor11  2.0.0.0
dcmotor11.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef DCMOTOR11_H
36 #define DCMOTOR11_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define DCMOTOR11_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
57 
63 #define DCMOTOR11_RETVAL uint8_t
64 
65 #define DCMOTOR11_OK 0x00
66 #define DCMOTOR11_INIT_ERROR 0xFF
67 
73 #define DCMOTOR11_DEVICE_SLAVE_ADDR_0_0 0x60
74 #define DCMOTOR11_DEVICE_SLAVE_ADDR_0_1 0x62
75 #define DCMOTOR11_DEVICE_SLAVE_ADDR_1_0 0x66
76 #define DCMOTOR11_DEVICE_SLAVE_ADDR_1_1 0x68
77 
83 #define DCMOTOR11_REGISTER_CONTROL 0x00
84 #define DCMOTOR11_REGISTER_FAULT 0x01
85 
91 #define DCMOTOR11_VSET_480mV 0x06 << 2
92 #define DCMOTOR11_VSET_560mV 0x07 << 2
93 #define DCMOTOR11_VSET_640mV 0x08 << 2
94 #define DCMOTOR11_VSET_720mV 0x09 << 2
95 #define DCMOTOR11_VSET_800mV 0x0A << 2
96 #define DCMOTOR11_VSET_880mV 0x0B << 2
97 #define DCMOTOR11_VSET_960mV 0x0C << 2
98 #define DCMOTOR11_VSET_1040mV 0x0D << 2
99 #define DCMOTOR11_VSET_1120mV 0x0E << 2
100 #define DCMOTOR11_VSET_1200mV 0x0F << 2
101 #define DCMOTOR11_VSET_1290mV 0x10 << 2
102 #define DCMOTOR11_VSET_1370mV 0x11 << 2
103 #define DCMOTOR11_VSET_1450mV 0x12 << 2
104 #define DCMOTOR11_VSET_1530mV 0x13 << 2
105 #define DCMOTOR11_VSET_1610mV 0x14 << 2
106 #define DCMOTOR11_VSET_1690mV 0x15 << 2
107 #define DCMOTOR11_VSET_1770mV 0x16 << 2
108 #define DCMOTOR11_VSET_1850mV 0x17 << 2
109 #define DCMOTOR11_VSET_1930mV 0x18 << 2
110 #define DCMOTOR11_VSET_2010mV 0x19 << 2
111 #define DCMOTOR11_VSET_2090mV 0x1A << 2
112 #define DCMOTOR11_VSET_2170mV 0x1B << 2
113 #define DCMOTOR11_VSET_2500mV 0x1C << 2
114 #define DCMOTOR11_VSET_2330mV 0x1D << 2
115 #define DCMOTOR11_VSET_2410mV 0x1E << 2
116 #define DCMOTOR11_VSET_2490mV 0x1F << 2
117 #define DCMOTOR11_VSET_2570mV 0x20 << 2
118 #define DCMOTOR11_VSET_2650mV 0x21 << 2
119 #define DCMOTOR11_VSET_2730mV 0x22 << 2
120 #define DCMOTOR11_VSET_2810mV 0x23 << 2
121 #define DCMOTOR11_VSET_2890mV 0x24 << 2
122 #define DCMOTOR11_VSET_2970mV 0x25 << 2
123 #define DCMOTOR11_VSET_3050mV 0x26 << 2
124 #define DCMOTOR11_VSET_3130mV 0x27 << 2
125 #define DCMOTOR11_VSET_3210mV 0x28 << 2
126 #define DCMOTOR11_VSET_3290mV 0x29 << 2
127 #define DCMOTOR11_VSET_3370mV 0x2A << 2
128 #define DCMOTOR11_VSET_3450mV 0x2B << 2
129 #define DCMOTOR11_VSET_3530mV 0x2C << 2
130 #define DCMOTOR11_VSET_3610mV 0x2D << 2
131 #define DCMOTOR11_VSET_3690mV 0x2E << 2
132 #define DCMOTOR11_VSET_3770mV 0x2F << 2
133 #define DCMOTOR11_VSET_3860mV 0x30 << 2
134 #define DCMOTOR11_VSET_3940mV 0x31 << 2
135 #define DCMOTOR11_VSET_4020mV 0x32 << 2
136 #define DCMOTOR11_VSET_4100mV 0x33 << 2
137 #define DCMOTOR11_VSET_4180mV 0x34 << 2
138 #define DCMOTOR11_VSET_4260mV 0x35 << 2
139 #define DCMOTOR11_VSET_4340mV 0x36 << 2
140 #define DCMOTOR11_VSET_4420mV 0x37 << 2
141 #define DCMOTOR11_VSET_4500mV 0x38 << 2
142 #define DCMOTOR11_VSET_4580mV 0x39 << 2
143 #define DCMOTOR11_VSET_4660mV 0x3A << 2
144 #define DCMOTOR11_VSET_4740mV 0x3B << 2
145 #define DCMOTOR11_VSET_4820mV 0x3C << 2
146 #define DCMOTOR11_VSET_4900mV 0x3D << 2
147 #define DCMOTOR11_VSET_4980mV 0x3E << 2
148 #define DCMOTOR11_VSET_5060mV 0x3F << 2
149 
155 #define DCMOTOR11_DIRECTION_FORWARD 0x01
156 #define DCMOTOR11_DIRECTION_BACKWARD 0x02
157 #define DCMOTOR11_DIRECTION_STOP 0x00
158 #define DCMOTOR11_DIRECTION_BREAK 0x03
159  // End group macro
162 // --------------------------------------------------------------- PUBLIC TYPES
171 typedef struct
172 {
173  // Input pins
174 
175  digital_in_t flt;
176 
177  // Modules
178 
179  i2c_master_t i2c;
180 
181  // ctx variable
182 
183  hal_i2c_address_t slave_address;
184 
185 } dcmotor11_t;
186 
190 typedef struct
191 {
192  // Communication gpio pins
193 
194  pin_name_t scl;
195  pin_name_t sda;
196 
197  // Additional gpio pins
198 
199  pin_name_t flt;
200 
201  // static variable
202 
203  hal_i2c_speed_t i2c_speed;
204  hal_i2c_address_t i2c_address;
205 
207  // End types group
209 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
210 
216 #ifdef __cplusplus
217 extern "C"{
218 #endif
219 
229 
238 
249 void dcmotor11_generic_write ( dcmotor11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
250 
262 void dcmotor11_generic_read ( dcmotor11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
263 
271 void dcmotor11_control ( dcmotor11_t *ctx, uint8_t dir, uint8_t speed );
272 
280 uint8_t dcmotor11_get_fault ( dcmotor11_t *ctx );
281 
288 void dcmotor11_clear_fault ( dcmotor11_t *ctx, uint8_t dev_data );
289 
295 void dcmotor11_stop ( dcmotor11_t *ctx );
296 
302 void dcmotor11_break ( dcmotor11_t *ctx );
303 
312 
313 #ifdef __cplusplus
314 }
315 #endif
316 #endif // _DCMOTOR11_H_
317  // End public_function group
320 
321 // ------------------------------------------------------------------------- END
dcmotor11_cfg_t
Click configuration structure definition.
Definition: dcmotor11.h:190
dcmotor11_clear_fault
void dcmotor11_clear_fault(dcmotor11_t *ctx, uint8_t dev_data)
Set Fault.
dcmotor11_control
void dcmotor11_control(dcmotor11_t *ctx, uint8_t dir, uint8_t speed)
Motor Control.
dcmotor11_generic_read
void dcmotor11_generic_read(dcmotor11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
dcmotor11_stop
void dcmotor11_stop(dcmotor11_t *ctx)
Motor Stop.
dcmotor11_cfg_t::sda
pin_name_t sda
Definition: dcmotor11.h:195
dcmotor11_cfg_t::scl
pin_name_t scl
Definition: dcmotor11.h:194
dcmotor11_t::flt
digital_in_t flt
Definition: dcmotor11.h:175
dcmotor11_t::slave_address
hal_i2c_address_t slave_address
Definition: dcmotor11.h:183
dcmotor11_cfg_t::flt
pin_name_t flt
Definition: dcmotor11.h:199
dcmotor11_get_interrupt_state
uint8_t dcmotor11_get_interrupt_state(dcmotor11_t *ctx)
Interrupt state on the INT pin.
dcmotor11_generic_write
void dcmotor11_generic_write(dcmotor11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
dcmotor11_init
DCMOTOR11_RETVAL dcmotor11_init(dcmotor11_t *ctx, dcmotor11_cfg_t *cfg)
Initialization function.
DCMOTOR11_RETVAL
#define DCMOTOR11_RETVAL
Definition: dcmotor11.h:63
dcmotor11_get_fault
uint8_t dcmotor11_get_fault(dcmotor11_t *ctx)
Get Fault.
dcmotor11_cfg_setup
void dcmotor11_cfg_setup(dcmotor11_cfg_t *cfg)
Config Object Initialization function.
dcmotor11_t::i2c
i2c_master_t i2c
Definition: dcmotor11.h:179
dcmotor11_cfg_t::i2c_speed
hal_i2c_speed_t i2c_speed
Definition: dcmotor11.h:203
dcmotor11_cfg_t::i2c_address
hal_i2c_address_t i2c_address
Definition: dcmotor11.h:204
dcmotor11_t
Click ctx object definition.
Definition: dcmotor11.h:171
dcmotor11_break
void dcmotor11_break(dcmotor11_t *ctx)
Motor Break.