dslinux/user/pixil/libs/pixlib/platform/ipaq backlight.c calibrate.c ipaq.c powermgmt.c sound_dsp.c sysinfo.c
amadeus
dslinux_amadeus at user.in-berlin.de
Tue Oct 3 13:25:31 CEST 2006
Update of /cvsroot/dslinux/dslinux/user/pixil/libs/pixlib/platform/ipaq
In directory antilope:/tmp/cvs-serv11916/libs/pixlib/platform/ipaq
Added Files:
backlight.c calibrate.c ipaq.c powermgmt.c sound_dsp.c
sysinfo.c
Log Message:
adding pristine copy of pixil to HEAD so I can branch from it
--- NEW FILE: calibrate.c ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
/* Feature test switches */
/* System header files */
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
/* Local header files */
#include <h3600_ts.h>
#include <pixlib/pixlib.h>
/* Typedef, macros, enum/struct/union defintions */
#define CAL_GETX(f,p) (((f) == 0) ? ((p).x) : ((p).y))
#define CAL_GETY(f,p) (((f) == 0) ? ((p).y) : ((p).x))
#define CAL_FLAGS_EHAND 0x01 /* Exit handler has been registered */
#define CAL_FLAGS_DEVOPEN 0X02 /* Device file has been opened */
#define CAL_DFLT_DEVNAME "/dev/h3600_tsraw" /* Default FQPN of the device file */
#define CAL_MAX_SAMPLE 5
#define CAL_NUM_CTRLPTS 5
#define CAL_OFFVAL1 30
#define CAL_OFFVAL2 50
/* Global scope variables */
/* Local scope variables */
static char *devname; /* Device name */
static unsigned char cal_flags = 0; /* Global flags variable */
static int devfd = -1, /* Device file descriptor */
rotated = 1, /* Default to the color ipaq */
screen_h, /* Screen height */
screen_w; /* Screen width */
/* Static function prototypes */
static void cal_ExitHandler(void);
static int cal_OpenDev();
/*-----------------------------------------------------------------------------*\
--
-- Static function definitions
--
\*-----------------------------------------------------------------------------*/
/*******************************************************************************\
**
** Function: void cal_ExitHandler()
** Desc: Exit handler for this module, responsible for closing the
** file descriptor
** Accepts: Nothing (void)
** Returns: Nothing (void)
**
\*******************************************************************************/
static void
cal_ExitHandler(void)
{
/* Close the open file descriptor for the device */
if ((cal_flags & CAL_FLAGS_DEVOPEN) && devfd > -1)
close(devfd);
return;
} /* end of cal_ExitHandler() */
/*******************************************************************************\
**
** Function: int cal_OpenDev()
** Desc: Opens the device file and sets up the appropriate global flags
** to handle clean up.
** Accepts: Nothing (void)
** Returns: int; >= 0 the fd, or -1 on error
**
\*******************************************************************************/
static int
cal_OpenDev(void)
{
int fd = -1; /* File descriptor to pass back */
/* Check the environment variable to see if we are overriding the default device file */
if ((devname = getenv("CAL_DEVICE")) == NULL)
devname = CAL_DFLT_DEVNAME;
if ((fd = open(devname, O_RDONLY)) != -1) {
cal_flags |= CAL_FLAGS_DEVOPEN;
if (!(cal_flags & CAL_FLAGS_EHAND)) {
if (atexit(cal_ExitHandler) == 0)
cal_flags |= CAL_FLAGS_EHAND;
} /* end of if */
}
/* end of if */
return (fd);
} /* end of cal_OpenDev() */
/*-----------------------------------------------------------------------------*\
--
-- External function definitions
--
\*-----------------------------------------------------------------------------*/
/*******************************************************************************\
**
** Function: int pix_cal_GetCtrlPts()
** Desc: Gets the calibration control points for this device
** Accepts: int *npts = Ptr to storage for number of poitns
** CalPt_t **ctrldata = Ptr to Ptr of address to dynamically allocate
** memory
** int w = screen width
** int h = screen height
** int bpp = Bits per pixel
** Returns: int; 0 on success -1 on error
**
\*******************************************************************************/
int
pix_cal_GetCtrlPts(int *npts, CalPt_t ** ctrldata, int w, int h, int bpp)
{
/* Assign the memory */
if (ctrldata == NULL)
return (-1);
/* We are allocating CAL_NUM_CTRLPTS */
if ((*ctrldata =
(CalPt_t *) calloc(CAL_NUM_CTRLPTS, sizeof(CalPt_t))) == NULL)
return (-1);
if (npts)
*npts = CAL_NUM_CTRLPTS;
/* Determine the rotation */
/*
** NOTE: This is a big time hack...Apparently the B/W ipaqs are rotated 180 degrees
** from their color counterparts...
*/
if (bpp == 4)
rotated = 2;
if (rotated) {
screen_w = h;
screen_h = w;
} /* end of if */
else {
screen_w = w;
screen_h = h;
} /* end of else */
(*ctrldata)[0].x = CAL_OFFVAL1;
(*ctrldata)[0].y = CAL_OFFVAL1;
(*ctrldata)[1].x = screen_w - CAL_OFFVAL2 - 1;
(*ctrldata)[1].y = CAL_OFFVAL2;
(*ctrldata)[2].x = CAL_OFFVAL2;
(*ctrldata)[2].y = screen_h - CAL_OFFVAL2 - 1;
(*ctrldata)[3].x = screen_w - CAL_OFFVAL1 - 1;
(*ctrldata)[3].y = screen_h - CAL_OFFVAL1 - 1;
(*ctrldata)[4].x = screen_w / 2;
(*ctrldata)[4].y = screen_h / 2;
return (0);
} /* end of pix_cal_GetCtrlPts() */
/*******************************************************************************\
**
** Function: int pix_cal_GetDrawpt()
** Desc: Gets the draw points (based on any rotation that is necessary)
** Accepts: CalPt_t *ctrlpt = Ptr to the Control point
** CalPt_t *drawpt = Ptr to the storage for draw point
** Returns: int; 0 on success, -1 on error
**
\*******************************************************************************/
int
pix_cal_GetDrawPt(CalPt_t * ctrlpt, CalPt_t * drawpt)
{
if (ctrlpt == NULL || drawpt == NULL)
return (-1);
if (rotated == 1) {
/* This is the color ipaq */
drawpt->x = ctrlpt->y;
drawpt->y = screen_w - ctrlpt->x;
} /* end of if */
else if (rotated == 2) {
/* This is the gray-scale ipaq */
drawpt->x = screen_h - ctrlpt->y;
drawpt->y = screen_w - (screen_w - ctrlpt->x);
} /* end of else if */
else {
/* No rotation necessary */
drawpt->x = ctrlpt->x;
drawpt->y = ctrlpt->y;
} /* end of else */
return (0);
} /* end of pix_cal_GetDrawPt() */
/*******************************************************************************\
**
** Function: int pix_cal_GetDataPt()
** Desc: Gets the raw data (point data) from the device file and stores
** it into the CalPt_t structure passed in
** Accepts: CalPt_t *ptdata = Ptr to storage of x/y coordinates
** Returns: int; 0 on successful read, -1 on error
**
\*******************************************************************************/
int
pix_cal_GetDataPt(CalPt_t * ptdata)
{
int nsample = 0, /* Current number of samples received */
rc = 0, /* Result code */
rdsz; /* read size */
CalPt_t cur_data = { 0, 0 }; /* Current data */
TS_EVENT ts_ev; /* Event structure */
/*
** Determine if the device needs to be opened (this will only happen the first
** time this function is called
*/
if (!(cal_flags & CAL_FLAGS_DEVOPEN) || devfd == -1) {
if ((devfd = cal_OpenDev()) == -1)
return (devfd);
}
/* end of if */
/* Get CAL_MAX_SAMPLE samples to average out */
while (1) {
rdsz = 0;
while (rdsz < sizeof(TS_EVENT)) {
if ((rc = read(devfd, &ts_ev, sizeof(TS_EVENT))) == -1) {
if (errno == EINTR)
continue;
else
break;
} /* end of if */
rdsz += rc;
} /* end of if */
/* Again, check for error condition */
if (rc == -1)
break;
printf("DATA[%d] %d, %d, %d\n", nsample, ts_ev.x, ts_ev.y,
ts_ev.pressure);
if (ts_ev.pressure == 0 && nsample > CAL_MAX_SAMPLE) {
break;
} /* end of if */
else if (ts_ev.x >= 0 && ts_ev.y >= 0) {
/*
** The if conditional was added 10/29/01 -- JMW, because holding down the stylus
** would cause erroneous readings due to pressure variance....If this isn't the
** case, please correct me....
x */
if (nsample <= CAL_MAX_SAMPLE) {
cur_data.x += ts_ev.x;
cur_data.y += ts_ev.y;
nsample++;
} /* end of if */
} /* end of else-if */
} /* end of while */
if (nsample) {
cur_data.x /= nsample;
cur_data.y /= nsample;
memcpy(ptdata, &cur_data, sizeof(CalPt_t));
}
/* end of if */
return ((nsample == 0) ? -1 : 0);
} /* end of pix_cal_GetDataPtr() */
/*******************************************************************************\
**
** Function: int pix_cal_Calibrate()
** Desc: ipaq calibration routine which calculates the calibration values
** based on the control and user specific data points
** Accepts: int npts = Number of control/data points to process
** CalPt_t *ctrldata = Array of npts control points
** CalPt_t *userdata = Array of npts user points
** Returns: int; 0 on success, -1 on error, PIXLIB_STUB_VAL for a stubbed
** function.
**
\*******************************************************************************/
int
pix_cal_Calibrate(int npts, CalPt_t * ctrldata, CalPt_t * userdata)
{
int x, y, dx, dy, flag;
int xscale0, xscale1, xtrans0, xtrans1;
int yscale0, yscale1, ytrans0, ytrans1;
int xyswap, xraw, yraw;
TS_CAL new_cal; /* Calibration values to send to kernel */
flag = 0;
/* See if the device file needs to be opened */
if (!(cal_flags & CAL_FLAGS_DEVOPEN) || devfd == -1) {
if ((devfd = cal_OpenDev()) == -1) {
printf("Unable to open device!\n");
return (devfd);
}
}
/* end of if */
/* Calculate ABS(x1-x0) */
dx = ((x = userdata[1].x - userdata[0].x) < 0 ? -x : x);
dy = ((y = userdata[1].y - userdata[0].y) < 0 ? -y : y);
/* CF
(0,0) --------->Y
X +-------+---------------+-
| | | |
V | |xa0,ya0 |
+-------O---------------+ --
| | | dx or dy
+-------+---------------O --
^ | | | xa1,ya1
| | | |
Y +-------+---------------+
(0,0) -------->X
Work out where the origin is, either at the TLH or BLH corners.
Initialise xp such that it points to the array containing the X coords
Initialise yp such that it points to the array containing the Y coords
*/
if (dx < dy) {
xyswap = 1;
} else {
xyswap = 0;
}
xraw = CAL_GETX(xyswap, userdata[4]);
yraw = CAL_GETY(xyswap, userdata[4]);
/*
We have MAX_CAL_POINTS sets of x,y coordinates.
If we plot Xcal against Xraw we get two equations, each of a straight
line. One for the Xcoord and the other for the Y coord.
This line models the linear characteristics of the ts A/D
converter.
Xcal = m*Xraw + Cx
Ycal = m*Yraw + Cy
X/Ycal is the calibrated coord which is the pixel pos on the screen.
X/Yraw is the uncalibrated X coord.
m is the xscale ( gradient of line)
Cx/y is the trans (constant)
xscale
'm' can be got by calculating the gradient between two data points
Example Xscale0 = (Xcal1 - Xcal0 ) / (Xraw1 - Xraw0)
trans = Xcal - mXraw
What is actualy done is to take the Ave of two measurements
Example Xtrans0 = ( (Xcal0 - mXraw0) + (Xcal3 - mXraw3) ) / 2
We repeat the above procedure to calculate
Yscale0 and Ytrans0 and repeat the whole lot again using two
new data indexes 1 and 2 giving 4 new variables
Xscale1, Xtrans1, Yscale1,Ytrans1, making a total of eight.
The final calibration variables are the average of data ponts
0,3 and 1,2
xscale = (Xscale0 + Xscale1) / 2
yscale = (Yscale0 + Yscale1) / 2
xtrans = (Xtrans0 + Xtrans1) /2
ytrans = (Ytrans0 + Ytrans1) /2
*/
xscale0 = ((ctrldata[0].x - ctrldata[3].x) << 8) /
(CAL_GETX(xyswap, userdata[0]) - CAL_GETX(xyswap, userdata[3]));
xtrans0 =
((ctrldata[0].x - ((CAL_GETX(xyswap, userdata[0]) * xscale0) >> 8)) +
(ctrldata[3].x -
((CAL_GETX(xyswap, userdata[3]) * xscale0) >> 8))) / 2;
yscale0 = ((ctrldata[0].y - ctrldata[3].y) << 8) /
(CAL_GETY(xyswap, userdata[0]) - CAL_GETY(xyswap, userdata[3]));
ytrans0 =
((ctrldata[0].y - ((CAL_GETY(xyswap, userdata[0]) * yscale0) >> 8)) +
(ctrldata[3].y -
((CAL_GETY(xyswap, userdata[3]) * yscale0) >> 8))) / 2;
xscale1 = ((ctrldata[1].x - ctrldata[2].x) << 8) /
(CAL_GETX(xyswap, userdata[1]) - CAL_GETX(xyswap, userdata[2]));
xtrans1 =
((ctrldata[1].x - ((CAL_GETX(xyswap, userdata[1]) * xscale1) >> 8)) +
(ctrldata[2].x -
((CAL_GETX(xyswap, userdata[2]) * xscale1) >> 8))) / 2;
yscale1 = ((ctrldata[1].y - ctrldata[2].y) << 8) /
(CAL_GETY(xyswap, userdata[1]) - CAL_GETY(xyswap, userdata[2]));
ytrans1 =
((ctrldata[1].y - ((CAL_GETY(xyswap, userdata[1]) * yscale1) >> 8))
+ (ctrldata[2].y -
((CAL_GETY(xyswap, userdata[2]) * yscale1) >> 8))) / 2;
new_cal.xscale = (xscale0 + xscale1) / 2;
new_cal.xtrans = (xtrans0 + xtrans1) / 2;
new_cal.yscale = (yscale0 + yscale1) / 2;
new_cal.ytrans = (ytrans0 + ytrans1) / 2;
new_cal.xyswap = xyswap;
#ifdef FOO
new_cal.yscale = (xscale0 + xscale1) / 2;
new_cal.ytrans = (xtrans0 + xtrans1) / 2;
new_cal.xscale = (yscale0 + yscale1) / 2;
new_cal.xtrans = (ytrans0 + ytrans1) / 2;
new_cal.xyswap = xyswap;
#endif
/* Now check it with center coords */
printf("CHECK with Center Coords (160,120): xraw=%d yraw=%d\n", xraw,
yraw);
x = ((new_cal.xscale * xraw) >> 8) + new_cal.xtrans;
y = ((new_cal.yscale * yraw) >> 8) + new_cal.ytrans;
printf("CHECK: x(center)=%d y(center)=%d\n", x, y);
/* store this calibration in the device */
if (ioctl(devfd, TS_SET_CAL, (void *) &new_cal) != 0) {
perror("TS_SET_CALIBRATION ioctl fail\n");
return -1;
}
printf("SET %d, %d, %d, %d, %d\n",
new_cal.xscale, new_cal.yscale, new_cal.xtrans, new_cal.ytrans,
new_cal.xyswap);
printf("Set the calibration\n");
return 0;
} /* end of pix_cal_Calibrate() */
--- NEW FILE: powermgmt.c ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
/* Feature test switches */
/* System header files */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/* Local header files */
#include <pixlib/pixlib.h>
/* Typedef, macros, enum/struct/union definitions */
typedef struct
{
char ldrvr_v[4 + 1], bios_v[4 + 1], metric[4 + 1];
unsigned char apmflg, linests, batsts, batflg;
int batper, batunit;
}
apm_values_t;
/* Global scope variables */
/* File scope variables */
/* Static function prototypes */
static int parseApm(apm_values_t * apmval);
/*******************************************************************************\
**
** Static function definitions
**
\*******************************************************************************/
/*******************************************************************************\
**
** Function: static int parseApm()
** Desc: Reads the /proc/apm file and fills in the apm_values_t struct
** Accepts: apm_values_t *apmval = Ptr to the struct to fill in
** Returns: int; 0 on success, -1 on error
**
\*******************************************************************************/
static int
parseApm(apm_values_t * apmval)
{
int apmflg, batsts, batflg, linests, retval = -1; /* Return value */
char apmbuf[255]; /* Buffer */
FILE *fin; /* File ptr */
if (apmval == NULL)
return (retval);
if ((fin = fopen("/proc/apm", "r")) == NULL)
return (retval);
/* Get the first line */
if (fgets(apmbuf, sizeof(apmbuf), fin) != NULL) {
sscanf(apmbuf, "%s %s %i %i %i %i %d%*c %d %s", apmval->ldrvr_v,
apmval->bios_v, &apmflg, &linests, &batsts, &batflg,
&apmval->batper, &apmval->batunit, apmval->metric);
apmval->apmflg = (unsigned char) apmflg;
apmval->linests = (unsigned char) linests;
apmval->batsts = (unsigned char) batsts;
apmval->batflg = (unsigned char) batflg;
retval = 0;
}
/* end of if */
fclose(fin);
return (retval);
} /* end of parseApm() */
/******************************************************************************\
**
** Externally callable function definitions
**
\*******************************************************************************/
/*******************************************************************************\
**
** Function: int pix_pwr_getbat()
** Desc: Returns the current battery level from the device
** Acecpts: int flags = Flag indicating how to return the value;
** PWR_BAT_PERCENT = return as a percent (int)
** PWR_BAT_SECONDS = return as # of seconds remaining
** Returns: int; value as described (>= 0), -1 on unknown, PIXLIB_STUB_VAL
** for stubbed functions
**
\*******************************************************************************/
int
pix_pwr_getbat(int flags)
{
int retval = -1; /* Return value */
apm_values_t apmval; /* Apm values from the device */
/* get data from /proc/apm */
if (parseApm(&apmval) != -1 && apmval.linests == 0x00) {
if (flags == PWR_BAT_PERCENT) {
retval = apmval.batper;
} /* end of if */
else {
if (!memcmp(apmval.metric, "min", 3))
retval = apmval.batunit * 60;
else if (!memcmp(apmval.metric, "sec", 3))
retval = apmval.batunit;
else
retval = -1;
} /* end of else */
}
/* end of if */
return (retval);
} /* end of pix_pwr_getbat() */
/*******************************************************************************\
**
** Function: int pix_pwr_isCharging()
** Desc: Attempts to determine if the device's battery is charging
** Accepts: Nothing (void)
** Returns: int; 1 for charging, 0 for not charging, -1 on unknown, PIXLIB_STUB_VAL
** if stubbed
**
\*******************************************************************************/
int
pix_pwr_isCharging(void)
{
int retval = 0; /* Default to Not Charging */
apm_values_t apmval; /* Apm values */
if (parseApm(&apmval) != -1 && apmval.batflg != 0x80) {
if (apmval.batsts == 0x03 || apmval.batflg == 0x03) {
/* Battery is charging */
retval = 1;
} /* end of if */
}
/* end of if */
return (retval);
} /* end of pix_pwr_isCharging() */
/*******************************************************************************\
**
** Function: int pix_pwr_OnBattery()
** Desc: Determines if the device is on batter power
** Accepts: Nothing (void)
** Returns: int; 1 for on battery, 0 on line power, -1 on unknown, PIXLIB_STUB_VAL
** if stubbed.
**
\*******************************************************************************/
int
pix_pwr_onBattery(void)
{
int retval = -1; /* Default to unknown */
apm_values_t apmval; /* apm values */
if (parseApm(&apmval) != -1) {
if (apmval.linests == 0x00)
retval = 1;
else if (apmval.linests == 0xff)
retval = -1;
else
retval = 0;
}
/* end of if */
return (retval);
} /* end of pix_pwr_onBattery() */
/* Bitch at Jordan because he was too lazy to do the sript path
properly
*/
#define PIXIL_SUSPEND_SCRIPT "/usr/pixil/share/scripts/pixil_suspend.sh"
int
pix_pwr_suspend(void)
{
int retval = system(PIXIL_SUSPEND_SCRIPT);
if (retval == 127 || retval == -1)
return -1;
else
return 0;
}
--- NEW FILE: sound_dsp.c ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/soundcard.h>
#include <pixlib/pixlib.h>
#include <sound_dsp.h>
#define AUDIO_FILE "/dev/dsp"
/* This array ties the PIXIO_MIXER defines to the */
/* LINUX defines */
static int pix_io2linux_values[PIXIO_MIXER_COUNT] = {
SOUND_MIXER_VOLUME,
SOUND_MIXER_BASS,
SOUND_MIXER_TREBLE,
SOUND_MIXER_MIC,
SOUND_MIXER_LINE1,
SOUND_MIXER_LINE2
};
static int
OpenAudioDevice(int direction)
{
int omode;
int fd;
if (direction == PIXIO_PLAY) {
printf("set mode wronly\n");
omode = O_WRONLY;
} else
omode = O_RDONLY | O_NONBLOCK;
fd = open(AUDIO_FILE, omode, 0);
if (fd == -1)
perror("OPEN_AUDIO");
return (fd);
}
int
dspOpenStream(int direction, pix_io_audio_t * settings)
{
int err = PIXIO_ERROR;
int tmp, bsize;
int fd;
fd = OpenAudioDevice(direction);
if (fd < 0)
return (err);
/* Sync the device */
if (ioctl(fd, SNDCTL_DSP_SYNC, NULL) < 0) {
perror("OPEN_STREAM (SYNC)");
goto exit_dspOpenStream;
}
/* Set the sample size */
tmp = settings->sample;
ioctl(fd, SNDCTL_DSP_SAMPLESIZE, &tmp);
settings->speed = settings->speed / 2;
if (tmp != settings->sample) {
/* Failure - Try setting it to 16 bits */
tmp = 16;
ioctl(fd, SNDCTL_DSP_SAMPLESIZE, &tmp);
if (tmp != 16) {
perror("OPEN_STREAM (SIZE)");
goto exit_dspOpenStream;
}
}
/* Set the sample rate */
printf("speed [%d]\n", settings->speed);
if (ioctl(fd, SNDCTL_DSP_SPEED, &settings->speed) < 0) {
perror("OPEN_STREAM (SPEED)");
goto exit_dspOpenStream;
}
/* Finally, set the stereo setting */
if (settings->stereo)
if (ioctl(fd, SNDCTL_DSP_STEREO, &settings->stereo) < 0)
settings->stereo = 0;
/* Last step, grab the block size and return it to the caller */
/* Get the biggest block we can read */
bsize = -1;
ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &bsize);
if (bsize < 4 || bsize > 65536) {
if (bsize == -1) {
perror("OPEN_STREAM (BLOCKSIZE)");
goto exit_dspOpenStream;
}
bsize = 1024;
}
settings->blocksize = bsize;
err = PIXIO_OK;
return (fd);
exit_dspOpenStream:
if (fd >= 0)
close(fd);
return (err);
}
static int
open_mixer()
{
int fd;
fd = open("/dev/mixer", O_RDWR);
if (fd == -1)
perror("OPEN_MIXER");
return (fd);
}
static unsigned long
read_mixer(int device)
{
int mixer = 0;
int level = -1;
if ((mixer = open_mixer()) == -1)
return (-1);
if (ioctl(mixer, MIXER_READ(device), &level) == -1) {
perror("MIXER_READ (IOCTL)");
level = -1;
}
close(mixer);
return (level);
}
static int
write_mixer(int device, unsigned int level)
{
int err = -1;
int mixer = 0;
if ((mixer = open_mixer()) == -1)
return (-1);
if (ioctl(mixer, MIXER_WRITE(device), &level) == -1) {
perror("MIXER_WRITE (IOCTL)");
err = -1;
} else
err = 0;
close(mixer);
return (err);
}
int
mixer_set_level(int device, pix_io_level_t * level)
{
int linux_device;
unsigned int set_level;
if (device > PIXIO_MIXER_COUNT)
return (PIXIO_BAD_DEVICE);
else
linux_device = pix_io2linux_values[device];
set_level = (level->right + level->left) / 2;
if (write_mixer(linux_device, (unsigned int) set_level) == -1)
return (PIXIO_ERROR);
else
return (PIXIO_OK);
}
int
mixer_get_level(int device, pix_io_level_t * level)
{
int linux_device;
int levelin;
int l, r;
if (device > PIXIO_MIXER_COUNT)
return (PIXIO_BAD_DEVICE);
else
linux_device = pix_io2linux_values[device];
if ((levelin = read_mixer(linux_device)) == -1)
return (PIXIO_ERROR);
l = levelin;
r = (levelin >> 8);
level->left = l;
level->right = r;
return (PIXIO_OK);
}
--- NEW FILE: sysinfo.c ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
/* Feature test switches */
/* System header files */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Local header files */
#include <pixlib/pixlib.h>
/* Typedef, macro, enum/struct/union definitions */
/* Global scope variables */
/* File scope variables */
/* Static function prototypes */
/*******************************************************************************\
**
** Static function definitions
**
\*******************************************************************************/
/*******************************************************************************\
**
** External function definitions
**
\*******************************************************************************/
/*******************************************************************************\
**
** Function: int pix_sys_cpuinfo()
** Desc: Parses /proc/cpu info and organizes the data in a system independant
** way
** Accepts: pixCpuInfo_t *pcpu = Ptr to the cpu info
** Returns: int; 0 on success, -1 on error
**
\*******************************************************************************/
int
pix_sys_cpuinfo(pixCpuInfo_t * pcpu)
{
char buffer[512], /* Buffer */
model_name[80];
int rc = -1; /* Return code */
FILE *fp; /* File pointer */
/* Validate the incoming arguments */
if (pcpu == NULL)
return (rc);
if ((fp = fopen("/proc/cpuinfo", "r")) == NULL)
return (rc);
/*
** Start parsing the file. The only fields that are interesting are
** Processor.
*/
while (fgets(buffer, sizeof(buffer), fp)) {
char *cp;
int len = strlen(buffer);
if (buffer[len - 1] == '\n')
buffer[--len] = '\0';
/* Set up cp to point to the data */
if ((cp = strchr(buffer, ':')) == NULL)
continue;
if (!memcmp(buffer, "Processor", 9)) {
cp += 2; /* Skip the space */
strcpy(model_name, cp);
rc++;
} /* end of if */
} /* end of while */
if (rc > -1) {
sprintf(pcpu->cpu, "%s", model_name);
rc = 0;
}
/* end of if */
return (rc);
} /* end of pix_sys_cpuinfo() */
--- NEW FILE: backlight.c ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
/* System header files */
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
/* Local header files */
#include <pixlib/pixlib.h>
#include <h3600_ts.h>
/* Typedef, macros, enum/struct/union definitions */
/* Global scope variables */
/* File scope variables */
unsigned char f_maxval = 255; /* Maximum backlight value */
/* Static function prototypes */
/*******************************************************************************\
**
** Static function definitions
**
\*******************************************************************************/
/*******************************************************************************\
**
** Externally callable function definitions
**
\*******************************************************************************/
/*******************************************************************************\
**
** Function: int pix_bl_ctrl()
** Desc: Controls the backlight settings on the iPAQ
** Accepts: int pwr = Power settings (0 = off, 1 = on)
** int level = Brightness level (0 - f_maxval) will be clamped
** Returns: int; 0 on success, -1 on error (with errno being set)
**
\*******************************************************************************/
int
pix_bl_ctrl(int pwr, int level)
{
int bl_fd, /* Backlight filedescriptor */
retval = -1; /* Return val */
FLITE_IN bl; /* iPAQ backlight struct */
/* Open the device */
if ((bl_fd = open("/dev/h3600_tsraw", O_RDWR)) == -1)
return (retval);
/* Set everything */
bl.mode = (unsigned char) FLITE_MODE1;
bl.pwr = ((pwr != 0) ? (unsigned char) FLITE_PWR_ON :
(unsigned char) FLITE_PWR_OFF);
if (level < 0)
bl.brightness = 0;
else if (level > f_maxval)
bl.brightness = (unsigned char) f_maxval;
else
bl.brightness = (unsigned char) level;
retval = ioctl(bl_fd, FLITE_ON, (void *) &bl);
close(bl_fd);
return (retval);
} /* end of pix_bl_ctrl() */
/*******************************************************************************\
**
** Function: int pix_bl_getmxval()
** Desc: Returns the maximum backlite value supported by hardware for the
** given platform (default is 255)
** Accepts: Nothing (void)
** Returns: int; >= 0 on success, -1 on error
**
\*******************************************************************************/
int
pix_bl_getmxval(void)
{
return (f_maxval);
} /* end of bl_getmxval() */
--- NEW FILE: ipaq.c ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
/* System header files */
/* Local header files */
#include <pixlib/pixlib.h>
/* Typedef, macros, enum/struct/union definitions */
/* Global scope variables */
/* Local scope variables */
static unsigned long f_capmask = (PIX_HW_BACKLIGHT | PIX_HW_CALIBRATION | PIX_HW_POWER_MGMT); /* capability mask for the iPAQ platform */
/* Static function prototypes */
/*******************************************************************************\
**
** Static function definitions
**
\*******************************************************************************/
/*******************************************************************************\
**
** Extern function definitions
**
\*******************************************************************************/
/*******************************************************************************\
**
** Function: int pix_PDSupprt()
** Desc: Determines if the given platform support the specified capabilites
** Accepts: int capability = Flag for a given capability
** Returns: int; 0 = not supported, non-zero for capabilties supported
**
\*******************************************************************************/
int
pix_PDSupport(int capability)
{
return (capability & f_capmask);
} /* end of pix_PDSupport() */
More information about the dslinux-commit
mailing list