📄 hw_gpio_api.c
字号:
/* set tabstop=4 *//******************************************************************************** * * * Copyright(C) 2004 Penta-Micro * * * * ALL RIGHT RESERVED * * * * This software is the property of Penta-Micro and is furnished under * * license by Penta-Micro. This software may be used only in accordance * * with the terms of said license. This copyright notice may not be * * removed, modified or obliterated without the prior written permission * * of Penta-Micro. * * * * This software may not be copyed, transmitted, provided to or otherwise * * made available to any other person, company, corporation or other entity * * except as specified in the terms of said license. * * * * No right, title, ownership or other interest in the software is hereby * * granted or transferred. * * * * The information contained herein is subject to change without notice and * * should not be construed as a commitment by Penta-Micro. * * * ******************************************************************************** MODULE NAME: HW_GPIO_API.C REVISION HISTORY: Date Ver Name Description ---------- --- --------------------- ----------------------------------------- 12/13/2004 1.0 jigwan Kang(xchannel) Created ............................................................................... DESCRIPTION: This Module contains functions for PPC405 GPIO. ...............................................................................*/ /** ************************************************************************* ** ** includes ** ************************************************************************* **/#include <fcntl.h>#include <stdio.h>#include <stdlib.h>#include <asm/ioctl.h>#include <asm/errno.h>#include "ppc405_gpio.h"#include "hw_gpio_api.h"/** ************************************************************************* ** ** defines ** ************************************************************************* **///#define m_DEBUG(format, args...) printf(format, ## args) #define m_DEBUG(format, args...) #define m_MSG(format, args...) printf(format, ## args);fflush(stdout); #define m_ERROR(format, args...) printf(format, ## args);fflush(stdout);/** ************************************************************************* ** ** typedefs ** ************************************************************************* **/ /** ************************************************************************* ** ** globals ** ************************************************************************* **/ /** ************************************************************************* ** ** locals ** ************************************************************************* **/static S32 fd_gpio;/** ************************************************************************* ** ** forward declarations ** ************************************************************************* **/ RETURN ppc405_gpio_open(void) { if((fd_gpio=open( "/dev/405_gpio", O_RDWR)) < 0 ) { m_DEBUG("/dev/ppc405_gpio open error\n"); return FAILURE; } return SUCCESS;}void ppc405_gpio_close(void){ close(fd_gpio);}VIDEO_MODE get_video_mode(){ struct ppc405gpio_ioctl_data ioctl_data; ioctl_data.device = 0; ioctl_data.mask = 0x10000000; ioctl(fd_gpio, PPC405GPIO_IN, &ioctl_data);//read port return (ioctl_data.data & ioctl_data.mask) ? NTSC: PAL;; }RETURN set_live_audio_ch(UNS32 arg){ struct ppc405gpio_ioctl_data ioctl_data; ioctl_data.device = 0; ioctl_data.mask = SPEECH_MASK; switch(arg) { case 0: ioctl_data.data = SPEECH_CH1; break; case 1: ioctl_data.data = SPEECH_CH2; break; case 2: ioctl_data.data = SPEECH_CH3; break; case 3: ioctl_data.data = SPEECH_CH4; break; case 4: ioctl_data.data = SPEECH_EN; break; default: ioctl_data.data = SPEECH_CH1; break; } ioctl(fd_gpio, PPC405GPIO_OUT, &ioctl_data); return SUCCESS; }RETURN set_spot_out_ch(UNS32 arg){ struct ppc405gpio_ioctl_data ioctl_data; ioctl_data.device = 0; ioctl_data.mask = SPOT_MASK; switch(arg) { case 0: ioctl_data.data = SPOT_CH1; break; case 1: ioctl_data.data = SPOT_CH2; break; case 2: ioctl_data.data = SPOT_CH3; break; case 3: ioctl_data.data = SPOT_CH4; break; default: ioctl_data.data = SPOT_CH1; break; } ioctl(fd_gpio, PPC405GPIO_OUT, &ioctl_data); return SUCCESS; }RETURN set_sensor_out_ch(UNS32 arg, BOOL normal_open){ struct ppc405gpio_ioctl_data ioctl_data; UNS32 sensor_out_pin_table[4] = { 0x02000000, 0x00020000, 0x00010000, 0x00008000 }; ioctl_data.device = 0; if(normal_open) { /* normal close set */ ioctl_data.mask = sensor_out_pin_table[arg]; /* pin 6(out 0), 14(out 1), 15(out 2), 16(out 3) */ ioctl_data.data = sensor_out_pin_table[arg]; } else { /* normal open set */ ioctl_data.mask = sensor_out_pin_table[arg]; /* pin 6(out 0), 14(out 1), 15(out 2), 16(out 3) */ ioctl_data.data = 0x00; } ioctl(fd_gpio, PPC405GPIO_OUT, &ioctl_data); return SUCCESS; }RETURN ppc405_gpio_in(UNS32 *arg){ struct ppc405gpio_ioctl_data ioctl_data; ioctl_data.device = 0; ioctl_data.mask = 0xc3; /* pin 24(in 2), 25(in 3), 30(in 0), 31(in 1) */ ioctl(fd_gpio, PPC405GPIO_IN, &ioctl_data); *arg = ioctl_data.data & ioctl_data.mask; return SUCCESS;}RETURN ppc405_gpio_ioctl(UNS32 cmd, UNS32 *arg){#if 0 ioctl(fd_gpio, cmd, arg);#endif return SUCCESS;}void ppc405_gpio_at2041_reset(void){ struct ppc405gpio_ioctl_data ioctl_data; /* hw reset at2041 */ m_MSG("\nAT2041 Reset\n"); ioctl_data.device = 0; ioctl_data.mask = 0x4000000; // pin 5 ioctl_data.data = 0x00; ioctl(fd_gpio, PPC405GPIO_OUT, &ioctl_data); sleep(2);// usleep(100); ioctl_data.mask = 0x4000000; // pin 5 ioctl_data.data = 0x4000000; ioctl(fd_gpio, PPC405GPIO_OUT, &ioctl_data); sleep(1);// usleep(100);}/* end of hw_gpio_api.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -