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 
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_digital_in.h"
51 #include "drv_spi_master.h"
52 #include "spi_specifics.h"
53 
74 #define DCMOTOR16_DIR_FORWARD 0
75 #define DCMOTOR16_DIR_BACKWARD 1
76 
77 #define DCMOTOR16_ENABLE 1
78 #define DCMOTOR16_DISABLE 0
79 
87 #define DCMOTOR16_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
88 #define DCMOTOR16_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
89  // dcmotor16_set
91 
106 #define DCMOTOR16_MAP_MIKROBUS( cfg, mikrobus ) \
107  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
108  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
109  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
110  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
111  cfg.fwd = MIKROBUS( mikrobus, MIKROBUS_RST ); \
112  cfg.rev = MIKROBUS( mikrobus, MIKROBUS_PWM )
113  // dcmotor16_map // dcmotor16
116 
121 typedef struct
122 {
123  // Output pins
124  digital_out_t fwd;
125  digital_out_t rev;
127  // Modules
128  spi_master_t spi;
130  pin_name_t chip_select;
132 } dcmotor16_t;
133 
138 typedef struct
139 {
140  // Communication gpio pins
141  pin_name_t miso;
142  pin_name_t mosi;
143  pin_name_t sck;
144  pin_name_t cs;
146  // Additional gpio pins
147  pin_name_t fwd;
148  pin_name_t rev;
150  // static variable
151  uint32_t spi_speed;
152  spi_master_mode_t spi_mode;
153  spi_master_chip_select_polarity_t cs_polarity;
156 
161 typedef enum
162 {
164  DCMOTOR16_ERROR = -1
165 
167 
184 
199 
214 err_t dcmotor16_generic_write ( dcmotor16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
215 
230 err_t dcmotor16_generic_read ( dcmotor16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
231 
232 
241 void dcmotor16_set_direction( dcmotor16_t *ctx, uint8_t dir );
242 
251 void dcmotor16_ctrl_fwd_pin( dcmotor16_t *ctx, uint8_t state );
252 
261 void dcmotor16_ctrl_rev_pin( dcmotor16_t *ctx, uint8_t state );
262 
271 void dcmotor16_ctrl_vref( dcmotor16_t *ctx, uint16_t value );
272 
281 
282 #ifdef __cplusplus
283 }
284 #endif
285 #endif // DCMOTOR16_H
286  // dcmotor16
288 
289 // ------------------------------------------------------------------------ END
dcmotor16_cfg_t
DC Motor 16 Click configuration object.
Definition: dcmotor16.h:139
dcmotor16_cfg_t::sck
pin_name_t sck
Definition: dcmotor16.h:143
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:141
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:153
dcmotor16_t
DC Motor 16 Click context object.
Definition: dcmotor16.h:122
dcmotor16_t::rev
digital_out_t rev
Definition: dcmotor16.h:125
dcmotor16_cfg_t::mosi
pin_name_t mosi
Definition: dcmotor16.h:142
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:148
dcmotor16_return_value_t
dcmotor16_return_value_t
DC Motor 16 Click return value data.
Definition: dcmotor16.h:162
DCMOTOR16_OK
@ DCMOTOR16_OK
Definition: dcmotor16.h:163
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:147
DCMOTOR16_ERROR
@ DCMOTOR16_ERROR
Definition: dcmotor16.h:164
dcmotor16_cfg_t::spi_speed
uint32_t spi_speed
Definition: dcmotor16.h:151
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:144
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:128
dcmotor16_t::chip_select
pin_name_t chip_select
Definition: dcmotor16.h:130
dcmotor16_t::fwd
digital_out_t fwd
Definition: dcmotor16.h:124
dcmotor16_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: dcmotor16.h:152
dcmotor16_ctrl_fwd_pin
void dcmotor16_ctrl_fwd_pin(dcmotor16_t *ctx, uint8_t state)
Control FWD pin.