The eighth chapter makes the Development Board sound: Buzzer driver

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.