-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.c
41 lines (37 loc) · 1.28 KB
/
controller.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
/**
* @author Dalton Caron
* @version 11/28/2018
*/
#include "controller.h"
#include <msp430.h>
#define GBC_BYTE_BUFFER_SIZE 0x08
void controller_init()
{
TA0CCTL0 = CCIE; // CCR0 interrupt enabled
TA0CTL = TASSEL_1 + MC_1; // 1 mHz cpu and counting up to CCR0
TA0CCR0 = 96; // 16 mHz/s = 16 cycle/us
P1DIR |= 0x01;
P1OUT |= 0x01;
gbc.buttons = 0;
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void PollingTimer()
{
byte_t poll_command[] = { 0x40, 0x03, 0x02 }, output_buffer[GBC_BYTE_BUFFER_SIZE];
volatile unsigned int i = 0;
while(i < GBC_BYTE_BUFFER_SIZE)
output_buffer[i++] = 0;
volatile byte_t read = gbc_rw(poll_command, sizeof(poll_command), output_buffer, sizeof(output_buffer)); // the compiler is annopying. We will only be here for 500us tops
if(read != GBC_BYTE_BUFFER_SIZE) return; // disregard results if we didn't read everything
volatile unsigned int buttons = 0;
buttons |= output_buffer[0];
buttons = buttons << 8;
buttons |= output_buffer[1];
gbc.buttons = buttons;
gbc.joy1X = output_buffer[2];
gbc.joy1Y = output_buffer[3];
gbc.joy2X = output_buffer[4];
gbc.joy2Y = output_buffer[5];
gbc.left = output_buffer[6];
gbc.right = output_buffer[7];
}