git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@409 05563f52-14a8-4384-a975-3d1654cca0fa
168 lines
5.2 KiB
C
168 lines
5.2 KiB
C
// -----------------------------------------------------------------------------
|
|
/// @file Buzzer.h
|
|
/// @brief File description
|
|
// -----------------------------------------------------------------------------
|
|
// Micro-Key bv
|
|
// Industrieweg 28, 9804 TG Noordhorn
|
|
// Postbus 92, 9800 AB Zuidhorn
|
|
// The Netherlands
|
|
// Tel: +31 594 503020
|
|
// Fax: +31 594 505825
|
|
// Email: support@microkey.nl
|
|
// Web: www.microkey.nl
|
|
// -----------------------------------------------------------------------------
|
|
/// $Revision$
|
|
/// $Author$
|
|
/// $Date$
|
|
// (c) 2015 Micro-Key bv
|
|
// -----------------------------------------------------------------------------
|
|
|
|
/// @defgroup {group_name} {group_description}
|
|
/// Description
|
|
|
|
/// @file Buzzer.h
|
|
/// @ingroup {group_name}
|
|
|
|
#ifndef INC_BUZZER_H_
|
|
#define INC_BUZZER_H_
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// Include files
|
|
// -----------------------------------------------------------------------------
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include "FreeRTOS.h"
|
|
#include "task.h"
|
|
#include "semphr.h"
|
|
|
|
#include "stm32f10x.h"
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// Constant and macro definitions
|
|
// -----------------------------------------------------------------------------
|
|
|
|
#define BUZZER_MIN_PULSEWIDTH_MS (10)
|
|
#define BUZZER_KEYPAD_PULSEWIDTH_MS (60)
|
|
#define BUZZER_ERROR_PULSEWIDTH_MS (1000)
|
|
#define BUZZER_WARNING_PULSEWIDTH_MS (250)
|
|
|
|
#define BUZZER_KEYPAD_ACKNOWLEDGE(self) \
|
|
Buzzer_singleTone(self, BUZZER_KEYPAD_PULSEWIDTH_MS)
|
|
|
|
#define BUZZER_ERROR(self) \
|
|
Buzzer_start(self, BUZZER_ERROR_PULSEWIDTH_MS)
|
|
|
|
#define BUZZER_WARNING(self) \
|
|
Buzzer_start(self, BUZZER_WARNING_PULSEWIDTH_MS)
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// Type definitions.
|
|
// -----------------------------------------------------------------------------
|
|
|
|
struct Buzzer
|
|
{
|
|
// General
|
|
bool initialized;
|
|
struct Gpio* gpio;
|
|
// Functionary properties
|
|
unsigned int pulseWidth;
|
|
// Task properties
|
|
bool runTask;
|
|
bool runPeriodically;
|
|
SemaphoreHandle_t semaphore;
|
|
xTaskHandle taskHandle;
|
|
int taskPriority;
|
|
uint16_t stackSize;
|
|
};
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// Function declarations
|
|
// -----------------------------------------------------------------------------
|
|
|
|
/** ----------------------------------------------------------------------------
|
|
* Buzzer_construct
|
|
* Constructor for a new buzzer instance
|
|
*
|
|
* @param self The buzzer object that gets created
|
|
* @param gpio The GPIO to use
|
|
* @param taskPriority FreeRTOS task priority
|
|
* @param stackSize FreeRTOS stack size
|
|
*
|
|
* @return ErrorStatus SUCCESS if constructor was successful,
|
|
* including generation/start of task
|
|
* ERROR otherwise
|
|
*
|
|
* @todo
|
|
* -----------------------------------------------------------------------------
|
|
*/
|
|
extern ErrorStatus Buzzer_construct(struct Buzzer* self, struct Gpio* gpio, int taskPriority, uint16_t stackSize);
|
|
|
|
|
|
/** ----------------------------------------------------------------------------
|
|
* Buzzer_destruct
|
|
* Destructor for buzzer instance. Also removes the buzzer task
|
|
*
|
|
* @param self The buzzer instance to destruct
|
|
*
|
|
* @return void
|
|
*
|
|
* @todo
|
|
* -----------------------------------------------------------------------------
|
|
*/
|
|
extern void Buzzer_destruct(struct Buzzer* self);
|
|
|
|
|
|
/** ----------------------------------------------------------------------------
|
|
* Buzzer_start
|
|
* Starts the buzzer with a repeating tone.
|
|
* Tone length is given with argument pulseWidth
|
|
*
|
|
* @param self The buzzer instance to use
|
|
* @param pulseWidth The length of the tone in ms. Also defines
|
|
* the length of the pause between two
|
|
* tones
|
|
*
|
|
* @return void
|
|
*
|
|
* @todo
|
|
* -----------------------------------------------------------------------------
|
|
*/
|
|
extern void Buzzer_start(struct Buzzer* self, unsigned int pulseWidth);
|
|
|
|
|
|
/** ----------------------------------------------------------------------------
|
|
* Buzzer_stop
|
|
* Stops the repeating buzzer tone
|
|
*
|
|
* @param self THe buzzer instance to stop
|
|
*
|
|
* @return void
|
|
*
|
|
* @todo
|
|
* -----------------------------------------------------------------------------
|
|
*/
|
|
extern void Buzzer_stop(struct Buzzer* self);
|
|
|
|
|
|
/** ----------------------------------------------------------------------------
|
|
* Buzzer_singleTone
|
|
* Creates a single tone with the length given in pulseWidth
|
|
*
|
|
* @param self The buzzer instance to use
|
|
* @param pulseWidth The length of the tone in ms
|
|
*
|
|
* @return void
|
|
*
|
|
* @todo
|
|
* -----------------------------------------------------------------------------
|
|
*/
|
|
extern void Buzzer_singleTone(struct Buzzer* self, unsigned int pulseWidth);
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* INC_BUZZER_H_ */
|