Example #1
0
/////////////////////////////////////////////////////////////////////
// First byte, hex: Row number if less then 32, Display text in title else
// Rest: Text to display, up to 16 char.
// 00:title (big font).
// 01-08:body
// 09:scroll up, add row at bottom
// 0A:scroll down, add row at top
// 0B:redraw screen.
// FF:control functions: Switch LCD on/of, set contrast
void
lcdfunc(char *in)
{
  uint8_t hb[4];
  uint8_t narg = fromhex(in+1, hb, 4);

  if(narg > 0 && hb[0] == 0xFF) {

    if(hb[1] != 0xFF) lcd_switch(hb[1]);
    if(hb[2] != 0xFF) lcd_contrast(hb[2]);
#ifdef LCD_BL_PWM
    if(hb[3] != 0xFF) lcd_brightness(hb[3]);
#endif

    return;
  }

  if(narg == 0 || hb[0] >=  0x20) {   // Strange lines go to the title
    hb[0] = 0;
    in += 1;
  } else {
    in += 3;
  }
  lcd_putline(hb[0], in);
}
Example #2
0
void env_relocate(bd_t *bd)
{
    char *s, *e;
	int reg;

   
    bd->bi_env = malloc(sizeof(env_t));

    if (board_env_copy(bd, bd->bi_env, sizeof(env_t)) < 0)
    {
	printf("*** Using default environment\n");
	memcpy(bd->bi_env_data, default_environment, 
	       sizeof(default_environment));
	bd->bi_env_crc = crc32(0, bd->bi_env_data, sizeof(bd->bi_env_data));
    }
    
    /* now initialise some variables */
    
    /* MAC address */
    s = getenv(bd, "ethaddr");
    for (reg=0; reg<6; reg++) 
    {
	bd->bi_enetaddr[reg] = s ? simple_strtoul(s, &e, 16) : 0;
	if (s)
	  s = (*e) ? e+1 : e;
    }

#if (CONFIG_COMMANDS & CFG_CMD_NET)
    /* IP address */
    s = getenv(bd, "ipaddr");
    bd->bi_ip_addr = string_to_ip(s);
#endif
    
    if ((s = getenv(bd, "loadaddr")) != NULL) {    
        load_addr = simple_strtoul(s, NULL, 16);
    }
    
    if ((s = getenv(bd, "pagelength")) != NULL) {
       pagelength = simple_strtoul(s, NULL, 10);
    }

#if (CONFIG_COMMANDS & CFG_CMD_NET)
    if ((s = getenv(bd, "bootfile")) != NULL) {    
        copy_filename (BootFile, s, sizeof(BootFile));
    }
#endif  /* CFG_CMD_NET */

#ifdef CONFIG_KEYBOARD
    if ((s = getenv(bd, "keymap")) != NULL) {
		kbd_mapping (s);
    }
#endif	/* CONFIG_KEYBOARD */

#ifdef CONFIG_ADJUST_LCD
    if ((s = getenv(bd, "contrast")) != NULL) {
		lcd_contrast(simple_strtoul(s, NULL, 10));
	}
    if ((s = getenv(bd, "brightness")) != NULL) {
		lcd_brightness(simple_strtoul(s, NULL, 10));
	}
#endif	/* CONFIG_ADJUST_LCD */

}
Example #3
0
int _do_setenv (bd_t *bd, int flag, int argc, char *argv[])
{
    int   i, len, oldval;
    uchar *env, *nxt = 0;
    uchar *name;
    
    /* need writable copy in RAM */
    if (!bd->bi_env_data)
      return 1;

    name = argv[1];
    
    /*
     * search if variable with this name already exists
     */
    oldval = -1;
    for (env = bd->bi_env_data; *env; env = nxt+1) {
	for (nxt = env; *nxt; ++nxt)
	  ;
	if ((oldval = envmatch(bd, name, (ulong)env - (ulong)bd->bi_env_data)) >= 0)
	  break;
    }
    
    /*
     * Delete any existing definition
     */
    if (oldval >= 0) {
#ifndef CONFIG_ENV_OVERWRITE
	
	/*
	 * Ethernet Address and serial# can be set only once
	 */
	if ( (strcmp (name, "serial#") == 0) ||
	    ((strcmp (name, "ethaddr") == 0)
# if defined(CONFIG_OVERWRITE_ETHADDR_ONCE) && defined(CONFIG_ETHADDR)
	     && (strcmp (get_env_addr(bd, oldval),MK_STR(CONFIG_ETHADDR)) != 0)
# endif	/* CONFIG_OVERWRITE_ETHADDR_ONCE && CONFIG_ETHADDR */
	     ) ) {
	    printf ("Can't overwrite \"%s\"\n", name);
	    return 1;
	}
#endif
	
	/*
	 * Switch to new baudrate if new baudrate is supported
	 */
	if (strcmp(argv[1],"baudrate") == 0) {
	    int baudrate = simple_strtoul(argv[2], NULL, 10);
	    int i;
	    for (i=0; i<N_BAUDRATES; ++i) {
		if (baudrate == baudrate_table[i])
		  break;
	    }
	    if (i == N_BAUDRATES) {
		printf ("## Baudrate %d bps not supported\n",
			baudrate);
		return 1;
	    }
	    printf ("## Switch baudrate to %d bps and press ENTER ...\n",
		    baudrate);
	    udelay(50000);
	    serial_setbrg (bd, baudrate);
	    udelay(50000);
	    for (;;) {
		if (getc() == '\r')
		  break;
	    }
	    bd->bi_baudrate = baudrate;
	}
	
	if (*++nxt == '\0') {
	    if ((ulong)env > (ulong)bd->bi_env_data) {
		env--;
	    } else {
		*env = '\0';
	    }
	} else {
	    for (;;) {
		*env = *nxt++;
		if ((*env == '\0') && (*nxt == '\0'))
		  break;
		++env;
	    }
	}
	*++env = '\0';
    }
    /* Delete only ? */
    if ((argc < 3) || argv[2] == NULL) {    
	/* Update CRC */
	bd->bi_env_crc = crc32(0, bd->bi_env_data, sizeof(bd->bi_env_data));
	return 0;
    }

    /*
     * Append new definition at the end
     */
    for (env = bd->bi_env_data; *env || *(env+1); ++env)
      ;
    if ((ulong)env > (ulong)bd->bi_env_data)
      ++env;
    /*
     * Overflow when:
     * "name" + "=" + "val" +"\0\0"  > 
     *      sizeof(bd->bi_env_data) - (env-bd->bi_env_data)
     */
    len = strlen(name) + 2;
    /* add '=' for first arg, ' ' for all others */
    for (i=2; i<argc; ++i) {
	len += strlen(argv[i]) + 1;
    }
    if (len > sizeof(bd->bi_env_data)) {
	printf ("## Error: environment overflow, \"%s\" deleted\n", name);
	return 1;
    }
    while ((*env = *name++) != '\0')
      env++;
    for (i=2; i<argc; ++i) {
	char *val = argv[i];
	
	*env = (i==2) ? '=' : ' ';
	while ((*++env = *val++) != '\0')
	  ;
    }
    
    /* end is marked with double '\0' */
    *++env = '\0';
    
    /* Update CRC */
    bd->bi_env_crc = crc32(0, bd->bi_env_data, sizeof(bd->bi_env_data));

    /*
     * Some variables should be updated when the corresponding
     * entry in the enviornment is changed
     */
    
    if (strcmp(argv[1],"ethaddr") == 0) {
	char *s = argv[2];	/* always use only one arg */
	char *e;
	for (i=0; i<6; ++i) {
	    bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0;
	    if (s) s = (*e) ? e+1 : e;
	}
	return 0;
    }

#if (CONFIG_COMMANDS & CFG_CMD_NET)
    if (strcmp(argv[1],"ipaddr") == 0) {
	char *s = argv[2];	/* always use only one arg */
	bd->bi_ip_addr = string_to_ip(s);
	return 0;
    }
#endif

    if (strcmp(argv[1],"loadaddr") == 0) {
	load_addr = simple_strtoul(argv[2], NULL, 16);
	return 0;
    }

    if (strcmp(argv[1],"pagelength") == 0) {
	pagelength = simple_strtoul(argv[2], NULL, 10);
	return 0;
    }

#if (CONFIG_COMMANDS & CFG_CMD_NET)
    if (strcmp(argv[1],"bootfile") == 0) {
	copy_filename (BootFile, argv[2], sizeof(BootFile));
	return 0;
    }
#endif	/* CFG_CMD_NET */

#ifdef CONFIG_KEYBOARD
    if (strcmp(argv[1],"keymap") == 0) {
	kbd_mapping (argv[2]);
	return 0;
    }
#endif	/* CONFIG_KEYBOARD */

#ifdef CONFIG_ADJUST_LCD
    if (strcmp(argv[1],"contrast") == 0) {
	lcd_contrast(simple_strtoul(argv[2], NULL, 10));
	return 0;
	}
    if (strcmp(argv[1],"brightness") == 0) {
	lcd_brightness(simple_strtoul(argv[2], NULL, 10));
	return 0;
	}
#endif	/* CONFIG_ADJUST_LCD */

    return 0;
}
Example #4
0
static int lcd_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
  switch (cmd)
    {

      /* SLCDIOC_GETATTRIBUTES:  Get the attributes of the SLCD
       *
       * argument:  Pointer to struct slcd_attributes_s in which values will be
       *            returned
       */

      case SLCDIOC_GETATTRIBUTES:
        {
          FAR struct slcd_attributes_s *attr = (FAR struct slcd_attributes_s *)((uintptr_t)arg);

          lcdinfo("SLCDIOC_GETATTRIBUTES:\n");

          if (!attr)
            {
              return -EINVAL;
            }

          attr->nrows         = LCD_NROWS;
          attr->ncolumns      = LCD_NCOLUMNS;
          attr->nbars         = 0;
          attr->maxcontrast   = CONFIG_LCD_MAXCONTRAST;
          attr->maxbrightness = CONFIG_LCD_MAXPOWER;
        }
        break;

      /* SLCDIOC_CURPOS:  Get the SLCD cursor positioni (rows x characters)
       *
       * argument:  Pointer to struct slcd_curpos_s in which values will be
       *            returned
       */


      case SLCDIOC_CURPOS:
        {
          FAR struct slcd_curpos_s *curpos = (FAR struct slcd_curpos_s *)((uintptr_t)arg);

          lcdinfo("SLCDIOC_CURPOS: row=%d column=%d\n", g_lcd1602.currow, g_lcd1602.curcol);

          if (!curpos)
            {
              return -EINVAL;
            }

          curpos->row    = g_lcd1602.currow;
          curpos->column = g_lcd1602.curcol;
        }
        break;

      /* SLCDIOC_GETBRIGHTNESS: Get the current brightness setting
       *
       * argument:  Pointer type int that will receive the current brightness
       *            setting
       */

      case SLCDIOC_GETBRIGHTNESS:
        {
          FAR int *brightness = (FAR int *)((uintptr_t)arg);
          if (!brightness)
            {
              return -EINVAL;
            }

          *brightness = (int)g_lcd1602.brightness;
          lcdinfo("SLCDIOC_GETCONTRAST: brightness=%d\n", *brightness);
        }
        break;

      /* SLCDIOC_SETBRIGHTNESS: Set the brightness to a new value
       *
       * argument:  The new brightness value
       */

      case SLCDIOC_SETBRIGHTNESS:
        {
          lcdinfo("SLCDIOC_SETCONTRAST: arg=%ld\n", arg);

          if (arg > CONFIG_LCD_MAXPOWER)
            {
              return -ERANGE;
            }

          lcd_brightness((uint8_t)arg);
        }
        break;

      case SLCDIOC_SETBAR:         /* SLCDIOC_SETBAR: Set bars on a bar display */
      case SLCDIOC_GETCONTRAST:    /* SLCDIOC_GETCONTRAST: Get the current contrast setting */
      case SLCDIOC_SETCONTRAST:    /* SLCDIOC_SETCONTRAST: Set the contrast to a new value */
      default:
        return -ENOTTY;
    }

  return OK;
}