DRV8830/Texas Instruments H-Bridge Voltage-Controlled Motor Driver library for Brushed DC Motor
Dependents: NucleoF401_motor_test_simple Frequency_Counter_w_GPS_1PPS Nucleo_ACM1602_I2C_DC_Angle Frequency_Cntr_1PPS_F746ZG
Revision 4:323a62f5fff3, committed 2017-08-23
- Comitter:
- kenjiArai
- Date:
- Wed Aug 23 09:24:05 2017 +0000
- Parent:
- 3:98a9369ed390
- Commit message:
- countermeasure for NonCopyable
Changed in this revision
DRV8830.cpp | Show annotated file Show diff for this revision Revisions of this file |
DRV8830.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 98a9369ed390 -r 323a62f5fff3 DRV8830.cpp --- a/DRV8830.cpp Tue Dec 23 23:28:54 2014 +0000 +++ b/DRV8830.cpp Wed Aug 23 09:24:05 2017 +0000 @@ -3,17 +3,11 @@ * Texas Instruments / DRV8830 H-Bridge Voltage-Controlled Motor Driver * http://www.ti.com/product/drv8830 * - * Copyright (c) 2014 Kenji Arai / JH1PJL + * Copyright (c) 2014,'17 Kenji Arai / JH1PJL * http://www.page.sannet.ne.jp/kenjia/index.html * http://mbed.org/users/kenjiArai/ - * Created: August 6th, 2014 - * Revised: November 28th, 2014 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE - * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * Created: August 6th, 2014 + * Revised: August 23rd, 2017 */ #include "mbed.h" @@ -70,11 +64,15 @@ 4.98, 5.06 }; -DRV8830::DRV8830 (PinName p_sda, PinName p_scl, uint8_t addr) : i2c(p_sda, p_scl){ +DRV8830::DRV8830 (PinName p_sda, PinName p_scl, uint8_t addr) + : _i2c_p(new I2C(p_sda, p_scl)), _i2c(*_i2c_p) +{ DRV8830_addr = (char)addr; } -DRV8830::DRV8830 (I2C& p_i2c, uint8_t addr) : i2c(p_i2c){ +DRV8830::DRV8830 (I2C& p_i2c, uint8_t addr) + : _i2c(p_i2c) +{ DRV8830_addr = (char)addr; } @@ -101,7 +99,7 @@ } dt[0] = DRV8830_CONTROL; dt[1] = (pwm_rate << 2) + direction; - i2c.write((int)DRV8830_addr, (char *)dt, 2); + _i2c.write((int)DRV8830_addr, (char *)dt, 2); } void DRV8830::set_voltage(float volt) { @@ -134,15 +132,15 @@ //printf("volt=%f, pwm=0x%x, dir=%d\r\n", volt, pwm_rate, direction); dt[0] = DRV8830_CONTROL; dt[1] = (pwm_rate << 2) + direction; - i2c.write((int)DRV8830_addr, (char *)dt, 2); + _i2c.write((int)DRV8830_addr, (char *)dt, 2); } uint8_t DRV8830::status() { uint8_t dt[2]; dt[0] = DRV8830_FAULT; - i2c.write((int)DRV8830_addr, (char *)dt, 1); // write register address - i2c.read((int)DRV8830_addr, (char *)dt, 1); // read register content + _i2c.write((int)DRV8830_addr, (char *)dt, 1); // write register address + _i2c.read((int)DRV8830_addr, (char *)dt, 1); // read register content return dt[0]; } @@ -151,6 +149,8 @@ dt[0] = DRV8830_FAULT; dt[1] = DRV8830_F_CLEAR; - i2c.write((int)DRV8830_addr, (char *)dt, 2); + _i2c.write((int)DRV8830_addr, (char *)dt, 2); } + +
diff -r 98a9369ed390 -r 323a62f5fff3 DRV8830.h --- a/DRV8830.h Tue Dec 23 23:28:54 2014 +0000 +++ b/DRV8830.h Wed Aug 23 09:24:05 2017 +0000 @@ -3,17 +3,11 @@ * Texas Instruments / DRV8830 H-Bridge Voltage-Controlled Motor Driver * http://www.ti.com/product/drv8830 * - * Copyright (c) 2014 Kenji Arai / JH1PJL + * Copyright (c) 2014,'17 Kenji Arai / JH1PJL * http://www.page.sannet.ne.jp/kenjia/index.html * http://mbed.org/users/kenjiArai/ - * Created: August 6th, 2014 - * Revised: November 24th, 2014 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE - * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * Created: August 6th, 2014 + * Revised: August 23rd, 2017 */ #ifndef MBED_DRV8830 @@ -111,10 +105,12 @@ void reset(); protected: - I2C i2c; + I2C *_i2c_p; + I2C &_i2c; private: char DRV8830_addr; }; #endif // MBED_DRV8830 +