Espresso 0.0.2c
This commit is contained in:
46
drivers/audio/pcspeaker.c
Normal file
46
drivers/audio/pcspeaker.c
Normal file
@ -0,0 +1,46 @@
|
||||
#include <stdlib.h>
|
||||
#include <port_io.h>
|
||||
|
||||
#include <drivers/audio/pcspeaker.h>
|
||||
|
||||
/*
|
||||
this code is taken from the OSDev wiki: https://wiki.osdev.org/PC_Speaker
|
||||
with slight modifications to the local variable and parameter names,
|
||||
along with removing the 'static' keyword from play_sound and nosound (which is renamed to stop_sound)
|
||||
*/
|
||||
|
||||
void play_sound(uint32_t nfrequence)
|
||||
{
|
||||
uint32_t div;
|
||||
uint8_t tmp;
|
||||
|
||||
// Set the PIT to the desired frequency
|
||||
div = 1193180 / nfrequence;
|
||||
outb(0x43, 0xb6);
|
||||
outb(0x42, (uint8_t) (div));
|
||||
outb(0x42, (uint8_t) (div >> 8));
|
||||
|
||||
// And play the sound using the PC speaker
|
||||
tmp = inb(0x61);
|
||||
if (tmp != (tmp | 3))
|
||||
{
|
||||
outb(0x61, tmp | 3);
|
||||
}
|
||||
}
|
||||
|
||||
// make it shut up
|
||||
void stop_sound(void)
|
||||
{
|
||||
uint8_t tmp = inb(0x61) & 0xFC;
|
||||
outb(0x61, tmp);
|
||||
}
|
||||
|
||||
// Make a beep
|
||||
void beep(void)
|
||||
{
|
||||
play_sound(1000);
|
||||
//timer_wait(10);
|
||||
sleep(10);
|
||||
stop_sound();
|
||||
//set_PIT_2(old_frequency);
|
||||
}
|
||||
Reference in New Issue
Block a user