upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
md.h
Go to the documentation of this file.
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2016 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <upm.h>
27 #include <mraa/i2c.h>
28 
29 #include "md_defs.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
46  typedef struct _md_context {
47  mraa_i2c_context i2c;
48 
49  // steps per revolution
50  int stepsPerRev;
51  int currentStep;
52  uint32_t stepDelay;
53  uint32_t totalSteps;
54  MD_STEP_MODE_T stepMode;
55 
56  // step direction: - 1 = forward, -1 = backward
57  int stepDirection;
58 
59  // initialized?
60  bool initialized;
61 
62  } *md_context;
63 
71  md_context md_init(int bus, uint8_t address);
72 
78  void md_close(md_context dev);
79 
89  bool md_write_packet(const md_context dev, MD_REG_T reg, uint8_t data1,
90  uint8_t data2);
91 
101  bool md_set_motor_speeds(const md_context dev, uint8_t speedA,
102  uint8_t speedB);
103 
114  bool md_set_pwm_frequency_prescale(const md_context dev, uint8_t freq);
115 
124  bool md_set_motor_directions(const md_context dev, MD_DC_DIRECTION_T dirA,
125  MD_DC_DIRECTION_T dirB);
126 
142  bool md_enable_stepper(const md_context dev, MD_STEP_DIRECTION_T dir,
143  uint8_t speed);
144 
151  bool md_disable_stepper(const md_context dev);
152 
165  bool md_set_stepper_steps(const md_context dev, unsigned int steps);
166 
180  void md_config_stepper(const md_context dev, unsigned int stepsPerRev,
181  MD_STEP_MODE_T mode);
182 
183 
184 #ifdef __cplusplus
185 }
186 #endif
void md_config_stepper(const md_context dev, unsigned int stepsPerRev, MD_STEP_MODE_T mode)
Definition: md.c:254
bool md_enable_stepper(const md_context dev, MD_STEP_DIRECTION_T dir, uint8_t speed)
Definition: md.c:179
struct _md_context * md_context
bool md_disable_stepper(const md_context dev)
Definition: md.c:221
bool md_set_motor_speeds(const md_context dev, uint8_t speedA, uint8_t speedB)
Definition: md.c:156
bool md_write_packet(const md_context dev, MD_REG_T reg, uint8_t data1, uint8_t data2)
Definition: md.c:129
Definition: md.h:46
void md_close(md_context dev)
Definition: md.c:113
bool md_set_pwm_frequency_prescale(const md_context dev, uint8_t freq)
Definition: md.c:163
md_context md_init(int bus, uint8_t address)
Definition: md.c:60
bool md_set_stepper_steps(const md_context dev, unsigned int steps)
Definition: md.c:233
bool md_set_motor_directions(const md_context dev, MD_DC_DIRECTION_T dirA, MD_DC_DIRECTION_T dirB)
Definition: md.c:170