-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
153 lines (128 loc) · 3.81 KB
/
main.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* Author: Rob Capo
*/
#include "subsys.h"
#include "task.h"
#include "buffer_printf.h"
#include "button.h"
#include "tap_tempo.h"
#include "inc/tm4c123gh6pm.h"
/** Communication is very simple. We are only sending two types of messages,
* one to cycle through the effect, and one to change the tempo. Therefore,
* our message can simply be two bytes. If the byte is 0xFFFF, assume change FX,
* otherwise assume it is the number of milliseconds to set the delay to.
*/
/** This function will tell the Raspberry Pi to cycle to the next effect. */
void cycle_fx(void);
/** This function will keep track of how quickly the user presses a button and set the tempo of the delay
*
* The user should push this button as quickly as he/she wants the echo to repeat. The last 4 taps are
* considered and averaged.
*/
void tap_tempo_pushed(void);
void blink_led(void);
void turn_off_led(void);
//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
//*****************************************************************************
//
// Main 'C' Language entry point.
// See http://www.ti.com/tm4c123g-launchpad/project0 for more information and
// tutorial videos.
//
//*****************************************************************************
int main(void)
{
volatile char cThisChar, c;
//
// Setup the system clock to run at 50 Mhz from PLL with crystal reference
//
SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|
SYSCTL_OSC_MAIN);
// Initialize system (including UART0 and UART1
TimingInit();
TaskInit();
SystemInit();
volatile uint32_t ui32Loop;
//*
//
// Enable the GPIO port that is used for the on-board LED.
//
SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOF;
//*
//
// Do a dummy read to insert a few cycles after enabling the peripheral.
//
ui32Loop = SYSCTL_RCGC2_R;
//
// Enable the GPIO pin for the LED (PF3). Set the direction as output, and
// enable the GPIO pin for digital function.
//
GPIO_PORTF_DIR_R = 0x08;
GPIO_PORTF_DEN_R = 0x08;
/*
//
// Turn on the LED.
//
//GPIO_PORTF_DATA_R |= 0x08;
//GPIO_PORTF_DATA_R &= ~(0x08);
*/
ButtonInit();
ButtonRegisterCallback(LEFT_BUTTON, 0, cycle_fx);
ButtonRegisterCallback(RIGHT_BUTTON, 1, tap_tempo_pushed);
// print a message to each terminal
Push_printf(&tx0, "Hello terminal 0\r\n");
Push_printf(&tx1, "Hello terminal 1\r\n");
while(1)
{
// SystemTick will call our receivers when there is data in the
// buffers. We do it this way so that we aren't calling the
// receivers from within the interrupt.
SystemTick();
// Button tick will call our button callbacks when the buttons are
// pressed.
ButtonTick();
}
}
void cycle_fx(void)
{
Push_printf(&tx0, "Left button down\r\n");
Push_printf(&tx1, "a\r\n");
}
void tap_tempo_pushed(void)
{
RegisterTap();
tint_t tempo = GetTempo();
/*
char msg[3];
msg[0] = tempo / 0xF;
msg[1] = tempo % msg[0];
msg[2] = 0;
*/
if (tempo > 0) {
Push_printf(&tx0, "%d\r\n", tempo);
Push_printf(&tx1, "%d\r\n", tempo);
TaskQueueAdd(blink_led, 10);
}
}
void blink_led(void)
{
GPIO_PORTF_DATA_R |= 0x08;
RemoveTaskFromSchedule(turn_off_led);
RemoveTaskFromSchedule(blink_led);
TaskScheduleAdd(turn_off_led, 10, 100, 0);
TaskScheduleAdd(blink_led, 10, GetTempo(), 0);
}
void turn_off_led(void)
{
GPIO_PORTF_DATA_R &= ~0x08;
}