eeprom at24c signs of life
[cortex-from-scratch] / drivers / led.c
1 /* (CC-BY-NC-SA) ROBIN KRENS - ROBIN @ ROBINKRENS.NL
2  * 
3  * $LOG$
4  * 2019/7/25 - ROBIN KRENS      
5  * Initial version 
6  * 
7  * $DESCRIPTION$
8  * Hardly a driver, but a driver nonetheless. Enables clock on 
9  * a GPIOx range and sets the GPIOx pin in push-pull output mode. 
10  * Basic on - off function (writing a 1 or zero 0) 
11  * 
12  * $USAGE$
13  * In the code below we enable GPIOC and use PC0 as output. But 
14  * basically any GPIO range or pin could be used. Note that the 
15  * output register is only word accessible.
16  *
17  * */
18
19 #include <stdbool.h>
20 #include <stddef.h>
21 #include <stdint.h>
22
23 #include <sys/mmap.h>
24 #include <sys/robsys.h>
25
26 #include <lib/regfunc.h>
27 #include <lib/string.h>
28
29 #include <drivers/led.h>
30
31
32 void led_init() {
33
34         rsetbit(RCC_APB2ENR, 5); // enable GPIOD
35         rsetbit(RCC_APB2ENR, 2); // enable GPIOA
36
37         //rwrite(GPIOD_CRL, 0x44444644); 
38         rsetbitsfrom(GPIOD_CRL, 8, 0x6);
39         rsetbitsfrom(GPIOA_CRH, 0, 0x6);
40 //      rsetbit(GPIOD_ODR, 2);
41 //      rclrbit(GPIOA_ODR, 8);
42
43 }
44
45 void led_on() {
46         rsetbit(GPIOD_ODR, 2);
47         rclrbit(GPIOA_ODR, 8);
48
49 }
50
51 void led_off() {
52         rclrbit(GPIOD_ODR, 2);
53         rsetbit(GPIOA_ODR, 8);
54 }
55