-
Notifications
You must be signed in to change notification settings - Fork 0
/
brake.c
executable file
·50 lines (44 loc) · 1 KB
/
brake.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
/*
* TongSheng TSDZ2 motor controller firmware/
*
* Copyright (C) Casainho, 2018.
*
* Released under the GPL License, Version 3
*/
#include <stdint.h>
#include "stm8s.h"
#include "stm8s_it.h"
#include "pins.h"
#include "main.h"
#include "interrupts.h"
#include "brake.h"
#include "motor.h"
// Brake signal
void EXTI_PORTC_IRQHandler(void) __interrupt(EXTI_PORTC_IRQHANDLER)
{
if (brake_is_set())
{
motor_controller_set_state (MOTOR_CONTROLLER_STATE_BRAKE);
}
else
{
motor_controller_reset_state (MOTOR_CONTROLLER_STATE_BRAKE);
}
}
void brake_init (void)
{
//brake pin as external input pin interrupt
GPIO_Init(BRAKE__PORT,
BRAKE__PIN,
GPIO_MODE_IN_FL_IT); // with external interrupt
//initialize the Interrupt sensitivity
EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOC,
EXTI_SENSITIVITY_RISE_FALL);
}
BitStatus brake_is_set (void)
{
if (GPIO_ReadInputPin(BRAKE__PORT, BRAKE__PIN) == 0)
return 1;
else
return 0;
}