Landtiger LPC1768 C BigLib 1
A self made, custom C library for the LandTiger board.
 
Loading...
Searching...
No Matches
buttons.h File Reference
#include "button_types.h"
#include "types.h"

Go to the source code of this file.

Functions

BUTTON_Error BUTTON_Init (u8 options)
 Initializes the BUTTON peripherals.
 
void BUTTON_Deinit (void)
 Deinitializes the buttons, by removing all jobs, disabling the interrupts, and removing the debouncing job from the RIT.
 
BUTTON_Error BUTTON_EnableSource (BUTTON_Source source, u8 int_priority)
 Enables the interrupt generation of the given source, provided that there's a function associated to it.
 
void BUTTON_DisableSource (BUTTON_Source source)
 Disables the interrupt generation of the given source, but it leaves the function binding.
 
void BUTTON_SetFunction (BUTTON_Source source, BUTTON_Function func)
 Binds a given interrupt to a functionality.
 
void BUTTON_UnsetFunction (BUTTON_Source source)
 Unbinds the previously set function from the selected interrupt source.
 

Function Documentation

◆ BUTTON_Deinit()

void BUTTON_Deinit ( void  )

Deinitializes the buttons, by removing all jobs, disabling the interrupts, and removing the debouncing job from the RIT.

Definition at line 43 of file buttons.c.

44{
45 // Disabling EINT[0..2] in PINSEL4. In the table, these PINS behave
46 // like EINTs when set to 01.
47 LPC_PINCON->PINSEL4 &= ~(0b010101 << 20);
48 LPC_SC->EXTMODE = 0x0;
49 LPC_SC->EXTPOLAR = 0x0;
50
51 NVIC_DisableIRQ(EINT0_IRQn);
52 NVIC_DisableIRQ(EINT1_IRQn);
53 NVIC_DisableIRQ(EINT2_IRQn);
54
55 if (debouncer_on)
56 {
57 debouncer_on = false;
59 }
60}
_DECL_EXTERNALLY void handle_debouncing(void)
RIT job for handling debouncing. Defined & used in button_irq.c.
Definition buttons_irq.c:29
_USED_EXTERNALLY bool debouncer_on
Flag to indicate if the debouncer is currently active. Used in button_irq.c.
Definition buttons.c:8
RIT_Error RIT_RemoveJob(RIT_Job job)
Removes a job from the RIT interrupt handler job queue.
Definition rit_job.c:117

◆ BUTTON_DisableSource()

void BUTTON_DisableSource ( BUTTON_Source  source)

Disables the interrupt generation of the given source, but it leaves the function binding.

Parameters
sourceTHe source to disable.

Definition at line 121 of file buttons_irq.c.

122{
123 if (!handlers[source].handler)
124 return; // No handler associated
125
126 handlers[source].source_enabled = false;
127}
_PRIVATE InterruptHandlerWrapper handlers[BTN_SRC_COUNT]
Array of function pointers to the interrupt handlers for each BUTTON peripheral. This is defined rega...
Definition buttons_irq.c:20

◆ BUTTON_EnableSource()

BUTTON_Error BUTTON_EnableSource ( BUTTON_Source  source,
u8  int_priority 
)

Enables the interrupt generation of the given source, provided that there's a function associated to it.

Parameters
sourceThe source to enable.
int_priorityThe priority to assign to the specified source.

Definition at line 84 of file buttons_irq.c.

85{
86 if (!handlers[source].handler)
87 return BTN_ERR_NO_HANDLER_TO_ENABLE; // No handler associated
88
89 handlers[source].source_enabled = true;
90
91 switch (source)
92 {
93 case BTN_SRC_EINT0:
94 NVIC_EnableIRQ(EINT0_IRQn);
95 if (!IS_DEF_PRIORITY(int_priority) && IS_BETWEEN_EQ(int_priority, 0, 15))
96 NVIC_SetPriority(EINT0_IRQn, int_priority);
97 else
99 break;
100 case BTN_SRC_EINT1:
101 NVIC_EnableIRQ(EINT1_IRQn);
102 if (!IS_DEF_PRIORITY(int_priority) && IS_BETWEEN_EQ(int_priority, 0, 15))
103 NVIC_SetPriority(EINT1_IRQn, int_priority);
104 else
106 break;
107 case BTN_SRC_EINT2:
108 NVIC_EnableIRQ(EINT2_IRQn);
109 if (!IS_DEF_PRIORITY(int_priority) && IS_BETWEEN_EQ(int_priority, 0, 15))
110 NVIC_SetPriority(EINT2_IRQn, int_priority);
111 else
113 break;
114 default:
116 }
117
118 return BTN_ERR_OK;
119}
@ BTN_SRC_EINT1
EINT1: First button from the left.
@ BTN_SRC_EINT0
INT0: Third button from the left (next to RES)
@ BTN_SRC_EINT2
EINT2: Second button from the left.
@ BTN_ERR_INT_PRIO_INVALID
An invalid priority was specified (must be 0 <= prio <= 15). This is not necessarily an error,...
@ BTN_ERR_NO_HANDLER_TO_ENABLE
It was requested to enable a button interrupt, but no function was bound to it.
@ BTN_ERR_OK
No error.
#define IS_DEF_PRIORITY(prio)
Definition types.h:42
#define IS_BETWEEN_EQ(value, low, hi)
Definition types.h:23

◆ BUTTON_Init()

BUTTON_Error BUTTON_Init ( u8  options)

Initializes the BUTTON peripherals.

Parameters
optionsButton options from the BUTTON_Config enum
Returns
BUTTON_Error The error.

Definition at line 15 of file buttons.c.

16{
17 // Enabling EINT[0..2] in PINSEL4. In the table, these PINS behave
18 // like EINTs when set to 01.
19 LPC_PINCON->PINSEL4 |= (0b010101 << 20);
20
21 // EITs mapped to PINs 2.[10..12]. Need to set them to 0, i.e. input.
22 LPC_GPIO2->FIODIR &= ~(0b111 << 10);
23
24 // Setting how EINTs are raised using EXTMODE in SC. Setting 1 to the
25 // bottom 3 bits to set interrupt edge sensitive. Since we're not modifying
26 // EXTPOLAR in SC, ints are raised on FALLING EDGE.
27 LPC_SC->EXTMODE = 0x7;
28 LPC_SC->EXTPOLAR = 0x0;
29
30 if (options & BTN_DEBOUNCE_WITH_RIT)
31 {
32 if (!RIT_IsEnabled())
33 return BTN_ERR_RIT_UNINIT;
34
35 debouncer_on = true;
38 }
39
40 return BTN_ERR_OK;
41}
@ BTN_DEBOUNCE_WITH_RIT
Definition button_types.h:6
@ BTN_ERR_RIT_UNINIT
During initialization, DEBOUNCE_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

◆ BUTTON_SetFunction()

void BUTTON_SetFunction ( BUTTON_Source  source,
BUTTON_Function  func 
)

Binds a given interrupt to a functionality.

Parameters
sourceButton interrupt source (enum BUTTON_Source)
handlerFunction pointer to the interrupt handler.
int_priorityThe priority to assign to the interrupts coming from the selected source.
enableWhether to enable the function binding right away.

Definition at line 129 of file buttons_irq.c.

130{
132 .handler = func,
133 .source_enabled = false,
134 };
135}
BUTTON_Function handler
Definition buttons_irq.c:12

◆ BUTTON_UnsetFunction()

void BUTTON_UnsetFunction ( BUTTON_Source  source)

Unbinds the previously set function from the selected interrupt source.

Parameters
sourceInterrupt source (enum BUTTON_Source)

Definition at line 137 of file buttons_irq.c.

138{
140 .handler = NULL,
141 .source_enabled = false,
142 };
143}