AT91SAM9X5 Linux 4.1.0 enable buzzer driver

Source: Internet
Author: User

Test environment: linux-at91-linux4sam_5.3 provided by cpu:at91sam9x35 Linux:atmel (Linux-4.1.0)

Reprint Please specify: Lingyun Mesh Intelligent Embedded Laboratory: http://iot-yun.com/Guo Wenxu <[email protected]>

The latest Atmel code uses device tree to replace the previous platform Virtual bus architecture, which describes how the latest Linux kernel adds the entire process of enabling PWM control buzzer. Directory structure:

1, DTS Modification

2, make menuconfig option

3, Application

4, test

1, DTS Modification

DTS documentation for PWM-BEEPER drivers in the Linux kernel:

[Email protected] linux-at91-linux4sam_5. 3 Cat documentation/devicetree/bindings/input/pwm-beeper.txt   * PWM beeper device Tree bindingsregisters A PWM device as beeper. Required Properties:"pwm-beeper"-Pwms:phandle to the physical PWM device

In the Linux kernel DTS file, only the mini6410 DTS file uses the Pwm-beeper driver, so we need to refer to him to modify:

[Email protected] linux-at91-linux4sam_5. 3] $ vim  arch/arm/boot/dts/s3c6410-Mini6410.dts    buzzer {        "pwm-beeper" ;         0 1000000 0>;        Pinctrl"default";        Pinctrl-0 = <&pwm0_out>;    };

Modify the At91sam9x35ek DTS file to add a pwm-beeper device

[Email protected] linux-at91-linux4sam_5.3]$ Vim arch/arm/boot/dts/At91sam9x35ek.dts AHB {apb {macb0: [email protected] {PHY-mode ="Rmii"; Status="Okay";            }; PWM0: [email protected] {Pinctrl-names ="default"; Pinctrl-0= <&pinctrl_pwm0_pwm2_0>; Status="Okay";    }; ..... buzzer {compatible ). ....="Pwm-beeper"; Pwms= <&pwm02 1000000 0>; Pinctrl-names ="default"; Pinctrl-0= <&pinctrl_pwm0_pwm2_0>; Status="Okay";   }; ...............

2, kernel make Menuconfig

The Linux kernel comes with a PWM beeper driver drivers/input/misc/pwm-beeper.c, and we need to select and enable it in make menuconfig.

Device Drivers  --->     Input  deviceSupport--->             [*]   Miscellaneous Devices  --->                <*>                 PWM beeper Support

After kernel compilation is started, we can see the new buzzer device:

~;:Cat/proc/bus/input/Devices Handlers~;:Cat/proc/bus/input/Devices I:bus=0019vendor=001f product=0001version=0100N:name="Pwm-beeper"P:phys=pwm/Input0s:sysfs=/devices/soc0/buzzer/input/Input0u:uniq=h:handlers=kbd event0 B:prop=0B:ev=40001b:snd=6~;:ls/sys/class/input/event0/Dev Device Power subsystem uevent~;:ls/dev/input/event0/dev/input/event0

3, write the buzzer test application

/********************************************************************************* * Copyright: (C) Guo Wenxu E<[email protected]> * All rights reserved.          * * FILENAME:TEST_BUZZER.C * description:this file * * version:1.0.0 (08/06/2016) * Author:guo Wenxue <[email protected]> * changelog:1, Release initial version on "08/06/2016 03:16: "* ********************************************************************************/#include<stdio.h>#include<unistd.h>#include<stdint.h>#include<fcntl.h>#include<linux/input.h>#include<errno.h>#include<string.h>#defineDev_buzzer "/dev/input/event0"#defineBuzzer_freq 2700/* 2.7KHz */intMainintargcChar**argv) {    intFD =-1; intversion; intRV; structInput_eventEvent; intFreq =Buzzer_freq; if(ARGC! =2) {printf ("Usage:%s [freq<2700/0>]\n", argv[0]); return-1; } freq= Atoi (argv[1]); if((Fd=open (Dev_buzzer, O_RDWR)) <0) {printf ("Open buzzer '%s ' failure:%s\n", Dev_buzzer, Strerror (errno)); return-2; }    Event. Type =ev_snd; Event. Code =Snd_tone; Event. Value =freq; Write (FD,&Event,sizeof(structinput_event));    Close (FD); return 0;}

4, compiling and testing

PC-side compilation:

[Email protected] utils]$/opt/buildroot-2012.08/arm926t/usr/bin/arm-linux-gcc test_buzzer.c-  file1 (SYSV), dynamically linked (uses shared libs), not stripped

Arm-Side Download test

 ~;: tftp-gr test_buzzer 192.168 . 2.18  test_buzzer   100 % |*******************************| 5712  0 :  XX : 00   ETA  ~;: chmod  a+x test_buzzer  ~;:./test_ Buzzer Usage:.  /test_buzzer [Freq<2700 /]  ~;:./test_buzzer 2700   Buzzer operating frequency is 2.7KHz, turn on the buzzer  ~;:./test_buzzer 0  pass parameter 0 to turn off the buzzer 

AT91SAM9X5 Linux 4.1.0 enable 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.