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#
Direction Enums#
DATA TYPES *********************************
enum for finding the position of Joystick.
Enumerations#
Joystick state (ENABLE / DISABLE) enum.
Typedefs#
sl_joystick_t is the alias name of sl_joystick.
Functions#
PROTOTYPES **********************************.
Get joystick position.
Start Analog Joystick data acquisition.
Stop Analog Joystick data acquisition.
Macros#
DEFINES ************************************.
MACROS to Set CLK_SRC_ADC_FREQ and CLK_ADC_FREQ.
A MACRO for clock ADC, clock ADC frequency is 1 MHz.
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. |
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. |
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.
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 **********************************.
[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
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.
[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
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.
[in] | joystick_handle | Pointer to joystick handle |
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.
[in] | joystick_handle | Pointer to joystick handle |
165
of file hardware/driver/joystick/inc/sl_joystick.h
Macro Definition Documentation#
ENABLE_SECONDARY_DIRECTIONS#
#define ENABLE_SECONDARY_DIRECTIONSValue:
0
DEFINES ************************************.
56
of file hardware/driver/joystick/inc/sl_joystick.h
CLK_SRC_ADC_FREQ#
#define CLK_SRC_ADC_FREQValue:
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.
68
of file hardware/driver/joystick/inc/sl_joystick.h
CLK_ADC_FREQ#
#define CLK_ADC_FREQValue:
1000000
A MACRO for clock ADC, clock ADC frequency is 1 MHz.
69
of file hardware/driver/joystick/inc/sl_joystick.h
JOYSTICK_HANDLE_DEFAULT#
#define JOYSTICK_HANDLE_DEFAULTValue:
Default Joystick handle structure.
Default Joystick handle structure
72
of file hardware/driver/joystick/inc/sl_joystick.h