Subversion Repositories Code-Repo

Rev

Rev 231 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
200 Kevin 1
#include "defines.h"
2
#include "BTN.h"
3
 
201 Kevin 4
static BTN_DATA *btn_data_ptr;
200 Kevin 5
 
201 Kevin 6
void BTN_Init(BTN_DATA *data, void (*callback_1)(void), void (*callback_2)(void), void (*callback_3)(void)) {
7
    btn_data_ptr = data;
8
 
9
    btn_data_ptr->callback_function_1 = callback_1;
10
    btn_data_ptr->callback_function_2 = callback_2;
11
    btn_data_ptr->callback_function_3 = callback_3;
200 Kevin 12
 
13
    BTN1_TRIS = 1;
14
    BTN2_TRIS = 1;
15
    BTN3_TRIS = 1;
16
 
17
    INTDisableInterrupts();
18
 
19
    CNCONSET = 0x8000;  // Turn on change notice interrupt
212 Kevin 20
#if defined CEREBOT_32MX7
200 Kevin 21
    CNENSET = 0x80300;  // Set interrupt on CN8/9/19
212 Kevin 22
#elif defined CEREBOT_MX7CK
23
    CNENSET = 0x00300;  // Set interrupt on CN8/9
24
#endif
231 Kevin 25
    int32_t tmp = BTN1_PORT;
200 Kevin 26
    tmp = BTN2_PORT;
27
    tmp = BTN3_PORT;
212 Kevin 28
    IPC6SET = 0xD0000;  // Set priority level = 3, sub-priority level = 1
200 Kevin 29
    IFS1CLR = 0x1;      // Clear interrupt flag
30
    IEC1SET = 0x1;      // Enable interrupt
31
 
32
    INTEnableInterrupts();
33
}
34
 
212 Kevin 35
void __ISR(_CHANGE_NOTICE_VECTOR, ipl3) __CN_Interrupt_Handler(void) {
201 Kevin 36
    // Upon interrupt, debounce input and call saved function
37
    if (BTN1_PORT == 1) {
38
        Delay_MS(BTN_DEBOUNCE_MS);
200 Kevin 39
        if (BTN1_PORT == 1) {
201 Kevin 40
            if (btn_data_ptr->callback_function_1 != NULL)
41
                (*btn_data_ptr->callback_function_1)();
200 Kevin 42
        }
201 Kevin 43
    }
44
    if (BTN2_PORT == 1) {
45
        Delay_MS(BTN_DEBOUNCE_MS);
200 Kevin 46
        if (BTN2_PORT == 1) {
201 Kevin 47
            if (btn_data_ptr->callback_function_2 != NULL)
48
                (*btn_data_ptr->callback_function_2)();
200 Kevin 49
        }
201 Kevin 50
    }
212 Kevin 51
#ifdef CEREBOT_32MX7
201 Kevin 52
    if (BTN3_PORT == 1) {
53
        Delay_MS(BTN_DEBOUNCE_MS);
200 Kevin 54
        if (BTN3_PORT == 1) {
201 Kevin 55
            if (btn_data_ptr->callback_function_3 != NULL)
56
                (*btn_data_ptr->callback_function_3)();
200 Kevin 57
        }
201 Kevin 58
    }
212 Kevin 59
#endif
200 Kevin 60
    IFS1CLR = 0x1; // Clear interrupt flag
61
}