GPIO

From Altera Wiki
Jump to: navigation, search

This is a simple custom gpio interface and gpio driver.

You may find the component by cloning this git repo, git://sopc.et.ntust.edu.tw/git/openip.git

I have updated the neek_ocm_spi example hardware design in the nioswiki. I used a custom gpio core to control led0 and i2c ports on NEEK. The gpio core is also available on the openip.git of sopc server. It is simpler than altera PIO, and uses less LE. You can control quite a lot of port pins (tens or hundreds) in a single instance, much more than 32 as Altera PIO. It was designed exactly for the Linux GPIO driver. It does not support interrupts. I don't really think button switches need interrupts as the input layer support polling. I have tried directional buttons as gpio mouse like that of iPod.

I also tried i2c rtc on NEEK. You can add a four pin header to the i2c port on the NEEK, as pointed out in the nios wiki. Then you can connect a simple Maxim DS1338 chip with battery. It is not difficult. And it is very nice to have correct time mark on your local storage, be it mtd or sd card.

The WM8731 is on the i2c bus, with alsa soc driver in the mainline kernel. Though the support of nios2/neek is still on the wish list.

neek_ocm_spi.zip

You will need to modify the gpio pins on arch/nios2/kernel/config.c for your custom boards.

1. enable gpio support

Processor type and features --> 
    *** Platform drivers Options *** 
[*] GPIO interface

2. LEDs with gpio,

Device Drivers -->

[*] LED Support  ---> 
[*]   LED Class Support 
[*]   LED Support for GPIO connected LEDs

You may use sysfs to control the LED on/off, see, http://www.avrfreaks.net/wiki/index....ion:Linux/LEDs

Heart beat LED on LED0 of NEEK, you can have a blinking LED with the rate changed according to CPU loading.

[*]   LED Trigger support 
[*]     LED Heartbeat Trigger 

3. i2c gpio support

There are three I2C buses on NEEK.

0 - WM8731, ADV7180 
1 - 24LC00 
2 - LCD 

It takes much less LE to use gpio than the opencore i2c, just around 8 LE for each i2c port.

[*] I2C --> 
I2C Hardware Bus support --> 
[*] GPIO-based bitbanging I2C 

i2c /dev entries driver 
rtc-ds1307 0-0068: rtc core: registered ds1307 as rtc0 
rtc-ds1307 0-0068: 56 bytes nvram 
i2c-gpio i2c-gpio.0: using pins 7 (SDA) and 6 (SCL, no clock stretching) 
at24 1-0050: 16 byte 24c00 EEPROM (writable) 
i2c-gpio i2c-gpio.1: using pins 1 (SDA) and 0 (SCL, no clock stretching) 
i2c-gpio i2c-gpio.2: using pins 5 (SDA) and 4 (SCL, no clock stretching) 

4. i2c eerom 24LC00 on NEEK, which stores the board id and mac addr.

[*] Misc devices  ---> 
      EEPROM support  ---> 
[*] I2C EEPROMs from most vendors 

/> hexdump /sys/class/i2c-adapter/i2c-1/1-0050/eeprom 
   0: 10 10 00 07 ED 08 01 C3-0F 6A 0F 09 00 84 00 94 .........j...... 

5. i2c rtc external ds1338 added to NEEK

[*] Real Time Clock  ---> 
[*]   Set system time from RTC on startup and resume 
(rtc0)  RTC used to set the system time 
[*]   /dev/rtcN (character devices) 
[*]   Dallas/Maxim DS1307/37/38/39/40, ST M41T00 

rtc-ds1307 0-0068: setting system clock to 2009-05-02 19:24:37 UTC (1241292277) 

You can enable the hwclock in busybox. And "hwclock -w" to write system time to rtc.

6. gpio mouse, not enough button switches on NEEK, you will need custom hardware.

    Input device support  ---> 
[*]   Mice  ---> 
[*]   GPIO mouse 

input: gpio_mouse as /class/input/input0 

You may enable the "evtest, event test" from misc apps, to test the gpio mouse (or other input devices)

/> event_test /dev/input/event0 
Input driver version is 1.0.0 
Input device ID: bus 0x19 vendor 0x0 product 0x0 version 0x0 
Input device name: "gpio_mouse" 
Supported events: 
  Event type 0 (Reset) 
    Event code 0 (Reset) 
    Event code 1 (Key) 
    Event code 2 (Relative) 
  Event type 1 (Key) 
    Event code 272 (LeftBtn) 
    Event code 273 (RightBtn) 
    Event code 274 (MiddleBtn) 
  Event type 2 (Relative) 
    Event code 0 (X) 
    Event code 1 (Y) 
Testing ... (interrupt to exit) 
Event: time 943920197.200302, type 2 (Relative), code 1 (Y), value -1 
Event: time 943920197.200640, type 0 (Reset), code 0 (Reset), value 0 
Event: time 943920197.210330, type 2 (Relative), code 1 (Y), value -1 
Event: time 943920197.210668, type 0 (Reset), code 0 (Reset), value 0 
Event: time 943920197.220348, type 2 (Relative), code 1 (Y), value -1 
Event: time 943920197.220685, type 0 (Reset), code 0 (Reset), value 0 
Event: time 943920197.230337, type 2 (Relative), code 1 (Y), value -1 
Event: time 943920197.230674, type 0 (Reset), code 0 (Reset), value 0 
Event: time 943920197.240338, type 2 (Relative), code 1 (Y), value -1 
Event: time 943920197.240674, type 0 (Reset), code 0 (Reset), value 0 
Event: time 943920197.250331, type 2 (Relative), code 1 (Y), value -1 
Event: time 943920197.250668, type 0 (Reset), code 0 (Reset), value 0 
Event: time 943920197.260345, type 2 (Relative), code 1 (Y), value -1 
Event: time 943920197.260681, type 0 (Reset), code 0 (Reset), value 0 
Event: time 943920197.270339, type 2 (Relative), code 1 (Y), value -1 
Event: time 943920197.270677, type 0 (Reset), code 0 (Reset), value 0 
Event: time 943920197.280332, type 2 (Relative), code 1 (Y), value -1 

7. Dallas one-wire, I haven't tried on real boards yet.

[*] Dallas's 1-wire support  ---> 
1-wire Bus Masters  ---> 
[*] GPIO 1-wire busmaster
Personal tools