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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define DCMOTOR16_DIR_FORWARD 0
61 #define DCMOTOR16_DIR_BACKWARD 1
62 
63 #define DCMOTOR16_ENABLE 1
64 #define DCMOTOR16_DISABLE 0
65 
73 #define DCMOTOR16_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
74 #define DCMOTOR16_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
75  // dcmotor16_set
77 
92 #define DCMOTOR16_MAP_MIKROBUS( cfg, mikrobus ) \
93  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
94  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
95  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
96  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
97  cfg.fwd = MIKROBUS( mikrobus, MIKROBUS_RST ); \
98  cfg.rev = MIKROBUS( mikrobus, MIKROBUS_PWM )
99  // dcmotor16_map // dcmotor16
102 
107 typedef struct
108 {
109  // Output pins
110  digital_out_t fwd;
111  digital_out_t rev;
113  // Modules
114  spi_master_t spi;
116  pin_name_t chip_select;
118 } dcmotor16_t;
119 
124 typedef struct
125 {
126  // Communication gpio pins
127  pin_name_t miso;
128  pin_name_t mosi;
129  pin_name_t sck;
130  pin_name_t cs;
132  // Additional gpio pins
133  pin_name_t fwd;
134  pin_name_t rev;
136  // static variable
137  uint32_t spi_speed;
138  spi_master_mode_t spi_mode;
139  spi_master_chip_select_polarity_t cs_polarity;
142 
147 typedef enum
148 {
151 
153 
170 
184 err_t dcmotor16_init ( dcmotor16_t *ctx, dcmotor16_cfg_t *cfg );
185 
200 err_t dcmotor16_generic_write ( dcmotor16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
201 
216 err_t dcmotor16_generic_read ( dcmotor16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
217 
218 
227 void dcmotor16_set_direction( dcmotor16_t *ctx, uint8_t dir );
228 
237 void dcmotor16_ctrl_fwd_pin( dcmotor16_t *ctx, uint8_t state );
238 
247 void dcmotor16_ctrl_rev_pin( dcmotor16_t *ctx, uint8_t state );
248 
257 void dcmotor16_ctrl_vref( dcmotor16_t *ctx, uint16_t value );
258 
266 void dcmotor16_stop( dcmotor16_t *ctx );
267 
268 #ifdef __cplusplus
269 }
270 #endif
271 #endif // DCMOTOR16_H
272  // dcmotor16
274 
275 // ------------------------------------------------------------------------ END
dcmotor16_cfg_t
DC Motor 16 Click configuration object.
Definition: dcmotor16.h:124
dcmotor16_cfg_t::sck
pin_name_t sck
Definition: dcmotor16.h:129
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:127
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:139
dcmotor16_t
DC Motor 16 Click context object.
Definition: dcmotor16.h:107
dcmotor16_t::rev
digital_out_t rev
Definition: dcmotor16.h:111
dcmotor16_cfg_t::mosi
pin_name_t mosi
Definition: dcmotor16.h:128
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:134
dcmotor16_return_value_t
dcmotor16_return_value_t
DC Motor 16 Click return value data.
Definition: dcmotor16.h:147
DCMOTOR16_OK
Definition: dcmotor16.h:149
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:133
DCMOTOR16_ERROR
Definition: dcmotor16.h:150
dcmotor16_cfg_t::spi_speed
uint32_t spi_speed
Definition: dcmotor16.h:137
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:130
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:114
dcmotor16_t::chip_select
pin_name_t chip_select
Definition: dcmotor16.h:116
dcmotor16_t::fwd
digital_out_t fwd
Definition: dcmotor16.h:110
dcmotor16_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: dcmotor16.h:138
dcmotor16_ctrl_fwd_pin
void dcmotor16_ctrl_fwd_pin(dcmotor16_t *ctx, uint8_t state)
Control FWD pin.