KEY ???? ???? - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

KEY ???? ????

Description:

KEY Lecture #12 GPIO Control Registers KEY KEY Driver key-driver.c ... – PowerPoint PPT presentation

Number of Views:76
Avg rating:3.0/5.0
Slides: 22
Provided by: ackr
Category:
Tags: key | gpio

less

Transcript and Presenter's Notes

Title: KEY ???? ????


1
KEY ???? ????
  • Lecture 12

2
??
  • GPIO ? Control Registers
  • KEY ???? ??
  • KEY Driver ???? key-driver.c
  • ?? ?? ???? key-app.c

3
GPIO(General-Purpose I/O)
  • PXA255 processor? 81?? GPIO pin? ??
  • GPIO? 27?? ?? register? ??? ????
  • set pin direction (GPDR02)
  • read pin level (GPLR02)
  • set or clear pin level (GPSR02, GPCR02)
  • set rising/falling edge detection (GRER02,
    GFER02)
  • edge detection (GEDR02)
  • alternate function (GAFR_L02, GAFR_U02)
  • ???? ?? GPIO? output?? configure?? ?? ??? ???

4
GPIO Control Registers (1)
  • Pin Direction (GPDR) - 3?
  • ?? GPIO ?? input ?? output?? ??? ??? ???
  • 0?? input?? 1?? output?? ???
  • Pin Level (GPLR) - 3?
  • ?? GPIO ?? ?? level? ???
  • 0?? low?? 1?? high?
  • Set or Clear (GPSR, GPCR) - ?? 3?
  • ?? output GPIO ?? level? high? ???. 1?? high
  • ?? output GPIO ?? level? low? ???. 1?? low

5
GPIO Control Registers (2)
  • Rising or Falling Edge (GRER, GFER) - ?? 3?
  • ?? GPIO ?? ??? ???. 1?? rising edge? ???
  • ?? GPIO ?? ??? ???. 1?? falling edge ? ???
  • Edge Detection (GEDR) - 3?
  • ?? GPIO ?? ??? ???
  • 1?? rising/falling edge? ??? ?????? ??
  • ?? bit? clear??? ? bit? 1? ?

6
GPIO Control Registers - 3/3
  • Alternate Functions (GAFR_L, GAFR_U) - 6?
  • ?? GPIO ?? generic GPIO ??? ? ??? ?? ??? ?? ??? ?
    ??? ???.
  • 00 - GPIO ??
  • 01 - ?? ?? 1
  • 10 - ?? ?? 2
  • 11 - ?? ?? 3

7
Key Switch - ???? ??
8
Key Encoder ???? ??
74C922 chip (Key Encoder)
1. Key Switch? ??
2. ??? ??(4bits)
1. Key Switch? ??
2. Key? ???? ???? ??
1. Key Switch? ??
3. ????? GPIO 0? ??
9
Bidirectional Transceiver - ???? ??
4. ??? ??? ???
3. Key Encoder?? ??? ???
10
74C922 ? 74LVT245
  • 74C922 - Key Encoder
  • KEY_ROW 13? KEY_COL 14 ? Key Switch(3x4)? ??
  • Encoding ? ?? KEY_14 ???? ??
  • KEY_AVAL ??? PXA255 GPIO 0? ?? (interrupt ??)
  • 74LVT245 - Bidirectional Transceiver
  • KEY_14 ??? ??
  • DATA0003 ??? ??
  • ?? ???? ??? ??? ??? ?? ?? 0x14000000? ??

11
?? Configure/Compile
  • ?? ?? ????? key driver? ???? ?? ??? key driver
    ?????? ???? ???? ??? "Character devices"? ???
    "KEY GPIO" ??? disable?? ?? ??? ??? ??

12
Key Device Driver - ????
Driver start
Application start
module_init()
open()
key_open() ?? call
key_open()
key_read() ?? call
Key_read()
read()
read() blocking
Interruptible_sleep_on()
waiting
waiting key interrupt
key_handler()
wakeup_interruptible()
read() waking
13
Key Device Driver ?? ??
  • set_GPIO_IRQ_edge() GPDR? ??? GPIO ?? ??
  • GAFR? ??? alternate function ??
  • ??? GPIO detect ?? ??
  • request_irq() ??? interrupt ??
  • key_handler() ??? ???? ??? ??
  • ioremap(), iounmap()? ???? ????? access

14
key-driver.c Header files
  • include ltlinux/module.hgt // ??? ?? ??
    ex)MOD_INC_USE_COUNT
  • include ltlinux/init.hgt // init_module() ?
    cleanup_module()
  • include ltlinux/delay.hgt // udelay()
  • include ltasm/uaccess.hgt // copy_to_user()
  • include ltasm/io.hgt // GPIO controller? ?? ??
  • include ltasm/irq.hgt // interrupt? ?? ??

15
key-driver.c ???/?? ??
  • define DEVICE_NAME "key"
  • define KEY_MAJOR 242
  • define KEY_ADDRESS 0x14000000
  • static DECLARE_WAIT_QUEUE_HEAD(wq)
  • static char key_address
  • static char key_value

16
key-driver.c ?? prototype ??
  • / Prototypes /
  • int init_module (void )
  • void cleanup_module(void)
  • int key_open(struct inode , struct file )
  • int key_release(struct inode , struct file )
  • ssize_t key_read (struct file inode, char
    gdata, size_t length, loff_t off_what)
  • void key_handler(int irq, void dev_id, struct
    pt_regs regs)
  • static struct file_operations key_fops
  • open key_open,
  • read key_read,
  • release key_release,

17
key-driver.c init/cleanup
  • int init_module(void)
  • int i
  • if((iregister_chrdev(KEY_MAJOR,DEVICE_NAME,key
    _fops))lt0)
  • return i
  • GPDR0 (GPIO_0) // GPIO 0? input
  • GAFR0_L (0x3) // alternate function?
    generic GPIO?
  • // GPIO 0? falling edge
  • set_GPIO_IRQ_edge(0,GPIO_FALLING_EDGE)
  • if((irequest_irq(IRQ_GPIO(0),key_handler,SA_INT
    ERRUPT,"key",NULL))lt0)
  • return i
  • return 0
  • void cleanup_module(void)
  • unregister_chrdev(KEY_MAJOR,DEVICE_NAME)

18
key-driver.c open/release
  • int key_open(struct inode inode, struct file
    file)
  • MOD_INC_USE_COUNT
  • return 0
  • int key_release(struct inode inode, struct file
    file)
  • MOD_DEC_USE_COUNT
  • return 0

19
key-driver.c read interrupt
  • ssize_t key_read(struct file inode, char gdata,
    size_t length, loff_t off_what)
  • interruptible_sleep_on(wq)
  • copy_to_user(gdata,key_value,1)
  • return 1
  • void key_handler(int irq, void dev_id, struct
    pt_regs regs)
  • key_address(char)ioremap(KEY_ADDRESS,0x10)
  • key_value(key_address)0x0f
  • iounmap(key_address)
  • wake_up_interruptible(wq)

20
?? ?? ???? (key-app.c)
  • include ltstdio.hgt
  • include ltfcntl.hgt
  • int main(void)
  • int fd char c
  • if((fdopen("/dev/key",O_RDONLY))lt0)
  • fprintf(stderr,"can not open /dev/key\n")
  • return 1
  • while(1)
  • read(fd,c,1)
  • printf("c0xx\n",c)
  • if(c0x00) break
  • close(fd)
  • return 0

21
Makefile
  • all key-driver.o key-app
  • key-driver.o key-driver.c
  • arm-linux-gcc O2 Wall -D__KERNEL__ -DMODULE \
  • -I/root/pxa255pro/linux-2.4.19/include \
  • -c key-driver.c -o key-driver.o
  • key-app key-app.c
  • arm-linux-gcc key-app.c -o key-app
  • clean
  • rm -f key-driver.o key-app
Write a Comment
User Comments (0)
About PowerShow.com