81 lines
1.5 KiB
C
81 lines
1.5 KiB
C
#pragma once
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* Includes ----------------------------------------------------------------- */
|
|
#include "device.h"
|
|
#include "bsp/pwm.h"
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
/* USER INCLUDE BEGIN */
|
|
|
|
/* USER INCLUDE END */
|
|
|
|
/* Exported constants ------------------------------------------------------- */
|
|
|
|
/* USER DEFINE BEGIN */
|
|
|
|
/* USER DEFINE END */
|
|
|
|
/* Exported types ----------------------------------------------------------- */
|
|
|
|
typedef enum {
|
|
NOTE_C = 0,
|
|
NOTE_CS = 1, // C#
|
|
NOTE_D = 2,
|
|
NOTE_DS = 3, // D#
|
|
NOTE_E = 4,
|
|
NOTE_F = 5,
|
|
NOTE_FS = 6, // F#
|
|
NOTE_G = 7,
|
|
NOTE_GS = 8, // G#
|
|
NOTE_A = 9,
|
|
NOTE_AS = 10, // A#
|
|
NOTE_B = 11,
|
|
NOTE_REST = 255 // 休止符
|
|
} NOTE_t;
|
|
|
|
typedef struct {
|
|
NOTE_t note; // 音符名称
|
|
uint8_t octave; // 八度
|
|
uint16_t duration_ms; // 持续时间,单位毫秒
|
|
} Tone_t;
|
|
|
|
typedef enum {
|
|
MUSIC_RM,
|
|
MUSIC_NOKIA,
|
|
} MUSIC_t;
|
|
|
|
|
|
typedef struct {
|
|
DEVICE_Header_t header;
|
|
BSP_PWM_Channel_t channel;
|
|
} BUZZER_t;
|
|
|
|
/* USER STRUCT BEGIN */
|
|
|
|
/* USER STRUCT END */
|
|
|
|
/* Exported functions prototypes -------------------------------------------- */
|
|
|
|
int8_t BUZZER_Init(BUZZER_t *buzzer, BSP_PWM_Channel_t channel);
|
|
|
|
int8_t BUZZER_Start(BUZZER_t *buzzer);
|
|
|
|
int8_t BUZZER_Stop(BUZZER_t *buzzer);
|
|
|
|
int8_t BUZZER_Set(BUZZER_t *buzzer, float freq, float duty_cycle);
|
|
|
|
int8_t BUZZER_PlayMusic(BUZZER_t *buzzer, MUSIC_t music);
|
|
|
|
/* USER FUNCTION BEGIN */
|
|
|
|
/* USER FUNCTION END */
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|