1 2 3 4 5 6 7 8 9 10 11
12 import ti.catalog.msp430.peripherals.communication.USI as USI;
13 import ti.catalog.msp430.peripherals.adc.ADC10 as ADC10;
14
15 /*!
16 * ======== GPIO for MSP430F20x2 ========
17 * MSP430 General Purpose Input Output Ports
18 */
19 metaonly module GPIO_MSP430F20x2 inherits IGPIO {
20 /*!
21 * ======== create ========
22 * Create an instance of this peripheral.
23 */
24 create(USI.Instance usi, ADC10.Instance adc10);
25
26 instance:
27 /*! @_nodoc */
28 config USI.Instance usi;
29
30 /*! @_nodoc */
31 config ADC10.Instance adc10;
32
33 /*! Define an array to describe all device pins. The 1st dimension
34 * denotes the port, the second the pin on that port. On an
35 * MSP430F20x2 device, there are 8 + 2 = 10 pins total.
36 */
37
38 39
40 readonly config DevicePin_t devicePins[2][8] =
41 [
42 [
43 {
44 pinName : "P1.0",
45 pinFunction : {
46 functionName : [
47 "GPIO Input",
48 "GPIO Output",
49 "Timer_A2.TACLK/INCLK",
50 "ACLK",
51 "A0"
52 ],
53 functionConfig : [
54 [
55 { register : "P1DIR", bitSetMask : 0x00, bitClearMask : 0x01 },
56 { register : "P1SEL", bitSetMask : 0x00, bitClearMask : 0x01 },
57 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x01 }
58 ],
59 [
60 { register : "P1DIR", bitSetMask : 0x01, bitClearMask : 0x00 },
61 { register : "P1SEL", bitSetMask : 0x00, bitClearMask : 0x01 },
62 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x01 }
63 ],
64 [
65 { register : "P1DIR", bitSetMask : 0x00, bitClearMask : 0x01 },
66 { register : "P1SEL", bitSetMask : 0x01, bitClearMask : 0x00 },
67 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x01 }
68 ],
69 [
70 { register : "P1DIR", bitSetMask : 0x01, bitClearMask : 0x00 },
71 { register : "P1SEL", bitSetMask : 0x01, bitClearMask : 0x00 },
72 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x01 }
73 ],
74 [
75 { register : "ADC10AE0", bitSetMask : 0x01, bitClearMask : 0x00 }
76 ]
77 ]
78 }
79 },
80 {
81 pinName : "P1.1",
82 pinFunction : {
83 functionName : [
84 "GPIO Input",
85 "GPIO Output",
86 "Timer_A2.CCI0A",
87 "Timer_A2.TA0",
88 "A1"
89 ],
90 functionConfig : [
91 [
92 { register : "P1DIR", bitSetMask : 0x00, bitClearMask : 0x02 },
93 { register : "P1SEL", bitSetMask : 0x00, bitClearMask : 0x02 },
94 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x02 }
95 ],
96 [
97 { register : "P1DIR", bitSetMask : 0x02, bitClearMask : 0x00 },
98 { register : "P1SEL", bitSetMask : 0x00, bitClearMask : 0x02 },
99 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x02 }
100 ],
101 [
102 { register : "P1DIR", bitSetMask : 0x00, bitClearMask : 0x02 },
103 { register : "P1SEL", bitSetMask : 0x02, bitClearMask : 0x00 },
104 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x02 }
105 ],
106 [
107 { register : "P1DIR", bitSetMask : 0x02, bitClearMask : 0x00 },
108 { register : "P1SEL", bitSetMask : 0x02, bitClearMask : 0x00 },
109 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x02 }
110 ],
111 [
112 { register : "ADC10AE0", bitSetMask : 0x02, bitClearMask : 0x00 }
113 ]
114 ]
115 }
116 },
117 {
118 pinName : "P1.2",
119 pinFunction : {
120 functionName : [
121 "GPIO Input",
122 "GPIO Output",
123 "Timer_A2.CCI1A",
124 "Timer_A2.TA1",
125 "A2"
126 ],
127 functionConfig : [
128 [
129 { register : "P1DIR", bitSetMask : 0x00, bitClearMask : 0x04 },
130 { register : "P1SEL", bitSetMask : 0x00, bitClearMask : 0x04 },
131 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x04 }
132 ],
133 [
134 { register : "P1DIR", bitSetMask : 0x04, bitClearMask : 0x00 },
135 { register : "P1SEL", bitSetMask : 0x00, bitClearMask : 0x04 },
136 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x04 }
137 ],
138 [
139 { register : "P1DIR", bitSetMask : 0x00, bitClearMask : 0x04 },
140 { register : "P1SEL", bitSetMask : 0x04, bitClearMask : 0x00 },
141 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x04 }
142 ],
143 [
144 { register : "P1DIR", bitSetMask : 0x04, bitClearMask : 0x00 },
145 { register : "P1SEL", bitSetMask : 0x04, bitClearMask : 0x00 },
146 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x04 }
147 ],
148 [
149 { register : "ADC10AE0", bitSetMask : 0x04, bitClearMask : 0x00 }
150 ]
151 ]
152 }
153 },
154 {
155 pinName : "P1.3",
156 pinFunction : {
157 functionName : [
158 "GPIO Input",
159 "GPIO Output",
160 "ADC10CLK",
161 "A3/VREF-/VeREF-"
162 ],
163 functionConfig : [
164 [
165 { register : "P1DIR", bitSetMask : 0x00, bitClearMask : 0x08 },
166 { register : "P1SEL", bitSetMask : 0x00, bitClearMask : 0x08 },
167 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x08 }
168 ],
169 [
170 { register : "P1DIR", bitSetMask : 0x08, bitClearMask : 0x00 },
171 { register : "P1SEL", bitSetMask : 0x00, bitClearMask : 0x08 },
172 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x08 }
173 ],
174 [
175 { register : "P1DIR", bitSetMask : 0x08, bitClearMask : 0x00 },
176 { register : "P1SEL", bitSetMask : 0x08, bitClearMask : 0x00 },
177 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x08 }
178 ],
179 [
180 { register : "ADC10AE0", bitSetMask : 0x08, bitClearMask : 0x00 }
181 ]
182 ]
183 }
184 },
185 {
186 pinName : "P1.4",
187 pinFunction : {
188 functionName : [
189 "GPIO Input",
190 "GPIO Output",
191 "SMCLK",
192 "A4/VREF+/VeREF+"
193 ],
194 functionConfig : [
195 [
196 { register : "P1DIR", bitSetMask : 0x00, bitClearMask : 0x10 },
197 { register : "P1SEL", bitSetMask : 0x00, bitClearMask : 0x10 },
198 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x10 }
199 ],
200 [
201 { register : "P1DIR", bitSetMask : 0x10, bitClearMask : 0x00 },
202 { register : "P1SEL", bitSetMask : 0x00, bitClearMask : 0x10 },
203 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x10 }
204 ],
205 [
206 { register : "P1DIR", bitSetMask : 0x10, bitClearMask : 0x00 },
207 { register : "P1SEL", bitSetMask : 0x10, bitClearMask : 0x00 },
208 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x10 }
209 ],
210 [
211 { register : "ADC10AE0", bitSetMask : 0x10, bitClearMask : 0x00 }
212 ]
213 ]
214 }
215 },
216 {
217 pinName : "P1.5",
218 pinFunction : {
219 functionName : [
220 "GPIO Input",
221 "GPIO Output",
222 "Timer_A2.TA0",
223 "SCLK",
224 "A5"
225 ],
226 functionConfig : [
227 [
228 { register : "P1DIR", bitSetMask : 0x00, bitClearMask : 0x20 },
229 { register : "P1SEL", bitSetMask : 0x00, bitClearMask : 0x20 },
230 { register : "USICTL0", bitSetMask : 0x00, bitClearMask : 0x20 },
231 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x20 }
232 ],
233 [
234 { register : "P1DIR", bitSetMask : 0x20, bitClearMask : 0x00 },
235 { register : "P1SEL", bitSetMask : 0x00, bitClearMask : 0x20 },
236 { register : "USICTL0", bitSetMask : 0x00, bitClearMask : 0x20 },
237 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x20 }
238 ],
239 [
240 { register : "P1DIR", bitSetMask : 0x20, bitClearMask : 0x00 },
241 { register : "P1SEL", bitSetMask : 0x20, bitClearMask : 0x00 },
242 { register : "USICTL0", bitSetMask : 0x00, bitClearMask : 0x20 },
243 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x20 }
244 ],
245 [
246 { register : "USICTL0", bitSetMask : 0x20, bitClearMask : 0x00 },
247 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x20 }
248 ],
249 [
250 { register : "USICTL0", bitSetMask : 0x00, bitClearMask : 0x20 },
251 { register : "ADC10AE0", bitSetMask : 0x20, bitClearMask : 0x00 }
252 ]
253 ]
254 }
255 },
256 {
257 pinName : "P1.6",
258 pinFunction : {
259 functionName : [
260 "GPIO Input",
261 "GPIO Output",
262 "Timer_A2.CCI1B",
263 "Timer_A2.TA1",
264 "SDO/SCL",
265 "A6"
266 ],
267 functionConfig : [
268 [
269 { register : "P1DIR", bitSetMask : 0x00, bitClearMask : 0x40 },
270 { register : "P1SEL", bitSetMask : 0x00, bitClearMask : 0x40 },
271 { register : "USICTL0", bitSetMask : 0x00, bitClearMask : 0x40 },
272 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x40 }
273 ],
274 [
275 { register : "P1DIR", bitSetMask : 0x40, bitClearMask : 0x00 },
276 { register : "P1SEL", bitSetMask : 0x00, bitClearMask : 0x40 },
277 { register : "USICTL0", bitSetMask : 0x00, bitClearMask : 0x40 },
278 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x40 }
279 ],
280 [
281 { register : "P1DIR", bitSetMask : 0x00, bitClearMask : 0x40 },
282 { register : "P1SEL", bitSetMask : 0x40, bitClearMask : 0x00 },
283 { register : "USICTL0", bitSetMask : 0x00, bitClearMask : 0x40 },
284 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x40 }
285 ],
286 [
287 { register : "P1DIR", bitSetMask : 0x40, bitClearMask : 0x00 },
288 { register : "P1SEL", bitSetMask : 0x40, bitClearMask : 0x00 },
289 { register : "USICTL0", bitSetMask : 0x00, bitClearMask : 0x40 },
290 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x40 }
291 ],
292 [
293 { register : "USICTL0", bitSetMask : 0x40, bitClearMask : 0x00 },
294 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x40 }
295 ],
296 [
297 { register : "USICTL0", bitSetMask : 0x00, bitClearMask : 0x40 },
298 { register : "ADC10AE0", bitSetMask : 0x40, bitClearMask : 0x00 }
299 ]
300 ]
301 }
302 },
303 {
304 pinName : "P1.7",
305 pinFunction : {
306 functionName : [
307 "GPIO Input",
308 "GPIO Output",
309 "DVss",
310 "SDI/SDA",
311 "A7"
312 ],
313 functionConfig : [
314 [
315 { register : "P1DIR", bitSetMask : 0x00, bitClearMask : 0x80 },
316 { register : "P1SEL", bitSetMask : 0x00, bitClearMask : 0x80 },
317 { register : "USICTL0", bitSetMask : 0x00, bitClearMask : 0x80 },
318 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x80 }
319 ],
320 [
321 { register : "P1DIR", bitSetMask : 0x80, bitClearMask : 0x00 },
322 { register : "P1SEL", bitSetMask : 0x00, bitClearMask : 0x80 },
323 { register : "USICTL0", bitSetMask : 0x00, bitClearMask : 0x80 },
324 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x80 }
325 ],
326 [
327 { register : "P1DIR", bitSetMask : 0x80, bitClearMask : 0x00 },
328 { register : "P1SEL", bitSetMask : 0x80, bitClearMask : 0x00 },
329 { register : "USICTL0", bitSetMask : 0x00, bitClearMask : 0x80 },
330 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x80 }
331 ],
332 [
333 { register : "USICTL0", bitSetMask : 0x80, bitClearMask : 0x00 },
334 { register : "ADC10AE0", bitSetMask : 0x00, bitClearMask : 0x80 }
335 ],
336 [
337 { register : "USICTL0", bitSetMask : 0x00, bitClearMask : 0x80 },
338 { register : "ADC10AE0", bitSetMask : 0x80, bitClearMask : 0x00 }
339 ]
340 ]
341 }
342 }
343 ],
344 [
345 {
346 pinName : "P2.0",
347 pinFunction : {
348 functionName : [
349 ""
350 ],
351 functionConfig : [
352 [
353
354 ]
355 ]
356 }
357 },
358 {
359 pinName : "P2.1",
360 pinFunction : {
361 functionName : [
362 ""
363 ],
364 functionConfig : [
365 [
366
367 ]
368 ]
369 }
370 },
371 {
372 pinName : "P2.2",
373 pinFunction : {
374 functionName : [
375 ""
376 ],
377 functionConfig : [
378 [
379
380 ]
381 ]
382 }
383 },
384 {
385 pinName : "P2.3",
386 pinFunction : {
387 functionName : [
388 ""
389 ],
390 functionConfig : [
391 [
392
393 ]
394 ]
395 }
396 },
397 {
398 pinName : "P2.4",
399 pinFunction : {
400 functionName : [
401 ""
402 ],
403 functionConfig : [
404 [
405
406 ]
407 ]
408 }
409 },
410 {
411 pinName : "P2.5",
412 pinFunction : {
413 functionName : [
414 ""
415 ],
416 functionConfig : [
417 [
418
419 ]
420 ]
421 }
422 },
423 {
424 pinName : "P2.6",
425 pinFunction : {
426 functionName : [
427 "GPIO Input",
428 "GPIO Output",
429 "XIN",
430 "Timer_A2.TA1"
431 ],
432 functionConfig : [
433 [
434 { register : "P2DIR", bitSetMask : 0x00, bitClearMask : 0x40 },
435 { register : "P2SEL", bitSetMask : 0x00, bitClearMask : 0x40 }
436 ],
437 [
438 { register : "P2DIR", bitSetMask : 0x40, bitClearMask : 0x00 },
439 { register : "P2SEL", bitSetMask : 0x00, bitClearMask : 0x40 }
440 ],
441 [
442 { register : "P2DIR", bitSetMask : 0x00, bitClearMask : 0x40 },
443 { register : "P2SEL", bitSetMask : 0x40, bitClearMask : 0x00 }
444 ],
445 [
446 { register : "P2DIR", bitSetMask : 0x40, bitClearMask : 0x00 },
447 { register : "P2SEL", bitSetMask : 0x40, bitClearMask : 0x00 }
448 ]
449 ]
450 }
451 },
452 {
453 pinName : "P2.7",
454 pinFunction : {
455 functionName : [
456 "GPIO Input",
457 "GPIO Output",
458 "XOUT"
459 ],
460 functionConfig : [
461 [
462 { register : "P2DIR", bitSetMask : 0x00, bitClearMask : 0x80 },
463 { register : "P2SEL", bitSetMask : 0x00, bitClearMask : 0x80 }
464 ],
465 [
466 { register : "P2DIR", bitSetMask : 0x80, bitClearMask : 0x00 },
467 { register : "P2SEL", bitSetMask : 0x00, bitClearMask : 0x80 }
468 ],
469 [
470 { register : "P2SEL", bitSetMask : 0x80, bitClearMask : 0x00 }
471 ]
472 ]
473 }
474 }
475 ]
476 ];
477
478 /*! Implementation of Device Pin Functional Configuration */
479 override config DevicePinFunctionSetting_t devicePinSetting[2][8];
480
481 /*! Determine if each Register needs to be forced set or not */
482 readonly config ForceSetDefaultRegister_t forceSetDefaultRegister[] =
483 [
484 { register : "P1OUT" , regForceSet : true },
485 { register : "P1SEL" , regForceSet : false },
486 { register : "P1DIR" , regForceSet : false },
487 { register : "P1REN" , regForceSet : false },
488 { register : "P1IES" , regForceSet : true },
489 { register : "P1IFG" , regForceSet : true },
490 { register : "P1IE" , regForceSet : false },
491 { register : "P2OUT" , regForceSet : true },
492 { register : "P2SEL" , regForceSet : false },
493 { register : "P2DIR" , regForceSet : false },
494 { register : "P2REN" , regForceSet : false },
495 { register : "P2IES" , regForceSet : true },
496 { register : "P2IFG" , regForceSet : true },
497 { register : "P2IE" , regForceSet : false }
498 ];
499
500 501 502 503 504 505
506
507 /*! Port 1 Output Register */
508 config GpioBits8PxOut_t P1OUT = {
509 Bit0 : BIT0_OFF,
510 Bit1 : BIT1_OFF,
511 Bit2 : BIT2_OFF,
512 Bit3 : BIT3_OFF,
513 Bit4 : BIT4_OFF,
514 Bit5 : BIT5_OFF,
515 Bit6 : BIT6_OFF,
516 Bit7 : BIT7_OFF
517 };
518
519 /*! Port 1 Port Select Register */
520 config GpioBits8PxSel_t P1SEL = {
521 Bit0 : BIT0_OFF,
522 Bit1 : BIT1_OFF,
523 Bit2 : BIT2_OFF,
524 Bit3 : BIT3_OFF,
525 Bit4 : BIT4_OFF,
526 Bit5 : BIT5_OFF,
527 Bit6 : BIT6_OFF,
528 Bit7 : BIT7_OFF
529 };
530
531 /*! Port 1 Direction Register */
532 config GpioBits8PxDir_t P1DIR = {
533 Bit0 : BIT0_OFF,
534 Bit1 : BIT1_OFF,
535 Bit2 : BIT2_OFF,
536 Bit3 : BIT3_OFF,
537 Bit4 : BIT4_OFF,
538 Bit5 : BIT5_OFF,
539 Bit6 : BIT6_OFF,
540 Bit7 : BIT7_OFF
541 };
542
543 /*! Port 1 Resistor Enable Register */
544 config GpioBits8PxRen_t P1REN = {
545 Bit0 : BIT0_OFF,
546 Bit1 : BIT1_OFF,
547 Bit2 : BIT2_OFF,
548 Bit3 : BIT3_OFF,
549 Bit4 : BIT4_OFF,
550 Bit5 : BIT5_OFF,
551 Bit6 : BIT6_OFF,
552 Bit7 : BIT7_OFF
553 };
554
555 /*! Port 2 Output Register */
556 config GpioBits8PxOut_t P2OUT = {
557 Bit0 : BIT0_OFF,
558 Bit1 : BIT1_OFF,
559 Bit2 : BIT2_OFF,
560 Bit3 : BIT3_OFF,
561 Bit4 : BIT4_OFF,
562 Bit5 : BIT5_OFF,
563 Bit6 : BIT6_OFF,
564 Bit7 : BIT7_OFF
565 };
566
567 /*! Port 2 Port Select Register */
568 config GpioBits8PxSel_t P2SEL = {
569 Bit0 : BIT0_OFF,
570 Bit1 : BIT1_OFF,
571 Bit2 : BIT2_OFF,
572 Bit3 : BIT3_OFF,
573 Bit4 : BIT4_OFF,
574 Bit5 : BIT5_OFF,
575 Bit6 : BIT6,
576 Bit7 : BIT7
577 };
578
579 /*! Port 2 Direction Register */
580 config GpioBits8PxDir_t P2DIR = {
581 Bit0 : BIT0_OFF,
582 Bit1 : BIT1_OFF,
583 Bit2 : BIT2_OFF,
584 Bit3 : BIT3_OFF,
585 Bit4 : BIT4_OFF,
586 Bit5 : BIT5_OFF,
587 Bit6 : BIT6_OFF,
588 Bit7 : BIT7_OFF
589 };
590
591 /*! Port 2 Resistor Enable Register */
592 config GpioBits8PxRen_t P2REN = {
593 Bit0 : BIT0_OFF,
594 Bit1 : BIT1_OFF,
595 Bit2 : BIT2_OFF,
596 Bit3 : BIT3_OFF,
597 Bit4 : BIT4_OFF,
598 Bit5 : BIT5_OFF,
599 Bit6 : BIT6_OFF,
600 Bit7 : BIT7_OFF
601 };
602 }