hpkeyb49.h File Reference

Keyboard management routines for the HP49. More...

Go to the source code of this file.

Data Structures

union  keymatrix
 A matrix of simultaneous key states. More...

Defines

#define KB_A   41
 Constant for the F1 (A) key.
#define KB_B   42
 Constant for the F2 (B) key.
#define KB_C   43
 Constant for the F3 (C) key.
#define KB_D   44
 Constant for the F4 (D) key.
#define KB_E   45
 Constant for the F5 (E) key.
#define KB_F   46
 Constant for the F6 (F) key.
#define KB_G   47
 Constant for the APPS (G) key.
#define KB_H   53
 Constant for the MODE (H) key.
#define KB_I   54
 Constant for the TOOL (I) key.
#define KB_J   55
 Constant for the VAR (J) key.
#define KB_K   57
 Constant for the STO (K) key.
#define KB_L   58
 Constant for the NXT (L) key.
#define KB_M   33
 Constant for the HIST (M) key.
#define KB_N   25
 Constant for the EVAL (N) key.
#define KB_O   17
 Constant for the ' (O) key.
#define KB_P   9
 Constant for the SYMB (P) key.
#define KB_Q   34
 Constant for the Y^X (Q) key.
#define KB_R   26
 Constant for the Sqrt (R) key.
#define KB_S   18
 Constant for the SIN (S) key.
#define KB_T   10
 Constant for the COS (T) key.
#define KB_U   2
 Constant for the TAN (U) key.
#define KB_V   35
 Constant for the EEX (V) key.
#define KB_W   27
 Constant for the +/- (W) key.
#define KB_X   19
 Constant for the X (X) key.
#define KB_Y   11
 Constant for the 1/X (Y) key.
#define KB_Z   KB_DIV
 Constant for the / (Z) key.
#define KB_0   31
 Constant for the 0 key.
#define KB_1   30
 Constant for the 1 key.
#define KB_2   22
 Constant for the 2 key.
#define KB_3   14
 Constant for the 3 key.
#define KB_4   29
 Constant for the 4 key.
#define KB_5   21
 Constant for the 5 key.
#define KB_6   13
 Constant for the 6 key.
#define KB_7   28
 Constant for the 7 key.
#define KB_8   20
 Constant for the 8 key.
#define KB_9   12
 Constant for the 9 key.
#define KB_BKS   1
 Constant for the backspace key.
#define KB_DIV   3
 Constant for the / (Z) key.
#define KB_MUL   4
 Constant for the * key.
#define KB_ADD   6
 Constant for the + key.
#define KB_SUB   5
 Constant for the - key.
#define KB_DOT   23
 Constant for the . key.
#define KB_SPC   15
 Constant for the SPC key.
#define KB_ENT   7
 Constant for the ENT key.
#define KB_UP   49
 Constant for the up arrow key.
#define KB_DN   51
 Constant for the down arrow key.
#define KB_LF   50
 Constant for the left arrow key.
#define KB_RT   52
 Constant for the right arrow key.
#define KB_ALPHA   60
 Constant for the ALPHA key.
#define KB_LSHIFT   61
 Constant for the left shift key.
#define KB_RSHIFT   62
 Constant for the right shift key.
#define KB_ON   63
 Constant for the ON key.
#define KB_MASK64(a)   (((ULONGLONG)1)<<(a))
 Create a bitmask representing the given key.
#define KB_MASK32(a)   (((unsigned int)1)<<(a&31))
 Create a bitmask representing the given key (32-bit).
#define KB_MASK8(a)   (((unsigned int)1)<<(a&7))
 Create a bitmask representing the given key (8-bit).
#define KB_CURS   ((ULONGLONG)0x001e000000000000)
 A bitmask to represent the arrow keys.
#define KBH_CURS32   ((unsigned int)0x001e0000)
 A bitmask to represent the arrow keys (32-bit).
#define KB_FUNC   ((ULONGLONG)0x00007e0000000000)
 A bitmask to represent the function keys.
#define KBH_FUNC32   ((unsigned int)0x00007e00)
 A bitmask to represent the function keys (32-bit).
#define SHFT_LS   0x40000000
 Shift constant to use in a combined shiftcode. Left Shift.
#define SHFT_RS   0x20000000
 Shift constant to use in a combined shiftcode. Right Shift.
#define SHFT_ALPHA   0x10000000
 Shift constant to use in a combined shiftcode. Alpha.
#define SHFT_ON   0x80000000
 Shift constant to use in a combined shiftcode. On key.
#define SHFT_ANY   0xf0000000
 Shift constant to use in a combined shiftcode. Any Shift or ON.
#define KEYCODE(shftcode)   ((shftcode)&0xff)
 Extracts a keycode from a combined shiftcode.
#define SHFTPLANE(shftcode)   ((shftcode)&0xf0000000)
 Extracts shift plane from a combined shiftcode.
#define WAIT_CANCEL   {while(keyb_isON()); while(! keyb_isON());}

Typedefs

typedef unsigned long long ULONGLONG
typedef long long LONGLONG

Functions

int keyb_isKeyPressed (unsigned char col, unsigned char row)
 Tests the current state of a key.
int keyb_isAnyKeyPressed (void)
 Tests whether any key is being pressed on the keyboard.
void keyb_waitKeyPressed (void)
 Waits for a key to be pressed.
int keyb_isLeft (void)
 Tests if the left arrow key is down.
int keyb_isRight (void)
 Tests if the right arrow key is down.
int keyb_isUp (void)
 Tests if the up arrow key is down.
int keyb_isDown (void)
 Tests if the down arrow key is down.
int keyb_isAlpha (void)
 Tests if the alpha key is down.
int keyb_isLS (void)
 Tests if the left shift key is down.
int keyb_isRS (void)
 Tests if the right shift key is down.
int keyb_isON (void)
 Tests if the on key is down.
int keyb_getkey (int wait)
 Returns an identifier for the first key pressed.
void keyb_getmatrix (keymatrix *ptr)
 Retrieves the state of the complete keyboard.
int keyb_isKeyPrM (int keycode)
 Tests the current state of a key. Keymatrix version.
int keyb_isShiftKeyPrM (int shiftcode)
 Tests the current state of a key with shift plane.
int keyb_getkeyM (int wait)
 Returns the shiftcode for the first key pressed.
int keyb_getnextkey (keymatrix *ptr, int keycode)
 Gets the keycode for the next key pressed in a key combination.


Detailed Description

Keyboard management routines for the HP49.

Interaction with the calculator keyboard can be done at a high level, or a low level. Functions defined in this file are used to interact at a low level with the calculator keyboard. For higher-level user input routines, see getchar, gets, getkey, readint, readuint, readhex, readlonglong, readulonglong, and readdouble.

At the moment, keys are identified in various hodge-podge manners by the various functions defined in this file. Here is a compilation of them all. Logical rows and columns are for the HP49G+; these values probably apply to the HP48gII as well, but this fact has not been verified. The HP39G+ has a somewhat different keyboard layout, which is not yet documented.

Todo:
Include a diagram of key positions
Todo:
Document keyboard constants and layout for the HP48gII and HP39G+.
Todo:
Define separate constants for letters versus the function key. That way, on the HP39G+, they can be set to different values because the letters are in different places.

Definition in file hpkeyb49.h.


Define Documentation

#define KB_0   31

Constant for the 0 key.

Definition at line 375 of file hpkeyb49.h.

#define KB_1   30

Constant for the 1 key.

Definition at line 377 of file hpkeyb49.h.

#define KB_2   22

Constant for the 2 key.

Definition at line 379 of file hpkeyb49.h.

#define KB_3   14

Constant for the 3 key.

Definition at line 381 of file hpkeyb49.h.

#define KB_4   29

Constant for the 4 key.

Definition at line 383 of file hpkeyb49.h.

#define KB_5   21

Constant for the 5 key.

Definition at line 385 of file hpkeyb49.h.

#define KB_6   13

Constant for the 6 key.

Definition at line 387 of file hpkeyb49.h.

#define KB_7   28

Constant for the 7 key.

Definition at line 389 of file hpkeyb49.h.

#define KB_8   20

Constant for the 8 key.

Definition at line 391 of file hpkeyb49.h.

#define KB_9   12

Constant for the 9 key.

Definition at line 393 of file hpkeyb49.h.

#define KB_A   41

Constant for the F1 (A) key.

Definition at line 323 of file hpkeyb49.h.

#define KB_ADD   6

Constant for the + key.

Definition at line 401 of file hpkeyb49.h.

#define KB_ALPHA   60

Constant for the ALPHA key.

Definition at line 419 of file hpkeyb49.h.

#define KB_B   42

Constant for the F2 (B) key.

Definition at line 325 of file hpkeyb49.h.

#define KB_BKS   1

Constant for the backspace key.

Definition at line 395 of file hpkeyb49.h.

#define KB_C   43

Constant for the F3 (C) key.

Definition at line 327 of file hpkeyb49.h.

#define KB_CURS   ((ULONGLONG)0x001e000000000000)

A bitmask to represent the arrow keys.

The keymatrix::full field of a keymatrix can be combined with this mask via a bitwise and (&) to eliminate everything except the state of the arrow keys (aka cursor keys). This is a convenience constant, and its value is equivalent to: KB_MASK64(KB_UP) | KB_MASK64(KB_DN) | KB_MASK64(KB_LF) | KB_MASK64(KB_RT).

Definition at line 466 of file hpkeyb49.h.

#define KB_D   44

Constant for the F4 (D) key.

Definition at line 329 of file hpkeyb49.h.

#define KB_DIV   3

Constant for the / (Z) key.

Definition at line 397 of file hpkeyb49.h.

#define KB_DN   51

Constant for the down arrow key.

Definition at line 413 of file hpkeyb49.h.

#define KB_DOT   23

Constant for the . key.

Definition at line 405 of file hpkeyb49.h.

#define KB_E   45

Constant for the F5 (E) key.

Definition at line 331 of file hpkeyb49.h.

#define KB_ENT   7

Constant for the ENT key.

Definition at line 409 of file hpkeyb49.h.

#define KB_F   46

Constant for the F6 (F) key.

Definition at line 333 of file hpkeyb49.h.

#define KB_FUNC   ((ULONGLONG)0x00007e0000000000)

A bitmask to represent the function keys.

The keymatrix::full field of a keymatrix can be combined with this mask via a bitwise and (&) to eliminate everything except the state of the function keys. This is a convenience constant, and its value is equivalent to: KB_MASK64(KB_A) | KB_MASK64(KB_B) | KB_MASK64(KB_C) | KB_MASK64(KB_D) | KB_MASK64(KB_E) | KB_MASK64(KB_F).

Definition at line 490 of file hpkeyb49.h.

#define KB_G   47

Constant for the APPS (G) key.

Definition at line 335 of file hpkeyb49.h.

#define KB_H   53

Constant for the MODE (H) key.

Definition at line 337 of file hpkeyb49.h.

#define KB_I   54

Constant for the TOOL (I) key.

Definition at line 339 of file hpkeyb49.h.

#define KB_J   55

Constant for the VAR (J) key.

Definition at line 341 of file hpkeyb49.h.

#define KB_K   57

Constant for the STO (K) key.

Definition at line 343 of file hpkeyb49.h.

#define KB_L   58

Constant for the NXT (L) key.

Definition at line 345 of file hpkeyb49.h.

#define KB_LF   50

Constant for the left arrow key.

Definition at line 415 of file hpkeyb49.h.

#define KB_LSHIFT   61

Constant for the left shift key.

Definition at line 421 of file hpkeyb49.h.

#define KB_M   33

Constant for the HIST (M) key.

Definition at line 347 of file hpkeyb49.h.

#define KB_MASK32 (  )     (((unsigned int)1)<<(a&31))

Create a bitmask representing the given key (32-bit).

The bitmask returned by this macro can be compared with the keymatrix::hiword or keymatrix::loword field of a keymatrix result. When the key is known, it's more efficient to compare a 32-bit number than a 64-bit number.

Definition at line 443 of file hpkeyb49.h.

#define KB_MASK64 (  )     (((ULONGLONG)1)<<(a))

Create a bitmask representing the given key.

The bitmask returned by this macro can be compared with the keymatrix::full field of a keymatrix result.

Definition at line 434 of file hpkeyb49.h.

#define KB_MASK8 (  )     (((unsigned int)1)<<(a&7))

Create a bitmask representing the given key (8-bit).

The bitmask returned by this macro can be compared with the keymatrix::bytes[] field of a keymatrix result. When the column of the key is known, single-byte comparisons might be more efficient than a 64-bit number.

Definition at line 452 of file hpkeyb49.h.

#define KB_MUL   4

Constant for the * key.

Definition at line 399 of file hpkeyb49.h.

#define KB_N   25

Constant for the EVAL (N) key.

Definition at line 349 of file hpkeyb49.h.

#define KB_O   17

Constant for the ' (O) key.

Definition at line 351 of file hpkeyb49.h.

#define KB_ON   63

Constant for the ON key.

Definition at line 425 of file hpkeyb49.h.

#define KB_P   9

Constant for the SYMB (P) key.

Definition at line 353 of file hpkeyb49.h.

#define KB_Q   34

Constant for the Y^X (Q) key.

Definition at line 355 of file hpkeyb49.h.

#define KB_R   26

Constant for the Sqrt (R) key.

Definition at line 357 of file hpkeyb49.h.

#define KB_RSHIFT   62

Constant for the right shift key.

Definition at line 423 of file hpkeyb49.h.

#define KB_RT   52

Constant for the right arrow key.

Definition at line 417 of file hpkeyb49.h.

#define KB_S   18

Constant for the SIN (S) key.

Definition at line 359 of file hpkeyb49.h.

#define KB_SPC   15

Constant for the SPC key.

Definition at line 407 of file hpkeyb49.h.

#define KB_SUB   5

Constant for the - key.

Definition at line 403 of file hpkeyb49.h.

#define KB_T   10

Constant for the COS (T) key.

Definition at line 361 of file hpkeyb49.h.

#define KB_U   2

Constant for the TAN (U) key.

Definition at line 363 of file hpkeyb49.h.

#define KB_UP   49

Constant for the up arrow key.

Definition at line 411 of file hpkeyb49.h.

#define KB_V   35

Constant for the EEX (V) key.

Definition at line 365 of file hpkeyb49.h.

#define KB_W   27

Constant for the +/- (W) key.

Definition at line 367 of file hpkeyb49.h.

#define KB_X   19

Constant for the X (X) key.

Definition at line 369 of file hpkeyb49.h.

#define KB_Y   11

Constant for the 1/X (Y) key.

Definition at line 371 of file hpkeyb49.h.

#define KB_Z   KB_DIV

Constant for the / (Z) key.

Definition at line 373 of file hpkeyb49.h.

#define KBH_CURS32   ((unsigned int)0x001e0000)

A bitmask to represent the arrow keys (32-bit).

The keymatrix::hiword field of a keymatrix can be combined with this mask via a bitwise and (&) to eliminate everything except the state of the arrow keys (aka cursor keys). This is a convenience constant, and its value is equivalent to: KB_MASK32(KB_UP) | KB_MASK32(KB_DN) | KB_MASK32(KB_LF) | KB_MASK32(KB_RT).

Definition at line 478 of file hpkeyb49.h.

#define KBH_FUNC32   ((unsigned int)0x00007e00)

A bitmask to represent the function keys (32-bit).

The keymatrix::hiword field of a keymatrix can be combined with this mask via a bitwise and (&) to eliminate everything except the state of the function keys. This is a convenience constant, and its value is equivalent to: KB_MASK64(KB_A) | KB_MASK64(KB_B) | KB_MASK64(KB_C) | KB_MASK64(KB_D) | KB_MASK64(KB_E) | KB_MASK64(KB_F).

Definition at line 501 of file hpkeyb49.h.

#define KEYCODE ( shftcode   )     ((shftcode)&0xff)

Extracts a keycode from a combined shiftcode.

Definition at line 519 of file hpkeyb49.h.

#define SHFT_ALPHA   0x10000000

Shift constant to use in a combined shiftcode. Alpha.

Definition at line 511 of file hpkeyb49.h.

#define SHFT_ANY   0xf0000000

Shift constant to use in a combined shiftcode. Any Shift or ON.

Definition at line 515 of file hpkeyb49.h.

#define SHFT_LS   0x40000000

Shift constant to use in a combined shiftcode. Left Shift.

Definition at line 507 of file hpkeyb49.h.

#define SHFT_ON   0x80000000

Shift constant to use in a combined shiftcode. On key.

Definition at line 513 of file hpkeyb49.h.

#define SHFT_RS   0x20000000

Shift constant to use in a combined shiftcode. Right Shift.

Definition at line 509 of file hpkeyb49.h.

#define SHFTPLANE ( shftcode   )     ((shftcode)&0xf0000000)

Extracts shift plane from a combined shiftcode.

Definition at line 521 of file hpkeyb49.h.

#define WAIT_CANCEL   {while(keyb_isON()); while(! keyb_isON());}

Definition at line 646 of file hpkeyb49.h.


Typedef Documentation

typedef long long LONGLONG

Definition at line 42 of file hpkeyb49.h.

typedef unsigned long long ULONGLONG

Definition at line 41 of file hpkeyb49.h.


Function Documentation

int keyb_getkey ( int  wait  ) 

Returns an identifier for the first key pressed.

Optionally waits for a key to be pressed, and then returns an identifier specifying which key was pressed. The identifier is calculated from the logical row and column of the key, according to the formula col * 0xf + row .

If the wait parameter is non-zero, this function does not return until a key has been completely pressed and released. If multiple keys are pressed simultaneously, the function does not return until all keys have been released; but the return value will be the identifier of the first key. If the wait parameter is zero, the function will wait neither for a key to be pressed or released.

Parameters:
wait If 0, return a -1 identifier if no key is pressed; If non-zero, wait until a key is pressed.
Returns:
An identifier for the key pressed, or -1 if no normal key was pressed and the wait parameter was zero. If wait is nonzero, then the upper bits of the value contain information on the modifier keys (ON, Shift, Alpha).
ON = bit 8, Right shift = bit 9, Left shift = bit 10, ALPHA = bit 11

Note:
The RTC Tick interrupt is used for debouncing, but the frequency is not altered.

int keyb_getkeyM ( int  wait  ) 

Returns the shiftcode for the first key pressed.

Optionally waits for a non-shift key to be pressed, and then returns a shiftcode specifying which key was pressed and the shift state.

If the wait parameter is non-zero, this function does not return until a key has been completely pressed and released (only the key, shift can remain pressed). If multiple keys are pressed simultaneously, the function does not return until all keys have been released; but the return value will be the identifier of the first key. If the wait parameter is zero, the function will wait neither for a key to be pressed or released. The ON key is detected as a normal key, but Shift-ON is not detected.

Parameters:
wait If 0, return a 0 identifier if no key is pressed; If non-zero, wait until a key is pressed.
Returns:
A shiftcode for the key pressed, or 0 if no key was pressed and the wait parameter was zero. The shiftcode will be comprised of a KB_... constant and a combination of the SHFT_... constants. Use the KEYCODE() macro to extract the keycode from the shiftcode. For example, int key=keyb_getkeyM(1); To check for A regardless of shift state: if(KEYCODE(key)==KB_A) ... To check for LS-A (LS only): if(key==(KB_A | SHFT_LS)) ... or if(KEYCODE(key)==KB_A && SHFTPLANE(key)==SHFT_LS)
Note:
Hardware registers in use: GPGDAT, GPGCON

void keyb_getmatrix ( keymatrix ptr  ) 

Retrieves the state of the complete keyboard.

This function retrieves the state of the entire keyboard in one operation. The result can then be inspected using the various KB_* preprocessor macros and constants.

Parameters:
ptr A pointer to a keymatrix, which will hold the result.

int keyb_getnextkey ( keymatrix ptr,
int  keycode 
)

Gets the keycode for the next key pressed in a key combination.

When multiple keys are expected to be pressed at the same time, this function aids in detecting all the keys correctly. Given a keymatrix, this function returns the keycode of the next key pressed in the matrix, or 0 when no more keys are pressed. Notice that the keyboard is not read by this function. A valid keymatrix is expected as an input argument. To use this function: keymatrix mat; keyb_getmatrix(&mat); // read keyboard int key=keyb_getnextkey(&mat,-1); // get first key while (key!=0) { ... process the key ... key=keyb_getnextkey(&mat,key); // get the next keycode }

Parameters:
ptr Pointer to the keymatrix to be processed.
keycode Keycode of the last key returned by this function. Use -1 to retrieve the first key in the group.
Returns:
A keycode for the key pressed, or 0 if no more keys are pressed in the given matrix.
Note:
Hardware registers in use: GPGDAT, GPGCON

int keyb_isAlpha ( void   ) 

Tests if the alpha key is down.

Returns:
1 if the key is pressed; 0 otherwise
Note:
Hardware registers in use: GPFDAT

int keyb_isAnyKeyPressed ( void   ) 

Tests whether any key is being pressed on the keyboard.

Returns:
1 if a key is pressed; 0 otherwise
Note:
Hardware registers in use: GPFDAT, GPGCON

int keyb_isDown ( void   ) 

Tests if the down arrow key is down.

This is a convenience function. It behaves exactly like keyb_isKeyPressed (6,2) does.

Returns:
1 if the key is pressed; 0 otherwise

int keyb_isKeyPressed ( unsigned char  col,
unsigned char  row 
)

Tests the current state of a key.

The key to be tested is identified by the row and col parameters. These parameters, however, do not identify the physical position of the key on the keyboard. Instead, they refer to the key's "logical" position. Refer to the documentation for the header file hpkeyb49.h for a list of keys with their logical rows and columns.

Certain keys, namely ON, ALPHA, and both shift keys, cannot be tested with this function. Instead, please use keyb_isON, keyb_isAlpha, keyb_isLS, and keyb_isRS to test these keys. As a convenience, the functions keyb_isLeft, keyb_isRight, keyb_isUp, and keyb_isDown are also provided, although those keys can be tested using this function as well.

Parameters:
col The logical column of the key to test.
row The logical row of the key to test.
Returns:
1 if the key is pressed; 0 otherwise
Note:
Hardware registers in use: GPFDAT, GPGCON

int keyb_isKeyPrM ( int  keycode  ) 

Tests the current state of a key. Keymatrix version.

This function detects if a key is pressed. Unlike the row/column version, (keyb_isKeyPressed) this routine can detect all the keys.

Parameters:
keycode The KB_... constant of a key.
Returns:
1 if the key is pressed; 0 otherwise
Note:
Hardware registers in use: GPFDAT, GPGCON

int keyb_isLeft ( void   ) 

Tests if the left arrow key is down.

This is a convenience function. It behaves exactly like keyb_isKeyPressed (6,1) does.

Returns:
1 if the key is pressed; 0 otherwise

int keyb_isLS ( void   ) 

Tests if the left shift key is down.

Returns:
1 if the key is pressed; 0 otherwise
Note:
Hardware registers in use: GPFDAT

int keyb_isON ( void   ) 

Tests if the on key is down.

Returns:
1 if the key is pressed; 0 otherwise
Note:
Hardware registers in use: GPFDAT

int keyb_isRight ( void   ) 

Tests if the right arrow key is down.

This is a convenience function. It behaves exactly like keyb_isKeyPressed (6,3) does.

Returns:
1 if the key is pressed; 0 otherwise

int keyb_isRS ( void   ) 

Tests if the right shift key is down.

Returns:
1 if the key is pressed; 0 otherwise
Note:
Hardware registers in use: GPFDAT

int keyb_isShiftKeyPrM ( int  shiftcode  ) 

Tests the current state of a key with shift plane.

This function detects if a shifted key is pressed.

Parameters:
shiftcode The KB_... constant of a key, combined (OR '|') with one or more SHFT_... constants. For example, to detect Left-Shift A, the argument should be KB_A | SHFT_LS
Returns:
1 if the key is pressed; 0 otherwise
Note:
Hardware registers in use: GPFDAT, GPGCON

int keyb_isUp ( void   ) 

Tests if the up arrow key is down.

This is a convenience function. It behaves exactly like keyb_isKeyPressed (6,0) does.

Returns:
1 if the key is pressed; 0 otherwise

void keyb_waitKeyPressed ( void   ) 

Waits for a key to be pressed.

This convenience function waits for a key to be completely pressed and released. It can be used to wait for user acknowledgement of some kind. Because the function does not return until the key has been released, it can be used without worrying about the key registering later in the application code.


Generated on Fri Feb 16 16:43:16 2007 for HP-GCCLibrary by  doxygen 1.5.0