Exemplo n.º 1
0
/*
 * Reports an error. reason should roughly give the reason for the error. Further
 * details can be supplied in the message (which may contain null bytes and whose
 * length is indicated by length). action describes which actions to take after the
 * error has been reported.
 */
void error(err_reason_t reason, char *message, int length, err_action_t action) {
	switch(action) {
	case EA_RESUME:
		dled_toggle();
#ifdef TRACE_ERRORS
		dled_blink((int) reason);
		debug_write(message, length);
#endif
		return;
		break;
	case EA_RESET:
		led_set_state(LED_STOP);
		
		dled_blink((int) reason);
		debug_write(message, length);
		
		// Reset the system
		SCB_AIRCR |= SCB_AIRCR_SYSRESETREQ;
		break;
	case EA_PANIC:
		led_set_state(LED_STOP);
		
		while (1) {
			dled_blink((int) reason);
			debug_write(message, length);
		}
		
		break;
	}
}
Exemplo n.º 2
0
void run_4bit_toggle(uint8_t *value, const uint16_t menu_item)
{
    // Run a menu page where 4 bits can be independently toggled.
    //
    //   .  .  *  .    <- menu item
    //   .  .  .  .
    //   #  #  #  #    <- bits to be toggled.
    //   .  .  .  .

    int16_t leds = REVERSE_BYTE(*value) << 4;
    // Add in the dim background for the toggle bits
    leds |= 0b0000111100000000 & dim_mask;
    // Add the flashing exit lights
    leds |= menu_item & flash_mask;
    // Update LEDs.
    led_set_state(leds);

    // Process key presses.
    // Multiple key presses are sorted out by importance: Exit buttons
    // first, then increment/decrement, then toggle bits.
    if (g_key_down & menu_item) {
        // exit key is pressed
       g_menu_state = TOP_LEVEL;
    } else if (g_key_down & 0x0f00) {
        // toggle bits using an exclusive-or of the keydown bits.
        uint16_t bits = g_key_down & 0x0f00;
        uint8_t toggle = bits >> 4;
        // Then we reverse the LSB, moving the top 4 bits to the bottom 4.
        *value = *value ^ REVERSE_BYTE(toggle);
    }
Exemplo n.º 3
0
void run_bool_toggle(bool *value, const uint16_t menu_item)
{
    // Run a menu page for toggling a single vaue bar.
    //
    //   .  .  *  .    <- menu item
    //   .  .  .  .
    //   #  #  #  #    <- bits to be toggled.
    //   .  .  .  .    <- toggle

    // Add the bar for the value.
    int16_t leds = (*value) ? 0b0000111100000000 : 0x0000;
    // Add in the dim background for the toggle bits
    leds |= 0b0000111100000000 & dim_mask;
    // Add the flashing exit light
    leds |= menu_item & flash_mask;
    // Update LEDs.
    led_set_state(leds);

    // Process key presses.
    if (g_key_down & menu_item) {
        // exit key is pressed.
       g_menu_state = TOP_LEVEL;
    } else if (g_key_down & 0b0000111100000000) {
        // if any of the keys inside the bar are pressed, toggle the bar.
        *value = !(*value);
    }
}
// Device has enumerated. Set up the Endpoints.
//
void EVENT_USB_Device_ConfigurationChanged(void)
{
    // Indicate that USB is now ready to use (followed by a short delay so
    // you can actually see it flash).
    led_set_state(0x0004);

    // Allow the LUFA MIDI Class drivers to configure the USB endpoints.
    if (!MIDI_Device_ConfigureEndpoints(g_midi_interface_info)) {
        // Setting up the endpoints failed, display the error state.
        led_set_state(0x0008);
    }

    // Success. Add a short delay so the final USB state LEDs can be seen
    // before the MIDI task takes over the LEDs.
    _delay_ms(40);
    led_set_state(0x0000);
	// Now we can enable the watchdog timer
	wdt_enable(WDTO_120MS);
}
Exemplo n.º 5
0
void run_empty(const uint8_t menu_item)
{
    // Add the flashing exit lights
    uint16_t leds = menu_item & flash_mask;
    // Update LEDs.
    led_set_state(leds);

    // Process key presses.
    if (g_key_down & menu_item) {
        // exit key is pressed
       g_menu_state = TOP_LEVEL;
    }
}
Exemplo n.º 6
0
// Turn each LED on for a short time, one by one.  Note the blocking
// delays. Not designed to be used in any situation that requires immediate
// response.
//
void led_count_all_leds(void)
{
    const int kDelay = 60;
    // Run through the LEDs turning them on one by one.
    uint16_t value = 0;
    for(uint8_t i=0; i<16; ++i) {
        value = 1<<i;
        led_set_state(value);
        // This is a blocking wait, so don't use this function if you need
        // timely USB service. It's purely decorative.
        _delay_ms(kDelay);
    }
}
Exemplo n.º 7
0
/* Test that we can toggle LEDs */
static int dm_test_led_toggle(struct unit_test_state *uts)
{
	const int offset = 1;
	struct udevice *dev, *gpio;

	/*
	 * Check that we can manipulate an LED. LED 1 is connected to GPIO
	 * bank gpio_a, offset 1.
	 */
	ut_assertok(uclass_get_device(UCLASS_LED, 1, &dev));
	ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio));
	ut_asserteq(0, sandbox_gpio_get_value(gpio, offset));
	ut_assertok(led_set_state(dev, LEDST_TOGGLE));
	ut_asserteq(1, sandbox_gpio_get_value(gpio, offset));
	ut_asserteq(LEDST_ON, led_get_state(dev));

	ut_assertok(led_set_state(dev, LEDST_TOGGLE));
	ut_asserteq(0, sandbox_gpio_get_value(gpio, offset));
	ut_asserteq(LEDST_OFF, led_get_state(dev));

	return 0;
}
Exemplo n.º 8
0
// Return the EEPROM values to their factory default values, erasing any
// customizations you may have made. Sorry dude!
//
void eeprom_factory_reset(void)
{
    // NOTE: hardware check on first boot only occurs if the eeprom was zeroed.
    // and not every time we reflash an eeprom. That keeps it a rare event.

    eeprom_write(EE_EEPROM_VERSION,      EEPROM_VERSION); // This layout version
    eeprom_write(EE_FIRST_BOOT_CHECK,    0xff); // No h/w check on first boot

    // Reset the global variables to their default versions, as they were
    // read with their old values before the factory reset happened and they
    // could get written back if the user leaves menu mode through the exit
    // button.
    g_self_test_passed = 0xff;

    g_midi_channel = 2;                     // MIDI channel (3)
    g_midi_velocity = 127;                  // MIDI velocity (127)
    g_led_keypress_enable = 1;              // Light LED of pressed key (on)
    g_key_fourbanks_mode = FOURBANKS_OFF;   // Fourbanks mode (off)
    //g_exp_digital_read = 0;                 // Read from digital (all off)
    //g_exp_analog_read = 0;                  // Read from analog (all off)
    g_auto_update = 1;                      // Auto update firmware (on)
    g_device_mode = TRAKTOR;                // Default mode is Traktor
    g_combos_enable = 1;                    // Combos (on)
    //g_multiplexer_enable = 0;               // Multiplexer (off)
	g_rotate_enable = 0;
    // Save changes
    eeprom_save_edits();

    // Flash to signal success.
    led_set_state(0xffff);
    _delay_ms(100);
    led_set_state(0x0000);
    _delay_ms(100);
    led_set_state(0xffff);
    _delay_ms(100);
}
Exemplo n.º 9
0
static int dm_test_led_blink(struct unit_test_state *uts)
{
	const int offset = 1;
	struct udevice *dev, *gpio;

	/*
	 * Check that we get an error when trying to blink an LED, since it is
	 * not supported by the GPIO LED driver.
	 */
	ut_assertok(uclass_get_device(UCLASS_LED, 1, &dev));
	ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio));
	ut_asserteq(0, sandbox_gpio_get_value(gpio, offset));
	ut_asserteq(-ENOSYS, led_set_state(dev, LEDST_BLINK));
	ut_asserteq(0, sandbox_gpio_get_value(gpio, offset));
	ut_asserteq(LEDST_OFF, led_get_state(dev));
	ut_asserteq(-ENOSYS, led_set_period(dev, 100));

	return 0;
}
Exemplo n.º 10
0
int main(void)
{

  // Set the system clock source to HS XOSC and max CPU speed,
  // ref. [clk]=>[clk_xosc.c]
  SLEEP &= ~SLEEP_OSC_PD;
  while( !(SLEEP & SLEEP_XOSC_S) );
  CLKCON = (CLKCON & ~(CLKCON_CLKSPD | CLKCON_OSC)) | CLKSPD_DIV_1;
  while (CLKCON & CLKCON_OSC);
  SLEEP |= SLEEP_OSC_PD;


  // init LEDS
  HARDWARE_LED_INIT;       // see hardware.h
  led_set_state(0, 0); //GREEN_LED = 0;
  led_set_state(1, 0); //BLUE_LED = 0;

  // Global interrupt enable
  init_timer();
  EA = 1;

  //LED test
  led_set_state(0, 1); //GREEN_LED = 1;
  delay(1000);
  led_set_state(0, 0); //GREEN_LED = 0;
  led_set_state(1, 1); //BLUE_LED = 1;
  delay(1000);
  led_set_state(1, 0); //BLUE_LED = 0;

  configure_radio();
  configure_serial();

  while(1) {
    //led_set_state(0,2);
    get_command();
  }
}
// The device is no longer connected to a host.
//
void EVENT_USB_Device_Disconnect(void)
{
    // Indicate that USB is disconnected.
    led_set_state(0x0001);
}
// We are in the process of enumerating but not yet ready to generate MIDI.
//
void EVENT_USB_Device_Connect(void)
{
    // Indicate that USB is enumerating.
    led_set_state(0x0002);
}