⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 amf_buttoncontrol.c

📁 ADI SHARC DSP 音频算法标准模块库
💻 C
字号:
// Copyright(c) 2005 Analog Devices, Inc. All Rights Reserved.
// This software is proprietary and confidential to Analog Devices, Inc. and its licensors.

// File    : $Id: //depot/Development/VisualAudio/Modules/Packs/ButtonsAndLEDs_EZKit/2.5.0/SHARC/Source/AMF_ButtonControl.c#2 $ 
// Part of : VisualAudio ButtonsAndLEDs_EZKit V2.0.1 
// Updated : $Date: 2006/10/12 $ by $Author: Fernando $



#include "AMF_ButtonControl.h"
#include <math.h>
#include "processor.h"
#include <sysreg.h>

#if __VERSIONNUM__ >= 0x07010000  //VDSP++4.0 or later
#if defined(__ADSP21364__) || defined(__ADSP21365__) || defined(__ADSP21366__)
#include <sru21365.h>
#endif
#if defined(__ADSP21369__) || defined(__ADSP21368__) || defined(__ADSP21367__)
#include <sru21369.h>
#endif
#if defined(__ADSP21262__) || defined(__ADSP21267__) || defined(__ADSP21266__)
#include <sru21262.h>
#endif
#endif

#if __VERSIONNUM__ >= 0x07000000 && __VERSIONNUM__ < 0x07010000 // VDSP++ 3.5 
#include <sru.h> 
#endif

/** Read a named integer port. */
#define RDPORT(name)    (*(const int*)(name))

void AMF_ButtonControl_Render(AMF_ButtonControl * restrict instance,float * restrict * buffers,int tickSize);

#if defined(__ADSP21369__) || defined(__ADSP21368__) || defined(__ADSP21367__)
#define GET_FLAG1_STATE(flags) (flags >> 2) & 0x1
#define GET_FLAG0_STATE(flags) (flags & 0x1)
#else
#define GET_FLAG1_STATE(flags) (flags >> 2) & 0x1
#define GET_FLAG0_STATE(flags) (flags >> 4) & 0x1
#endif

#define GET_BUTTON1_STATE(flags) GET_FLAG1_STATE(flags)
#define GET_BUTTON2_STATE(flags) GET_FLAG0_STATE(flags)
#define GET_BUTTON3_STATE(value) (value >> 18) & 0x1//(value & 0x40000)
#define GET_BUTTON4_STATE(value) (value >> 19) & 0x1//(value & 0x80000)

SEG_MOD_FAST_CODE  void AMF_ButtonControl_Render(AMF_ButtonControl * restrict instance,AMF_Signal * restrict * buffers,int tickSize) 
{
/***
    Design spec:
        The button state is scaned every time the render function is called.
        This is as "scanning" mechanism, an "asynchrous polling" which
        means the function does not wait for the polling status.
        
        The first 2 buttons are connected to the flag pins and the other 2
        buttons are hookup to the processor via the digital interface
***/    
    int i;
    AMF_Signal *pButton1Output = buffers[0];
    AMF_Signal *pButton2Output = buffers[1];
    AMF_Signal *pButton3Output = buffers[2];
    AMF_Signal *pButton4Output = buffers[3];
       int flagValue;
      int sruPinValue;

    //The initialization is required only once
    if (!instance->initialized)
    {
        //Dynamically configure the digital interface

        //setting up the button
        //assign pin buffer 19 low so it is an input
        SRU(LOW,DAI_PB19_I);

        //assign pin buffer 20 low so it is an input
        SRU(LOW,DAI_PB20_I);
        
       
        //Pin Buffer Disable in SRU_PINEN0 (Group F)
        //assign pin 19 low so it is an input
        SRU(LOW,PBEN19_I);
    
        //assign pin 20 low so it is an input
        SRU(LOW,PBEN20_I);   
        instance->initialized = 1;
    }
       flagValue = sysreg_read(sysreg_FLAGS);
      sruPinValue = RDPORT(DAI_PIN_STAT);

    *pButton1Output = GET_BUTTON1_STATE(flagValue) ? 1 : 0;
    *pButton2Output = GET_BUTTON2_STATE(flagValue) ? 1 : 0;
    *pButton3Output = GET_BUTTON3_STATE(sruPinValue) ? 1 : 0;
    *pButton4Output = GET_BUTTON4_STATE(sruPinValue) ? 1 : 0;
}

SEG_MOD_SLOW_CONST const AMF_ModuleClass AMFClassButtonControl = {
    
    /* Flags */
    0,
     
    /* Render function */
    (AMF_RenderFunction)AMF_ButtonControl_Render,

    /* Default bypass */
    (void *)0,
    
    /* Input descriptor - no inputs. */
    0, 0,

    /* Output descriptor - 4 outputs, and it is mono. */
    4, AMF_ControlPin(0)|AMF_ControlPin(1)|AMF_ControlPin(2)|AMF_ControlPin(3),
};


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -