The main content of this chapter is to make the Development Board sound-buzzer driver, in the Linux Drive development focused on the study of this part of the content, and finally our team's assessment is through the interrupt control buzzer to send seven notes tone.
In this section, to interrupt the control buzzer, the interrupt and buzzer code based on the increase. Interrupt and buzzer code unchanged, in the interrupted test code, the first to define seven notes, then the Development Board seven Keys and seven notes connected, and then the conversion of seven notes with the buzzer connected to achieve the desired effect.
Core code:
int main ()
{
int fd,fd1;
int div;
int keyval;
FD1 = open ("/DEV/PWM", O_RDWR | O_nonblock);
if (FD = open ("/dev/key", O_rdonly)) < 0)
{
Perror ("fail to open");
Exit (-1);
}
while (1)
{
if (read (FD, &keyval, sizeof (int)) < 0)
{
Perror ("fail to read");
}
printf ("Key%d is pressed\n", keyval);
IOCTL (FD1,BEEP_ON);
Switch (keyval) {
Case 1:
div = (pclk/256/16)/do;
IOCTL (FD1,SET_CNT,DIV);
Break
Case 2:
div = (pclk/256/16)/re;
IOCTL (FD1,SET_CNT,DIV);
Break
Case 3:
div = (pclk/256/16)/mi;
IOCTL (FD1,SET_CNT,DIV);
Break
Case 4:
div = (pclk/256/16)/fa;
IOCTL (FD1,SET_CNT,DIV);
Break
Case 5:
div = (pclk/256/16)/sol;
IOCTL (FD1,SET_CNT,DIV);
Break
Case 6:
div = (pclk/256/16)/la;
IOCTL (FD1,SET_CNT,DIV);
Break
Case 7:
div = (pclk/256/16)/si;
IOCTL (FD1,SET_CNT,DIV);
Break
}
}
return 0;
}
Static long fs210_pwm_ioctl (struct file *file, unsigned int cmd, unsigned long arg)
{
PRINTK ("Pwm:device ioctl\n");
Switch (CMD)
{
Case BEEP_ON:
PRINTK ("Pwm:beep on\n");
Beep_on ();
Break
Case Beep_off:
PRINTK ("Pwm:beep off\n");
Beep_off ();
Break
Case SET_CNT:
PRINTK ("Pwm:set cnt\n");
SET_CNT (ARG);
Break
Default
PRINTK ("Pwm:available command\n");
Return-einval;
}
return 0;
}
Of course, there are a lot of things to learn, such as initializing the function init, Exit Function exit, and the FDto be defined when piping is needed. You also have to learn to pass the frequency change to the buzzer and make a different sound.
The eighth chapter makes the Development Board sound: Buzzer driver