forked from mbonani/aseba-target-thymio2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpmp.c
153 lines (110 loc) · 3 KB
/
pmp.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
144
145
146
147
148
149
150
151
152
/*
Thymio-II Firmware
Copyright (C) 2011 Philippe Retornaz <philippe dot retornaz at epfl dot ch>,
Mobots group (http://mobots.epfl.ch), Robotics system laboratory (http://lsro.epfl.ch)
EPFL Ecole polytechnique federale de Lausanne (http://www.epfl.ch)
See authors.txt for more details about other contributors.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <p24Fxxxx.h>
#include "pmp.h"
void setup_io(void) {
// Setup PWM high side as opendrain, default high
_ODE3 = 1;
_LATE3 = 1;
_TRISE3 = 0;
_ODE5 = 1;
_LATE5 = 1;
_TRISE5 = 0;
_ODE0 = 1;
_LATE0 = 1;
_TRISE0 = 0;
_ODE1 = 1;
_LATE1 = 1;
_TRISE1 = 0;
// Output pin
_LATF0 = 1; // USB-500
_TRISF0 = 0;
// By default, enable 500mA charging.
// We will switch to 100mA right after making sure to disable the leds
_LATF1 = 1; // USB-Charge
_TRISF1 = 0;
_LATF5 = 0;
_TRISF5 = 0; // M1PWML1
_LATB15 = 0;
_TRISB15 = 0; // Sound out
_LATC13 = 0; // LED_CS
_TRISC13 = 0;
_LATD0 = 0; // LED CLK, make sure a default level is chosen when spi not enabled
_TRISD0 = 0;
_LATD4 = 0;
_TRISD4 = 0; // M2PWML1
_LATD5 = 0;
_TRISD5 = 0; // M2PWML2
_LATD6 = 0;
_TRISD6 = 0; // ir-pulse-groundL
_LATD8 = 0; // M1PWML2
_TRISD8 = 0;
_LATD11 = 0;
_TRISD11 = 0; // LED_SDO, make sure it's an output when spi not enabled
_LATE2 = 0; // VA, disabled by default
_TRISE2 = 0;
_LATE4 = 0; // ir-pulse-groundR
_TRISE4 = 0;
_LATF4 = 0; // ir-pulse-back
_TRISF4 = 0;
_LATD9 = 0; // ir-pulse-front
_TRISD9 = 0;
// Put SD card DAT[3] (CS) at low, then input, will be used for card detection...
_LATB14 = 0;
_TRISB14 = 0;
Nop();
_TRISB14 = 1;
_LATB14 = 1;
}
void setup_pps(void) {
/* Output only modules */
// PWM OC
_RP17R = 19;
_RP25R = 21;
_RP20R = 22;
_RP2R = 20;
// Sound OC
_RP29R = 23;
// Led SPI
_RP11R = 8;
_RP12R = 7;
_RP26R = 1; // Comparator output ...
// OC pulse ir sensors
_RP10R = 25;
_RP4R = 24;
/* Input only modules */
// IR Sensors
_IC1R = 7;
_IC2R = 27;
_IC3R = 8;
_IC4R = 19;
_IC5R = 9;
_IC6R = 3;
_IC7R = 37;
// NTC
_IC8R = 26;
// IR Remote control
_IC9R = 26;
/* Bidirectional modules */
// SD card SPI
// FIXME Handle correctly VA switchable LDO !!!!
// IO not enabled until SPI is enabled, so it's safe
// To do it now (TODO: Check this with a scope ... )
_RP24R = 11;
_RP23R = 10;
_SDI2R = 22;
}