Statistics
| Branch: | Tag: | Revision:

amiro-lld / drivers / PKxxxExxx / v1 / alld_PKxxxExxx.c @ 23ab29c0

History | View | Annotate | Download (4.446 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_PKxxxExxx.c
21
 * @brief   Buzzer function implementations.
22
 *
23
 * @addtogroup lld_buzzer
24
 * @{
25
 */
26

    
27
#include <alld_PKxxxExxx.h>
28

    
29
/******************************************************************************/
30
/* LOCAL DEFINITIONS                                                          */
31
/******************************************************************************/
32

    
33
/******************************************************************************/
34
/* EXPORTED VARIABLES                                                         */
35
/******************************************************************************/
36

    
37
/******************************************************************************/
38
/* LOCAL TYPES                                                                */
39
/******************************************************************************/
40

    
41
/******************************************************************************/
42
/* LOCAL VARIABLES                                                            */
43
/******************************************************************************/
44

    
45
/******************************************************************************/
46
/* LOCAL FUNCTIONS                                                            */
47
/******************************************************************************/
48

    
49
/******************************************************************************/
50
/* EXPORTED FUNCTIONS                                                         */
51
/******************************************************************************/
52

    
53
/**
54
 * @brief Check the configuration of the PWM for the correct frequency.
55
 * @param[in] pwm   The PWM driver to check.
56
 * @return  The return status indicates whether the function call was successful.
57
 */
58
apalExitStatus_t pkxxxexxx_lld_checkPWMconfiguration(apalPWMDriver_t* pwm)
59
{
60
  apalDbgAssert(pwm != NULL);
61

    
62
  apalPWMfrequency_t frequency = 0;
63
  apalPWMperiod_t period = 0;
64
  apalExitStatus_t status = apalPWMGetFrequency(pwm, &frequency);
65
  status |= apalPWMGetPeriod(pwm, &period);
66
  if (frequency / period == PKxxxExxx_LLD_FREQUENCY_SPEC) {
67
    status |= APAL_STATUS_OK;
68
  }
69
#if defined(PKxxxExxx_LLD_FREQUENCY_MIN) && !defined(PKxxxExxx_LLD_FREQUENCY_MAX)
70
  else if (frequency / period >= PKxxxExxx_LLD_FREQUENCY_MIN &&
71
           frequency / period <= PKxxxExxx_LLD_FREQUENCY_SPEC) {
72
    status |= APAL_STATUS_WARNING;
73
  }
74
#elif !defined(PKxxxExxx_LLD_FREQUENCY_MIN) && defined(PKxxxExxx_LLD_FREQUENCY_MAX)
75
  else if (frequency / period >= PKxxxExxx_LLD_FREQUENCY_SPEC &&
76
           frequency / period <= PKxxxExxx_LLD_FREQUENCY_MAX) {
77
    status |= APAL_STATUS_WARNING;
78
  }
79
#elif defined(PKxxxExxx_LLD_FREQUENCY_MIN) && defined(PKxxxExxx_LLD_FREQUENCY_MAX)
80
  else if (frequency / period >= PKxxxExxx_LLD_FREQUENCY_MIN &&
81
           frequency / period <= PKxxxExxx_LLD_FREQUENCY_MAX) {
82
    status |= APAL_STATUS_WARNING;
83
  }
84
#endif
85
  else {
86
    status |= APAL_STATUS_INVALIDARGUMENTS;
87
  }
88

    
89
  return status;
90
}
91

    
92
/**
93
 * @brief Turns the buzzer on or off.
94
 * @param[in] pwm       The PWM driver to use
95
 * @param[in] channel   The PWM channel to enable/disable.
96
 * @param[in] enable    Specifies whether the buzzer shall be turned on (true) or off (false).
97
 * @return  The return status indicates whether the function call was successful.
98
 */
99
apalExitStatus_t pkxxxexxx_lld_enable(apalPWMDriver_t* pwm, const apalPWMchannel_t channel, const bool enable)
100
{
101
  apalDbgAssert(pwm != NULL);
102

    
103
  if (enable) {
104
    apalPWMperiod_t period = 0;
105
    apalExitStatus_t status = apalPWMGetFrequency(pwm, &period);
106
    status |= apalPWMSet(pwm, channel, period/2);
107
    return status;
108
  } else {
109
    return apalPWMSet(pwm, channel, 0);
110
  }
111
}
112

    
113
/** @} */
114