Presentation is loading. Please wait.

Presentation is loading. Please wait.

UniMAP 1 Interfacing Peripherals. UniMAP 2 Interfacing devices on Embedded Linux In general, to interface to a device connected to an embedded Linux platform.

Similar presentations


Presentation on theme: "UniMAP 1 Interfacing Peripherals. UniMAP 2 Interfacing devices on Embedded Linux In general, to interface to a device connected to an embedded Linux platform."— Presentation transcript:

1 UniMAP 1 Interfacing Peripherals

2 UniMAP 2 Interfacing devices on Embedded Linux In general, to interface to a device connected to an embedded Linux platform requires a device driver, which of course has to be written by the programmer. However, in this class we are not gonna write device driver…simply because Device driver programming is a.. woops actually more course by itself.

3 UniMAP 3 What is device driver programming What u need to know –Indepth knowledge about the respective hardware. –Indepth knowledge about the OS that u want to write the device driver for. An error could leads to system crash Well enough of the threatening news….after all thousands of people had successfully written them… so it can be learned.

4 UniMAP 4 The LCD we are using

5 UniMAP 5 LCD Interface A 14-pin LCD connector is provided on the TS-5500 for interfacing with standard alphanumeric LCD displays. These displays use a common controller, the Hitachi HD44780 or equivalent. While software written for the HD44780 will work with all displays using the controller, the cable needed is dependent on the display used. For most displays, a straight-through type ribbon cable can be used. The connector on the LCD display is typically mounted on the backside of the display. Warning – using an incorrect cable or mounting the LCD connector on the front-side can result in a reverse power polarity and can damage the LCD display. Please refer to your LCD data sheets for in-depth information.

6 UniMAP 6 The LCD Header signals table is not the standard pin-outs given for LCD displays. But this pin-out allows a standard ribbon cable to be used when the ribbon cable is attached to the backside of the LCD.

7 UniMAP 7 Writing to LCD using C Using the LCD HD44780 Device Driver distributed under GNU Public License –lcdconf.h Header file defining some configuration values including various register values for control and data for the lcd –lcd.h Various functions that one may use to write to the LCD –lcd.c lcd.h implementation file

8 UniMAP 8 The lcdconf.h #ifndef LCDCONF_H #define LCDCONF_H #define LCD_MEMORY_INTERFACE #ifdef LCD_MEMORY_INTERFACE #ifndef LCD_CTRL_ADDR // CPU memory address of the LCD control register #define LCD_CTRL_ADDR 0x72 #endif #ifndef LCD_DATA_ADDR // CPU memory address of the LCD data register #define LCD_DATA_ADDR 0x73 #endif #ifndef LCD_DIR_PORT // CPU memory address of the LCD enable register #define LCD_DIR_PORT 0x7D #endif #ifndef LCD_ENABLE_PIN

9 UniMAP 9 Lcdconf.h… cont // CPU memory address of the LCD enable register #define LCD_ENABLE_PIN 4 #endif // LCD display geometry // change these definitions to adapt settings #define LCD_LINES 2 // visible lines #define LCD_LINE_LENGTH 24 // line length (in characters) // cursor position to DDRAM mapping #define LCD_LINE0_DDRAMADDR 0x00 #define LCD_LINE1_DDRAMADDR 0x40 #define LCD_LINE2_DDRAMADDR 0x14 #define LCD_LINE3_DDRAMADDR 0x54 #endif

10 UniMAP 10 The lcd.h #ifndef LCD_H #define LCD_H #include // include project-dependent configurations #include "lcdconf.h" typedef unsigned char u08; typedef unsigned short u16; #define sbi(port,bit) outb(inb(port) | 1<<bit, port) #define cbi(port,bit) outb(inb(port) & ~(1<<bit), port) // HD44780 LCD controller command set (do not modify these)

11 UniMAP 11 lcd.h… cont // writing: #define LCD_CLR 0 // DB0: clear display #define LCD_HOME 1 // DB1: return to home position #define LCD_ENTRY_MODE 2 // DB2: set entry mode #define LCD_ENTRY_INC 1 // DB1: increment #define LCD_ENTRY_SHIFT 0 // DB2: shift #define LCD_ON_CTRL 3 // DB3: turn lcd/cursor on #define LCD_ON_DISPLAY 2 // DB2: turn display on #define LCD_ON_CURSOR 1 // DB1: turn cursor on #define LCD_ON_BLINK 0 // DB0: blinking cursor #define LCD_MOVE 4 // DB4: move cursor/display #define LCD_MOVE_DISP 3 // DB3: move display (0-> move cursor) #define LCD_MOVE_RIGHT 2 // DB2: move right (0-> left) #define LCD_FUNCTION 5 // DB5: function set #define LCD_FUNCTION_8BIT 4 // DB4: set 8BIT mode (0->4BIT mode) #define LCD_FUNCTION_2LINES 3 // DB3: two lines (0->one line) #define LCD_FUNCTION_10DOTS 2 // DB2: 5x10 font (0->5x7 font) #define LCD_CGRAM 6 // DB6: set CG RAM address #define LCD_DDRAM 7 // DB7: set DD RAM address

12 UniMAP 12 lcd.h // reading: #define LCD_BUSY 7 // DB7: LCD is busy // Default LCD setup // this default setup is loaded on LCD initialization #ifdef LCD_DATA_4BIT #define LCD_FDEF_1 (0<<LCD_FUNCTION_8BIT) #else #define LCD_FDEF_1 (1<<LCD_FUNCTION_8BIT) #endif #define LCD_FDEF_2 (1<<LCD_FUNCTION_2LINES) #define LCD_FUNCTION_DEFAULT ((1<<LCD_FUNCTION) | LCD_FDEF_1 | LCD_FDEF_2) #define LCD_MODE_DEFAULT ((1<<LCD_ENTRY_MODE) | (1<<LCD_ENTRY_INC))

13 UniMAP 13 // custom LCD characters #define LCDCHAR_PROGRESS05 0 // 0/5 full progress block #define LCDCHAR_PROGRESS15 1 // 1/5 full progress block #define LCDCHAR_PROGRESS25 2 // 2/5 full progress block #define LCDCHAR_PROGRESS35 3 // 3/5 full progress block #define LCDCHAR_PROGRESS45 4 // 4/5 full progress block #define LCDCHAR_PROGRESS55 5 // 5/5 full progress block #define LCDCHAR_REWINDARROW 6 // rewind arrow #define LCDCHAR_STOPBLOCK 7 // stop block #define LCDCHAR_PAUSEBARS 8 // pause bars #define LCDCHAR_FORWARDARROW 9 // fast-forward arrow #define LCDCHAR_SCROLLUPARROW 10 // scroll up arrow #define LCDCHAR_SCROLLDNARROW 11 // scroll down arrow #define LCDCHAR_BLANK 12 // scroll down arrow #define LCDCHAR_ANIPLAYICON0 13 // animated play icon frame 0 #define LCDCHAR_ANIPLAYICON1 14 // animated play icon frame 1 #define LCDCHAR_ANIPLAYICON2 15 // animated play icon frame 2 #define LCDCHAR_ANIPLAYICON3 16 // animated play icon frame 3

14 UniMAP 14 // progress bar defines #define PROGRESSPIXELS_PER_CHAR 6 // initializes I/O pins connected to LCD void lcdInitHW(void); // waits until LCD is not busy void lcdBusyWait(void); // writes a control command to the LCD void lcdControlWrite(u08 data); // read the control status from the LCD u08 lcdControlRead(void); // writes a data byte to the LCD screen at the current position void lcdDataWrite(u08 data); // reads the data byte on the LCD screen at the current position u08 lcdDataRead(void); // initializes the LCD display (gets it ready for use) void lcdInit(void); // moves the cursor/position to Home (upper left corner) void lcdHome(void); // clears the LCD display void lcdClear(void); // moves the cursor/position to the row,col requested void lcdGotoXY(u08 row, u08 col);

15 UniMAP 15 // loads a special user-defined character into the LCD // is a pointer to a ROM array containing custom characters // is the index of the character to load from lcdCustomCharArray // is the RAM location in the LCD (legal value: 0-7) void lcdLoadCustomChar(u08* lcdCustomCharArray, u08 romCharNum, u08 lcdCharNum); // prints a series of bytes/characters to the display void lcdPrintData(char* data, u08 nBytes); // clears the screen then prints a series of bytes/characters to the display going to the // next line on a '\n' or when the end of the line is reached void lcdPrintScreen(char* data); // prints a string of bytes/characters to the display but does not wrap lines void lcdPrintString(char* data); // displays a horizontal progress bar at the current cursor location // is the value the bargraph should indicate // is the value at the end of the bargraph // is the number of LCD characters that the bargraph should cover void lcdProgressBar(u16 progress, u16 maxprogress, u08 length); #endif

16 UniMAP 16 Sample Code for u int main (void) { buf[0] = 0; //initialize LCD Hardware lcdInit(); lcdPrintScreen("Assalamualaikum\n"); sleep(2); lcdClear(); lcdPrintScreen("Press Enter to End This\nStage"); sleep(2); lcdClear(); while (buf[0] != 'D') { rtrn = read (fc, &buf, sizeof(char)); if (rtrn < 0 ) printf ("Errno: %s \n", strerror(errno)); else if (!rtrn) { buf[0] = '\0'; continue; } lcdPrintString(buf); } lcdPrintScreen("Goodbye!"); return 0; }

17 UniMAP 17 Keypad Interface The DIO2 port, signals DIO2_0 through DIO2_7, may be configured to support a 4 x 4 matrix keypad. When enabled, BIOS firmware performs all the work, making the matrix keypad appear as a simple 16- key keyboard to software. This allows the use of standard keyboard access routines. The default set of keys translated by the BIOS consists of 0 – 9, A – D, *, and #. The # key is returned as an ASCII Carriage Return character (Hex 0D). Because the user is writing the software, this set of keys is usually sufficient. However, a custom translation table can be loaded, allowing the use of function keys, arrowkeys, or any other key on the keyboard.

18 UniMAP 18 Installing Matrix Keypad Under kernel 2.4.23-2.5-ts, there is module for matrix keypad which is ts_keypad.o locates at –/lib/2.4.23-2.5-ts/kernel/drivers/char/. That module is not included under kernel 2.4.18-2.2- ts.leucosia. Copy entire source code sample from Linux Develop's Manual at Matrix Keypad section as readkeypad.c and compile it. ( i used to compile this file under RedHat 8.0) –gcc -o readkeypad readkeypad.c Copy that executable file onto SBC at /usr/bin.

19 UniMAP 19 …continue At SBC, to enable the keypad, firstly load the module for keypad. –#modprobe ts_keypad.o OR –#insmod ts_keypad.o Technologic System Matrix KeyPad Driver V. 1.0.00 To check that the ts_keypad module has been probed or enabled, type lsmod. –#lsmod ModuleSize Used by Tainted: P ts_keypad2752 0 (unsed) Right now, you can run the executable readkeypad by typing –#./readkeypad Starting Technologic Systems Matrix Keypad Example Program Testing continous read of device Press “#’ to end of this stage

20 UniMAP 20 So what have u learn What is device driver What it takes to develop device driver Application… simply use existing device driver… of course we have to leave with the limitation build inside the device driver


Download ppt "UniMAP 1 Interfacing Peripherals. UniMAP 2 Interfacing devices on Embedded Linux In general, to interface to a device connected to an embedded Linux platform."

Similar presentations


Ads by Google