upm  0.2.0
Sensor/Actuator repository for libmraa (v0.6.1)
grovemd.h
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2014 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 <string>
27 #include <mraa/i2c.h>
28 
29 #define GROVEMD_I2C_BUS 0
30 #define GROVEMD_DEFAULT_I2C_ADDR 0x0f
31 
32 // This is a NOOP value used to pad packets
33 #define GROVEMD_NOOP 0x01
34 
35 namespace upm {
67  class GroveMD {
68 
69  public:
70  // GroveMD registers
71  typedef enum { SET_SPEED = 0x82,
72  SET_PWM_FREQ = 0x84,
73  SET_DIRECTION = 0xaa,
74  SET_MOTOR_A = 0xa1, // not documented
75  SET_MOTOR_B = 0xa5, // not documented
76  STEPPER_ENABLE = 0x1a,
77  STEPPER_DISABLE = 0x1b,
78  STEPPER_NUM_STEPS = 0x1c
79  } REG_T;
80 
81  // legal directions for the stepper
82  typedef enum { STEP_DIR_CCW = 0x0a,
83  STEP_DIR_CW = 0x05
84  } STEP_DIRECTION_T;
85 
86  // legal directions for individual DC motors
87  typedef enum { DIR_CCW = 0x02,
88  DIR_CW = 0x01
89  } DC_DIRECTION_T;
90 
97  GroveMD(int bus=GROVEMD_I2C_BUS,
98  uint8_t address=GROVEMD_DEFAULT_I2C_ADDR);
99 
103  ~GroveMD();
104 
113  bool writePacket(REG_T reg, uint8_t data1, uint8_t data2);
114 
123  bool setMotorSpeeds(uint8_t speedA, uint8_t speedB);
124 
134  bool setPWMFrequencyPrescale(uint8_t freq=0x03);
135 
143  bool setMotorDirections(DC_DIRECTION_T dirA, DC_DIRECTION_T dirB);
144 
153  bool enableStepper(STEP_DIRECTION_T dir, uint8_t speed);
154 
160  bool disableStepper();
161 
169  bool setStepperSteps(uint8_t steps);
170 
171 
172  private:
173  mraa_i2c_context m_i2c;
174  uint8_t m_addr;
175  };
176 }
177 
178 
bool setStepperSteps(uint8_t steps)
Definition: grovemd.cxx:127
bool enableStepper(STEP_DIRECTION_T dir, uint8_t speed)
Definition: grovemd.cxx:117
bool disableStepper()
Definition: grovemd.cxx:122
C++ API for the Grove I2C Motor Driver.
Definition: grovemd.h:67
bool setMotorSpeeds(uint8_t speedA, uint8_t speedB)
Definition: grovemd.cxx:101
bool writePacket(REG_T reg, uint8_t data1, uint8_t data2)
Definition: grovemd.cxx:68
bool setPWMFrequencyPrescale(uint8_t freq=0x03)
Definition: grovemd.cxx:106
Definition: a110x.h:29
bool setMotorDirections(DC_DIRECTION_T dirA, DC_DIRECTION_T dirB)
Definition: grovemd.cxx:111
~GroveMD()
Definition: grovemd.cxx:62
GroveMD(int bus=GROVEMD_I2C_BUS, uint8_t address=GROVEMD_DEFAULT_I2C_ADDR)
Definition: grovemd.cxx:35