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 #ifndef FREERTOS_POSIX
24 #include "drv/hbridge.h"
27 static boolean_t initialized = FALSE;
34 #ifndef FREERTOS_POSIX
43 // Private function to set the H-Bridge to default OFF settings
44 static void rpp_hdr_reset()
46 #ifndef FREERTOS_POSIX
48 drv_hbr_pwm_set_duty(0);
55 static boolean_t enabled = FALSE;
57 int8_t rpp_hbr_enable(int32_t period)
63 period = 55; // ~18kHz (18181.818181818 Hz to be precise)
67 #ifndef FREERTOS_POSIX
70 if (drv_hbr_pwm_set_signal(period, 0) != SUCCESS)
77 int ret = drv_hbr_wdg_start();
78 if (ret != SUCCESS && ret != -RPP_EBUSY) // Don't fail if already started
89 int8_t rpp_hbr_control(double cmd)
94 // Check range of the command
95 if ((cmd < -1.0) || (cmd > 1.0))
98 #ifndef FREERTOS_POSIX
99 // Great, now scale and return to sanity world of ints :D
100 int32_t scaled = (int32_t)(cmd * 100.0);
104 drv_hbr_set_dir(scaled > 0);
106 // Set PWM duty cycle
107 drv_hbr_pwm_set_duty(abs(scaled));
114 int8_t rpp_hbr_disable()
119 #ifndef FREERTOS_POSIX
122 // We ignore is watchdog could not be stopped, because is harmless.
123 // It would be worse if we just could not stop the H-Bridge just because
124 // the watchdog could not be stopped.