dcmotor16  2.0.0.0
dcmotor16.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 DCMOTOR16_H
29 #define DCMOTOR16_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_spi_master.h"
48 #include "spi_specifics.h"
49 
70 #define DCMOTOR16_DIR_FORWARD 0
71 #define DCMOTOR16_DIR_BACKWARD 1
72 
73 #define DCMOTOR16_ENABLE 1
74 #define DCMOTOR16_DISABLE 0
75 
83 #define DCMOTOR16_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
84 #define DCMOTOR16_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
85  // dcmotor16_set
87 
102 #define DCMOTOR16_MAP_MIKROBUS( cfg, mikrobus ) \
103  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
104  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
105  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
106  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
107  cfg.fwd = MIKROBUS( mikrobus, MIKROBUS_RST ); \
108  cfg.rev = MIKROBUS( mikrobus, MIKROBUS_PWM )
109  // dcmotor16_map // dcmotor16
112 
117 typedef struct
118 {
119  // Output pins
120  digital_out_t fwd;
121  digital_out_t rev;
123  // Modules
124  spi_master_t spi;
126  pin_name_t chip_select;
128 } dcmotor16_t;
129 
134 typedef struct
135 {
136  // Communication gpio pins
137  pin_name_t miso;
138  pin_name_t mosi;
139  pin_name_t sck;
140  pin_name_t cs;
142  // Additional gpio pins
143  pin_name_t fwd;
144  pin_name_t rev;
146  // static variable
147  uint32_t spi_speed;
148  spi_master_mode_t spi_mode;
149  spi_master_chip_select_polarity_t cs_polarity;
152 
157 typedef enum
158 {
160  DCMOTOR16_ERROR = -1
161 
163 
180 
195 
210 err_t dcmotor16_generic_write ( dcmotor16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
211 
226 err_t dcmotor16_generic_read ( dcmotor16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
227 
228 
237 void dcmotor16_set_direction( dcmotor16_t *ctx, uint8_t dir );
238 
247 void dcmotor16_ctrl_fwd_pin( dcmotor16_t *ctx, uint8_t state );
248 
257 void dcmotor16_ctrl_rev_pin( dcmotor16_t *ctx, uint8_t state );
258 
267 void dcmotor16_ctrl_vref( dcmotor16_t *ctx, uint16_t value );
268 
277 
278 #ifdef __cplusplus
279 }
280 #endif
281 #endif // DCMOTOR16_H
282  // dcmotor16
284 
285 // ------------------------------------------------------------------------ END
dcmotor16_cfg_t
DC Motor 16 Click configuration object.
Definition: dcmotor16.h:135
dcmotor16_cfg_t::sck
pin_name_t sck
Definition: dcmotor16.h:139
dcmotor16_generic_read
err_t dcmotor16_generic_read(dcmotor16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
DC Motor 16 data reading function.
dcmotor16_cfg_t::miso
pin_name_t miso
Definition: dcmotor16.h:137
dcmotor16_ctrl_rev_pin
void dcmotor16_ctrl_rev_pin(dcmotor16_t *ctx, uint8_t state)
Control REV pin.
dcmotor16_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: dcmotor16.h:149
dcmotor16_t
DC Motor 16 Click context object.
Definition: dcmotor16.h:118
dcmotor16_t::rev
digital_out_t rev
Definition: dcmotor16.h:121
dcmotor16_cfg_t::mosi
pin_name_t mosi
Definition: dcmotor16.h:138
spi_specifics.h
This file contains SPI specific macros, functions, etc.
dcmotor16_cfg_setup
void dcmotor16_cfg_setup(dcmotor16_cfg_t *cfg)
DC Motor 16 configuration object setup function.
dcmotor16_cfg_t::rev
pin_name_t rev
Definition: dcmotor16.h:144
dcmotor16_return_value_t
dcmotor16_return_value_t
DC Motor 16 Click return value data.
Definition: dcmotor16.h:158
DCMOTOR16_OK
@ DCMOTOR16_OK
Definition: dcmotor16.h:159
dcmotor16_init
err_t dcmotor16_init(dcmotor16_t *ctx, dcmotor16_cfg_t *cfg)
DC Motor 16 initialization function.
dcmotor16_cfg_t::fwd
pin_name_t fwd
Definition: dcmotor16.h:143
DCMOTOR16_ERROR
@ DCMOTOR16_ERROR
Definition: dcmotor16.h:160
dcmotor16_cfg_t::spi_speed
uint32_t spi_speed
Definition: dcmotor16.h:147
dcmotor16_set_direction
void dcmotor16_set_direction(dcmotor16_t *ctx, uint8_t dir)
Set motor direction.
dcmotor16_stop
void dcmotor16_stop(dcmotor16_t *ctx)
Motor stop.
dcmotor16_ctrl_vref
void dcmotor16_ctrl_vref(dcmotor16_t *ctx, uint16_t value)
Control motor VRef (speed).
dcmotor16_cfg_t::cs
pin_name_t cs
Definition: dcmotor16.h:140
dcmotor16_generic_write
err_t dcmotor16_generic_write(dcmotor16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
DC Motor 16 data writing function.
dcmotor16_t::spi
spi_master_t spi
Definition: dcmotor16.h:124
dcmotor16_t::chip_select
pin_name_t chip_select
Definition: dcmotor16.h:126
dcmotor16_t::fwd
digital_out_t fwd
Definition: dcmotor16.h:120
dcmotor16_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: dcmotor16.h:148
dcmotor16_ctrl_fwd_pin
void dcmotor16_ctrl_fwd_pin(dcmotor16_t *ctx, uint8_t state)
Control FWD pin.