-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathled.h
112 lines (94 loc) · 2.34 KB
/
led.h
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* led.h
*
* API for interfacing with the MSOE dev board LEDs
*/
//Include Guards
#ifndef LED_H_
#define LED_H_
#include <inttypes.h>
//Find the Addresses for the following memory mapped control registers
//Check the STM Reference Manual
//Memory Map - Chapter 2.2
//RCC - Chapter 6.3.28
//GPIO - Chapter 7.4
#define RCC_AHB1ENR (volatile uint32_t*) 0x40023830
//Which bit enables GPIOB?
#define GPIOBEN 0x01
//Find the Addresses for the following memory mapped control registers
#define GPIOB_MODER (volatile uint32_t*) 0x40020400
#define GPIOB_PUPDR (volatile uint32_t*) 0x4002040C
#define GPIOB_IDR (volatile uint32_t*) 0x40020410
#define GPIOB_ODR (volatile uint32_t*) 0x40020414
#define GPIOB_BSRR (volatile uint32_t*) 0x40020418
/*
* led_init()
* This function should:
* 1. Enable the GPIOB in RCC_AHB1ENR
* 2. Turn on to set LED0 - LED9 to output mode ("01")
*/
void led_init();
/*
* led_allOn()
* 1. Turn on all leds (hint use ODR or BSRR)
* Note you should not effect other pins on PortB
*/
void led_allOn();
/*
* led_allOff()
* 1. Turn off all leds (hint use ODR or BSRR)
* Note you should not effect other pins on PortB
*/
void led_allOff();
/*
* led_on()
* Args: 0-9 to turn on specific led
* print error message is arg is out of range
*/
void led_on(uint8_t ledIndex);
/*
* led_off()
* Args: 0-9 to turn off specific led
* print error message is arg is out of range
*/
void led_off(uint8_t ledIndex);
/*
* led_scan()
* Scan the light across and back at the current speed
*/
void led_scan();
/*
* led_flash()
* flash all of the lights 10 times at the current speed
*/
void led_flash();
/*
* led_setSpeed (uint8_t speed)
* arg: speed (0 slow - 9 fast)
* Args out of range should print error to console
*/
void led_setSpeed(uint8_t speed);
/*
* led_incSpeed()
* increases the speed by one
* if maxed out leaves the speed at the max value
*/
void led_incSpeed();
/*
* led_decSpeed()
* decreases the speed by one
* if at zero should stay at zero
*/
void led_decSpeed();
/*
* getCurrentSpeed
* returns the current speed
*/
uint8_t getCurrentSpeed();
/*
* adjustIndex(uint32_t ledIndex)
* Adjusts LED index to the index of pin for corresponding LED as defined on dev. board
* Note: does not account for out-of-bound index
*/
uint32_t adjustIndex(uint32_t ledIndex);
#endif