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
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
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
90 // 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
114 // dcmotor16_map
115 // dcmotor16
116
121typedef 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;
133
138typedef 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
167
184
199
214err_t dcmotor16_generic_write ( dcmotor16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
215
230err_t dcmotor16_generic_read ( dcmotor16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
231
232
241void dcmotor16_set_direction( dcmotor16_t *ctx, uint8_t dir );
242
251void dcmotor16_ctrl_fwd_pin( dcmotor16_t *ctx, uint8_t state );
252
261void dcmotor16_ctrl_rev_pin( dcmotor16_t *ctx, uint8_t state );
262
271void dcmotor16_ctrl_vref( dcmotor16_t *ctx, uint16_t value );
272
281
282#ifdef __cplusplus
283}
284#endif
285#endif // DCMOTOR16_H
286
287 // dcmotor16
288
289// ------------------------------------------------------------------------ END
dcmotor16_return_value_t
DC Motor 16 Click return value data.
Definition dcmotor16.h:162
@ DCMOTOR16_OK
Definition dcmotor16.h:163
@ DCMOTOR16_ERROR
Definition dcmotor16.h:164
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:139
spi_master_chip_select_polarity_t cs_polarity
Definition dcmotor16.h:153
pin_name_t sck
Definition dcmotor16.h:143
spi_master_mode_t spi_mode
Definition dcmotor16.h:152
pin_name_t mosi
Definition dcmotor16.h:142
uint32_t spi_speed
Definition dcmotor16.h:151
pin_name_t miso
Definition dcmotor16.h:141
pin_name_t fwd
Definition dcmotor16.h:147
pin_name_t rev
Definition dcmotor16.h:148
pin_name_t cs
Definition dcmotor16.h:144
DC Motor 16 Click context object.
Definition dcmotor16.h:122
spi_master_t spi
Definition dcmotor16.h:128
pin_name_t chip_select
Definition dcmotor16.h:130
digital_out_t fwd
Definition dcmotor16.h:124
digital_out_t rev
Definition dcmotor16.h:125