forked from szemzoa/awboot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboard.c
More file actions
118 lines (99 loc) · 2.79 KB
/
board.c
File metadata and controls
118 lines (99 loc) · 2.79 KB
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
113
114
115
116
117
118
#include "common.h"
#include "board.h"
#include "sunxi_gpio.h"
#include "sunxi_sdhci.h"
#include "sunxi_usart.h"
#include "sunxi_spi.h"
#include "sunxi_wdg.h"
#include "sdmmc.h"
sunxi_usart_t usart0_dbg = {
.id = 0,
.gpio_tx = {GPIO_PIN(PORTE, 2), GPIO_PERIPH_MUX6},
.gpio_rx = {GPIO_PIN(PORTE, 3), GPIO_PERIPH_MUX6},
};
sunxi_usart_t usart3_dbg = {
.id = 3,
.gpio_tx = {GPIO_PIN(PORTB, 6), GPIO_PERIPH_MUX7},
.gpio_rx = {GPIO_PIN(PORTB, 7), GPIO_PERIPH_MUX7},
};
sunxi_spi_t sunxi_spi0 = {
.base = 0x04025000,
.id = 0,
.clk_rate = 25 * 1000 * 1000,
.gpio_cs = {GPIO_PIN(PORTC, 3), GPIO_PERIPH_MUX2},
.gpio_sck = {GPIO_PIN(PORTC, 2), GPIO_PERIPH_MUX2},
.gpio_mosi = {GPIO_PIN(PORTC, 4), GPIO_PERIPH_MUX2},
.gpio_miso = {GPIO_PIN(PORTC, 5), GPIO_PERIPH_MUX2},
.gpio_wp = {GPIO_PIN(PORTC, 6), GPIO_PERIPH_MUX2},
.gpio_hold = {GPIO_PIN(PORTC, 7), GPIO_PERIPH_MUX2},
};
sdhci_t sdhci0 = {
.name = "sdhci0",
.reg = (sdhci_reg_t *)0x04020000,
.voltage = MMC_VDD_27_36,
.width = MMC_BUS_WIDTH_4,
.clock = MMC_CLK_50M,
.removable = 0,
.isspi = FALSE,
.gpio_clk = {GPIO_PIN(PORTF, 2), GPIO_PERIPH_MUX2},
.gpio_cmd = {GPIO_PIN(PORTF, 3), GPIO_PERIPH_MUX2},
.gpio_d0 = {GPIO_PIN(PORTF, 1), GPIO_PERIPH_MUX2},
.gpio_d1 = {GPIO_PIN(PORTF, 0), GPIO_PERIPH_MUX2},
.gpio_d2 = {GPIO_PIN(PORTF, 5), GPIO_PERIPH_MUX2},
.gpio_d3 = {GPIO_PIN(PORTF, 4), GPIO_PERIPH_MUX2},
};
static const gpio_t led_board = GPIO_PIN(PORTD, 18);
static const gpio_t led_btn = GPIO_PIN(PORTB, 5);
static const gpio_t btn = GPIO_PIN(PORTE, 9);
static const gpio_t status = GPIO_PIN(PORTD, 22);
static const gpio_t power_on = GPIO_PIN(PORTD, 21);
// static const gpio_t phyaddr0 = GPIO_PIN(PORTE, 7);
// static const gpio_t phyaddr1 = GPIO_PIN(PORTE, 0);
// static const gpio_t phyaddr2 = GPIO_PIN(PORTE, 1);
// static const gpio_t phyaddr3 = GPIO_PIN(PORTE, 2);
// static const gpio_t phynrst = GPIO_PIN(PORTE, 11);
static void output_init(const gpio_t gpio)
{
sunxi_gpio_init(gpio, GPIO_OUTPUT);
sunxi_gpio_write(gpio, 0);
};
static void intput_init(const gpio_t gpio)
{
sunxi_gpio_init(gpio, GPIO_INPUT);
};
void board_set_led(uint8_t num, uint8_t on)
{
switch (num) {
case LED_BOARD:
sunxi_gpio_write(led_board, on);
break;
case LED_BUTTON:
sunxi_gpio_write(led_btn, on);
break;
default:
break;
}
}
bool board_get_button()
{
return !sunxi_gpio_read(btn);
}
bool board_get_power_on()
{
return sunxi_gpio_read(power_on);
}
void board_set_status(bool on)
{
sunxi_gpio_write(status, on);
}
void board_init()
{
output_init(led_board);
// intput_init(btn);
output_init(status);
intput_init(power_on);
sunxi_usart_init(&USART_DBG, USART_BAUDRATE);
sunxi_wdg_init();
// We need to set the pin to 1 for MCU to detect fallin edge later on.
board_set_status(1);
}