-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPIC32MK1024GPE_devboard.c
143 lines (118 loc) · 3.35 KB
/
PIC32MK1024GPE_devboard.c
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
* @file PIC32MK1024GPE_devboard.c
* @author Sebastien CAUX (sebcaux)
* @copyright Robotips 2017
* @copyright UniSwarm 2018-2023
*
* @date October 25, 2017, 17:13 AM
*
* @brief Code for PIC32MK1024GPE dev board board (DM320106)
*
* product page:
* http://www.microchip.com/Developmenttools/ProductDetails.aspx?PartNO=DM320106
* datasheet:
* http://ww1.microchip.com/downloads/en/DeviceDoc/70005316A.pdf
* http://ww1.microchip.com/downloads/en/DeviceDoc/50002568B.pdf
*/
#include "PIC32MK1024GPE_devboard.h"
#include <driver/gpio.h>
#include <driver/sysclock.h>
static rt_dev_t _board_leds[LED_COUNT];
static rt_dev_t _board_buttons[BUTTON_COUNT];
static int _board_init_io(void);
int _board_init_io(void)
{
#ifndef SIMULATOR
// analog inputs
ANSELA = 0x0000; // all analog inputs of port A as digital buffer
ANSELB = 0x0000; // all analog inputs of port B as digital buffer
ANSELC = 0x0000; // all analog inputs of port C as digital buffer
ANSELD = 0x0000; // all analog inputs of port D as digital buffer
ANSELE = 0x0000; // all analog inputs of port E as digital buffer
ANSELG = 0x0000; // all analog inputs of port G as digital buffer
// remappable pins
// Unlock configuration pin
unlockIoConfig();
U3RXR = 0b0101; // RX3 ==> RPC7
RPC6R = 0b00001; // TX3 ==> RPC6
U4RXR = 0b1101; // RX4 ==> RPD3
RPA12R = 0b00010; // TX4 ==> RPA12
C1RXR = 0b1000; // CAN1RX ==> RE14
RPE0R = 0b01100; // CAN1TX ==> RE0
C2RXR = 0b1100; // CAN2RX ==> RE1
RPE15R = 0b01100; // CAN2TX ==> RE15
C3RXR = 0b1010; // CAN3RX ==> RG6
RPC15R = 0b01100; // CAN3TX ==> RC15
C4RXR = 0b0110; // CAN4RX ==> RC2
RPB1R = 0b01100; // CAN4TX ==> RB1
lockIoConfig();
#endif
_board_leds[0] = gpio_pin(GPIO_PORTG, 12);
gpio_setBitConfig(_board_leds[0], GPIO_OUTPUT);
_board_leds[1] = gpio_pin(GPIO_PORTG, 13);
gpio_setBitConfig(_board_leds[1], GPIO_OUTPUT);
_board_leds[2] = gpio_pin(GPIO_PORTG, 14);
gpio_setBitConfig(_board_leds[2], GPIO_OUTPUT);
_board_buttons[0] = gpio_pin(GPIO_PORTG, 11);
gpio_setBitConfig(_board_buttons[0], GPIO_INPUT);
_board_buttons[1] = gpio_pin(GPIO_PORTF, 13);
gpio_setBitConfig(_board_buttons[1], GPIO_INPUT);
_board_buttons[2] = gpio_pin(GPIO_PORTF, 12);
gpio_setBitConfig(_board_buttons[2], GPIO_INPUT);
return 0;
}
int board_init(void)
{
sysclock_setSourceFreq(SYSCLOCK_SRC_POSC, 12000000); // 12MHz
sysclock_setSourceFreq(SYSCLOCK_SRC_SOSC, 32768); // 12MHz
archi_init();
_board_init_io();
return 0;
}
int board_setLed(uint8_t led, uint8_t state)
{
if (led >= LED_COUNT)
{
return -1;
}
if (state & 1)
{
gpio_setBit(_board_leds[led]);
}
else
{
gpio_clearBit(_board_leds[led]);
}
return 0;
}
int board_toggleLed(uint8_t led)
{
if (led >= LED_COUNT)
{
return -1;
}
gpio_toggleBit(_board_leds[led]);
return 0;
}
int8_t board_getLed(uint8_t led)
{
if (led >= LED_COUNT)
{
return -1;
}
return gpio_readBit(_board_leds[led]);
}
int8_t board_getButton(uint8_t button)
{
GPIO_VALUE value;
if (button >= BUTTON_COUNT)
{
return -1;
}
value = gpio_readBit(_board_buttons[button]);
if (value == GPIO_HIGH)
{
return 0;
}
return 1;
}