示例#1
0
文件: hal.c 项目: Kreyl/WitcherGlove
/**
 * @brief   HAL initialization.
 * @details This function invokes the low level initialization code then
 *          initializes all the drivers enabled in the HAL. Finally the
 *          board-specific initialization is performed by invoking
 *          @p boardInit() (usually defined in @p board.c).
 *
 * @init
 */
void halInit(void) {

  hal_lld_init();

#if HAL_USE_TM || defined(__DOXYGEN__)
  tmInit();
#endif
#if HAL_USE_PAL || defined(__DOXYGEN__)
  palInit(&pal_default_config);
#endif
#if HAL_USE_ADC || defined(__DOXYGEN__)
  adcInit();
#endif
#if HAL_USE_CAN || defined(__DOXYGEN__)
  canInit();
#endif
#if HAL_USE_EXT || defined(__DOXYGEN__)
  extInit();
#endif
#if HAL_USE_GPT || defined(__DOXYGEN__)
  gptInit();
#endif
#if HAL_USE_I2C || defined(__DOXYGEN__)
  i2cInit();
#endif
#if HAL_USE_ICU || defined(__DOXYGEN__)
  icuInit();
#endif
#if HAL_USE_MAC || defined(__DOXYGEN__)
  macInit();
#endif
#if HAL_USE_PWM || defined(__DOXYGEN__)
  pwmInit();
#endif
#if HAL_USE_SERIAL || defined(__DOXYGEN__)
  sdInit();
#endif
#if HAL_USE_SDC || defined(__DOXYGEN__)
  //KL All in Kl_sdc sdcInit();
#endif
#if HAL_USE_SPI || defined(__DOXYGEN__)
  spiInit();
#endif
#if HAL_USE_UART || defined(__DOXYGEN__)
  uartInit();
#endif
#if HAL_USE_USB || defined(__DOXYGEN__)
  usbInit();
#endif
#if HAL_USE_MMC_SPI || defined(__DOXYGEN__)
  mmcInit();
#endif
#if HAL_USE_SERIAL_USB || defined(__DOXYGEN__)
  sduInit();
#endif
#if HAL_USE_RTC || defined(__DOXYGEN__)
  rtcInit();
#endif
}
示例#2
0
/*
 * Load and tone-map a SGILOG TIFF.
 * Beware of greyscale input -- you must check the PHOTOMETRIC tag to
 * determine that the returned array contains only grey values, not RGB.
 * As in tmMapPicture(), grey values are also returned if flags&TM_F_BW.
 */
int
tmMapTIFF(uby8 **psp, int *xp, int *yp, int flags, RGBPRIMP monpri,
	double gamval, double Lddyn, double Ldmax, char *fname, TIFF *tp)
{
	char	*funcName = fname==NULL ? "tmMapTIFF" : fname;
	TMstruct	*tms = NULL;
	TMbright	*lp;
	uby8	*cp;
	int	err;
					/* check arguments */
	if ((psp == NULL) | (xp == NULL) | (yp == NULL) | (monpri == NULL) |
			((fname == NULL) & (tp == NULL)))
		returnErr(TM_E_ILLEGAL);
	if (gamval < MINGAM) gamval = DEFGAM;
	if (Lddyn < MINLDDYN) Lddyn = DEFLDDYN;
	if (Ldmax < MINLDMAX) Ldmax = DEFLDMAX;
	if (flags & TM_F_BW) monpri = stdprims;
					/* initialize tone mapping */
	if ((tms = tmInit(flags, monpri, gamval)) == NULL)
		returnErr(TM_E_NOMEM);
					/* load and convert TIFF */
	cp = TM_NOCHROM;
	err = tmLoadTIFF(tms, &lp, flags&TM_F_BW ? TM_NOCHROMP : &cp,
			xp, yp, fname, tp);
	if (err != TM_E_OK) {
		tmDone(tms);
		return(err);
	}
	if (cp == TM_NOCHROM) {
		*psp = (uby8 *)malloc(*xp * *yp * sizeof(uby8));
		if (*psp == NULL) {
			free((MEM_PTR)lp);
			tmDone(tms);
			returnErr(TM_E_NOMEM);
		}
	} else
		*psp = cp;
					/* compute color mapping */
	err = tmAddHisto(tms, lp, *xp * *yp, 1);
	if (err != TM_E_OK)
		goto done;
	err = tmComputeMapping(tms, gamval, Lddyn, Ldmax);
	if (err != TM_E_OK)
		goto done;
					/* map pixels */
	err = tmMapPixels(tms, *psp, lp, cp, *xp * *yp);

done:					/* clean up */
	free((MEM_PTR)lp);
	tmDone(tms);
	if (err != TM_E_OK) {		/* free memory on error */
		free((MEM_PTR)*psp);
		*psp = NULL;
		*xp = *yp = 0;
		returnErr(err);
	}
	returnOK;
}
示例#3
0
void
dev_open(
	char  *id
)
{
	extern char	*getenv();
	static RGBPRIMS	myprims = STDPRIMS;
	static int	atlBest[] = {GLX_RGBA, GLX_RED_SIZE,8,
				GLX_GREEN_SIZE,8, GLX_BLUE_SIZE,8,
				GLX_DEPTH_SIZE,15, None};
	char	*ev;
	double	gamval = GAMMA;
	RGBPRIMP	dpri = stdprims;
	XSetWindowAttributes	ourwinattr;
	XWMHints	ourxwmhints;
	XSizeHints	oursizhints;
					/* set quadtree globals */
	qtMinNodesiz = 3;
	qtDepthEps = 0.07;
					/* open display server */
	ourdisplay = XOpenDisplay(NULL);
	if (ourdisplay == NULL)
		error(USER, "cannot open X-windows; DISPLAY variable set?\n");
					/* find a usable visual */
	ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlBest);
	if (ourvinf == NULL)
		error(USER, "no suitable visuals available");
					/* get a context */
	gctx = glXCreateContext(ourdisplay, ourvinf, NULL, GL_TRUE);
					/* set gamma and tone mapping */
	if ((ev = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL
			|| (ev = getenv("DISPLAY_GAMMA")) != NULL)
		gamval = atof(ev);
	if ((ev = getenv("DISPLAY_PRIMARIES")) != NULL &&
			sscanf(ev, "%f %f %f %f %f %f %f %f",
				&myprims[RED][CIEX],&myprims[RED][CIEY],
				&myprims[GRN][CIEX],&myprims[GRN][CIEY],
				&myprims[BLU][CIEX],&myprims[BLU][CIEY],
				&myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6)
		dpri = myprims;
	tmGlobal = tmInit(mytmflags(), dpri, gamval);
	if (tmGlobal == NULL)
		error(SYSTEM, "not enough memory in dev_open");
					/* open window */
	ourwinattr.background_pixel = ourblack;
	ourwinattr.border_pixel = ourblack;
	ourwinattr.event_mask = ourmask;
					/* this is stupid */
	ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot,
				ourvinf->visual, AllocNone);
	gwind = XCreateWindow(ourdisplay, ourroot, 0, 0,
		DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH,
		DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH,
		BORWIDTH, ourvinf->depth, InputOutput, ourvinf->visual,
		CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &ourwinattr);
	if (gwind == 0)
		error(SYSTEM, "cannot create window\n");
   	XStoreName(ourdisplay, gwind, id);
					/* set window manager hints */
	ourxwmhints.flags = InputHint|IconPixmapHint;
	ourxwmhints.input = True;
	ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay,
			gwind, x11icon_bits, x11icon_width, x11icon_height);
	XSetWMHints(ourdisplay, gwind, &ourxwmhints);
	oursizhints.min_width = MINWIDTH;
	oursizhints.min_height = MINHEIGHT;
	oursizhints.flags = PMinSize;
	XSetNormalHints(ourdisplay, gwind, &oursizhints);
					/* set GLX context */
	glXMakeCurrent(ourdisplay, gwind, gctx);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glShadeModel(GL_FLAT);
	glDisable(GL_DITHER);
	glDisable(GL_CULL_FACE);
	glMatrixMode(GL_PROJECTION);
	glOrtho(0., 1., 0., 1., -.01, 1.01);
	glTranslated(0., 0., -1.01);
					/* figure out sensible view */
	pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) /
			DisplayWidth(ourdisplay, ourscreen);
	pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) /
			DisplayHeight(ourdisplay, ourscreen);
	odev.v = stdview;
	odev.v.type = VT_PER;
					/* map the window */
	XMapWindow(ourdisplay, gwind);
	dev_input();			/* sets size and view angles */
					/* allocate our leaf pile */
	if (!qtAllocLeaves(DisplayWidth(ourdisplay,ourscreen) *
			DisplayHeight(ourdisplay,ourscreen) * 3 /
			(qtMinNodesiz*qtMinNodesiz*2)))
		error(SYSTEM, "insufficient memory for value storage");
	odev.name = id;
	odev.ifd = ConnectionNumber(ourdisplay);
					/* initialize cone array */
	initcones();
}
示例#4
0
int main(int argc, char *argv[])
{
  char          inkey=0, *prgdir, *curdir, *program_name;
  bool          ext, validcfg, quit = false, bkgply = false, batchply = false;
  unsigned int	opt, prgdrive, i;
  CWindow       *focus;

#ifdef DEBUG
  f_log = fopen(DEBUG_FILE,"wt");
#endif

  std::cout << ADPLAYVERS << ", Copyright (c) 2000 - 2006 Simon Peter <*****@*****.**>" << std::endl << std::endl;

  // check that no other instance is running
  {
    char *adplayenv = getenv("ADPLAY");

    if(adplayenv && !strcmp(adplayenv,"S")) {
      std::cout << "AdPlay already running!" << std::endl;
      exit(EXIT_FAILURE);
    } else
      setenv("ADPLAY","S",1); // flag our instance
  }

  // Build program executable name
  program_name = strrchr(argv[0], '\\') ? strrchr(argv[0], '\\') + 1 : argv[0];

  CAdPlug::debug_output("debug.log"); // Redirect AdPlug's debug to file
  // Build path to default configuration file (in program's directory)
  SPLITPATH(argv[0],configfile,configfile+2,NULL,NULL);
  strcat(configfile,CONFIGFILE);

  loadconfig(configfile,DEFCONFIG);       // load default configuration

  // parse commandline for general options
  while((opt = getopt(argc,argv)))
    switch(opt) {
    case 1:	// display help
    case 2:
      std::cout << "Usage: " << program_name << " [options]" << std::endl << std::endl;
      std::cout << "Options can be set with '-' or '/' respectively." << std::endl << std::endl;
      std::cout << " -?, -h      Display commandline help" << std::endl <<
	" -p port     Set OPL2 port" << std::endl <<
	" -o          Force OPL2 port" << std::endl <<
	" -f file     Use alternate configuration file" << std::endl <<
	" -c section  Load another configuration section" << std::endl <<
	" -b file     Immediate background playback using " <<
	"specified file" << std::endl <<
	" -q files    Immediate (batch mode) playback using " <<
	"specified files" << std::endl;
      showcursor();
      exit(EXIT_SUCCESS);
    case 3:	// set OPL2 port
      opl.setport(atoi(argv[myoptind++]));
      break;
    case 4: // force OPL2 port
      oplforce = true;
      break;
    case 7:	// background playback
      bkgply = true;
      break;
    case 8: // batch mode playback
      batchply = true;
      break;
    }

  // Bail out if OPL2 not detected and not force
  if(!opl.detect() && !oplforce) {
    std::cout << "No OPL2 detected!" << std::endl;
    showcursor();
    exit(EXIT_FAILURE);
  }

  // Hand our database to AdPlug
  CAdPlug::set_database(&mydb);

  /*** Background playback mode ***/
  if(bkgply)
    if(!(p = CAdPlug::factory(argv[myoptind],&opl))) {
      std::cout << "[" << argv[myoptind] << "]: unsupported file type!" << std::endl;
      exit(EXIT_FAILURE);
    } else {
      std::cout << "Background playback... (type EXIT to stop)" << std::endl;
#ifdef HAVE_WCC_TIMER_H
      tmInit(poll_player,0xffff,DEFSTACK);
#elif defined HAVE_GCC_TIMER_H
      timer_init(poll_player);
#endif
      dopoll = true;
#ifdef __WATCOMC__
      _heapshrink();
#endif
      system(getenv("COMSPEC"));
#ifdef HAVE_WCC_TIMER_H
      tmClose();
#elif defined HAVE_GCC_TIMER_H
      timer_deinit();
#endif
      stop();
      exit(EXIT_SUCCESS);
    }

  /*** Batch playback mode ***/
  if(batchply) {
#ifdef HAVE_WCC_TIMER_H
    tmInit(poll_player,0xffff,DEFSTACK);
#elif defined HAVE_GCC_TIMER_H
    timer_init(poll_player);
#endif

    for(i = myoptind; i < argc; i++)
      if(!(p = CAdPlug::factory(argv[i],&opl))) {
	std::cout << "[" << argv[i] << "]: unsupported file type!" << std::endl;
#ifdef HAVE_WCC_TIMER_H
	tmClose();
#elif defined HAVE_GCC_TIMER_H
	timer_deinit();
#endif
	exit(EXIT_FAILURE);
      } else {
	dopoll = firsttime = true;
	std::cout << "Playing [" << argv[i] << "] ..." << std::endl;
	while(firsttime) ;	// busy waiting
	stop();
	dopoll = false;
      }

#ifdef HAVE_WCC_TIMER_H
    tmClose();
#elif defined HAVE_GCC_TIMER_H
    timer_deinit();
#endif
    exit(EXIT_SUCCESS);
  }

  /*** interactive (GUI) mode ***/
  getvideoinfo(&dosvideo);        // Save previous video state

  // register our windows with the window manager
  wnds.reg(titlebar); wnds.reg(filesel); wnds.reg(songwnd);
  wnds.reg(instwnd); wnds.reg(volbars); wnds.reg(mastervol);
  wnds.reg(infownd);

  // load default GUI layout
  validcfg = loadcolors(configfile,DEFCONFIG);

  // reparse commandline for GUI options
  myoptind = 1;     // reset option parser
  while((opt = getopt(argc,argv)))
    switch(opt) {
    case 5:	// set config file
      strcpy(configfile,argv[myoptind++]);
      if(loadcolors(configfile,DEFCONFIG))
	validcfg = true;
      break;
    case 6:	// load config section
      loadcolors(configfile,argv[myoptind++]);
      break;
    }

  // bail out if no configfile could be loaded
  if(!validcfg) {
    std::cout << "No valid default GUI layout could be loaded!" << std::endl;
    exit(EXIT_FAILURE);
  }

  // init GUI
  if((tmpfn = TEMPNAM(getenv("TEMP"),"_AP")))
#ifdef __WATCOMC__
    mkdir(tmpfn);
#else
  mkdir(tmpfn, S_IWUSR);
#endif
  prgdir = getcwd(NULL, PATH_MAX); _dos_getdrive(&prgdrive);
  setadplugvideo();
#ifdef HAVE_WCC_TIMER_H
  tmInit(poll_player,0xffff,DEFSTACK);
#elif defined HAVE_GCC_TIMER_H
  timer_init(poll_player);
#endif
  songwnd.setcaption("Song Info"); volbars.setcaption("VBars");
  titlebar.setcaption(ADPLAYVERS); filesel.setcaption("Directory");
  mastervol.setcaption("Vol"); filesel.refresh(); mastervol.set(63);
  display_help(infownd); filesel.setfocus(); reset_windows();

  // main loop
  do {
    if(p) {	// auto-update windows
      //                        wait_retrace();
      idle_ms(1000/70);
      refresh_songinfo(songwnd);
      refresh_volbars(volbars,opl);

      if(onsongend && !firsttime) {	// song ended
	switch(onsongend) {
	case 1:	// auto-rewind
	  dopoll = false; while(inpoll) ;	// critical section...
	  p->rewind(subsong);
	  last_ms = time_ms = 0.0f;
	  dopoll = true;	// ...End critical section
	  break;
	case 2:	// stop playback
	  stop();
	  reset_windows();
	  break;
	}
      }
    }

    // Check for keypress and read in, if any
    if(kbhit()) {
      if(!(inkey = toupper(getch()))) {
	ext = true;
	inkey = toupper(getch());
      } else
	ext = false;

      focus = CWindow::getfocus(); // cache focused window
      dbg_printf("main(): Key pressed: %d %s\n",
		 inkey, ext ? "(Ext)" : "(Norm)");
    } else
      inkey = 0;

    if(ext)	// handle all extended keys
      switch(inkey) {
      case 15:        // [Shift]+[TAB] - Back cycle windows
	window_cycle(true);
	break;
      case 59:	// [F1] - display help
	display_help(infownd);
	infownd.setfocus();
	wnds.update();
	break;
      case 60:	// [F2] - change screen layout
	curdir = getcwd(NULL, PATH_MAX);
	chdir(prgdir);
	select_colors();
	chdir(curdir);
	free(curdir);
	clearscreen(backcol);
	filesel.refresh();
	wnds.update();
	break;
      case 72:        // [Up Arrow] - scroll up
	if(focus == &filesel) {
	  filesel.select_prev();
	  filesel.update();
	} else if(focus == &infownd) {
	  infownd.scroll_up();
	  infownd.update();
	} else if(focus == &instwnd) {
	  instwnd.scroll_up();
	  instwnd.update();
	}
	break;
      case 80:        // [Down Arrow] - scroll down
	if(focus == &filesel) {
	  filesel.select_next();
	  filesel.update();
	} else if(focus == &infownd) {
	  infownd.scroll_down();
	  infownd.update();
	} else if(focus == &instwnd) {
	  instwnd.scroll_down();
	  instwnd.update();
	}
	break;
      case 75:	// [Left Arrow] - previous subsong
	if(p && subsong) {
	  subsong--;
	  dopoll = false; while(inpoll) ;	// critical section...
	  totaltime = p->songlength(subsong);
	  p->rewind(subsong);
	  last_ms = time_ms = 0.0f;
	  dopoll = true;	// ...End critical section
	}
	break;
      case 77:	// [Right Arrow] - next subsong
	if(p && subsong < p->getsubsongs()-1) {
	  subsong++;
	  dopoll = false; while(inpoll) ;	// critical section...
	  totaltime = p->songlength(subsong);
	  p->rewind(subsong);
	  last_ms = time_ms = 0.0f;
	  dopoll = true;	// ...End critical section
	}
	break;
      case 73:        // [Page Up] - scroll up half window
	if(focus == &filesel) {
	  filesel.select_prev(filesel.getsizey() / 2);
	  filesel.update();
	} else if(focus == &infownd) {
	  infownd.scroll_up(infownd.getsizey() / 2);
	  infownd.update();
	} else if(focus == &instwnd) {
	  instwnd.scroll_up(instwnd.getsizey() / 2);
	  instwnd.update();
	}
	break;
      case 81:        // [Page Down] - scroll down half window
	if(focus == &filesel) {
	  filesel.select_next(filesel.getsizey() / 2);
	  filesel.update();
	} else if(focus == &infownd) {
	  infownd.scroll_down(infownd.getsizey() / 2);
	  infownd.update();
	} else if(focus == &instwnd) {
	  instwnd.scroll_down(instwnd.getsizey() / 2);
	  instwnd.update();
	}
	break;
      case 71:        // [Home] - scroll to start
	if(focus == &filesel) {
	  filesel.setselection(0);
	  filesel.update();
	} else if(focus == &infownd) {
	  infownd.scroll_set(0);
	  infownd.update();
	} else if(focus == &instwnd) {
	  instwnd.scroll_set(0);
	  instwnd.update();
	}
	break;
      case 79:        // [End] - scroll to end
	if(focus == &filesel) {
	  filesel.setselection(0xffff);
	  filesel.update();
	} else if(focus == &infownd) {
	  infownd.scroll_set(0xffff);
	  infownd.update();
	} else if(focus == &instwnd) {
	  instwnd.scroll_set(0xffff);
	  instwnd.update();
	}
	break;
      }
    else		// handle all normal keys
      switch(inkey) {
      case 9:         // [TAB] - Cycle through windows
	window_cycle();
	break;
      case 13:        // [Return] - Activate
	if(focus == &filesel)
	  activate();
	break;
      case 27:        // [ESC] - Stop music / Exit to DOS
	if(p) {
	  stop();
	  reset_windows();
	} else
	  quit = true;
	break;
      case ' ':	// [Space] - fast forward
	fast_forward(FF_MSEC);
	break;
      case 'M':	// refresh song info
	refresh_songdesc(infownd);
	break;
      case 'D':	// shell to DOS
	dosshell(getenv("COMSPEC"));
	filesel.refresh(); wnds.update();
	break;
      case '+':       // [+] - Increase volume
	adjust_volume(-1);
	break;
      case '-':       // [-] - Decrease volume
	adjust_volume(+1);
	break;
      }
  } while(!quit);

  // deinit
#ifdef HAVE_WCC_TIMER_H
    tmClose();
#elif defined HAVE_GCC_TIMER_H
    timer_deinit();
#endif
  stop();
  setvideoinfo(&dosvideo);
  {
    unsigned int dummy;
    _dos_setdrive(prgdrive, &dummy);
  }
  chdir(prgdir);
  free(prgdir);
  if(tmpfn) { rmdir(tmpfn); free(tmpfn); }
#ifdef DEBUG
  dbg_printf("main(): clean shutdown.\n");
  fclose(f_log);
#endif
  return EXIT_SUCCESS;
}