-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslider.c
70 lines (61 loc) · 2.26 KB
/
slider.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* slider.c - Functions relates to SW1/SW2
*
*
* Author: Coppy Nawaphanarat, Grant Wong, Will Archer
*/
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "OrbitOLED/OrbitOLEDInterface.h" // Remove once we finish with this demo on slider
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "utils/ustdlib.h" // This too
#include <slider.h>
// *******************************************************
// Globals to module
// *******************************************************
static bool prevSliderState[NUM_SLIDERS];
static bool currSliderState[NUM_SLIDERS];
/**
* Initialising the sliders for SW1 and SW2
*/
void initSlider(void)
{
// Initialising SW1
SysCtlPeripheralEnable(SW1_PERIPH);
GPIOPinTypeGPIOInput(SLIDER_PORT_BASE, SW1_PORT_PIN);
GPIOPadConfigSet(SLIDER_PORT_BASE, SW1_PORT_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD);
// Setup the pin (PA6) (SW2 Soft Reset)
SysCtlPeripheralEnable(SW2_PERIPH);
GPIOPinTypeGPIOInput(SLIDER_PORT_BASE, SW2_PORT_PIN);
GPIOPadConfigSet(SLIDER_PORT_BASE, SW2_PORT_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD);
// Initialise state of the slider on TiVa board (SW1 and SW2)
prevSliderState[SW1_SLIDER] = GPIOPinRead(SLIDER_PORT_BASE, SW1_PORT_PIN) == SW1_PORT_PIN;
currSliderState[SW1_SLIDER] = GPIOPinRead(SLIDER_PORT_BASE, SW1_PORT_PIN) == SW1_PORT_PIN;
prevSliderState[SW2_SLIDER] = GPIOPinRead(SLIDER_PORT_BASE, SW2_PORT_PIN) == SW2_PORT_PIN;
currSliderState[SW2_SLIDER] = GPIOPinRead(SLIDER_PORT_BASE, SW2_PORT_PIN) == SW2_PORT_PIN;
}
/**
* Update the current state of the slider
*/
void updateSliders(void)
{
int i = 0;
// Storing the previous slider
for (i = 0; i < NUM_SLIDERS; i++) {
prevSliderState[i] = currSliderState[i];
}
currSliderState[SW1_SLIDER] = (GPIOPinRead(SLIDER_PORT_BASE, SW1_PORT_PIN) == SW1_PORT_PIN);
currSliderState[SW2_SLIDER] = (GPIOPinRead(SLIDER_PORT_BASE, SW2_PORT_PIN) == SW2_PORT_PIN);
}
/**
* Check the slider state
*/
sliderState checkSlider(switchSlider slider)
{
// If the current slider state is true, set to SLIDE_UP. Otherwise, SLIDE_DOWN.
return currSliderState[slider] ? SLIDE_UP : SLIDE_DOWN;
}