kernel/drivers/bios_speaker.c (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#include "drivers/speaker.h"
#include "pit.h"
#include "assembly.h"
#include <stdint.h>
/*!
* Initializes the bios speaker.
* \return 1 on success, 0 on failure
*/
int bios_sp_init(void);
/*!
* Sets the current frequency of the bios speaker.
* \param freq Frequency to by output by the bios speaker.
* \param volume Volume of the sound.
* \return 1 on success, 0 on failure.
*/
int bios_sp_make_sound(uint32_t freq, uint32_t volume);
/*!
* Mutes the bios speaker.
* \return 1 on success, 0 on failure.
*/
int bios_sp_mute();
//! Driver for the bios speaker.
SPEAKER_DRIVER bios_sp = {
bios_sp_init,
bios_sp_make_sound,
bios_sp_mute
};
int bios_sp_init(void) {
bios_sp_mute();
return 1;
}
int bios_sp_make_sound(uint32_t freq, uint32_t volume) {
/**
* volume for the bios speaker:
* - 0: mute
* - other: full volume
*/
if (volume) {
pit_setup_channel(PIT_CHANNEL_2, PIT_MODE_3, (uint16_t)(1193180 / freq));
outb(inb(0x61) | 0b00000011, 0x61);
} else {
bios_sp_mute();
}
return 1;
}
int bios_sp_mute() {
outb(inb(0x61) & (~0b00000011), 0x61);
return 1;
}