Joystick API#

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);

   sl_joystick_position_t pos;

   while (1) {

   sl_joystick_get_position(&sl_joystick_handle, &pos);

   ...

   }
}

Modules#

sl_joystick

Direction Enums#

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

enum
JOYSTICK_NONE = 0u
JOYSTICK_C
JOYSTICK_N
JOYSTICK_E
JOYSTICK_S
JOYSTICK_W
}

enum for finding the position of Joystick.

Enumerations#

enum
SL_JOYSTICK_DISABLED = 0U
SL_JOYSTICK_ENABLED = 1U
}

Joystick state (ENABLE / DISABLE) enum.

Typedefs#

typedef sl_joystick

sl_joystick_t is the alias name of sl_joystick.

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

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

#define

MACROS to Set CLK_SRC_ADC_FREQ and CLK_ADC_FREQ.

#define
CLK_ADC_FREQ 1000000

A MACRO for clock ADC, clock ADC frequency is 1 MHz.

#define

Default Joystick handle structure.

Direction Enums Documentation#

sl_joystick_position_t#

sl_joystick_position_t

enum for finding the position of Joystick.

Enumerator
JOYSTICK_NONE

Not pressed.

JOYSTICK_C

Center.

JOYSTICK_N

North.

JOYSTICK_E

East.

JOYSTICK_S

South.

JOYSTICK_W

West.


Definition at line 88 of file hardware/driver/joystick/inc/sl_joystick.h

Enumeration Documentation#

sl_joystick_state_t#

sl_joystick_state_t

Joystick state (ENABLE / DISABLE) enum.

Enumerator
SL_JOYSTICK_DISABLED

Analog Joystick data acquisition is disabled.

SL_JOYSTICK_ENABLED

Analog Joystick data acquisition is enabled.


Definition at line 106 of file hardware/driver/joystick/inc/sl_joystick.h

Typedef Documentation#

sl_joystick_t#

typedef sl_joystick sl_joystick_t

sl_joystick_t is the alias name of sl_joystick.


Definition at line 119 of file hardware/driver/joystick/inc/sl_joystick.h

Function Documentation#

sl_joystick_init#

sl_status_t sl_joystick_init (sl_joystick_t * joystick_handle)

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

Parameters
[in]joystick_handle

Pointer to joystick handle

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

Returns

  • Status Code:

    • SL_STATUS_OK Success

    • SL_STATUS_ALLOCATION_FAILED Bus Allocation error


Definition at line 135 of file hardware/driver/joystick/inc/sl_joystick.h

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_handle

Pointer to joystick handle

[out]pos

Pointer 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


Definition at line 149 of file hardware/driver/joystick/inc/sl_joystick.h

sl_joystick_start#

void sl_joystick_start (sl_joystick_t * joystick_handle)

Start Analog Joystick data acquisition.

Parameters
[in]joystick_handle

Pointer to joystick handle


Definition at line 157 of file hardware/driver/joystick/inc/sl_joystick.h

sl_joystick_stop#

void sl_joystick_stop (sl_joystick_t * joystick_handle)

Stop Analog Joystick data acquisition.

Parameters
[in]joystick_handle

Pointer to joystick handle


Definition at line 165 of file hardware/driver/joystick/inc/sl_joystick.h

Macro Definition Documentation#

ENABLE_SECONDARY_DIRECTIONS#

#define ENABLE_SECONDARY_DIRECTIONS
Value:
0

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


Definition at line 56 of file hardware/driver/joystick/inc/sl_joystick.h

CLK_SRC_ADC_FREQ#

#define CLK_SRC_ADC_FREQ
Value:
5000000

MACROS to Set CLK_SRC_ADC_FREQ and CLK_ADC_FREQ.

A MACRO for clock source ADC frequency, clock source ADC frequency is 5MHZ.


Definition at line 68 of file hardware/driver/joystick/inc/sl_joystick.h

CLK_ADC_FREQ#

#define CLK_ADC_FREQ
Value:
1000000

A MACRO for clock ADC, clock ADC frequency is 1 MHz.


Definition at line 69 of file hardware/driver/joystick/inc/sl_joystick.h

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*/ \
}

Default Joystick handle structure.

Default Joystick handle structure


Definition at line 72 of file hardware/driver/joystick/inc/sl_joystick.h