button.c File Reference

Simple button sensor readings for the UI board. More...

Go to the source code of this file.

Functions

unsigned int button_0 (void)
 Return the state of button 0.
unsigned int button_1 (void)
 Return the state of button 1.
unsigned int button_2 (void)
 Return the state of button 2.
unsigned int button_3 (void)
 Return the state of button 3.
unsigned int button_4 (void)
 Return the state of button 4.
unsigned int button_5 (void)
 Return the state of button 5.
unsigned int button_pushed (unsigned int button)
 Checks if a button is pushed.

Detailed Description

Simple button sensor readings for the UI board.

Example hardware/pin setup:

  // *******************************************************************************
  // Initialize Buttons
  // *******************************************************************************
  PINSEL0 &= ~(3<<24); //Button 1: P0.12 as GPIO
  PINSEL0 &= ~(3<<26); //Button 2: P0.13 as GPIO
  PINSEL1 &= ~(3<<24); //Button 3: P0.28 as GPIO
  PINSEL1 &= ~(3<<28); //Button 5: P0.30 as GPIO
  PINSEL2 &= ~(1<<3);  //Buttons 0 & 4: P1.18 and P1.16 GPIO (P1.16-25 GPIO)
  //set pins as inputs
  FIO0DIR &= ~(1<<12); 
  FIO0DIR &= ~(1<<13);
  FIO0DIR &= ~(1<<28);
  FIO0DIR &= ~(1<<30);
  FIO1DIR &= ~(1<<16);
  FIO1DIR &= ~(1<<18);
Author:
Nicolas Williamson
Date:
July 2009

Definition in file button.c.


Function Documentation

unsigned int button_0 ( void   ) 

Return the state of button 0.

Returns:
1 = pressed, 0 = not pressed.

Definition at line 64 of file button.c.

References button_pushed().

unsigned int button_1 ( void   ) 

Return the state of button 1.

Returns:
1 = pressed, 0 = not pressed.

Definition at line 65 of file button.c.

References button_pushed().

unsigned int button_2 ( void   ) 

Return the state of button 2.

Returns:
1 = pressed, 0 = not pressed.

Definition at line 66 of file button.c.

References button_pushed().

unsigned int button_3 ( void   ) 

Return the state of button 3.

Returns:
1 = pressed, 0 = not pressed.

Definition at line 67 of file button.c.

References button_pushed().

unsigned int button_4 ( void   ) 

Return the state of button 4.

Returns:
1 = pressed, 0 = not pressed.

Definition at line 68 of file button.c.

References button_pushed().

unsigned int button_5 ( void   ) 

Return the state of button 5.

Returns:
1 = pressed, 0 = not pressed.

Definition at line 69 of file button.c.

References button_pushed().

unsigned int button_pushed ( unsigned int  button  ) 

Checks if a button is pushed.

Parameters:
button The number of the button to check. Buttons are numbered 0 to 5.
Returns:
The state of the button; 1 = pressed, 0 = not pressed.

Definition at line 37 of file button.c.

References error_occurred().

Referenced by button_0(), button_1(), button_2(), button_3(), button_4(), and button_5().

00038 {
00039   unsigned int button_state;
00040   unsigned int p0_state = FIO0PIN;
00041   unsigned int p1_state = FIO1PIN;
00042   
00043   if (button > 5){
00044     error_occurred(ERROR_BUTTON_OOB);
00045   } else {
00046     switch (button){
00047       case 0: button_state = p1_state & (1<<18);
00048           break;
00049       case 1: button_state = p0_state & (1<<12);
00050           break;
00051       case 2: button_state = p0_state & (1<<13);
00052           break;
00053       case 3: button_state = p0_state & (1<<28);
00054           break;
00055       case 4: button_state = p1_state & (1<<16);
00056           break;
00057       case 5: button_state = p0_state & (1<<30);
00058           break;
00059     }
00060   }
00061   return button_state;
00062 }

Generated on Tue Jun 29 16:36:14 2010 by  doxygen 1.6.3