Example #1
0
void main(void)
{
  board_init();
  NVIC_Configuration();
  timer_init();
  state = 0;
#ifdef DEBUG
  debug_printf("hello world\n");
#endif

  while (1) {
    switch (state) {
      case 0:
        if (get_button()) {
          state = 1;
          set_leds(state);
        }
        break;
      case 1:
        if (get_button()) {
          state = 0;
          set_leds(state);
        }
        break;
    }
  }
}
Example #2
0
// Display fancy LED pattern waiting for any button to be pressed
// Wait for user to begin game
inline static void wait_start() {
	uint8_t mask = 0;
	uint8_t buttons;
	uint8_t cnt;
	uint8_t led = LED0;

	do {
		set_leds(led);
		mask = wait_buttons(100); // 100ms max wait
		led = led == LED3 ? LED0 : led << 1; // next led
	} while (mask == 0);

	// wait more until all buttons are released
	set_leds(0);
	buttons = mask;
	do {
		mask = get_buttons();
		buttons |= mask;
	} while (mask != 0);

	// configure game level depending on number of buttons pressed
	cnt = buttons_count(buttons);
	if (cnt == 2)
		game_level = 15;
	else if (cnt == 3)
		game_level = 20;
	else if (cnt == 4)
		game_level = 25;
}
Example #3
0
long int initdram (int board_type)
{
	long dram_size = 0;

	set_leds(1);			/* display boot info counter */
	dram_size = spd_sdram();
	set_leds(2);			/* display boot info counter */

	return dram_size;
}
Example #4
0
/* Never returns */
void led_flash (int led_pattern1, int led_pattern2)
{   
    while (1)
    {
        set_leds (led_pattern1);
        sleep(HZ/2);
        clear_leds (led_pattern1);
        
        set_leds(led_pattern2);
        sleep(HZ/2);
        clear_leds (led_pattern2);
    }
}
Example #5
0
void Port_1(void)
{
    short int i;
    P1IFG &= ~BUTTON; // P1.3 IFG clear
    for (i = 0; i < 10; i++)
    {
        set_leds(ON, OFF);
        __delay_cycles(200000);
        set_leds(OFF, ON);
        __delay_cycles(200000);
    }
    set_leds(OFF, OFF);
}
Example #6
0
void set_mode_lights(uint8_t mode)
{
    switch(mode)
    {
    case MODE_FREE_PLAY:
        set_leds(LED_3, ON);
        set_leds(LED_1 | LED_2 | LED_4, OFF);
        break;

    case MODE_HARD:
        set_leds(LED_4, ON);
        set_leds(LED_1 | LED_2 | LED_3, OFF);
        break;

    case MODE_SILENT:
        set_leds(LED_2, ON);
        set_leds(LED_1 | LED_3 | LED_4, OFF);
        break;

    case MODE_NORMAL:
        set_leds(LED_1, ON);
        set_leds(LED_2 | LED_3 | LED_4, OFF);
        break;
    }
}
Example #7
0
void show_boot_progress(int val)
{
	switch (val) {
	case BOOTSTAGE_ID_RUN_OS:		/* booting Linux */
		set_leds(BOTH_LEDS, NEITHER_LED);
		break;
	case BOOTSTAGE_ID_NET_ETH_START:	/* Ethernet initialization */
		set_leds(GREEN_LED, GREEN_LED);
		break;
	default:
		if (val < 0)	/* error */
			set_leds(ORANGE_LED, ORANGE_LED);
		break;
	}
}
Example #8
0
void show_boot_progress(int val)
{
	switch (val) {
	case 15:		/* booting Linux */
		set_leds(BOTH_LEDS, NEITHER_LED);
		break;
	case 64:		/* Ethernet initialization */
		set_leds(GREEN_LED, GREEN_LED);
		break;
	default:
		if (val < 0)	/* error */
			set_leds(ORANGE_LED, ORANGE_LED);
		break;
	}
}
Example #9
0
void display_mode(void) {
    uint8_t mode, last_mode;

    mode = last_mode = read_mode();
    set_mode_lights(mode);

    input_clear_button_pressed();
    while (1) {
        last_mode = mode;
        mode = read_mode();

        if(mode != last_mode)
        {
            set_mode_lights(mode);

            play_tone(2000,10);

            game_set_mode(mode);
        }

        if (input_button_pressed())
        {
            _delay_ms(100);
            break;
        }
    }

    set_leds(ALL_LEDS, OFF);
}
Example #10
0
bool rf_ctrl_process_ack_payloads(uint8_t* msg_buff_free, uint8_t* msg_buff_capacity)
{
	// set defaults
	if (msg_buff_free)		*msg_buff_free = 0;
	if (msg_buff_capacity)	*msg_buff_capacity = 0;

	bool ret_val = false;
	uint8_t buff[3];
	while (rf_ctrl_read_ack_payload(buff, sizeof buff))
	{
		if (buff[0] == MT_LED_STATUS)
		{
			set_leds(buff[1], 25);

		} else if (buff[0] == MT_TEXT_BUFF_FREE) {
			
			ret_val = true;
			
			// make a proper message pointer
			rf_msg_text_buff_state_t* msg_free_buff = (rf_msg_text_buff_state_t*) buff;
			
			if (msg_buff_free)
				*msg_buff_free = msg_free_buff->bytes_free;
				
			if (msg_buff_capacity)
				*msg_buff_capacity = msg_free_buff->bytes_capacity;
		}
	}
	
	return ret_val;
}
Example #11
0
void my_putchar(unsigned x, unsigned y, unsigned ch)
{
        unsigned line;
        unsigned char *bitmap = chars_bitmaps + (ch << 4);
        unsigned char *fb = (char *)frame_buffer_start + pos_x
                + ((y + (y << 4)) << 8);

        set_leds(x);

        *fb = *bitmap++, fb += 80;
        *fb = *bitmap++, fb += 80;
        *fb = *bitmap++, fb += 80;
        *fb = *bitmap++, fb += 80;
        *fb = *bitmap++, fb += 80;
        *fb = *bitmap++, fb += 80;
        *fb = *bitmap++, fb += 80;
        *fb = *bitmap++, fb += 80;
        *fb = *bitmap++, fb += 80;
        *fb = *bitmap++, fb += 80;
        *fb = *bitmap++, fb += 80;
        *fb = *bitmap++, fb += 80;
        *fb = *bitmap++, fb += 80;
        *fb = *bitmap++, fb += 80;
        *fb = *bitmap++, fb += 80;
        *fb = *bitmap++, fb += 80;

        ++pos_x;

        if (pos_x == 2400)
                pos_x = 0;
}
Example #12
0
// Plays the loser sounds
inline void play_loser(void) {
	uint8_t i;
	for (i = 0; i < 4; i++) {
		set_leds((i & 1) ? (LED2 | LED3) : (LED0 | LED1));
		buzzer_wait(FREQLEN2TONECNT(333.33, 250));
	}
}
Example #13
0
/*
 * This function is called when the module is loaded
 */
int init_module(void)
{
    int major;		/* Major number assigned to our device driver */
    int minor;		/* Minor number assigned to the associated character device */

    /* Register driver */
    if (alloc_chrdev_region (&start, 0, 1, DEVICE_NAME)) {
        printk(KERN_INFO "Can't register chrdev_region()");
        return -ENOMEM;
    }
    printk(KERN_INFO "Device registered correctly with major number %d\n", MAJOR(start));

    /* Create associated cdev */
    if ((chardev=cdev_alloc())==NULL) {
        printk(KERN_INFO "cdev_alloc() failed ");
        unregister_chrdev_region(start, 1);
        return -ENOMEM;
    }

    chardevClass = class_create(THIS_MODULE, CLASS_NAME);
    if (IS_ERR(chardevClass))    //$ls /sys/class
    {
        printk(KERN_INFO "class_create() failed ");
        unregister_chrdev_region(start, 1);
        return PTR_ERR(chardevClass);
    }

    cdev_init(chardev,&fops);

    if (cdev_add(chardev,start,1)) {
        printk(KERN_INFO "cdev_add() failed ");
        class_destroy(chardevClass);
        unregister_chrdev_region(start, 1);
        return -ENOMEM;
    }

    chardevDevice = device_create(chardevClass, NULL, start, NULL, DEVICE_NAME);
    if (IS_ERR(chardevDevice)) //$ls /dev/
    {
        device_destroy(chardevClass, start);
        class_destroy(chardevClass);
        unregister_chrdev_region(start, 1);
        return PTR_ERR(chardevDevice);
    }

    // Leds start

    kbd_driver= get_kbd_driver_handler();
    set_leds(kbd_driver,ALL_LEDS_ON);

    major=MAJOR(start);
    minor=MINOR(start);

    printk(KERN_INFO "I was assigned major number %d. To talk to\n", major);
    printk(KERN_INFO "the driver. Try to cat and echo to the device file.\n");
    printk(KERN_INFO "Remove the device file and module when done.\n");

    return SUCCESS;
}
Example #14
0
void sun_setledstate(struct kbd_struct *kbd, unsigned int led) {
    if (!(led & ~7)) {
	ledioctl = led;
	kbd->ledmode = LED_SHOW_IOCTL;
    } else
	kbd->ledmode = LED_SHOW_FLAGS;
    set_leds();
}
Example #15
0
// Plays the winner sounds
inline void play_winner(void) {
	uint8_t i;
	for (i = 0; i < 4; i++) {
		set_leds((i & 1) ? (LED0 | LED3) : (LED1 | LED2));
		winner_tone = 250;
		next_winner_tone();
		while (is_buzzer_working());
	}
}
Example #16
0
File: kb.c Project: raywill/maray
void init_kb(void)
{
	vector_t v;
	v.eip = (unsigned)kb_irq;
	v.access_byte = 0x8E; /* present, ring 0, '386 interrupt gate D=32bit gate*/
	setvect(&v, 0x21);
	enable_irq(KB_IRQ);
	set_leds(LED_NUM);
}
Example #17
0
void fade_to(const std::vector<uint16_t>& LEDs,
		useconds_t fade_time, const vlpp::rgba_color& old_color,
		const vlpp::rgba_color& new_color){
	useconds_t time_per_step = fade_time / settings::fade_steps;
	for(int i=0; i < settings::fade_steps; ++i){
		double p_new = double(i) / settings::fade_steps;
		double p_old = 1 - p_new;
		vlpp::rgba_color tmp{
			// i really WANT this narrowing conversion:
			uint8_t(old_color.r*p_old + new_color.r*p_new),
			uint8_t(old_color.g*p_old + new_color.g*p_new),
			uint8_t(old_color.b*p_old + new_color.b*p_new),
			uint8_t(old_color.alpha*p_old + new_color.alpha*p_new)
		};
		set_leds(LEDs, tmp);
		usleep(time_per_step);
	}
	set_leds(LEDs, new_color);
}
Example #18
0
void System_SetNumLock(int newValue)
{
    // doesn't work ... maybe allegro doesn't implement this on windows
    int ledState = key_shifts & (KB_SCROLOCK_FLAG | KB_CAPSLOCK_FLAG);
    if (newValue)
    {
        ledState |= KB_NUMLOCK_FLAG;
    }
    set_leds(ledState);
}
Example #19
0
static int keyboard_ioctl(dev_cookie cookie, int op, void *buf, size_t len)
{
	switch(op) {
		case _KEYBOARD_IOCTL_SET_LEDS:
			user_memcpy(&leds, buf, sizeof(leds));
			set_leds();
			return 0;
		default:
			return ERR_INVALID_ARGS;
	}
}
Example #20
0
void fade_to(const std::vector<uint16_t>& led_list,
		useconds_t fade_time, const vlpp::rgba_color& old_color,
		const vlpp::rgba_color& new_color){
	useconds_t time_per_step = fade_time / settings::fade_steps;
	for(int i=0; i < settings::fade_steps; ++i){
		auto color_shares = settings::color_ratio_function(i, settings::fade_steps);
		auto p_new = color_shares.first;
		auto p_old = color_shares.second;
		vlpp::rgba_color tmp{
			// i really WANT this narrowing conversion:
			uint8_t(old_color.red*p_old + new_color.red*p_new),
			uint8_t(old_color.green*p_old + new_color.green*p_new),
			uint8_t(old_color.blue*p_old + new_color.blue*p_new),
			uint8_t(old_color.alpha*p_old + new_color.alpha*p_new)
		};
		set_leds(led_list, tmp);
		usleep(time_per_step);
	}
	set_leds(led_list, new_color);
}
Example #21
0
void KeyboardController::handleLockingKeys(int scode) {
	// Scroll Lock keyLED
    if(scode == KEY_SCRLOCK)
    {
    	ScrLock = ScrLock ? 0 : 1;
    	if(ScrLock != 0)
			set_leds(KB_SCROLOCK_FLAG); // available when the BIOS support it.
		else
  			set_leds(-1);
    }
    // Number Lock keyLED
    else if(scode == KEY_NUMLOCK)
    {
		NumLock = NumLock ? 0 : 1;
    	if(NumLock != 0)
  			set_leds(KB_NUMLOCK_FLAG); // available when the BIOS support it.
  		else
  			set_leds(-1);
	}
	// Caps Lock keyLED
	else if(scode == KEY_CAPSLOCK)
	{
		CapsLock = CapsLock ? 0 : 1;
    	if(CapsLock != 0)
  			set_leds(KB_CAPSLOCK_FLAG); // available when the BIOS support it.
  		else
  			set_leds(-1);
	}
}
Example #22
0
/* This syscall modify the the led state */
SYSCALL_DEFINE1(ledctl,unsigned int,leds) {
	if((leds<0)||(leds>7))
		return -EINVAL;
	kbd_driver= get_kbd_driver_handler();

	if(kbd_driver==NULL)
		return -ENODEV;

	leds = convert(leds);
	if(set_leds(kbd_driver,leds) < 0)
		return -ENOTSUPP;
	return 0;
}
Example #23
0
File: modleds.c Project: rnov/LIN
static ssize_t key_write(struct file *filp, const char __user *buf, size_t len, loff_t *off) {
	
	unsigned char kbuf [4] = {}; /*No meter valores mayores a 4Bytes*/
	unsigned int aux;
	
	/* Transfer data from user to kernel space */
	if (copy_from_user(kbuf, buf, len )!=0)  
		return -ENOSPC;	
	
	kbuf[len] = '\0'; /* Add the `\0' */
	
	sscanf(kbuf,"%x",&aux);
	
	if(aux<0 || aux>7 ){  /* Fuera de rango */
		set_leds(kbd_driver,ALL_LEDS_OFF);		
	}else{
		set_leds(kbd_driver,aux);
		}
	
	*off+=len;        /* Update the file pointer */
	return len;
}
Example #24
0
/*======================================================================*
                           init_keyboard
*======================================================================*/
PUBLIC void init_keyboard()
{
    kb_in.count = 0;
    kb_in.p_head = kb_in.p_tail = kb_in.buf;

    caps_lock   = 0;
    num_lock    = 1;
    scroll_lock = 0;

    set_leds();

        put_irq_handler(KEYBOARD_IRQ, keyboard_handler);/*设定键盘中断处理程序*/
        enable_irq(KEYBOARD_IRQ);                       /*开键盘中断*/
}
Example #25
0
int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;
    LED_DIR |= (LED_0 | LED_1);
    set_leds(OFF, OFF);
    P1IE |= BUTTON;

    __eint();

    while(1)
    {
        LPM4; // Enter low-power mode 4
    }
}
Example #26
0
static int setup_keyboard(void)
{
	keyboard_sem = sem_create(0, "keyboard_sem");
	if(keyboard_sem < 0)
		panic("could not create keyboard sem!\n");

	if(mutex_init(&keyboard_read_mutex, "keyboard_read_mutex") < 0)
		panic("could not create keyboard read mutex!\n");

	leds = 0;
	set_leds();

	head = tail = 0;

	return 0;
}
Example #27
0
int board_early_init_f(void)
{
	register uint reg;

	set_leds(0);			/* display boot info counter */

	/*--------------------------------------------------------------------
	 * Setup the external bus controller/chip selects
	 *-------------------------------------------------------------------*/
	mtdcr(ebccfga, xbcfg);
	reg = mfdcr(ebccfgd);
	mtdcr(ebccfgd, reg | 0x04000000);	/* Set ATC */

	/*--------------------------------------------------------------------
	 * GPIO's are alreay setup in cpu/ppc4xx/cpu_init.c
	 * via define from board config file.
	 *-------------------------------------------------------------------*/

	/*--------------------------------------------------------------------
	 * Setup the interrupt controller polarities, triggers, etc.
	 *-------------------------------------------------------------------*/
	mtdcr(uic0sr, 0xffffffff);	/* clear all */
	mtdcr(uic0er, 0x00000000);	/* disable all */
	mtdcr(uic0cr, 0x00000001);	/* UIC1 crit is critical */
	mtdcr(uic0pr, 0xfffffe1f);	/* per ref-board manual */
	mtdcr(uic0tr, 0x01c00000);	/* per ref-board manual */
	mtdcr(uic0vr, 0x00000001);	/* int31 highest, base=0x000 */
	mtdcr(uic0sr, 0xffffffff);	/* clear all */

	mtdcr(uic1sr, 0xffffffff);	/* clear all */
	mtdcr(uic1er, 0x00000000);	/* disable all */
	mtdcr(uic1cr, 0x00000000);	/* all non-critical */
	mtdcr(uic1pr, 0xffffe0ff);	/* per ref-board manual */
	mtdcr(uic1tr, 0x00ffc000);	/* per ref-board manual */
	mtdcr(uic1vr, 0x00000001);	/* int31 highest, base=0x000 */
	mtdcr(uic1sr, 0xffffffff);	/* clear all */

	/*--------------------------------------------------------------------
	 * Setup other serial configuration
	 *-------------------------------------------------------------------*/
	mfsdr(sdr_pci0, reg);
	mtsdr(sdr_pci0, 0x80000000 | reg);	/* PCI arbiter enabled */
	mtsdr(sdr_pfc0, 0x00000100);	/* Pin function: enable GPIO49-63 */
	mtsdr(sdr_pfc1, 0x00048000);	/* Pin function: UART0 has 4 pins, select IRQ5 */

	return 0;
}
Example #28
0
File: keyboard.c Project: qq53/os
PUBLIC void init_keyboard()
{
	kb_in.head = kb_in.tail = -1;
	kb_in.count = 0;

	shift_l	= shift_r = 0;
	alt_l	= alt_r   = 0;
	ctrl_l	= ctrl_r  = 0;

	caps_lock = scroll_lock = 0;
	num_lock = 1;

	set_leds();

	put_irq_handler(KEYBOARD_IRQ,keyboard_handler);
	enable_irq(KEYBOARD_IRQ);
}
Example #29
0
File: keyboard.c Project: Zach41/OS
PUBLIC void init_keyboard(TTY *p_tty) {
    kb_in.count  = 0;
    kb_in.p_head = kb_in.p_tail = kb_in.buf;

    code_with_E0 = 0;
    shift_l = shift_r = 0;
    ctrl_l  = ctrl_r  = 0;
    alt_l   = alt_r   = 0;
    num_lock    = 1;
    caps_lock   = 0;
    scroll_lock = 0;

    set_leds();
	
    put_irq_handler(KEYBOARD_IRQ, keyboard_handler);
    enable_irq(KEYBOARD_IRQ);
}
Example #30
0
void stop_tty(struct tty_struct *tty)
{
	if (tty->stopped)
		return;
	tty->stopped = 1;
	if (tty->link && tty->link->packet) {
		tty->ctrl_status &= ~TIOCPKT_START;
		tty->ctrl_status |= TIOCPKT_STOP;
		wake_up_interruptible(&tty->link->secondary.proc_list);
	}
	if (tty->stop)
		(tty->stop)(tty);
	if (IS_A_CONSOLE(tty->line)) {
		set_vc_kbd_led(kbd_table + fg_console, VC_SCROLLOCK);
		set_leds();
	}
}