标准版
#第六届立创电赛#会唱歌的鼠标

创建时间:3年前

1628 2

视频

描述

<p>* 1、项目功能介绍</p> <p>这次制作一个带有USB声卡功能的鼠标,表面上看着是一个鼠标,其实它内置喇叭能够直接发声。</p> <p>*2、项目属性<br>首次公开,原创。</p> <p><br>* 3、开源协议<br>GPL3.0开源协议</p> <p>*4、硬件部分</p> <p>硬件上使用了 USB Hub 芯片对鼠标的 USB 信号进行扩展,转出2个USB接口,一个继续给鼠标使用,另外一个给 Arduino Leonardo (32U4)使用。理论上可以将32u4和USB Hub 芯片放在同一个 PCB 上,但是目前 32U4太贵了(立创商城 65元)。所以选择独立的"Badusb迷你型开发板 Beetle USB ATMEGA32U4虚拟键盘模块 "(22.88 元)。</p> <p>32u4 带有 USB Device 功能,通过编程,让它报告自己为一个 USB 声卡设备。这样插入电脑后,Windows 会增加一个音频输出设备,选择从这个设备输出后, Windows 会将音频发送到 32U4上。最终我们使用 PWM pin 作为模拟输出驱动喇叭发声。</p> <p>代码基于 Lufa USB 库开发,主要代码如下:</p> <p> </p> <p>#include "AudioOutput.h"</p> <p>/** LUFA Audio Class driver interface configuration and state information. This structure is<br> *  passed to all Audio Class driver functions, so that multiple instances of the same class<br> *  within a device can be differentiated from one another.<br> */<br>USB_ClassInfo_Audio_Device_t Speaker_Audio_Interface =<br>    {<br>        .Config =<br>            {<br>                .ControlInterfaceNumber   = INTERFACE_ID_AudioControl,<br>                .StreamingInterfaceNumber = INTERFACE_ID_AudioStream,<br>                .DataOUTEndpoint          =<br>                    {<br>                        .Address          = AUDIO_STREAM_EPADDR,<br>                        .Size             = AUDIO_STREAM_EPSIZE,<br>                        .Banks            = 2,<br>                    },<br>            },<br>    };</p> <p>/** Current audio sampling frequency of the streaming audio endpoint. */<br>static uint32_t CurrentAudioSampleFrequency = 48000;</p> <p><br>/** Main program entry point. This routine contains the overall program flow, including initial<br> *  setup of all components and the main program loop.<br> */<br>int main(void)<br>{<br>    SetupHardware();</p> <p>    //LAB_ZDebug LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);<br>    GlobalInterruptEnable();</p> <p>    for (;;)<br>    {<br>        Audio_Device_USBTask(&Speaker_Audio_Interface);<br>        USB_USBTask();<br>    }<br>}</p> <p>/** Configures the board hardware and chip peripherals for the demo's functionality. */<br>void SetupHardware(void)<br>{<br>#if (ARCH == ARCH_AVR8)<br>    /* Disable watchdog if enabled by bootloader/fuses */<br>    MCUSR &= ~(1 > 8);<br>        int8_t RightSample_8Bit = (Audio_Device_ReadSample16(&Speaker_Audio_Interface) >> 8);</p> <p>        /* Mix the two channels together to produce a mono, 8-bit sample */<br>        int8_t MixedSample_8Bit = (((int16_t)LeftSample_8Bit + (int16_t)RightSample_8Bit) >> 1);</p> <p>        #if defined(AUDIO_OUT_MONO)<br>        /* Load the sample into the PWM timer channel */<br>        OCR1A = (MixedSample_8Bit ^ (1 4)<br>          LEDMask = (LEDS_LED1 | LEDS_LED2);<br>        else if (MixedSample_8Bit > 2)<br>          LEDMask = (LEDS_LED1);</p> <p>        LEDs_SetAllLEDs(LEDMask);<br>        */<br>    }</p> <p>    Endpoint_SelectEndpoint(PrevEndpoint);<br>}</p> <p>/** Event handler for the library USB Connection event. */<br>void EVENT_USB_Device_Connect(void)<br>{<br>    //LAB_ZDebug LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);</p> <p>    /* Sample reload timer initialization */<br>    TIMSK0  = (1 </p>

文档

会唱歌的鼠标

会唱歌的鼠标

BOM

暂无

附件

附件名 下载
AudioOutput.zip

评论(1)

  • 表情
    emoji
    小嘉工作篇
    小嘉日常篇
  • 图片
成功
工程所有者当前已关闭评论
Zoologist 回复
&lt;p&gt;完整的工程在附件的 &lt;span class=&quot;colour&quot; style=&quot;color: rgb(38, 44, 50);&quot;&gt;AudioOutput.zip 文件中&lt;/span&gt;&lt;br&gt;<br/>&lt;br&gt;<br/>有兴趣的朋友可以直接将启动的 hex 文件刷写到 Arduino Leonardo 中&lt;/p&gt;
goToTop
svg-battery svg-battery-wifi svg-books svg-more svg-paste svg-pencil svg-plant svg-ruler svg-share svg-user svg-logo-cn svg-double-arrow