-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
76 lines (58 loc) · 1.4 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "stm32f405.h"
#include "clock.h"
#include "uart_dma.h"
#include "i2c.h"
int main(void)
{
initialize_clock();
initialize_dma_uart();
RCC_AHB1ENR |= 0x00000004;
GPIOC_MODER |= 0x00000050;
GPIOC_ODR |= 0x0000000C;
GPIOC_MODER |= 0x00000004;
GPIOC_ODR = 0x00000002;
initialize_i2c();
GPIOC_ODR = 0x00000000;
uint32_t t_next_led = get_time_us();
bool led_on = false;
uint8_t slave_led = 5;
const uint8_t slave_led_states[6] = {1, 2, 4, 3, 5, 6};
while (true)
{
process_dma_uart();
if (((int32_t)(get_time_us() - t_next_led)) >= 0)
{
led_on = !led_on;
t_next_led += 500000;
if (led_on)
{
GPIOC_ODR = 0x00000002;
}
else
{
GPIOC_ODR = 0x00000000;
}
slave_led++;
slave_led %= 6;
i2c_write(0x00, 0x09, slave_led_states[slave_led]);
}
}
}
void * memset(void * ptr1, int c, size_t length)
{
uint8_t * ptr2 = ptr1;
for (size_t i = 0; i < length; i++)
ptr2[i] = c;
return ptr1;
}
void * memcpy(void * dst, const void * src, size_t length)
{
uint8_t * dst2 = dst;
const uint8_t * src2 = src;
for (size_t i = 0; i < length; i++)
dst2[i] = src2[i];
return dst;
}