아두이노 모듈로 4*4 키패드 모듈이 있다.

아두이노에서는 keypad 라이브러리를 사용해서 손쉽게 사용할 수 있지만
Aurix는 지원하지않아 새롭게 구현해야한다.
LED 글을 통해 공부했던 GPIO를 통해 구현해보겠다.
핀이 8개있다.
C1 ~ C4, R1 ~ R4

Aurix에 핀을 연결하기 위해 GPIO 핀을 지원하는 port중
33번 포트를 사용하였다.
P33_0 ~ P33_3 은 R1 ~ R4
P33_4 ~ P33_7 은 C1 ~ C4
연결하였다.
void keypad_init(void)
{
IfxPort_setPinModeInput(&MODULE_P33, IfxPort_P33_0.pinIndex, IfxPort_InputMode_pullUp);
IfxPort_setPinModeInput(&MODULE_P33, IfxPort_P33_1.pinIndex, IfxPort_InputMode_pullUp);
IfxPort_setPinModeInput(&MODULE_P33, IfxPort_P33_2.pinIndex, IfxPort_InputMode_pullUp);
IfxPort_setPinModeInput(&MODULE_P33, IfxPort_P33_3.pinIndex, IfxPort_InputMode_pullUp);
IfxPort_setPinModeOutput(&MODULE_P33, IfxPort_P33_4.pinIndex, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
IfxPort_setPinModeOutput(&MODULE_P33, IfxPort_P33_5.pinIndex, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
IfxPort_setPinModeOutput(&MODULE_P33, IfxPort_P33_6.pinIndex, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
IfxPort_setPinModeOutput(&MODULE_P33, IfxPort_P33_7.pinIndex, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
}
P33_0 ~3 은 인풋 모드이며 pullUp 저항에 연결
P33_4 ~7 은 아웃풋 모드로 초기화를 하였다.
int keypad_read(void)
{
pressedkey = 0;
for(int col_num = 0; col_num<4; col_num++)
{
IfxPort_setPinLow(&MODULE_P33,colPins[col_num]);
for(int row_num = 0; row_num<4; row_num++)
{
if(!IfxPort_getPinState(&MODULE_P33,rowPins[row_num]))
{
pressedkey = keys[row_num][col_num];
}
}
IfxPort_setPinHigh(&MODULE_P33,colPins[col_num]);
if(pressedkey != 0)
{
break;
}
}
return pressedkey;
}
IfxPort_setPinLow() 를 통해 C와 연결된 핀들을 하나씩 GND에 연결한다.
그다음 IfxPort_getPinState() 함수를 통해 row 핀들 중 low값을 읽은 핀을 찾는다.
IfxPort_getPinState() 이 true 면 HIGH false 면 low 이고
눌린 핀의 번호를 pressedkey 변수에 넣는다.
IfxPort_setPinHigh() 를 통해 원상 복구 시킨다.
pressedkey가 업데이트되면 for문을 빠져나와 return 한다.

https://github.com/ysrhee6199/aurix-tc275-study/blob/main/Keypad/keypad.c
P33_0 과 P33_2 에 연결된 스위치는 작동을 하지않는다.
원인은 파악중..