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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
/*
****************************************************************************
PROJECT : device driver for V-Lib
FILE : $Id: r_dev_pin.c 13578 2017-05-29 13:31:52Z matthias.nippert $
============================================================================
DESCRIPTION
D1Mx pin functions
============================================================================
C O P Y R I G H T
============================================================================
Copyright (c) 2017
by
Renesas Electronics (Europe) GmbH.
Arcadiastrasse 10
D-40472 Duesseldorf
Germany
All rights reserved.
============================================================================
Purpose: only for testing, not for mass production
DISCLAIMER
LICENSEE has read, understood and accepted the terms and conditions defined in
the license agreement, especially the usage rights. In any case, it is
LICENSEE's responsibility to make sure that any user of the software complies
with the terms and conditions of the signed license agreement.
SAMPLE CODE is not part of the licensed software, as such it must not be used in
mass-production applications. It can only be used for evaluation and
demonstration purposes at customer's premises listed in the signed license
agreement.
****************************************************************************
*/
/*******************************************************************************
Title: upd703670 port-pin init functions
*/
/*******************************************************************************
Section: Includes
*/
#include "r_typedefs.h"
#include "r_dev_api.h"
#include "r_config_pin.h"
/* This macro defnition exist for debug purposes
because of its concept, MISRA always complains ...*/
#if defined (__ghs__)
#pragma ghs startnomisra
#endif /* __ghs */
#if defined (R_DBG_PRINT_DEV_REGS)
/* When using this, do not forget double (( ))*/
#define LOC_DBG_PRINTF(TXT) printf TXT
#else
#define LOC_DBG_PRINTF(TXT)
#endif
#if defined (__ghs__)
#pragma ghs endnomisra
#endif /* __ghs */
/*******************************************************************************
Section: Local Constants
*/
/*******************************************************************************
PORTC Register Offsets
*/
/************************************************************************************************
Port registers
<see r_dev_PinRegs_t> in the file "r_dev_pin_types.h".
*/
/*******************************************************************************
Array : R_GPIO_Offset_Table
The R_GPIO_Offset_Table array specifies Register offset in a Macro
*/
static const uint32_t loc_RegOffset[R_DEV_PIN_REG_LAST] = {
/*R_DEV_PIN_REG_PCR */ 0x2000u,
/*R_DEV_PIN_REG_P */ 0x0000u,
/*R_DEV_PIN_REG_PSR */ 0x0004u,
/*R_DEV_PIN_REG_PPR */ 0x000Cu,
/*R_DEV_PIN_REG_PM */ 0x0010u,
/*R_DEV_PIN_REG_PMC */ 0x0014u,
/*R_DEV_PIN_REG_PFC */ 0x0018u,
/*R_DEV_PIN_REG_PFCE */ 0x001Cu,
/*R_DEV_PIN_REG_PNOT */ 0x0008u,
/*R_DEV_PIN_REG_PMSR */ 0x0020u,
/*R_DEV_PIN_REG_PMCSR*/ 0x0024u,
/*R_DEV_PIN_REG_PFCAE*/ 0x0028u,
/* OS */
/*R_DEV_PIN_REG_PIBC */ (R_DEV_PIN_BASEO_OFFSET + 0x4000u),
/*R_DEV_PIN_REG_PBDC */ (R_DEV_PIN_BASEO_OFFSET + 0x4004u),
/*R_DEV_PIN_REG_PIPC */ (R_DEV_PIN_BASEO_OFFSET + 0x4008u),
/*R_DEV_PIN_REG_PU */ (R_DEV_PIN_BASEO_OFFSET + 0x400Cu),
/*R_DEV_PIN_REG_PD */ (R_DEV_PIN_BASEO_OFFSET + 0x4010u),
/*R_DEV_PIN_REG_PODC */ (R_DEV_PIN_BASEO_OFFSET + 0x4014u),
/*R_DEV_PIN_REG_PDSC */ (R_DEV_PIN_BASEO_OFFSET + 0x4018u),
/*R_DEV_PIN_REG_PIS */ (R_DEV_PIN_BASEO_OFFSET + 0x401Cu),
/*R_DEV_PIN_REG_PISA */ (R_DEV_PIN_BASEO_OFFSET + 0x4024u),
/*R_DEV_PIN_REG_PPCMD*/ (R_DEV_PIN_BASEO_OFFSET + 0x402Cu),
/*R_DEV_PIN_REG_PPROTS*/ (R_DEV_PIN_BASEO_OFFSET + 0x4034u),
};
static const r_dev_PortInputCapability_t loc_PortCapability[] =
/* Port InputType11, InputType10, InputType01, InputType00 */
{
{0u, R_DEV_PIN_TTL, R_DEV_PIN_TTL, R_DEV_PIN_SCHMITT4, R_DEV_PIN_SCHMITT1},
{1u, R_DEV_PIN_CMOS1, R_DEV_PIN_CMOS1, R_DEV_PIN_SCHMITT4, R_DEV_PIN_SCHMITT1},
{2u, R_DEV_PIN_CMOS1, R_DEV_PIN_CMOS1, R_DEV_PIN_SCHMITT4, R_DEV_PIN_SCHMITT1},
{3u, R_DEV_PIN_CMOS1, R_DEV_PIN_CMOS1, R_DEV_PIN_SCHMITT4, R_DEV_PIN_SCHMITT1},
{16u, R_DEV_PIN_CMOS1, R_DEV_PIN_CMOS1, R_DEV_PIN_SCHMITT4, R_DEV_PIN_SCHMITT1},
{17u, R_DEV_PIN_CMOS1, R_DEV_PIN_CMOS1, R_DEV_PIN_SCHMITT4, R_DEV_PIN_SCHMITT1},
{21u, R_DEV_PIN_TTL_MLB, R_DEV_PIN_TTL_MLB, R_DEV_PIN_CMOS1, R_DEV_PIN_CMOS1},
{42u, R_DEV_PIN_CMOS1, R_DEV_PIN_CMOS1, R_DEV_PIN_SCHMITT4, R_DEV_PIN_SCHMITT1},
{43u, R_DEV_PIN_CMOS1, R_DEV_PIN_CMOS1, R_DEV_PIN_SCHMITT4, R_DEV_PIN_SCHMITT1},
{46u, R_DEV_PIN_CMOS1, R_DEV_PIN_CMOS1, R_DEV_PIN_SCHMITT4, R_DEV_PIN_SCHMITT1},
{47u, R_DEV_PIN_CMOS1, R_DEV_PIN_CMOS1, R_DEV_PIN_SCHMITT4, R_DEV_PIN_SCHMITT1},
/* delimiter - do not remove */
{0xFFu, R_DEV_PIN_NONE, R_DEV_PIN_NONE, R_DEV_PIN_NONE, R_DEV_PIN_NONE},
};
/*******************************************************************************
Section: Local variables
*/
static uint8_t loc_PinEnable = 1;
/*******************************************************************************
Section: Global functions
*/
/*******************************************************************************
Function: R_DEV_PinOutStateGet
See: r_dev_api.h for details
*/
void R_DEV_PinOutStateSet(uint8_t State)
{
loc_PinEnable = State;
}
/*******************************************************************************
Function: R_DEV_PinOutStateGet
See: r_dev_api.h for details
*/
uint8_t R_DEV_PinOutStateGet(void)
{
return loc_PinEnable;
}
/*******************************************************************************
Function: R_DEV_PinConfig
See: r_dev_api.h for details
*/
uint8_t R_DEV_PinConfig(const r_dev_PinConfig_t * PinCfg)
{
uint8_t ret_val = 1u;
uint32_t addr = 0u;
uint32_t prot_addr = 0u;
uint32_t reg_val = 0u;
uint16_t pin_position = 1u;
uint8_t port_position = 0u;
uint8_t portHasPisaRegister = 0u;
uint8_t portHasPisRegister = 0u;
uint8_t PisaRegBitValue = 0u;
uint8_t PisRegBitValue = 0u;
R_DBG_PRINT(R_DBG_MSG_DET, "--- Pin Config Start ---");
if (0 == loc_PinEnable)
{
R_DBG_PRINT(R_DBG_MSG_DET, "--- Pin output disabled - exiting ---");
return ret_val;
}
pin_position = (uint16_t)(pin_position << PinCfg->Pin);
/* optional check if already configured */
/* read PMC, if 1 -> already set to other alternative mode, abort */
/* read PM, if not 1 -> already set to output, abort (this is in case of pure GPIO) */
/* Input or output */
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PM, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
if (R_DEV_PIN_OUT == PinCfg->Dir)
{
reg_val &= (uint16_t)(~pin_position);
LOC_DBG_PRINTF(("/* Set pin %d of port %d as output for ", PinCfg->Pin, PinCfg->Port));
}
else /* Set direction to input also in case of direct control */
{
reg_val |= pin_position;
LOC_DBG_PRINTF(("/* Set pin %d of port %d as input for ", PinCfg->Pin, PinCfg->Port));
}
LOC_DBG_PRINTF(("alternative function %d */\n", PinCfg->Func ));
R_DEV_WRITE_REG(16, addr, reg_val);
/* direct control */
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PIPC, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
if (R_DEV_PIN_DIRECT == PinCfg->Dir)
{
reg_val |= pin_position;
}
else
{
reg_val &= (uint16_t)(~pin_position);
}
R_DEV_WRITE_REG(16, addr, reg_val);
/* activate pull-up / pull-down resistors */
/* set pull-up */
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PU, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
if (R_DEV_PIN_PULLUP == PinCfg->Pull)
{
reg_val |= pin_position;
}
else
{
reg_val &= (uint16_t)(~pin_position);
}
R_DEV_WRITE_REG(16, addr, reg_val);
/* set pull-down */
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PD, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
if (R_DEV_PIN_PULLDOWN == PinCfg->Pull)
{
reg_val |= pin_position;
}
else
{
reg_val &= (uint16_t)(~pin_position);
}
R_DEV_WRITE_REG(16, addr, reg_val);
/* feedback input (bidirectional mode) */
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PBDC, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
if (1 == PinCfg->Feedback)
{
reg_val |= pin_position;
}
else
{
reg_val &= (uint16_t)(~pin_position);
}
R_DEV_WRITE_REG(16, addr, reg_val);
/*Set mode to GPIO or alternative function */
switch(PinCfg->Func)
{
case 0: /* GPIO */
/*Set PFC, PFCE and PFCAE bits to 0. */
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PFC, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
reg_val &= (uint16_t)(~pin_position);
R_DEV_WRITE_REG(16, addr, reg_val);
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PFCE, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
reg_val &= (uint16_t)(~pin_position);
R_DEV_WRITE_REG(16, addr, reg_val);
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PFCAE, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
reg_val &= (uint16_t)(~pin_position);
R_DEV_WRITE_REG(16, addr, reg_val);
break;
case 1: /* Alternative function 1 */
/*Set PFC, PFCE and PFCAE bits to 0. */
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PFC, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
reg_val &= (uint16_t)(~pin_position);
R_DEV_WRITE_REG(16, addr, reg_val);
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PFCE, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
reg_val &= (uint16_t)(~pin_position);
R_DEV_WRITE_REG(16, addr, reg_val);
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PFCAE, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
reg_val &= (uint16_t)(~pin_position);
R_DEV_WRITE_REG(16, addr, reg_val);
break;
case 2: /* Alternative function 2 */
/*Set PFC bit to 1 and PFCE bit to 0. */
/*Set PFCAE bit to 0. */
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PFC, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
reg_val |= pin_position;
R_DEV_WRITE_REG(16, addr, reg_val);
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PFCE, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
reg_val &= (uint16_t)(~pin_position);
R_DEV_WRITE_REG(16, addr, reg_val);
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PFCAE, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
reg_val &= (uint16_t)(~pin_position);
R_DEV_WRITE_REG(16, addr, reg_val);
break;
case 3: /* Alternative function 3 */
/*Set PFC bit to 0 and PFCE bit to 1. */
/*Set PFCAE bit to 0. */
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PFC, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
reg_val &= (uint16_t)(~pin_position);
R_DEV_WRITE_REG(16, addr, reg_val);
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PFCE, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
reg_val |= pin_position;
R_DEV_WRITE_REG(16, addr, reg_val);
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PFCAE, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
reg_val &= (uint16_t)(~pin_position);
R_DEV_WRITE_REG(16, addr, reg_val);
break;
case 4: /* Alternative function 4 */
/*Set PFC and PFCE bits to 1. */
/*Set PFCAE bit to 0. */
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PFC, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
reg_val |= pin_position;
R_DEV_WRITE_REG(16, addr, reg_val);
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PFCE, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
reg_val |= pin_position;
R_DEV_WRITE_REG(16, addr, reg_val);
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PFCAE, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
reg_val &= (uint16_t)(~pin_position);
R_DEV_WRITE_REG(16, addr, reg_val);
break;
case 5: /* Alternative function 5 */
/*Set PFC and PFCE bits to 0. */
/*Set PFCAE bit to 1. */
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PFC, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
reg_val &= (uint16_t)(~pin_position);
R_DEV_WRITE_REG(16, addr, reg_val);
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PFCE, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
reg_val &= (uint16_t)(~pin_position);
R_DEV_WRITE_REG(16, addr, reg_val);
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PFCAE, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
reg_val |= pin_position;
R_DEV_WRITE_REG(16, addr, reg_val);
break;
case 6: /* Alternative function 6 */
/*Set PFC bit to 1 and PFCE bit to 0. */
/*Set PFCAE bit to 1. */
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PFC, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
reg_val |= pin_position;
R_DEV_WRITE_REG(16, addr, reg_val);
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PFCE, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
reg_val &= (uint16_t)(~pin_position);
R_DEV_WRITE_REG(16, addr, reg_val);
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PFCAE, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
reg_val |= pin_position;
R_DEV_WRITE_REG(16, addr, reg_val);
break;
default:
R_DEV_ERROR(0u, R_DEV_ERR_NG, "We do not have what you want!");
break;
}
/* Some electrical charactersitics */
R_DBG_PRINT(R_DBG_MSG_DET, "--- Electrical charakteristics ---");
if ((PinCfg->Port != 21) && (PinCfg->Port != 22))
{
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PDSC, PinCfg->Port);
reg_val = R_DEV_READ_REG(32, addr);
if (0 != PinCfg->HiSpeed)
{
reg_val |= pin_position;
}
else
{
reg_val &= (uint16_t)(~pin_position);
}
prot_addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PPCMD, PinCfg->Port);
R_DEV_WRITE_PORT_PROT_REG(prot_addr ,addr, reg_val);
} else {
/* No PDSC available for P21 + P22 */
/* Exception: D1M2(H) which controls HS or MLB buffer selection by PDSC21.
Cite note below UM v2.10 table 2.122:
"PDSC21 has to be set 0000 03FFH in D1M2(H)."
*/
r_dev_Device_t dev = R_DEV_GetDev();
if ((dev >= R_DEV_R7F701408) && (dev <= R_DEV_R7F701412))
{
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PDSC, PinCfg->Port);
reg_val = 0x03FF;
prot_addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PPCMD, PinCfg->Port);
R_DEV_WRITE_PORT_PROT_REG(prot_addr ,addr, reg_val);
}
}
/* Activate pin */
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PMC, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
if (0 != PinCfg->Func)
{
reg_val |= pin_position;
}
else
{
reg_val &= (uint16_t)(~pin_position);
}
R_DEV_WRITE_REG(16, addr, reg_val);
/* Set input characteristic */
port_position = 0u;
portHasPisaRegister = 1u;
portHasPisRegister = 1u;
PisaRegBitValue = 0u;
PisRegBitValue = 0u;
do {
if (loc_PortCapability[port_position].Port == PinCfg->Port)
{
if (loc_PortCapability[port_position].InputType00 == PinCfg->InputType)
{
PisaRegBitValue = 0;
PisRegBitValue = 0;
}
if (loc_PortCapability[port_position].InputType01 == PinCfg->InputType)
{
PisaRegBitValue = 0;
PisRegBitValue = 1;
if (loc_PortCapability[port_position].InputType01
== loc_PortCapability[port_position].InputType00)
{
portHasPisRegister = 0;
}
}
if (loc_PortCapability[port_position].InputType10 == PinCfg->InputType)
{
PisaRegBitValue = 1;
PisRegBitValue = 0;
}
if (loc_PortCapability[port_position].InputType11 == PinCfg->InputType)
{
PisaRegBitValue = 1;
PisRegBitValue = 1;
if (loc_PortCapability[port_position].InputType11
== loc_PortCapability[port_position].InputType10)
{
portHasPisRegister = 0;
}
}
break;
}
port_position += 1;
}
while (0xFFu != loc_PortCapability[port_position].Port);
if (0 != portHasPisaRegister)
{
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PIS, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
if (0 != PisaRegBitValue)
{
reg_val |= pin_position;
}
else
{
reg_val &= (uint16_t)(~pin_position);
}
R_DEV_WRITE_REG(16, addr, reg_val);
}
if (0 != portHasPisRegister)
{
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PIS, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
if (0 != PisRegBitValue)
{
reg_val |= pin_position;
}
else
{
reg_val &= (uint16_t)(~pin_position);
}
R_DEV_WRITE_REG(16, addr, reg_val);
}
/* Activate input buffer in case of GP input */
addr = R_DEV_PinGetRegAddr(R_DEV_PIN_REG_PIBC, PinCfg->Port);
reg_val = R_DEV_READ_REG(16, addr);
if ((0 == PinCfg->Func) && (R_DEV_PIN_IN == PinCfg->Dir))
{
reg_val |= pin_position;
}
else
{
reg_val &= (uint16_t)(~pin_position);
}
R_DEV_WRITE_REG(16, addr, reg_val);
R_DBG_PRINT(R_DBG_MSG_DET, "--- Pin Config End ---");
return ret_val;
}
/*******************************************************************************
Function: R_DEV_PinInit
See: r_dev_api.h for details
*/
void R_DEV_PinInit(const r_dev_PinConfig_t * PinCfg)
{
uint16_t i = 0u;
/* Here we can glbally disable any pion configuration */
if (0 == loc_PinEnable)
{
R_DBG_PRINT(R_DBG_MSG_DET, "--- Pin output disabled - exiting ---");
return;
}
/* assuming we got a config table, we go through it until
we see the delimiter */
while (R_DEV_PIN_LAST != PinCfg[i].Pin)
{
R_DEV_PinConfig(&(PinCfg[i])) ;
i++;
}
}
/*******************************************************************************
Function: R_DEV_PinGetRegAddr
See: r_dev_api.h for details
*/
uint32_t R_DEV_PinGetRegAddr(r_dev_PinRegs_t Reg, uint32_t Port)
{
return R_DEV_PinGetRegAddrExt(Reg, Port, 0u);
}
/*******************************************************************************
Function: R_DEV_PinGetRegAddrExt
See: r_dev_api.h for details
*/
uint32_t R_DEV_PinGetRegAddrExt(r_dev_PinRegs_t Reg, uint32_t Port, uint32_t Pin)
{
uint32_t addr = R_DEV_PIN_BASE + (R_DEV_PORT_OFFSET * Port);
if (Reg < R_DEV_PIN_REG_LAST)
{
if (Port == 0)
{
/* add offset for port n = 0 */
addr += R_DEV_PIN_BASEOU_0_OFFSET;
}
if (R_DEV_PIN_REG_PCR == Reg)
{
/* only for PCRn register, that has pin based control */
addr += (R_DEV_PIN_OFFSET * Pin);
}
addr += loc_RegOffset[Reg];
}
else
{
R_DEV_ERROR((uint32_t)Reg, R_DEV_ERR_REG, "That register does not exist!");
}
return addr;
}