Landtiger LPC1768 C BigLib 1
A self made, custom C library for the LandTiger board.
 
Loading...
Searching...
No Matches
buttons.c
Go to the documentation of this file.
1#include "buttons.h"
2#include "rit.h"
3
4#include <LPC17xx.h>
5#include <stdbool.h>
6
9
12
13// PUBLIC FUNCTIONS
14
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}
42
43void BUTTON_Deinit(void)
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}
@ BTN_DEBOUNCE_WITH_RIT
Definition button_types.h:6
BUTTON_Error
@ BTN_ERR_RIT_UNINIT
During initialization, DEBOUNCE_WITH_RIT was requested but the RIT was not enabled.
@ BTN_ERR_OK
No error.
void BUTTON_Deinit(void)
Deinitializes the buttons, by removing all jobs, disabling the interrupts, and removing the debouncin...
Definition buttons.c:43
_DECL_EXTERNALLY void handle_debouncing(void)
RIT job for handling debouncing. Defined & used in button_irq.c.
Definition buttons_irq.c:29
BUTTON_Error BUTTON_Init(u8 options)
Initializes the BUTTON peripherals.
Definition buttons.c:15
_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_EnableJob(RIT_Job job)
Include this job in the RIT handler queue.
Definition rit_job.c:65
RIT_Error RIT_RemoveJob(RIT_Job job)
Removes a job from the RIT interrupt handler job queue.
Definition rit_job.c:117
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
uint8_t u8
Definition types.h:8
#define _USED_EXTERNALLY
Definition types.h:35
#define _DECL_EXTERNALLY
Definition types.h:36