Landtiger LPC1768 C BigLib 1
A self made, custom C library for the LandTiger board.
 
Loading...
Searching...
No Matches
joystick.c File Reference
#include "joystick.h"
#include "rit.h"
#include <LPC17xx.h>
#include <stdlib.h>

Go to the source code of this file.

Classes

struct  FunctionWrapper
 

Functions

_PRIVATE void handle_polling (void)
 
JOYSTICK_Error JOYSTICK_Init (void)
 Initializes the joystick peripheral with the given options.
 
void JOYSTICK_Deinit (void)
 Deinitializes the joystick, by removing all functions associated with the actions, and removing the polling job from the RIT.
 
void JOYSTICK_EnableAction (JOYSTICK_Action action)
 Enables the specified action, thus enabling the binding with the associated functionality, if set.
 
void JOYSTICK_DisableAction (JOYSTICK_Action action)
 Disables the specific action, and disables the binding with its functionality, without un-binding it completely.
 
void JOYSTICK_SetFunction (JOYSTICK_Action action, JOYSTICK_Function function)
 Sets a functionality for the given action.
 
void JOYSTICK_UnsetFunction (JOYSTICK_Action action)
 Unsets a functionality for the given action, if previously set.
 

Variables

_PRIVATE FunctionWrapper functions [JOY_ACTION_COUNT] = {0}
 Array of function pointers containing the hanlder for each joystick function.
 

Function Documentation

◆ handle_polling()

_PRIVATE void handle_polling ( void  )

Definition at line 18 of file joystick.c.

19{
20 if ((LPC_GPIO1->FIOPIN & (1 << 29)) == 0 && functions[JOY_ACTION_UP].function && functions[JOY_ACTION_UP].enabled)
22
23 if ((LPC_GPIO1->FIOPIN & (1 << 25)) == 0 && functions[JOY_ACTION_SEL].function && functions[JOY_ACTION_SEL].enabled)
25
26 if ((LPC_GPIO1->FIOPIN & (1 << 26)) == 0 && functions[JOY_ACTION_DOWN].function &&
29
30 if ((LPC_GPIO1->FIOPIN & (1 << 27)) == 0 && functions[JOY_ACTION_LEFT].function &&
33
34 if ((LPC_GPIO1->FIOPIN & (1 << 28)) == 0 && functions[JOY_ACTION_RIGHT].function &&
37}
_PRIVATE FunctionWrapper functions[JOY_ACTION_COUNT]
Array of function pointers containing the hanlder for each joystick function.
Definition joystick.c:14
@ JOY_ACTION_SEL
@ JOY_ACTION_RIGHT
@ JOY_ACTION_LEFT
@ JOY_ACTION_UP
@ JOY_ACTION_DOWN
JOYSTICK_Function function
Definition joystick.c:9

◆ JOYSTICK_Deinit()

void JOYSTICK_Deinit ( void  )

Deinitializes the joystick, by removing all functions associated with the actions, and removing the polling job from the RIT.

Definition at line 58 of file joystick.c.

59{
61}
_PRIVATE void handle_polling(void)
Definition joystick.c:18
RIT_Error RIT_RemoveJob(RIT_Job job)
Removes a job from the RIT interrupt handler job queue.
Definition rit_job.c:117

◆ JOYSTICK_DisableAction()

void JOYSTICK_DisableAction ( JOYSTICK_Action  action)

Disables the specific action, and disables the binding with its functionality, without un-binding it completely.

Parameters
actionThe action to disable.

Definition at line 86 of file joystick.c.

87{
88 if ((u8)action == JOY_ACTION_ALL)
89 {
90 for (u8 i = 0; i < JOY_ACTION_COUNT; i++)
91 {
92 if (!functions[i].function || !functions[i].enabled)
93 continue;
94
95 functions[i].enabled = false;
96 }
97
98 return;
99 }
100
101 if (!functions[action].function)
102 return; // No function associated.
103
104 functions[action].enabled = false;
105}
@ JOY_ACTION_COUNT
#define JOY_ACTION_ALL
uint8_t u8
Definition types.h:8

◆ JOYSTICK_EnableAction()

void JOYSTICK_EnableAction ( JOYSTICK_Action  action)

Enables the specified action, thus enabling the binding with the associated functionality, if set.

Parameters
actionThe action to enable.

Definition at line 65 of file joystick.c.

66{
67 if ((u8)action == JOY_ACTION_ALL)
68 {
69 for (u8 i = 0; i < JOY_ACTION_COUNT; i++)
70 {
71 if (!functions[i].function || functions[i].enabled)
72 continue;
73
74 functions[i].enabled = true;
75 }
76
77 return;
78 }
79
80 if (!functions[action].function)
81 return; // No function associated.
82
83 functions[action].enabled = true;
84}

◆ JOYSTICK_Init()

JOYSTICK_Error JOYSTICK_Init ( void  )

Initializes the joystick peripheral with the given options.

Parameters
optionsJoystick options from the JOYSTICK_Config enum

Definition at line 41 of file joystick.c.

42{
43 // Joystick PINS are 1.25 to 1.29. Need to set them as GPIO
44 // These go from bit 18 to 27 in the PINSEL3 register.
45 LPC_PINCON->PINSEL3 &= ~(0x3FF << 18);
46
47 // Setting Pin 25-29 as inputs (0) in the FIODIR for GPIO1
48 LPC_GPIO1->FIODIR &= ~(0x1F << 25);
49
50 if (!RIT_IsEnabled())
51 return JOY_ERR_RIT_UNINIT;
52
55 return JOY_ERR_OK;
56}
@ JOY_ERR_OK
No error.
@ JOY_ERR_RIT_UNINIT
During initialization, POLL_WITH_RIT was requested but the RIT was not enabled.
RIT_Error RIT_EnableJob(RIT_Job job)
Include this job in the RIT handler queue.
Definition rit_job.c:65
RIT_Error RIT_AddJob(RIT_Job job, u8 multiplier_factor)
Definition rit_job.c:104
bool RIT_IsEnabled(void)
Returns whether the RIT is counting or not.
Definition rit.c:60
#define RIT_NO_DIVIDER
Tells the RIT that the specified job needs to be executed at exactly the interval of interrupts chose...
Definition rit_types.h:8

◆ JOYSTICK_SetFunction()

void JOYSTICK_SetFunction ( JOYSTICK_Action  action,
JOYSTICK_Function  function 
)

Sets a functionality for the given action.

Parameters
actionThe action associated to the functionality
functionThe functionality.

Definition at line 107 of file joystick.c.

108{
109 functions[action] = (FunctionWrapper){
110 .function = function,
111 .enabled = false,
112 };
113}

◆ JOYSTICK_UnsetFunction()

void JOYSTICK_UnsetFunction ( JOYSTICK_Action  action)

Unsets a functionality for the given action, if previously set.

Parameters
actionThe action to un-bind.

Definition at line 115 of file joystick.c.

116{
117 functions[action] = (FunctionWrapper){
118 .function = NULL,
119 .enabled = false,
120 };
121}

Variable Documentation

◆ functions

Array of function pointers containing the hanlder for each joystick function.

Definition at line 14 of file joystick.c.

14{0};