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
32extern "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
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
107typedef 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;
119
124typedef 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
147typedef enum
148{
150 DCMOTOR16_ERROR = -1
151
153
170
185
200err_t dcmotor16_generic_write ( dcmotor16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
201
216err_t dcmotor16_generic_read ( dcmotor16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
217
218
227void dcmotor16_set_direction( dcmotor16_t *ctx, uint8_t dir );
228
237void dcmotor16_ctrl_fwd_pin( dcmotor16_t *ctx, uint8_t state );
238
247void dcmotor16_ctrl_rev_pin( dcmotor16_t *ctx, uint8_t state );
248
257void dcmotor16_ctrl_vref( dcmotor16_t *ctx, uint16_t value );
258
267
268#ifdef __cplusplus
269}
270#endif
271#endif // DCMOTOR16_H
272 // dcmotor16
274
275// ------------------------------------------------------------------------ END
dcmotor16_return_value_t
DC Motor 16 Click return value data.
Definition: dcmotor16.h:148
@ DCMOTOR16_OK
Definition: dcmotor16.h:149
@ DCMOTOR16_ERROR
Definition: dcmotor16.h:150
void dcmotor16_ctrl_rev_pin(dcmotor16_t *ctx, uint8_t state)
Control REV pin.
void dcmotor16_ctrl_fwd_pin(dcmotor16_t *ctx, uint8_t state)
Control FWD pin.
void dcmotor16_cfg_setup(dcmotor16_cfg_t *cfg)
DC Motor 16 configuration object setup function.
void dcmotor16_ctrl_vref(dcmotor16_t *ctx, uint16_t value)
Control motor VRef (speed).
void dcmotor16_set_direction(dcmotor16_t *ctx, uint8_t dir)
Set motor direction.
err_t dcmotor16_generic_read(dcmotor16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
DC Motor 16 data reading function.
err_t dcmotor16_generic_write(dcmotor16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
DC Motor 16 data writing function.
void dcmotor16_stop(dcmotor16_t *ctx)
Motor stop.
err_t dcmotor16_init(dcmotor16_t *ctx, dcmotor16_cfg_t *cfg)
DC Motor 16 initialization function.
This file contains SPI specific macros, functions, etc.
DC Motor 16 Click configuration object.
Definition: dcmotor16.h:125
spi_master_chip_select_polarity_t cs_polarity
Definition: dcmotor16.h:139
pin_name_t sck
Definition: dcmotor16.h:129
spi_master_mode_t spi_mode
Definition: dcmotor16.h:138
pin_name_t mosi
Definition: dcmotor16.h:128
uint32_t spi_speed
Definition: dcmotor16.h:137
pin_name_t miso
Definition: dcmotor16.h:127
pin_name_t fwd
Definition: dcmotor16.h:133
pin_name_t rev
Definition: dcmotor16.h:134
pin_name_t cs
Definition: dcmotor16.h:130
DC Motor 16 Click context object.
Definition: dcmotor16.h:108
spi_master_t spi
Definition: dcmotor16.h:114
pin_name_t chip_select
Definition: dcmotor16.h:116
digital_out_t fwd
Definition: dcmotor16.h:110
digital_out_t rev
Definition: dcmotor16.h:111