-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathled.c
More file actions
33 lines (28 loc) · 691 Bytes
/
Copy pathled.c
File metadata and controls
33 lines (28 loc) · 691 Bytes
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
#include "led.h"
#include <stdint.h>
/* STM32 Blue Pill Onboard LED = PC13 */
static uint32_t *pRccApb2Enr = (uint32_t*) (0x40021000 + 0x18);
static uint32_t *pGpioCModeReg = (uint32_t*) (0x40011000 + 0x04);
static uint32_t *pGpioCDataReg = (uint32_t*) (0x40011000 + 0x0C);
/**
* @brief Initialise on-board LED.
*/
void led_init(void)
{
*pRccApb2Enr |= 1 << 4; /* Enable GPIOC Clock */
*pGpioCModeReg |= 1 << 20; /* Configure PC13 - Ouput */
}
/**
* @brief Turn on-board LED on.
*/
void led_on()
{
*pGpioCDataReg &= ~(1 << 13); /* PC13 - Reset */
}
/**
* @brief Turn on-board LED off.
*/
void led_off()
{
*pGpioCDataReg |= 1 << 13; /* PC13 - Set */
}