Statistics
| Branch: | Tag: | Revision:

amiro-lld / source / alld_pklcs1212e4001.c @ 8c47f14b

History | View | Annotate | Download (2.61 KB)

1
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  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 Lesser 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 Lesser General Public License for more details.
14

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

    
19
/**
20
 * @file    alld_pklcs1212e4001.c
21
 * @brief   Buzzer function implementations.
22
 *
23
 * @addtogroup lld_buzzer
24
 * @{
25
 */
26

    
27
#include <alld_pklcs1212e4001.h>
28

    
29
#if defined(AMIROLLD_CFG_USE_PKLCS1212E4001) || defined(__DOXYGEN__)
30

    
31
/**
32
 * @brief Check the configuration of the PWM for the correct frequency.
33
 * @param[in] pwm   The PWM driver to check.
34
 * @return  The return status indicates whether the function call was successful.
35
 */
36
inline apalExitStatus_t
37
pklcs1212e4001_lld_checkPWMconfiguration(apalPWMDriver_t* pwm)
38
{
39
  apalDbgAssert(pwm != NULL);
40

    
41
  apalPWMfrequency_t frequency = 0;
42
  apalPWMperiod_t period = 0;
43
  apalExitStatus_t status = apalPWMGetFrequency(pwm, &frequency);
44
  status |= apalPWMGetPeriod(pwm, &period);
45
  if (frequency / period == PKLCS1212E4001_LLD_FREQUENCY_SPEC) {
46
    status |= APAL_STATUS_OK;
47
  } else if (frequency / period >= PKLCS1212E4001_LLD_FREQUENCY_MIN &&
48
             frequency / period <= PKLCS1212E4001_LLD_FREQUENCY_MAX) {
49
    status |= APAL_STATUS_WARNING;
50
  } else {
51
    status |= APAL_STATUS_INVALIDARGUMENTS;
52
  }
53

    
54
  return status;
55
}
56

    
57
/**
58
 * @brief Turns the buzzer on or off.
59
 * @param[in] pwm       The PWM driver to use
60
 * @param[in] channel   The PWM channel to enable/disable.
61
 * @param[in] enable    Specifies whether the buzzer shall be turned on (true) or off (false).
62
 * @return  The return status indicates whether the function call was successful.
63
 */
64
inline apalExitStatus_t
65
pklcs1212e4001_lld_enable(apalPWMDriver_t* pwm, const apalPWMchannel_t channel, const bool enable)
66
{
67
  apalDbgAssert(pwm != NULL);
68

    
69
  if (enable) {
70
    apalPWMperiod_t period = 0;
71
    apalExitStatus_t status = apalPWMGetFrequency(pwm, &period);
72
    status |= apalPWMSet(pwm, channel, period/2);
73
    return status;
74
  } else {
75
    return apalPWMSet(pwm, channel, 0);
76
  }
77
}
78

    
79
#endif /* defined(AMIROLLD_CFG_USE_PKLCS1212E4001) */
80

    
81
/** @} */