본문 바로가기

임베디드

ADC 키패드 입력 테스트

Allwinner I3(S3) CPU 내부에 LRADC 입력 장치가 포함되어 있다.

Low Resolution Analog to Digital Converter 인지 아니면 Low Rate Analog to Digital Converter인지 명확하지 않다.

나는 Low Resolution으로 부르고 싶지만 Sunxi community에는 후자의 Low Rate 용어를 사용하는 것 같다. 

 

6비트 분해능으로 디지털로 변환된 값의 범위는 0~63까지로 매우 허접하다.  최대 2.0Volt까지 입력이 가능하며 약 30mV의 분해능이다. 4msec의 ADC 변환 시간이 필요하므로 최대 250Hz의 샘플링 주기가 가능하다.

따라서 일반적인 계측용 ADC 입력 장치로 사용하는 것은 의미가 없어보이며, 버튼 몇개를 연결하여 debounce에 대한 고민없이 편리하게 키 입력 전용으로 사용해야 한다.  인터럽트와 홀드 기능이 있어 키입력에 최적화된 ADC로 보면 된다.

 

버튼 4개를 아래 회로와 같이 연결하였다. 버튼을 누르면 ADC 입력단에 걸리는 전압을 우측에 표기하였다.

200mV 단계로 배치하면 최대 10개 정도의 버튼을 연결할 수 있을것 같다.

해당 키패드 디바이스 드라이버는 "sun4i-lradc-keys.c"로 이미 메인라인 커널의 /drivers/input/keyboard/ 아래에 존재한다.

https://github.com/torvalds/linux/blob/master/drivers/input/keyboard/sun4i-lradc-keys.c

 

sun8i-v3s.dtsi에도 LRADC용 키 장치에 대한 드라이버 정의가 잘 되어 있다.

		lradc: lradc@1c22800 {
			compatible = "allwinner,sun4i-a10-lradc-keys";
			reg = <0x01c22800 0x400>;
			interrupts = <GIC_SPI 30 IRQ_TYPE_LEVEL_HIGH>;
			status = "disabled";
		};

 

드라이버는 잘 올라올테니 버튼 4개의 전압과 기능은 sun8i-s3-foxnux-one.dts에 기록하면 된다.

voltage 정의값의 단위는 micro-volt(uV)이다.

&lradc {
        vref-supply = <&reg_vcc3v0>;
        status = "okay";

        button@200 {
                label = "Volume Up";
                linux,code = <KEY_VOLUMEUP>;
                channel = <0>;
                voltage = <200000>;
        };

        button@400 {
                label = "Volume Down";
                linux,code = <KEY_VOLUMEDOWN>;
                channel = <0>;
                voltage = <400000>;
        };

        button@600 {
                label = "Select";
                linux,code = <KEY_SELECT>;
                channel = <0>;
                voltage = <600000>;
        };

        button@800 {
                label = "Start";
                linux,code = <KEY_OK>;
                channel = <0>;
                voltage = <800000>;
        };
};

 

해당 Key 입력에 대한 코드값은 아래 링크에 정의되어 있다.

https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h

 

변경된 내용은 Github에 Commit 하였다.

https://github.com/foxnux/linux/commit/c94a39f556bcb41152b3f5049f27f480fcebfa8b

 

Command 라인에서 evtest 프로그램으로 실제 입력값을 출력해 보았다.

4개의 키 모두 정상적인 KEY_CODE값이 올라오는 것을 확인하였다.

root@bionic-minimal:~# evtest /dev/input/event0
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "1c22800.lradc"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 114 (KEY_VOLUMEDOWN)
    Event code 115 (KEY_VOLUMEUP)
    Event code 352 (KEY_OK)
    Event code 353 (KEY_SELECT)
Properties:
Testing ... (interrupt to exit)
Event: time 1578286800.336533, type 1 (EV_KEY), code 352 (KEY_OK), value 1
Event: time 1578286800.336533, -------------- SYN_REPORT ------------
Event: time 1578286800.520125, type 1 (EV_KEY), code 352 (KEY_OK), value 0
Event: time 1578286800.520125, -------------- SYN_REPORT ------------
Event: time 1578286804.102228, type 1 (EV_KEY), code 353 (KEY_SELECT), value 1
Event: time 1578286804.102228, -------------- SYN_REPORT ------------
Event: time 1578286804.281918, type 1 (EV_KEY), code 353 (KEY_SELECT), value 0
Event: time 1578286804.281918, -------------- SYN_REPORT ------------
Event: time 1578286806.196015, type 1 (EV_KEY), code 114 (KEY_VOLUMEDOWN), value 1
Event: time 1578286806.196015, -------------- SYN_REPORT ------------
Event: time 1578286806.383506, type 1 (EV_KEY), code 114 (KEY_VOLUMEDOWN), value 0
Event: time 1578286806.383506, -------------- SYN_REPORT ------------
Event: time 1578286807.680393, type 1 (EV_KEY), code 115 (KEY_VOLUMEUP), value 1
Event: time 1578286807.680393, -------------- SYN_REPORT ------------
Event: time 1578286807.906957, type 1 (EV_KEY), code 115 (KEY_VOLUMEUP), value 0
Event: time 1578286807.906957, -------------- SYN_REPORT ------------

 

부트로더와 커널 개발이 어느정도 마무리 되었으니, Buildroot를 이용해서 루트파일시스템을 만들 계획이다.

Squonk42라는 분이 만든 V3S용 Buildroot를 참고해서 i3용으로 포팅을 해보겠다. 

https://github.com/Squonk42/buildroot-licheepi-zero

 

 

'임베디드' 카테고리의 다른 글

UART 포트 기능 테스트  (0) 2020.01.10
Buildroot 테스트  (0) 2020.01.06
카메라 입력 테스트  (0) 2020.01.03
동영상 재생 테스트  (0) 2020.01.02
Kernel 5.5 (rc4) 포팅과 부팅  (2) 2019.12.31