Author |
Topic |
|
jlackey
213 Posts |
Posted - 22 May 2002 : 14:15:13
|
ADSmartIO
ADSmartIO is a combination of hardware, firmware, and a driver that provides digital I/O, A/D conversion, keypad input, and LCD backlight control. ADSmartIO also provides other capabilities such as PS2 keyboard support on some platforms. These additional capabilities vary by platform and are beyond the scope of this topic. Consult the manual for your board to determine what is applicable.
Using ADSmartIO with Linux
The interface to ADSmartIO is provided by a set of character devices (/dev/sio*) with major number 58. The minor numbers for commonly provided devices are:
0 - ADSmartIO Version 1 - Port A Digital I/O 2 - Port B Digital I/O 3 - Port C Digital I/O 4 - Port D Digital I/O 5 - Select Option 6 - Backlight 7 - Keypad 8 - A/D Converter 9 - Vee PWM (passive panel contrast) 10 - reserved 11 - reserved 12 - Keyboard Sniffer 13 - EEPROM 14 - Thermistor Input 15 - Charger Control
Here is a library of ADSmartIO functions for linux and a sample program that uses it. Many of our customers find the library easier to use than the usual file based device interface. To use the library, just untar the libsio.tar.gz file and look at the Readme and/or type 'make help'. To try the sample program, untar the testsio.tar.gz file, edit sio.cc according to the comments at the top of the code and type make. Note: Both of these downloads require a cross compiler.
If you prefer to do it the usual way, here are some examples for reading, writing, and controlling ADSmartIO devices.
ADSmartIO Version
struct sio_ver { unsigned int DeviceVersion; // ASCII character rev unsigned int DeviceType; // hex part number unsigned int FirmwareLevel; // hex firmware ID } SioInfo;
int fd, ret;
fd = open("/dev/sio0", O_RDWR); ret = read(fd, &SioInfo, sizeof(SioInfo)); close(fd);
Backlight Control
#define SMARTIO_BL_CONTROL _IOW('s', 2, char) #define SMARTIO_BL_PWM _IOW('s', 3, char)
int fd, ret; char ch;
fd = open("/dev/sio6", O_RDWR);
ch = 0; // 0:backlight off ioctl(fd, SMARTIO_BL_CONTROL, &ch);
ch = 1; // backlight on ioctl(fd, SMARTIO_BL_CONTROL, &ch);
// Sweep brightness from dim (0xff) to bright (0) for (ch = 0xff; ch >= 0; --ch) ioctl(fd, SMARTIO_BL_PWM, &ch);
close(fd);
Digital I/O
// Ports suitable for digital I/O vary by platform, firmware revision, and option.
#define SMARTIO_PORT_CONFIG _IOW('s', 4, char)
int fd, ret; char option, config, value;
// Select option 2 (consult your manual) fd = open("/dev/sio5", O_RDWR); option = 2; write(fd, &option, 1); close(fd);
// Read and write from port C fd = open("/dev/sio3", O_RDWR); config = 0xAA; // 10101010 (1:Out, 0:In) ioctl(fd, SMARTIO_PORT_CONFIG, &config); ret = read(fd, &value, 1); ret = write(fd, &value, 1); close(fd);
A/D Conversion
int fd, ret; char option; short value;
// Select option 2 for A/D fd = open("/dev/sio5", O_RDWR); option = 2; write(fd, &option, 1); close(fd);
// Read A/D channel fd = open("/dev/sio8", O_RDWR); value = 3; // Channel to read ret = read(fd, &value, 2); // ~ 125 usec per conversion if (value > 0x3fff) { // error... } close(fd);
Keypad
#define SMARTIO_KPD_SETUP _IOW('s', 1, short) #define SMARTIO_KPD_TIMER _IOW('s', 0, int) #define COLS 3 #define ROWS 4
int fd, time, ret; char option, config[2], value, row, column;
// Select option 1 for keypad fd = open("/dev/sio5", O_RDWR); option = 1; write(fd, &option, 1); close(fd);
// Configure and read keypad fd = open("/dev/sio7", O_RDWR); config[0] = COLS; config[1] = ROWS; time = -1; ioctl(fd, SMARTIO_KPD_SETUP, &config) ioctl(fd, SMARTIO_KPD_TIMER, &time) ret = read(fd, &value, 1); value &= 3f; column = value / ROWS; row = value % ROWS; close(fd); |
Edited by - adrian on 07 Jan 2008 15:14:34 |
|
jlackey
213 Posts |
Posted - 02 Dec 2002 : 13:43:31
|
Beginning with Linux 2.4.9-ac10-rmk2-np1-ads3, support for UCB1200 digital I/O and A/D is provided in the Linux ADSmartIO drivers (for platforms that have a UCB1200). The device names and minor numbers are:
20 - UCB1200 digital I/O 30 - UCB1200 A/D 0 31 - UCB1200 A/D 1 32 - UCB1200 A/D 2 33 - UCB1200 A/D 3 The library includes functions to read the UCB1200 A/D converters and configure, read, and write the UCB1200 digital I/O. Examples are given in the sample program.
Edited by akidder 4-Feb-2004: Update forum post title from "ADSmartIO" to "ADSmartIO and UCB discrete I/O".
|
|
|
|
Topic |
|
|
|