Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F85613843
debug_gpio.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Sep 30, 08:10
Size
1 KB
Mime Type
text/x-c
Expires
Wed, Oct 2, 08:10 (2 d)
Engine
blob
Format
Raw Data
Handle
20860371
Attached To
R2671 HHRI-software
debug_gpio.c
View Options
#include "debug_gpio.h"
#define N_GPIOS 3
#define DIO_PORT GPIOB
const
uint32_t
dio_gpios
[
N_GPIOS
]
=
{
GPIO_Pin_14
,
GPIO_Pin_13
,
GPIO_Pin_12
};
void
dio_Init
(
void
)
{
int
i
;
GPIO_InitTypeDef
GPIO_InitStruct
;
for
(
i
=
0
;
i
<
N_GPIOS
;
i
++
)
{
GPIO_InitStruct
.
GPIO_Pin
=
dio_gpios
[
i
];
GPIO_InitStruct
.
GPIO_Mode
=
GPIO_Mode_OUT
;
GPIO_InitStruct
.
GPIO_OType
=
GPIO_OType_PP
;
GPIO_InitStruct
.
GPIO_PuPd
=
GPIO_PuPd_NOPULL
;
GPIO_Init
(
DIO_PORT
,
&
GPIO_InitStruct
);
GPIO_WriteBit
(
DIO_PORT
,
dio_gpios
[
i
],
Bit_RESET
);
}
}
bool
dio_Get
(
int
pinIndex
)
{
if
(
pinIndex
>=
0
&&
pinIndex
<
N_GPIOS
)
return
GPIO_ReadInputDataBit
(
DIO_PORT
,
dio_gpios
[
pinIndex
]);
else
return
0
;
}
void
dio_Set
(
int
pinIndex
,
bool
high
)
{
if
(
pinIndex
>=
0
&&
pinIndex
<
N_GPIOS
)
{
GPIO_WriteBit
(
DIO_PORT
,
dio_gpios
[
pinIndex
],
high
?
Bit_SET
:
Bit_RESET
);
}
}
void
dio_Toggle
(
int
pinIndex
)
{
if
(
pinIndex
>=
0
&&
pinIndex
<
N_GPIOS
)
{
bool
newState
=
!
GPIO_ReadInputDataBit
(
DIO_PORT
,
dio_gpios
[
pinIndex
]);
GPIO_WriteBit
(
DIO_PORT
,
dio_gpios
[
pinIndex
],
newState
?
Bit_SET
:
Bit_RESET
);
}
}
Event Timeline
Log In to Comment