Joystick API

Description

Joystick API.


Introduction

The joystick driver is a platform board level software module that provides the functionality to initialize and read joystick position through the joystick hardware present on the Wireless Pro Kit (BRD4002A)


Configuration

Joystick driver allows configuring the rate of signal acquisition. This can be configured from the joystick component, available options are:

  • 100 samples/second
  • 1000 samples/second
  • 5000 samples/second
  • 10000 samples/second
  • 25000 samples/second

Joystick driver also allows configuring the voltage values which correspond to a particular joystick position


Usage

Once the joystick handle of type sl_joystick_t is defined, joystick functions can be called being passed the defined handle. The functions include the following:

sl_joystick_init must be called followed by sl_joystick_start before attempting to read the position of the joystick.

The sl_joystick_get_position is used to update the position, and needs to be called from a tick function or similar by the user.

Basic example code to show usage of Joystick driver

#include "sl_joystick.h"
sl_joystick_t sl_joystick_handle = JOYSTICK_HANDLE_DEFAULT
int main( void )
{
// Initialize driver
sl_joystick_init(&sl_joystick_handle);
// Start acquiring joystick signal
sl_joystick_start(&sl_joystick_handle);
while (1) {
sl_joystick_get_position(&sl_joystick_handle, &pos);
...
}
}

Data Structures

struct  sl_joystick
 Joystick handle.
 

Functions

sl_status_t sl_joystick_init (sl_joystick_t *joystick_handle)
 PROTOTYPES **********************************.
 
sl_status_t sl_joystick_get_position (sl_joystick_t *joystick_handle, sl_joystick_position_t *pos)
 Get joystick position.
 
void sl_joystick_start (sl_joystick_t *joystick_handle)
 Start Analog Joystick data acquisition.
 
void sl_joystick_stop (sl_joystick_t *joystick_handle)
 Stop Analog Joystick data acquisition.
 

Macros

#define ENABLE_SECONDARY_DIRECTIONS   0
 DEFINES ************************************.
 
#define JOYSTICK_MV_ERROR   JOYSTICK_MV_ERR_CARDINAL_ONLY
 
#define CLK_SRC_ADC_FREQ   5000000
 
#define CLK_ADC_FREQ   1000000
 
#define JOYSTICK_HANDLE_DEFAULT
 

Typedefs

typedef sl_joystick sl_joystick_t
 

Enumerations

enum  sl_joystick_state_t {
  SL_JOYSTICK_DISABLED = 0U,
  SL_JOYSTICK_ENABLED = 1U
}
 

Direction Enums

DATA TYPES *********************************

enum  sl_joystick_position_t {
  JOYSTICK_NONE = 0u,
  JOYSTICK_C,
  JOYSTICK_N,
  JOYSTICK_E,
  JOYSTICK_S,
  JOYSTICK_W
}
 

Function Documentation

◆ sl_joystick_init()

sl_status_t sl_joystick_init ( sl_joystick_t joystick_handle)

PROTOTYPES **********************************.

Joystick init. This function should be called before calling any other Joystick function. Sets up the ADC.

Parameters
[in]joystick_handlePointer to joystick handle
Returns
Status Code:
  • SL_STATUS_OK Success
  • SL_STATUS_ALLOCATION_FAILED Bus Allocation error

◆ sl_joystick_get_position()

sl_status_t sl_joystick_get_position ( sl_joystick_t joystick_handle,
sl_joystick_position_t pos 
)

Get joystick position.

Parameters
[in]joystick_handlePointer to joystick handle
[out]posPointer to output variable of type sl_joystick_position_t
Returns
Status Code:
  • SL_STATUS_OK Success
  • SL_STATUS_NOT_READY Joystick acquition not started error

◆ sl_joystick_start()

void sl_joystick_start ( sl_joystick_t joystick_handle)

Start Analog Joystick data acquisition.

Parameters
[in]joystick_handlePointer to joystick handle

◆ sl_joystick_stop()

void sl_joystick_stop ( sl_joystick_t joystick_handle)

Stop Analog Joystick data acquisition.

Parameters
[in]joystick_handlePointer to joystick handle

Macro Definition Documentation

◆ ENABLE_SECONDARY_DIRECTIONS

#define ENABLE_SECONDARY_DIRECTIONS   0

DEFINES ************************************.

◆ JOYSTICK_HANDLE_DEFAULT

#define JOYSTICK_HANDLE_DEFAULT
Value:
{ \
SL_JOYSTICK_PORT, /*Joystick gpio port*/ \
SL_JOYSTICK_PIN, /*Joystick gpio pin*/ \
SL_JOYSTICK_DISABLED, /*Joystick signal acquisition not start*/ \
}

Enumeration Type Documentation

◆ sl_joystick_position_t

Enumerator
JOYSTICK_NONE 

Not pressed.

JOYSTICK_C 

Center.

JOYSTICK_N 

North.

JOYSTICK_E 

East.

JOYSTICK_S 

South.

JOYSTICK_W 

West.

◆ sl_joystick_state_t

Enumerator
SL_JOYSTICK_DISABLED 

Analog Joystick data acquisition is disabled.

SL_JOYSTICK_ENABLED 

Analog Joystick data acquisition is enabled.