BEEP-8 SDK 1.0.0
Loading...
Searching...
No Matches
hif.h File Reference

Human Interface definitions for the BEEP-8 system. More...

#include <b8/type.h>
#include <b8/register.h>
#include <stddef.h>

Go to the source code of this file.

Classes

struct  _b8HifEvent
 Structure representing a single HIF event. More...
 
struct  _b8HifEvents
 Structure representing a collection of HIF events. More...
 
struct  _b8HifMouseStatus
 Structure representing the current mouse or touch panel status. More...
 

Macros

#define B8_HIF_PAD_STATUS_START   (1 << 0)
 
#define B8_HIF_PAD_STATUS_SELECT   (1 << 1)
 
#define B8_HIF_PAD_STATUS_LEFT   (1 << 2)
 
#define B8_HIF_PAD_STATUS_UP   (1 << 3)
 
#define B8_HIF_PAD_STATUS_RIGHT   (1 << 4)
 
#define B8_HIF_PAD_STATUS_DOWN   (1 << 5)
 
#define B8_HIF_PAD_STATUS_BTN_A   (1 << 6)
 
#define B8_HIF_PAD_STATUS_BTN_B   (1 << 7)
 
#define B8_HIF_PAD_STATUS_BTN_X   B8_HIF_PAD_STATUS_BTN_A
 
#define B8_HIF_PAD_STATUS_BTN_Z   B8_HIF_PAD_STATUS_BTN_B
 
#define B8_HIF_ADDR   (0xffffa000)
 
#define B8_HIF_PAD(n)
 Access the gamepad input register.
 
#define B8_HIF_PAD0   B8_HIF_PAD(0)
 
#define B8_HIF_PAD1   B8_HIF_PAD(1)
 
#define B8_HIF_PAD2   B8_HIF_PAD(2)
 
#define B8_HIF_PAD3   B8_HIF_PAD(3)
 
#define B8_HIF_TOUCH_CTRL   _B8_REG(B8_HIF_ADDR + 0x40)
 
#define B8_HIF_TOUCH_CONNECT   _B8_REG(B8_HIF_ADDR + 0x44)
 
#define B8_HIF_KB_ADDR   (B8_HIF_ADDR + 0x20)
 
#define B8_HIF_KB_RX   _B8_REG(B8_HIF_KB_ADDR + 0x00)
 
#define B8_HIF_KB_LEN   _B8_REG(B8_HIF_KB_ADDR + 0x08)
 
#define B8_HIF_KB_STATUS   _B8_REG(B8_HIF_KB_ADDR + 0x10)
 
#define B8_HIF_KB_STATUS_ALT   (1 << 0)
 
#define B8_HIF_KB_STATUS_SHIFT   (1 << 1)
 
#define B8_HIF_KB_STATUS_META   (1 << 2)
 
#define B8_HIF_KB_STATUS_CONTROL   (1 << 3)
 
#define B8_HIF_KB_CODE_BACKSPACE   (8)
 
#define B8_HIF_KB_CODE_TAB   (9)
 
#define B8_HIF_KB_CODE_ENTER   (10)
 
#define B8_HIF_KB_CODE_ESCAPE   (27)
 
#define B8_HIF_KB_CODE_ARROW_LEFT   (128)
 
#define B8_HIF_KB_CODE_ARROW_RIGHT   (129)
 
#define B8_HIF_KB_CODE_ARROW_UP   (130)
 
#define B8_HIF_KB_CODE_ARROW_DOWN   (131)
 
#define B8_HIF_MAX_TOUCH_EVENTS   (32)
 

Typedefs

typedef struct _b8HifEvent b8HifEvent
 Structure representing a single HIF event.
 
typedef struct _b8HifEvents b8HifEvents
 Structure representing a collection of HIF events.
 
typedef struct _b8HifMouseStatus b8HifMouseStatus
 Structure representing the current mouse or touch panel status.
 

Enumerations

enum  b8HifEventType {
  B8_HIF_EV_TOUCH_START = 0xf0 , B8_HIF_EV_TOUCH_MOVE , B8_HIF_EV_TOUCH_CANCEL , B8_HIF_EV_TOUCH_END ,
  B8_HIF_EV_MOUSE_DOWN , B8_HIF_EV_MOUSE_MOVE , B8_HIF_EV_MOUSE_UP , B8_HIF_EV_MOUSE_HOVER_MOVE
}
 Enumeration of HIF event types. More...
 

Functions

int b8HifGetEvents (b8HifEvents *result)
 Retrieve the current HIF events.
 
const b8HifMouseStatusb8HifGetMouseStatus (void)
 Retrieve the current mouse or touch panel status.
 

Detailed Description

Human Interface definitions for the BEEP-8 system.

This file contains definitions for the Human Interface (HIF) system, including gamepad, keyboard, touch, and mouse functionalities. It provides macros for accessing various HIF registers and enumerations for handling different HIF events.

The HIF system allows interaction with gamepads, keyboards, and touch/mouse inputs, enabling the detection of button presses, directional inputs, and touch/mouse events.

For more detailed information, please refer to the BEEP-8 data sheet.

Macro Definition Documentation

◆ B8_HIF_PAD

#define B8_HIF_PAD ( n)
Value:
_B8_REG(B8_HIF_ADDR + (n)*4)

Access the gamepad input register.

Each bit in the register represents the status of a specific button:

  • B8_HIF_PAD_STATUS_START: Start button
  • B8_HIF_PAD_STATUS_SELECT: Select button
  • B8_HIF_PAD_STATUS_LEFT: Left button
    • Corresponds to the left arrow key if a keyboard is connected.
  • B8_HIF_PAD_STATUS_UP: Up button
    • Corresponds to the up arrow key if a keyboard is connected.
  • B8_HIF_PAD_STATUS_RIGHT: Right button
    • Corresponds to the right arrow key if a keyboard is connected.
  • B8_HIF_PAD_STATUS_DOWN: Down button
    • Corresponds to the down arrow key if a keyboard is connected.
  • B8_HIF_PAD_STATUS_BTN_A: Button A
    • Corresponds to the 'x' key if a keyboard is connected.
  • B8_HIF_PAD_STATUS_BTN_B: Button B
    • Corresponds to the 'z' key if a keyboard is connected.
  • B8_HIF_PAD_STATUS_BTN_X: X button (alias for Button A)
  • B8_HIF_PAD_STATUS_BTN_Z: O button (alias for Button B)

Each bit is active high; a value of '1' indicates the button is pressed.

Parameters
nThe index of the input register (0 to 3).
Returns
The value of the HIF input register.
Note
Example usage:
if (B8_HIF_PAD(0) & B8_HIF_PAD_STATUS_RIGHT) {
// Right button is pressed
}
#define B8_HIF_PAD(n)
Access the gamepad input register.
Definition hif.h:74

Typedef Documentation

◆ b8HifEvent

typedef struct _b8HifEvent b8HifEvent

Structure representing a single HIF event.

This structure defines a single event generated by the HIF system, including the event type, coordinates, and an identifier.

◆ b8HifEvents

typedef struct _b8HifEvents b8HifEvents

Structure representing a collection of HIF events.

This structure defines a collection of HIF events, including the number of events and an array of individual event structures.

  • num: The number of events currently stored.
  • events: An array of b8HifEvent structures.

◆ b8HifMouseStatus

Structure representing the current mouse or touch panel status.

This structure provides information about the current position and state of the mouse or touch panel. Although the API refers to "mouse," it is also compatible with touch panel inputs. In the case of multiple touch points, the status prioritizes the most recently initiated touch.

For example:

  • If the index finger starts touching at 1 second and ends at 5 seconds, and the middle finger starts touching at 3 seconds and ends at 4 seconds:
    • From 1 second to 3 seconds, the position corresponds to the index finger.
    • From 3 seconds to 4 seconds, the position corresponds to the middle finger.
    • After 4 seconds, no touch is detected, and the state resets accordingly.

Members:

  • mouse_x: The current X coordinate of the mouse or touch panel (16-bit signed fixed-point number with 4 fractional bits).
  • mouse_y: The current Y coordinate of the mouse or touch panel (16-bit signed fixed-point number with 4 fractional bits).
  • is_dragging: Indicates whether the mouse or touch is in a dragging state (1: dragging, 0: not dragging).
Note
  • The mouse_x and mouse_y values are 16-bit signed fixed-point numbers with 4 bits dedicated to the fractional part. To obtain the actual floating-point value, divide by 16. For example, a mouse_x value of 160 represents 10.0 (160 / 16 = 10.0).

Enumeration Type Documentation

◆ b8HifEventType

Enumeration of HIF event types.

This enumeration defines various event types that can be generated by the HIF system. Events include touch events, mouse events, and other input-related events.

Function Documentation

◆ b8HifGetEvents()

int b8HifGetEvents ( b8HifEvents * result)
extern

Retrieve the current HIF events.

This function retrieves the current HIF events and stores them in the provided result structure. It safely copies the events from the internal buffer to the user-provided buffer.

Parameters
resultA pointer to a b8HifEvents structure where the events will be stored.
Returns
0 on success; a negative error code on failure.
Return values
0Success.
-EINVALInvalid argument (e.g., result is NULL).
OtherError codes as returned by semaphore functions.
Note
The function is thread-safe and ensures that the events are copied atomically.

◆ b8HifGetMouseStatus()

const b8HifMouseStatus * b8HifGetMouseStatus ( void )
extern

Retrieve the current mouse or touch panel status.

This function returns a pointer to the b8HifMouseStatus structure, which contains the current state of the mouse or touch panel. The API handles both mouse and touch panel input, with a priority on the most recently initiated touch.

Usage:

if (status->is_dragging) {
// Handle dragging
int x = status->mouse_x;
int y = status->mouse_y;
}
const b8HifMouseStatus * b8HifGetMouseStatus(void)
Retrieve the current mouse or touch panel status.
Definition hif.c:164
Structure representing the current mouse or touch panel status.
Definition hif.h:193
s16 mouse_y
Definition hif.h:195
s16 mouse_x
Definition hif.h:194
u8 is_dragging
Definition hif.h:196
Note
  • The returned pointer points to an internal structure; do not modify its contents.
  • The function provides real-time information and is updated dynamically based on input events.
  • If no touch or mouse activity is detected, the coordinates and state may reset.
Returns
A pointer to the current b8HifMouseStatus structure.