1 /* Copyright (C) 2013, 2014 Czech Technical University in Prague
4 * - Carlos Jenkins <carlos@jenkins.co.cr>
6 * This document contains proprietary information belonging to Czech
7 * Technical University in Prague. Passing on and copying of this
8 * document, and communication of its contents is not permitted
9 * without prior written authorization.
13 * H-Bridge Output RPP API implementation file.
17 * RPP API documentation.
23 #if rppCONFIG_DRV == 1
24 #include "drv/hbridge.h"
27 static boolean_t initialized = FALSE;
35 #if rppCONFIG_DRV == 1
44 // Private function to set the H-Bridge to default OFF settings
45 static void rpp_hdr_reset()
47 #if rppCONFIG_DRV == 1
49 drv_hbr_pwm_set_duty(0);
56 static boolean_t enabled = FALSE;
58 int8_t rpp_hbr_enable(int32_t period)
65 period = 55; // ~18kHz (18181.818181818 Hz to be precise)
70 #if rppCONFIG_DRV == 1
73 if (drv_hbr_pwm_set_signal(period, 0) != SUCCESS) {
81 int ret = drv_hbr_wdg_start();
82 if (ret != SUCCESS && ret != -RPP_EBUSY) { // Don't fail if already started
93 int8_t rpp_hbr_control(double cmd)
99 // Check range of the command
100 if((cmd < -1.0) || (cmd > 1.0)) {
104 #if rppCONFIG_DRV == 1
105 // Great, now scale and return to sanity world of ints :D
106 int32_t scaled = (int32_t)(cmd * 100.0);
110 drv_hbr_set_dir(scaled > 0);
112 // Set PWM duty cycle
113 drv_hbr_pwm_set_duty(abs(scaled));
120 int8_t rpp_hbr_disable()
126 #if rppCONFIG_DRV == 1
129 // We ignore is watchdog could not be stopped, because is harmless.
130 // It would be worse if we just could not stop the H-Bridge just because
131 // the watchdog could not be stopped.