Statistics
| Branch: | Tag: | Revision:

amiro-lld / source / alld_pklcs1212e4001.c @ d6728c5b

History | View | Annotate | Download (2.454 KB)

1
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2018  Thomas Schöpping et al.
4

5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14

15
You should have received a copy of the GNU General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18

    
19
#include <alld_pklcs1212e4001.h>
20

    
21
#if defined(AMIROLLD_CFG_USE_PKLCS1212E4001) || defined(__DOXYGEN__)
22

    
23
/**
24
 * @brief Check the configuration of the PWM for the correct frequency.
25
 * @param[in] pwm   The PWM driver to check.
26
 * @return  The return status indicates whether the function call was successful.
27
 */
28
inline apalExitStatus_t
29
pklcs1212e4001_lld_checkPWMconfiguration(apalPWMDriver_t* pwm)
30
{
31
  apalDbgAssert(pwm != NULL);
32

    
33
  apalPWMfrequency_t frequency = 0;
34
  apalPWMperiod_t period = 0;
35
  apalExitStatus_t status = apalPWMGetFrequency(pwm, &frequency);
36
  status |= apalPWMGetPeriod(pwm, &period);
37
  if (frequency / period == PKLCS1212E4001_LLD_FREQUENCY_SPEC) {
38
    status |= APAL_STATUS_OK;
39
  } else if (frequency / period >= PKLCS1212E4001_LLD_FREQUENCY_MIN &&
40
             frequency / period <= PKLCS1212E4001_LLD_FREQUENCY_MAX) {
41
    status |= APAL_STATUS_WARNING;
42
  } else {
43
    status |= APAL_STATUS_INVALIDARGUMENTS;
44
  }
45

    
46
  return status;
47
}
48

    
49
/**
50
 * @brief Turns the buzzer on or off.
51
 * @param[in] pwm       The PWM driver to use
52
 * @param[in] channel   The PWM channel to enable/disable.
53
 * @param[in] enable    Specifies whether the buzzer shall be turned on (true) or off (false).
54
 * @return  The return status indicates whether the function call was successful.
55
 */
56
inline apalExitStatus_t
57
pklcs1212e4001_lld_enable(apalPWMDriver_t* pwm, const apalPWMchannel_t channel, const bool enable)
58
{
59
  apalDbgAssert(pwm != NULL);
60

    
61
  if (enable) {
62
    apalPWMperiod_t period = 0;
63
    apalExitStatus_t status = apalPWMGetFrequency(pwm, &period);
64
    status |= apalPWMSet(pwm, channel, period/2);
65
    return status;
66
  } else {
67
    return apalPWMSet(pwm, channel, 0);
68
  }
69
}
70

    
71
#endif /* defined(AMIROLLD_CFG_USE_PKLCS1212E4001) */