-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexternal_delay.c
53 lines (49 loc) · 1.03 KB
/
external_delay.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
#include "external_delay.h"
volatile uint32_t delayct = 0;
volatile uint32_t delaytg = 0;
volatile uint8_t ctturn = 0;
volatile uint8_t innerct = 0;
static void IH_32kHz(void* pCBParam, uint32_t Port, void* Pin)
{
if(Port == IO13.port && *(uint32_t*)Pin == IO13.pin)
{
//3*38+1*37
innerct++;
if(ctturn < 3 && innerct == 38)
{
delayct++;
innerct = 0;
ctturn++;
}
else if(ctturn == 3 && innerct == 37)
{
delayct++;
innerct = 0;
ctturn = 0;
}
}
}
ADI_GPIO_RESULT external_delaySetup()
{
ADI_GPIO_RESULT result;
result = pinMode(IO13, INPUT_PULLUP);
if(result)
{
return result;
}
result = setupInterrupt(IO13, IH_32kHz, RISING, ADI_GPIO_INTB_IRQ);
if(result)
{
return result;
}
return result;
}
void delay(int ms)
{
delaytg = ms;
delayct = 0;
innerct = 0;
adi_gpio_RegisterCallback(ADI_GPIO_INTB_IRQ, IH_32kHz, (void*)ADI_GPIO_INTB_IRQ);
while(delayct < delaytg);
adi_gpio_RegisterCallback(ADI_GPIO_INTB_IRQ, NULL, (void*)ADI_GPIO_INTB_IRQ);
}