blob: aebea8bdcefae5c43469170deb5e0b22a0b99455 (
plain)
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
|
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*
*/
#include <MK64F12.h>
#include "led.h"
const rt_uint32_t led_mask[] = {1 << 21, 1 << 22, 1 << 26};
void rt_hw_led_init(void)
{
SIM->SCGC5 |= (1 << SIM_SCGC5_PORTB_SHIFT);
SIM->SCGC5 |= (1 << SIM_SCGC5_PORTE_SHIFT);
PORTB->PCR[21] &= ~PORT_PCR_MUX_MASK;
PORTB->PCR[21] |= PORT_PCR_MUX(1); //PTB21 is GPIO pin
PORTB->PCR[22] &= ~PORT_PCR_MUX_MASK;
PORTB->PCR[22] |= PORT_PCR_MUX(1); //PTB22 is GPIO pin
PORTE->PCR[26] &= ~PORT_PCR_MUX_MASK;
PORTE->PCR[26] |= PORT_PCR_MUX(1); //PTE26 is GPIO pin
/* Switch LEDs off and enable output*/
PTB->PDDR |= GPIO_PDDR_PDD(led_mask[1] | led_mask[0]);
PTE->PDDR |= GPIO_PDDR_PDD(led_mask[2]);
rt_hw_led_off(LED_RED);
rt_hw_led_off(LED_GREEN);
rt_hw_led_off(LED_BLUE);
}
void rt_hw_led_uninit(void)
{
PORTB->PCR[21] &= ~PORT_PCR_MUX_MASK;
PORTB->PCR[22] &= ~PORT_PCR_MUX_MASK;
PORTE->PCR[26] &= ~PORT_PCR_MUX_MASK;
}
void rt_hw_led_on(rt_uint32_t n)
{
if (n != LED_GREEN)
{
PTB->PCOR |= led_mask[n];
}
else
{
PTE->PCOR |= led_mask[n];
}
}
void rt_hw_led_off(rt_uint32_t n)
{
if (n != LED_GREEN)
{
PTB->PSOR |= led_mask[n];
}
else
{
PTE->PSOR |= led_mask[n];
}
}
|