28
DOT Matrix 디디디디 디디 2012 디디디 디디디 디디 2012. 11. 14

2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

Embed Size (px)

Citation preview

Page 1: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

DOT Matrix 디바이스 제어

2012 내장형 시스템 설계

2012. 11. 14

Page 2: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리 작성 DOT Matrix 안드로이드 App 구현 JNI 라이브러리 빌드 결과 화면 Homework #5

2

Table of Contents

Page 3: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

Dot Matrix

DOT Matrix 디바이스 구성 (1)

3

◦ FPGA 내부의 컨트롤러에 의해 제어됨

Page 4: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

DOT Matrix 디바이스 구성 (2)

4

Dot_Scan_RegPhysical Address 0x0500_0040 Dot_Scan_Reg

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0  

ReservedSCAN10

SCAN9

SCAN8

SCAN7

SCAN6

SCAN5

SCAN4

SCAN3

SCAN2

SCAN1

 

X X X X X X 0 0 0 0 0 0 0 0 0 0  

Bits Name Description  

0 SCAN1 Dot Matrix Scan Bit0 (Active High)  

1 SCAN2 Dot Matrix Scan Bit1 (Active High)  

2 SCAN3 Dot Matrix Scan Bit2 (Active High)  

3 SCAN4 Dot Matrix Scan Bit3 (Active High)  

4 SCAN5 Dot Matrix Scan Bit4 (Active High)  

5 SCAN6 Dot Matrix Scan Bit5 (Active High)  

6 SCAN7 Dot Matrix Scan Bit6 (Active High)  

7 SCAN8 Dot Matrix Scan Bit7 (Active High)  

8 SCAN9 Dot Matrix Scan Bit8 (Active High)  

9 SCAN10 Dot Matrix Scan Bit9 (Active High)  

Page 5: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

DOT Matrix 디바이스 구성 (3)

5

Dot_Data_RegPhysical Address 0x0500_0042 Dot_Data_Reg

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0  DOT_EN

Reserved DATA7

DATA6

DATA5

DATA4

DATA3

DATA2

DATA1  

0 X X X X X X X 0 0 0 0 0 0 0 0  

Bits Name Description  

0 DATA1 Dot Matrix Data Bit0 (Active High)  

1 DATA2 Dot Matrix Data Bit1 (Active High)  

2 DATA3 Dot Matrix Data Bit2 (Active High)  

3 DATA4 Dot Matrix Data Bit3 (Active High)  

4 DATA5 Dot Matrix Data Bit4 (Active High)  

5 DATA6 Dot Matrix Data Bit5 (Active High)  

6 DATA7 Dot Matrix Data Bit6 (Active High)  

15 DOT_EN Dot Matrix Enable Bit (Active High)  

Page 6: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

DOT Matrix 디바이스 구성 (4)

6

DATA1

DATA2

DATA3

DATA4

DATA5

DATA6

DATA7

SC

AN

1

SC

AN

2

SC

AN

3

SC

AN

4

SC

AN

5

SC

AN

6

SC

AN

7

SC

AN

8

SC

AN

9

SC

AN

10

Page 7: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

DOT Matrix 디바이스 드라이버 (1)

7

◦ 드라이버 코드 위치 “~/linux-3.0.15-s4210/drivers/hanback“ 디렉토리에

포함되어있음

◦ 드라이버 소스 코드 (dotmatrix.c)#include <linux/init.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/fs.h>#include <linux/types.h>#include <linux/ioport.h>#include <asm/io.h>#include <asm/ioctl.h>#include <asm/uaccess.h>#include <linux/delay.h>#include <linux/miscdevice.h>#include <linux/platform_device.h>#include <asm/ioctl.h>#include <asm/uaccess.h>#include <asm/io.h>

Page 8: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

DOT Matrix 디바이스 드라이버 (2)

8

◦ 드라이버 소스 코드 (dotmatrix.c)#define DRIVER_AUTHOR "Hanback Electronics"#define DRIVER_DESC "dotmatrix program"

#define DOT_NAME "dotmatrix"#define DOT_MODULE_VERSION "DOTMATRIX V1.0"#define DOT_PHY_ADDR 0x05000000#define DOT_ADDR_RANGE 0x1000

#define NUMSIZE 4#define DELAY 2

//Global variablestatic int dot_usage = 0;static unsigned long dot_ioremap;static unsigned short *dot_row_addr,*dot_col_addr;

// Delay func.void m_delay(int num) {

volatile int i,j;for(i=0;i<num;i++)

for(j=0;j<16384;j++);}

Page 9: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

DOT Matrix 디바이스 드라이버 (3)

9

◦ 드라이버 소스 코드 (dotmatrix.c)// define functions...int dot_open(struct inode *minode, struct file *mfile) {

if(dot_usage != 0) return -EBUSY;

dot_ioremap=(unsigned long)ioremap(DOT_PHY_ADDR,DOT_ADDR_RANGE);

dot_row_addr =(unsigned short *)(dot_ioremap+0x40);dot_col_addr =(unsigned short *)(dot_ioremap+0x42);*dot_row_addr =0;*dot_col_addr =0;

if(!check_mem_region(dot_ioremap, DOT_ADDR_RANGE)) {request_mem_region(dot_ioremap, DOT_ADDR_RANGE, DOT_NAME);

}else printk("driver: unable to register this!\n");

dot_usage = 1;return 0;

}

int dot_release(struct inode *minode, struct file *mfile) {

iounmap((unsigned long*)dot_ioremap);

release_mem_region(dot_ioremap, DOT_ADDR_RANGE);dot_usage = 0;return 0;

}

Page 10: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

DOT Matrix 디바이스 드라이버 (4)

10

◦ 드라이버 소스 코드 (dotmatrix.c)int htoi(const char hexa){

int ch = 0;if('0' <= hexa && hexa <= '9')

ch = hexa - '0';if('A' <= hexa && hexa <= 'F')

ch = hexa - 'A' + 10;if('a' <= hexa && hexa <= 'f')

ch = hexa - 'a' + 10;return ch;

}

ssize_t dot_write(struct file *inode, const char *gdata, size_t length, loff_t *off_what){

int ret=0, i;char buf[20];unsigned short result[10] = { 0 };unsigned int init=0x001; //Scan valueunsigned int n1, n2;

ret = copy_from_user(buf, gdata, length);if(ret<0) return -1;

for (i=0; i < 10; i++) {n1 = htoi( buf[2*i] );n2 = htoi( buf[2*i+1] );

result[i] = n1*16+n2;

*dot_row_addr = init << i;*dot_col_addr = 0x8000 | result[ i ];m_delay(3);

}return length;

}

Page 11: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

DOT Matrix 디바이스 드라이버 (5)

11

◦ 드라이버 소스 코드 (dotmatrix.c)struct file_operations dot_fops = {

.owner = THIS_MODULE,

.write = dot_write,

.open = dot_open,

.release = dot_release,};

static struct miscdevice dot_driver = {.fops = &dot_fops,.name = DOT_NAME,.minor = MISC_DYNAMIC_MINOR,

};

int dot_init(void) {

misc_register(&dot_driver);return 0;

}

void dot_exit(void) {

misc_deregister(&dot_driver);printk("driver: %s DRIVER EXIT\n", DOT_NAME);

}

module_init(dot_init);module_exit(dot_exit);

MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_LICENSE("Dual BSD/GPL");

Page 12: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

DOT Matrix 드라이버 테스트 프로그램 (1)

12

◦ 테스트 환경 VMWare 기반의 Ubuntu 10.10 작성한 디바이스 드라이버의 정상 동작 여부를 쉽게

확인하기 위한 목적으로 사용됨

◦ 테스트 프로그램용 디렉토리의 생성 및 이동 # cd~/ # mkdir test_dot # cd test_dot # vi dot_test.c

Page 13: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

DOT Matrix 드라이버 테스트 프로그램 (2)

13

#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>

int main(){ int dev; int value=1;

dev = open("/dev/dotmatrix", O_WRONLY); if(dev != -1) { while(value != 0) { printf("Input counter value: [1-99] (0 : exit program) \n"); scanf("%d", &value); if(value < 100) { write(dev, &value, 4); usleep(1000); } else { printf(" Error : Number length 1-99 \n"); exit(1); }

dot_test.c } close(dev); } else { printf("Device Open ERROR!\n"); exit(1); } printf("Program Exit !!\n"); return 0;}

Page 14: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

DOT Matrix 드라이버 테스트 프로그램 (3)

14

◦ make 명령을 위해 다음과 같이 Makefile 을 작성 Makefile

(1) 컴파일 시 사용될 컴파일러 (2) 컴파일 완료 시 작성되는 실행파일명(3) make 입력 시 수행될 내용(4) make clean 입력 시 수행될 내용

(1) 

(2)  

(3) 

(4)

CC = arm-linux-gnueabi-gccCFLAGS = -DNO_DEBUGEXEC=dot_testOBJS=$(EXEC).oall: $(EXEC)$(EXEC): $(OBJS)

$(CC) -o $@ $^ -staticclean:

rm -f $(OBJS) $(EXEC)

Page 15: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

DOT Matrix 드라이버 테스트 프로그램 (4)

15

◦ make 명령을 통해 컴파일을 진행 # make

◦ adb push 명령을 통해 타겟보드로 전송 # adb push ./dot_test /

◦ 파일을 실행하기 위해 다음 명령어를 통해 타겟보드에 접속 # adb shell

◦ 실행 권한을 부여하고 파일 실행 # chmod 777 dot_test # ./dot_test

Page 16: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

DOT Matrix JNI 라이브러리 작성 (1)

16

◦ DOT Matrix 드라이버를 안드로이드 앱에서 사용하기 위해서는 JNI 인터페이스 라이브러리가 필요

◦ 이 라이브러리는 구글의 NDK 를 이용하여 빌드

Page 17: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

DOT Matrix JNI 라이브러리 작성 (2)

17

◦ JNI 프로그램 소스 dotmatrix.c

#include <string.h>#include <jni.h>#include <termios.h>#include <sys/mman.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <android/log.h>

jint Java_package_dotmatrix_DotMatrixActivity_DotMatrixControl(JNIEnv* env, jobject thiz, jstring data){const char *buf;

int dev,ret, len;char str[100];

buf = (*env)->GetStringUTFChars(env, data, 0);len = (*env)->GetStringLength(env, data);

dev = open("/dev/dotmatrix", O_RDWR | O_SYNC);

if(dev != -1) {ret = write(dev, buf, len);close(dev);

} return 0;

}

jint : 함수의 리턴 타입package_dotmatrix : 안드로이드 앱의 package 이름DotMatrixActivity : 안드로이드 앱의 Activity 이름DotMatrixControl : 안드로이드 앱에서 사용할 함수 이름

Page 18: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

DOT Matrix JNI 라이브러리 작성 (3)

18

◦ 안드로이드용 Makefile 인 Android.mk 작성하기 Android.mk

(1) 컴파일의 결과물로서 생성되는 라이브러리 이름이며 , NDK 에서는 이 이름 앞에 lib 가 추가되고 , 뒤에 .so 가 붙어 libdotmatrix.so 라는 파일이 만들어짐(2) 컴파일 할 소스 파일의 이름(3) Shared Library 용으로 빌드한다는 표시로서 확장자 .so 가 붙음

     (1)(2) (3)

LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := dotmartixLOCAL_SRC_FILES:= dotmartix.c include $(BUILD_SHARED_LIBRARY)

Page 19: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

Application name◦ DotMatrix

Project Name◦ DotMatrix

Package name◦ {name}. DotMatrix

Activity name◦ DotMatrixActivity

Layout name◦ main

19

DOT Matrix 안드로이드 App 구현 (1)

Page 20: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

DOT Matrix 안드로이드 App 구현 (2)<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/widget0" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/bgimage" >

<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="30dp" android:gravity="center" android:orientation="vertical" >

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Dot Matrix Control" android:textSize="18sp" android:textStyle="bold" />

<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:orientation="horizontal" >

<EditText android:id="@+id/input" android:layout_width="210px" android:layout_height="wrap_content" android:text="Hello!" android:textSize="18sp" />

<Button android:id="@+id/ButStart" android:layout_width="170px" android:layout_height="wrap_content" android:text="Start" android:textSize="18sp" android:textStyle="bold" /> </LinearLayout>

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="Input Text(Alphanumeric only)." /> </LinearLayout>

</LinearLayout>

main.xml

20

Page 21: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

package com.hanback.dotmatrix;

import android.app.Activity;import android.app.Dialog;import android.os.Bundle;import android.os.Handler;import android.view.KeyEvent;import android.view.Window;import android.view.WindowManager;import android.view.View;import android.widget.Button;import android.widget.EditText;

public class DotMatrixActivity extends Activity { /** Called when the activity is first created. */ protected static final int DIALOG_SIMPLE_MESSAGE = 0; protected static final int DIALOG_ERROR_MESSAGE = 1; String result = new String(); BackThread thread = new BackThread(); boolean start = false, restart = false; boolean alive = true; private int speed = 20; String value; Handler handler = new Handler();

public native int DotMatrixControl(String data);

@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); System.loadLibrary("dotmatrix"); // Start thread thread.setDaemon(true); thread.start();

7-Segment 안드로이드 App 구현 (3)DotMatrixActivity.java (1)

21

Page 22: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

final EditText input = (EditText) findViewById(R.id.input); final Button ButStart = (Button) findViewById(R.id.ButStart); ButStart.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { value = input.getText().toString(); if (start) { restart = true; start = false; ButStart.setText("Start"); } else { start = true; restart = true; ButStart.setText("Stop"); } } }); }

class BackThread extends Thread { public void run() { while (alive) { if (!start) { // do nothing } else { // check string length if (value.length() > 50) { // show dialog handler.post(new Runnable() { public void run() { showDialog(DIALOG_SIMPLE_MESSAGE); } }); start = false; continue; } else { int i, j, ch; char buf[] = new char[100]; buf = value.toCharArray(); result = "00000000000000000000";

7-Segment 안드로이드 App 구현 (4)DotMatrixActivity.java (2) for (i = 0; i < value.length(); i++) {

ch = Integer.valueOf(buf[i]); if (ch < 32 || ch > 126) { handler.post(new Runnable() { public void run() { showDialog(DIALOG_ERROR_MESSAGE); } }); start = false; restart = false; break; } ch -= 0x20;

// copy for (j = 0; j < 5; j++) { String str = new String(); str = Integer.toHexString((font[ch][j])); if (str.length() < 2) result += "0";

result += str; } result += "00"; } result += "00000000000000000000"; // print for (i = 0; i < (result.length() - 18) / 2; i++) { // speed control for (j = 0; j < speed; j++) { // thread control if (!start) { break; // stop display } else { DotMatrixControl(result.substring(2 * i, 2 * i + 20)); } } } } DotMatrixControl("00000000000000000000"); } } } } 22

Page 23: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { start = false; alive = false; thread.interrupt(); } return super.onKeyDown(keyCode, event); }

@Override protected Dialog onCreateDialog(int id) { // TODO Auto-generated method stub Dialog d = new Dialog(DotMatrixActivity.this); Window window = d.getWindow(); window.setFlags(WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW, WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW);

switch (id) { case DIALOG_SIMPLE_MESSAGE: d.setTitle("Max input length is 50."); d.show(); return d; case DIALOG_ERROR_MESSAGE: d.setTitle("Unsupported character."); d.show(); return d; } return super.onCreateDialog(id); }

7-Segment 안드로이드 App 구현 (5)DotMatrixActivity.java (3)

23

Page 24: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

public int font[][] = { /* 5x7 ASCII character font */ { 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 0x20 space */ { 0x00, 0x00, 0x4f, 0x00, 0x00 }, /* 0x21 ! */ { 0x00, 0x07, 0x00, 0x07, 0x00 }, /* 0x22 " */ { 0x14, 0x7f, 0x14, 0x7f, 0x14 }, /* 0x23 # */ { 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, /* 0x24 $ */ { 0x23, 0x13, 0x08, 0x64, 0x62 }, /* 0x25 % */ { 0x36, 0x49, 0x55, 0x22, 0x50 }, /* 0x26 & */ { 0x00, 0x05, 0x03, 0x00, 0x00 }, /* 0x27 ' */ { 0x00, 0x1c, 0x22, 0x41, 0x00 }, /* 0x28 ( */ { 0x00, 0x41, 0x22, 0x1c, 0x00 }, /* 0x29 ) */ { 0x14, 0x08, 0x3e, 0x08, 0x14 }, /* 0x2a * */ { 0x08, 0x08, 0x3e, 0x08, 0x08 }, /* 0x2b + */ { 0x00, 0x50, 0x30, 0x00, 0x00 }, /* 0x2c , */ { 0x08, 0x08, 0x08, 0x08, 0x08 }, /* 0x2d - */ { 0x00, 0x60, 0x60, 0x00, 0x00 }, /* 0x2e . */ { 0x20, 0x10, 0x08, 0x04, 0x02 }, /* 0x2f / */ { 0x3e, 0x51, 0x49, 0x45, 0x3e }, /* 0x30 0 */ { 0x00, 0x42, 0x7f, 0x40, 0x00 }, /* 0x31 1 */ { 0x42, 0x61, 0x51, 0x49, 0x46 }, /* 0x32 2 */ { 0x21, 0x41, 0x45, 0x4b, 0x31 }, /* 0x33 3 */ { 0x18, 0x14, 0x12, 0x7f, 0x10 }, /* 0x34 4 */ { 0x27, 0x45, 0x45, 0x45, 0x39 }, /* 0x35 5 */ { 0x3c, 0x4a, 0x49, 0x49, 0x30 }, /* 0x36 6 */ { 0x01, 0x71, 0x09, 0x05, 0x03 }, /* 0x37 7 */ { 0x36, 0x49, 0x49, 0x49, 0x36 }, /* 0x38 8 */ { 0x06, 0x49, 0x49, 0x29, 0x1e }, /* 0x39 9 */ { 0x00, 0x36, 0x36, 0x00, 0x00 }, /* 0x3a : */ { 0x00, 0x56, 0x36, 0x00, 0x00 }, /* 0x3b ; */ { 0x08, 0x14, 0x22, 0x41, 0x00 }, /* 0x3c < */ { 0x14, 0x14, 0x14, 0x14, 0x14 }, /* 0x3d = */ { 0x00, 0x41, 0x22, 0x14, 0x08 }, /* 0x3e > */ { 0x02, 0x01, 0x51, 0x09, 0x06 }, /* 0x3f ? */ { 0x32, 0x49, 0x79, 0x41, 0x3e }, /* 0x40 @ */ { 0x7e, 0x11, 0x11, 0x11, 0x7e }, /* 0x41 A */ { 0x7f, 0x49, 0x49, 0x49, 0x36 }, /* 0x42 B */ { 0x3e, 0x41, 0x41, 0x41, 0x22 }, /* 0x43 C */ { 0x7f, 0x41, 0x41, 0x22, 0x1c }, /* 0x44 D */ { 0x7f, 0x49, 0x49, 0x49, 0x41 }, /* 0x45 E */ { 0x7f, 0x09, 0x09, 0x09, 0x01 }, /* 0x46 F */ { 0x3e, 0x41, 0x49, 0x49, 0x7a }, /* 0x47 G */ { 0x7f, 0x08, 0x08, 0x08, 0x7f }, /* 0x48 H */ { 0x00, 0x41, 0x7f, 0x41, 0x00 }, /* 0x49 I */

7-Segment 안드로이드 App 구현 (6)DotMatrixActivity.java (4, Font)

{ 0x20, 0x40, 0x41, 0x3f, 0x01 }, /* 0x4a J */ { 0x7f, 0x08, 0x14, 0x22, 0x41 }, /* 0x4b K */ { 0x7f, 0x40, 0x40, 0x40, 0x40 }, /* 0x4c L */ { 0x7f, 0x02, 0x0c, 0x02, 0x7f }, /* 0x4d M */ { 0x7f, 0x04, 0x08, 0x10, 0x7f }, /* 0x4e N */ { 0x3e, 0x41, 0x41, 0x41, 0x3e }, /* 0x4f O */ { 0x7f, 0x09, 0x09, 0x09, 0x06 }, /* 0x50 P */ { 0x3e, 0x41, 0x51, 0x21, 0x5e }, /* 0x51 Q */ { 0x7f, 0x09, 0x19, 0x29, 0x46 }, /* 0x52 R */ { 0x26, 0x49, 0x49, 0x49, 0x32 }, /* 0x53 S */ { 0x01, 0x01, 0x7f, 0x01, 0x01 }, /* 0x54 T */ { 0x3f, 0x40, 0x40, 0x40, 0x3f }, /* 0x55 U */ { 0x1f, 0x20, 0x40, 0x20, 0x1f }, /* 0x56 V */ { 0x3f, 0x40, 0x38, 0x40, 0x3f }, /* 0x57 W */ { 0x63, 0x14, 0x08, 0x14, 0x63 }, /* 0x58 X */ { 0x07, 0x08, 0x70, 0x08, 0x07 }, /* 0x59 Y */ { 0x61, 0x51, 0x49, 0x45, 0x43 }, /* 0x5a Z */ { 0x00, 0x7f, 0x41, 0x41, 0x00 }, /* 0x5b [ */ { 0x02, 0x04, 0x08, 0x10, 0x20 }, /* 0x5c \ */ { 0x00, 0x41, 0x41, 0x7f, 0x00 }, /* 0x5d ] */ { 0x04, 0x02, 0x01, 0x02, 0x04 }, /* 0x5e ^ */ { 0x40, 0x40, 0x40, 0x40, 0x40 }, /* 0x5f _ */ { 0x00, 0x01, 0x02, 0x04, 0x00 }, /* 0x60 ` */ { 0x20, 0x54, 0x54, 0x54, 0x78 }, /* 0x61 a */ { 0x7f, 0x48, 0x44, 0x44, 0x38 }, /* 0x62 b */ { 0x38, 0x44, 0x44, 0x44, 0x20 }, /* 0x63 c */ { 0x38, 0x44, 0x44, 0x48, 0x7f }, /* 0x64 d */ { 0x38, 0x54, 0x54, 0x54, 0x18 }, /* 0x65 e */ { 0x08, 0x7e, 0x09, 0x01, 0x02 }, /* 0x66 f */ { 0x0c, 0x52, 0x52, 0x52, 0x3e }, /* 0x67 g */ { 0x7f, 0x08, 0x04, 0x04, 0x78 }, /* 0x68 h */ { 0x00, 0x04, 0x7d, 0x00, 0x00 }, /* 0x69 i */ { 0x20, 0x40, 0x44, 0x3d, 0x00 }, /* 0x6a j */ { 0x7f, 0x10, 0x28, 0x44, 0x00 }, /* 0x6b k */ { 0x00, 0x41, 0x7f, 0x40, 0x00 }, /* 0x6c l */ { 0x7c, 0x04, 0x18, 0x04, 0x7c }, /* 0x6d m */ { 0x7c, 0x08, 0x04, 0x04, 0x78 }, /* 0x6e n */ { 0x38, 0x44, 0x44, 0x44, 0x38 }, /* 0x6f o */ { 0x7c, 0x14, 0x14, 0x14, 0x08 }, /* 0x70 p */ { 0x08, 0x14, 0x14, 0x18, 0x7c }, /* 0x71 q */ { 0x7c, 0x08, 0x04, 0x04, 0x08 }, /* 0x72 r */ { 0x48, 0x54, 0x54, 0x54, 0x20 }, /* 0x73 s */ { 0x04, 0x3f, 0x44, 0x40, 0x20 }, /* 0x74 t */

{ 0x3c, 0x40, 0x40, 0x20, 0x7c }, /* 0x75 u */ { 0x1c, 0x20, 0x40, 0x20, 0x1c }, /* 0x76 v */ { 0x3c, 0x40, 0x30, 0x40, 0x3c }, /* 0x77 w */ { 0x44, 0x28, 0x10, 0x28, 0x44 }, /* 0x78 x */ { 0x0c, 0x50, 0x50, 0x50, 0x3c }, /* 0x79 y */ { 0x44, 0x64, 0x54, 0x4c, 0x44 }, /* 0x7a z */ { 0x00, 0x08, 0x36, 0x41, 0x00 }, /* 0x7b { */ { 0x00, 0x00, 0x77, 0x00, 0x00 }, /* 0x7c | */ { 0x00, 0x41, 0x36, 0x08, 0x00 }, /* 0x7d } */ { 0x08, 0x04, 0x08, 0x10, 0x08 } }; /* 0x7e ~ */}

24

Page 25: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

빌드 순서

◦ JNI 소스인 dotmatrix.c 와 Android.mk 파일을프로젝트의 jni 폴더에 추가

◦ “ 윈도키 +r” 을 입력하여 실행창을 오픈한 다음 , “cmd” 를 입력하여 커맨드 창을 오픈함

◦ 안드로이드 App 프로젝트가 있는 폴더로 이동

◦ 빌드 명령을 실행 빌드를 위해 프로젝트 폴더에 아래와 같은 명령어를 입력

> /EmbeddedSystem/Android/ndk/ndk-build

◦ 빌드가 성공하면 , libdotmatrix.so 파일이 생성된 것을 확인

25

JNI 라이브러리 빌드

Page 26: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

결과 ( 에뮬레이터 )

26

Page 27: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

결과 ( 타겟보드 )

27

Page 28: 2012 내장형 시스템 설계 2012. 11. 14. DOT Matrix 디바이스 구성 DOT Matrix 디바이스 드라이버 DOT Matrix 드라이버 테스트 프로그램 DOT Matrix JNI 라이브러리

DOT Matrix 디바이스 드라이버의 수정

◦ 요구사항1. DOT Matrix 디바이스 드라이버 내에 Font 를 지원하도록 수정

안드로이드 애플리케이션 소스코드 내에 있는 Font(PPT 24page 참조 ) 를 드라이버 내부에서 지원하도록 수정

날짜를 표시할 수 있도록 , 월 , 화 , 수 , 목 , 금 , 토 , 일을 Font 로 추가 자신의 이름 또한 Font 로 추가 JNI 에서 드라이버의 Font 를 사용할 수 있는 API 를 구현

2. 안드로이드 애플리케이션 UI 에 CalendarView 를 추가하고 , Calendar 에서 임의의 날짜를 선택하면 현재 날짜가 DOT Matrix 에 출력

출력은 년 , 월 , 일 , 요일 순으로 출력 Ex: 2012 년 11 월 14 일 수요일

3. Calendar On / Off 버튼을 만들어 On 일 경우 현재 날짜가 DOT Matrix 에 출력 , Off 일 경우 자신의 이름을 출력

◦ 제출 일시 및 제출물 11/21 ( 수 ) 수업시간 이전 제출 하드카피 소프트카피 ([email protected])

28

Homework #5*

* Take Home Exam 을 대체하는 Home-work 임 .