upm  0.3.1
Sensor/Actuator repository for libmraa (v0.7.2)
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 {
68  class GroveMD {
69 
70  public:
71  // GroveMD registers
72  typedef enum { SET_SPEED = 0x82,
73  SET_PWM_FREQ = 0x84,
74  SET_DIRECTION = 0xaa,
75  SET_MOTOR_A = 0xa1, // not documented
76  SET_MOTOR_B = 0xa5, // not documented
77  STEPPER_ENABLE = 0x1a,
78  STEPPER_DISABLE = 0x1b,
79  STEPPER_NUM_STEPS = 0x1c
80  } REG_T;
81 
82  // legal directions for the stepper
83  typedef enum { STEP_DIR_CCW = 0x0a,
84  STEP_DIR_CW = 0x05
85  } STEP_DIRECTION_T;
86 
87  // legal directions for individual DC motors
88  typedef enum { DIR_CCW = 0x02,
89  DIR_CW = 0x01
90  } DC_DIRECTION_T;
91 
98  GroveMD(int bus=GROVEMD_I2C_BUS,
99  uint8_t address=GROVEMD_DEFAULT_I2C_ADDR);
100 
104  ~GroveMD();
105 
114  bool writePacket(REG_T reg, uint8_t data1, uint8_t data2);
115 
124  bool setMotorSpeeds(uint8_t speedA, uint8_t speedB);
125 
135  bool setPWMFrequencyPrescale(uint8_t freq=0x03);
136 
144  bool setMotorDirections(DC_DIRECTION_T dirA, DC_DIRECTION_T dirB);
145 
154  bool enableStepper(STEP_DIRECTION_T dir, uint8_t speed);
155 
161  bool disableStepper();
162 
170  bool setStepperSteps(uint8_t steps);
171 
172 
173  private:
174  mraa_i2c_context m_i2c;
175  uint8_t m_addr;
176  };
177 }
178 
179 
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
API for the Grove I2C Motor Driver.
Definition: grovemd.h:68
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