-
Notifications
You must be signed in to change notification settings - Fork 0
/
seven_seg_port.c
52 lines (46 loc) · 1.38 KB
/
seven_seg_port.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
#include "seven_seg_port.h"
#include "seven_seg.h"
#include "io_define.h"
const SevenSeg_Driver SEVEN_SEG_DRIVER = {
SevenSeg_initPin,
SevenSeg_writePin,
};
#if SEVEN_SEG_HW == SEVEN_SEG_HW_AVR | SEVEN_SEG_HW == SEVEN_SEG_HW_STM32F0
void SevenSeg_initPin(const SevenSeg_pinConfig* config) {
config->IO->Direction.reg |= (1 << config->pin);
}
void SevenSeg_writePin(const SevenSeg_pinConfig* config, GPIO_PinState state) {
if(state != GPIO_PIN_RESET)
{
config->IO->OutputData.reg |= (1 << config->pin);
}
else
{
config->IO->OutputData.reg &= ~(1 << config->pin);
}
}
#elif SEVEN_SEG_HW == SEVEN_SEG_HW_STM32F0
// TODO: Implement me later
#elif SEVEN_SEG_HW == SEVEN_SEG_HW_STM32F1
// TODO: Implement me later
#elif SEVEN_SEG_HW == SEVEN_SEG_HW_STM32F2
// TODO: Implement me later
#elif SEVEN_SEG_HW == SEVEN_SEG_HW_STM32F3
// TODO: Implement me later
#elif SEVEN_SEG_HW == SEVEN_SEG_HW_STM32F4
void SevenSeg_initPin(const SevenSeg_pinConfig* config) {
config->IO->MODER |= (0x03 << (config->pin + config->pin));
}
void SevenSeg_writePin(const SevenSeg_pinConfig* config, GPIO_PinState state) {
if(state != GPIO_PIN_RESET)
{
config->IO->BSRR = GPIO_Pin;
}
else
{
config->IO->BSRR = (uint32_t)GPIO_Pin << 16U;
}
}
#else
#error "Please select your hardware"
#endif // SEVEN_SEG_HW