Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Unnamed
Friday, December 15th, 2006 at 7:20:09pm UTC 

  1. /***************************************************************************
  2.  *             __________               __   ___.
  3.  *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
  4.  *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
  5.  *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
  6.  *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
  7.  *                     \/            \/     \/    \/            \/
  8.  * $Id: button-e200.c,v 1.2 2006-10-16 00:18:49 dan_a Exp $
  9.  *
  10.  * Copyright (C) 2006 by Barry Wardell
  11.  *
  12.  * All files in this archive are subject to the GNU General Public License.
  13.  * See the file COPYING in the source tree root for full license agreement.
  14.  *
  15.  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  16.  * KIND, either express or implied.
  17.  *
  18.  ****************************************************************************/
  19.  
  20. /* Taken from button-h10.c by Barry Wardell and reverse engineering by MrH. */
  21.  
  22. #include <stdlib.h>
  23. #include "config.h"
  24. #include "cpu.h"
  25. #include "system.h"
  26. #include "button.h"
  27. #include "kernel.h"
  28. #include "backlight.h"
  29. #include "system.h"
  30.  
  31. static unsigned int old_wheel_value = 0;
  32. static unsigned int wheel_repeat = BUTTON_NONE;
  33.  
  34. void button_init_device(void)
  35. {
  36.     /* Enable all buttons */
  37.     GPIOF_ENABLE |= 0xff;
  38.     GPIOH_ENABLE |= 0xc0;
  39.    
  40.     /* Read initial wheel value (bit 6-7 of GPIOH) */
  41.     old_wheel_value = GPIOH_INPUT_VAL & 0xc0;
  42. }
  43.  
  44. bool button_hold(void)
  45. {
  46.     return (GPIOF_INPUT_VAL & 0x80)?true:false;
  47. }
  48.  
  49. /*
  50.  * Get button pressed from hardware
  51.  */
  52. int button_read_device(void)
  53. {
  54.     int btn = BUTTON_NONE;
  55.     unsigned char state;
  56.     static bool hold_button = false;
  57.     bool hold_button_old;
  58.     unsigned int new_wheel_value;
  59.  
  60.     /* Hold */
  61.     hold_button_old = hold_button;
  62.     hold_button = button_hold();
  63.  
  64. #if 0
  65. #ifndef BOOTLOADER
  66.     /* light handling */
  67.     if (hold_button != hold_button_old)
  68.     {
  69.         backlight_hold_changed(hold_button);
  70.     }
  71. #endif
  72. #endif
  73.  
  74.     /* device buttons */
  75.     if (!hold_button)
  76.     {
  77.         /* Read normal buttons */
  78.         state = GPIOF_INPUT_VAL & 0xff;
  79.         if ((state & 0x1) == 0) btn |= BUTTON_REC;
  80.         if ((state & 0x2) == 0) btn |= BUTTON_DOWN;
  81.         if ((state & 0x4) == 0) btn |= BUTTON_RIGHT;
  82.         if ((state & 0x8) == 0) btn |= BUTTON_LEFT;
  83.         if ((state & 0x10) == 0) btn |= BUTTON_SELECT; /* The centre button */
  84.         if ((state & 0x20) == 0) btn |= BUTTON_UP; /* The "play" button */
  85.         if ((state & 0x40) != 0) btn |= BUTTON_POWER;
  86.        
  87.         /* Read wheel
  88.          * Bits 6 and 7 of GPIOH change as follows:
  89.          * Clockwise rotation   01 -> 00 -> 10 -> 11
  90.          * Counter-clockwise    11 -> 10 -> 00 -> 01
  91.          *
  92.          * This is equivalent to wheel_value of:
  93.          * Clockwise rotation   0x40 -> 0x00 -> 0x80 -> 0xc0
  94.          * Counter-clockwise    0xc0 -> 0x80 -> 0x00 -> 0x40
  95.          */
  96.         new_wheel_value = GPIOH_INPUT_VAL & 0xc0;
  97.         switch(new_wheel_value){
  98.         case 0x00:
  99.             if(old_wheel_value==0x80)
  100.                 btn |= BUTTON_SCROLL_UP;
  101.             else if (old_wheel_value==0x40)
  102.                 btn |= BUTTON_SCROLL_DOWN;
  103.             break;
  104.         case 0x40:
  105.             if(old_wheel_value==0x00)
  106.                 btn |= BUTTON_SCROLL_UP;
  107.             else if (old_wheel_value==0xc0)
  108.                 btn |= BUTTON_SCROLL_DOWN;
  109.             break;
  110.         case 0x80:
  111.             if(old_wheel_value==0xc0)
  112.                 btn |= BUTTON_SCROLL_UP;
  113.             else if (old_wheel_value==0x00)
  114.                 btn |= BUTTON_SCROLL_DOWN;
  115.             break;
  116.         case 0xc0:
  117.             if(old_wheel_value==0x40)
  118.                 btn |= BUTTON_SCROLL_UP;
  119.             else if (old_wheel_value==0x80)
  120.                 btn |= BUTTON_SCROLL_DOWN;
  121.             break;
  122.         }
  123.        
  124.         if(wheel_repeat == BUTTON_NONE){
  125.             if(btn & BUTTON_SCROLL_UP)
  126.                 wheel_repeat = BUTTON_SCROLL_UP;
  127.            
  128.             if(btn & BUTTON_SCROLL_DOWN)
  129.                 wheel_repeat = BUTTON_SCROLL_DOWN;
  130.         } else if (wheel_repeat == BUTTON_SCROLL_UP)  {
  131.             btn |= BUTTON_SCROLL_UP;
  132.             wheel_repeat = BUTTON_NONE;
  133.         } else if (wheel_repeat == BUTTON_SCROLL_DOWN) {
  134.             btn |= BUTTON_SCROLL_DOWN;
  135.             wheel_repeat = BUTTON_NONE;
  136.         }
  137.        
  138.         old_wheel_value = new_wheel_value;
  139.     }
  140.  
  141.     return btn;
  142. }

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right