Esempio n. 1
0
// Función que ilumina la barra de leds según el valor del parámetro.
void barraLed(uint8_t val)
{
    if (val > 255/5) clearPin(&LED[3]); else setPin(&LED[3]);
    if (val > 255/5*2) clearPin(&LED[2]); else setPin(&LED[2]);
    if (val > 255/5*3) clearPin(&LED[1]); else setPin(&LED[1]);
    if (val > 255/5*4) clearPin(&LED[0]); else setPin(&LED[0]);
}
Esempio n. 2
0
void main(void)
{
	int state = 0;
	init ();
			
	while (1){
		if( PORTAbits.RA0 == 1 ){
			clearPin( A, A_A0 );
		}
		else{
			setPin( A, A_A0 );
		}
		if( PORTAbits.RA1 == 1 ){
			clearPin( A, A_LCDRESET );
		}
		else{
			setPin( A, A_LCDRESET ); 
		}

		if( state == 0 ){
			state = 1;
			setPin( B, B_CS1B );
		}
		else{
			state = 0;
			clearPin( B, B_CS1B );
		}
		delay();
	}
}
Esempio n. 3
0
int main()
{
	// Changing this clock speed also requires a change to the argument
	// to systickEnable().
	scuPostReset(CLKCR_M8_P8);

	// Configure GPIO
	enablePin(1, 0, GPIO_OUT_PP_ALT6);  // LED is ACMP1.OUT
	enablePin(1, 1, GPIO_OUT_PP);       // LED
	enablePin(2, 1, GPIO_OUT_PP_ALT6);  // P2.1 alt6 is USIC0_CH0_DOUT0
	enablePin(2, 2, GPIO_IN_FLOAT);     // P2.2 is the debug serial input
	// enablePin(2, 8, GPIO_IN_FLOAT);     // P2.8 ACMP0.INN (Vref/2)
	// enablePin(2, 9, GPIO_OUT_PP);       // P2.9 ACMP0.INP
	enablePin(2, 6, GPIO_IN_FLOAT);     // P2.6 ACMP1.INN
	enablePin(2, 7, GPIO_IN_FLOAT);     // P2.7 ACMP1.INP (Vref/2)
	enablePin(2, 11, GPIO_OUT_PP);      // P2.11 ACMP.Vref
	clearPin(1, 1);

	// 1Hz (8MHz / 8M)
	systickEnable(8000000 - 1);

	// Configure ACMP
	acmpEnable();
	// ACMP1 enabled with 15mv hysteresis and INP is Vref/2
	acmpConfigure(1, ACMP_CMP_EN |
	                 // ACMP_CMP1_DIV_EN |
	                 ACMP_CMP_HYST_ADJ_15);
	// ACMP0 enabled with 15mv hysteresis and INN is Vref/2
	//acmpConfigure(0, ACMP_CMP_EN |
	//                 ACMP_CMP0_SEL |
	//                 ACMP_CMP_HYST_ADJ_15);

	// Turn on Vref
	clearPin(2, 11);  // Vref
	// Turn off ACMP inputs
	// clearPin(2, 6);  // ACMP1.INN
	// clearPin(2, 7);  // ACMP1.INP

	enable_interrupts();

	while(1)
	{
		asm("wfi");
	}
	return 0;
}
Esempio n. 4
0
int main()
{
	scuPostReset(CLKCR_M32_P64);

	// On board LEDs.
	enablePin(1, 0, GPIO_OUT_PP);
	enablePin(1, 1, GPIO_OUT_PP);

	// Pins used for USIC channel 0 ASC mode.
	enablePin(2, 1, GPIO_OUT_PP_ALT6);  // USIC0_CH0_DOUT0
	enablePin(2, 2, GPIO_IN_FLOAT);     // debug serial input
	clearPin(1, 0);
	clearPin(1, 1);

	// Pins used for USIC channel 1 SSC mode.
	enablePin(0, 6, GPIO_IN_FLOAT);  // DX0C in
	enablePin(0, 7, GPIO_OUT_PP_ALT7);  // data out
	enablePin(0, 8, GPIO_OUT_PP_ALT7);  // sclk out
	enablePin(0, 9, GPIO_OUT_PP_ALT7);  // chip select out

	ch0_cbase = usicConfigure(0, USIC_PROTO_ASC);
	ch1_cbase = usicConfigure(1, USIC_PROTO_SSC);
	while (ch0_cbase == 0 || ch1_cbase == 0) {
		asm("wfi");
	}
	usicFifoEnable(0);

        systickEnable(8000000 - 1);

	enable_interrupts();

	usicBufferedSendCh0("Ready.\r\n");
	while(1)
	{
		asm("wfi");
	}
	return 0;
}
Esempio n. 5
0
// Input character handler.  Echo received characters to output.
void usicCh0Receive(unsigned int val) {
	char msg[2];
	msg[0] = (unsigned char)(val & 0xFF);
	msg[1] = '\0';
	switch(msg[0]) {
	case '0':
		target_on_percent = 0;
		break;
	case '1':
		target_on_percent = 5;
		break;
	case '2':
		target_on_percent = 10;
		break;
	case '3':
		target_on_percent = 15;
		break;
	case '4':
		target_on_percent = 20;
		break;
	case '5':
		target_on_percent = 25;
		break;
	case '6':
		target_on_percent = 30;
		break;
	case '7':
		target_on_percent = 35;
		break;
	case '8':
		target_on_percent = 40;
		break;
	case '9':
		target_on_percent = 45;
		break;
	case '^':
		invert_output = invert_output? 0:1;
		target_on_percent = 0;
		current_on_percent = 1;
		break;
	default:
		;
	}
	usicBufferedSendCh0(msg);
	if (invert_output) {
		setPin(1, 0);
	} else {
		clearPin(1, 0);
	}
}
Esempio n. 6
0
void kIrqHandler()
{
	unsigned int tmp;
	int a, x;
	for (a = 1; a <= 4; a++) {
		/*
		 * only one line from 1-4 should be high
		 * at one moment                                
		 */

		for (x = 1; x <= 4; x++) {
			if (x != a) {
				setGpioFunct(pinToGpio[x], GPINPUT);
			}
		}
		setGpioFunct(pinToGpio[a], GPOUTPUT);
		setPin(pinToGpio[a]);

		waitCycles(30);
		/*
		 * for every output line going high, check
		 * which input line goes high; store in kBuffer 
		 */
		for (x = 5; x <= 8; x++) {
			if (getPinLevel(pinToGpio[x]) == 1) {
				kBuffer = (4 * (a - 1)) + (x - 5);
				//      very sorry - it's
				//      probably the best way
				goto exit;
			}
		}
		clearPin(pinToGpio[a]);
	}

 exit:	for (x = 1; x <= 4; x++) {
		setGpioFunct(pinToGpio[x], GPOUTPUT);
		setPin(pinToGpio[x]);
	}

	if(extKIrqHandler!=0) extKIrqHandler();
	return;
}
Esempio n. 7
0
void ProgramManager::programReady(){
  // updateButtons(getProgramVector()->buttons);
  //   static uint16_t buttons = programVector->buttons;
  //  if(buttons & (1<<PUSHBUTTON) != getProgramVector()->buttons & (1<<PUSHBUTTON))
  //    togglePushButton();
  if(buttons != programVector->buttons){
    for(int i=1; i<NOF_BUTTONS; ++i) // skip bypass button
      if((buttons & (1<<i)) != (programVector->buttons & (1<<i)))
  	buttonChanged(i, programVector->buttons & (1<<i));
  }
#ifdef DEBUG_DWT
  programVector->cycles_per_block = *DWT_CYCCNT;
  // getProgramVector()->cycles_per_block = *DWT_CYCCNT;
    // (*DWT_CYCCNT + getProgramVector()->cycles_per_block)>>1;
#endif /* DEBUG_DWT */
#ifdef DEBUG_AUDIO
  clearPin(GPIOC, GPIO_Pin_5); // PC5 DEBUG
#endif

#ifdef AUDIO_TASK_SUSPEND
  vTaskSuspend(xProgramHandle);
#elif defined AUDIO_TASK_SEMAPHORE
  xSemaphoreTake(xSemaphore, 0);
#elif defined AUDIO_TASK_YIELD
  taskYIELD(); // this will only suspend the task if another is ready to run
#elif defined AUDIO_TASK_DIRECT
  while(audioStatus != AUDIO_READY_STATUS);
  audioStatus = AUDIO_PROCESSING_STATUS;
#else
  #error "Invalid AUDIO_TASK setting"
#endif
#ifdef DEBUG_DWT
  *DWT_CYCCNT = 0; // reset the performance counter
#endif /* DEBUG_DWT */
#ifdef DEBUG_AUDIO
  setPin(GPIOC, GPIO_Pin_5); // PC5 DEBUG
#endif
  buttons = programVector->buttons;
}
Esempio n. 8
0
void run(){
#ifdef DEBUG_DWT
  volatile unsigned int *DWT_CYCCNT = (volatile unsigned int *)0xE0001004; //address of the register
  volatile unsigned int *DWT_CONTROL = (volatile unsigned int *)0xE0001000; //address of the register
  volatile unsigned int *SCB_DEMCR = (volatile unsigned int *)0xE000EDFC; //address of the register
  *SCB_DEMCR = *SCB_DEMCR | 0x01000000;
  *DWT_CONTROL = *DWT_CONTROL | 1 ; // enable the counter
#endif
  for(;;){
    if(doProcessAudio){
#ifdef DEBUG_AUDIO
      setPin(GPIOC, GPIO_Pin_5); // PC5 DEBUG
#endif
#ifdef DEBUG_DWT
      *DWT_CYCCNT = 0; // reset the counter
#endif
      buffer.split(source);
      patches.process(buffer);
      buffer.comb(dest);
      if(collision){
	collision = false;
#ifdef DEBUG_AUDIO
	debugToggle();
#endif
      }else{
	doProcessAudio = false;
      }
#ifdef DEBUG_AUDIO
      clearPin(GPIOC, GPIO_Pin_5); // PC5 DEBUG
#endif
#ifdef DEBUG_DWT
      dwt_count = *DWT_CYCCNT;
#endif
    }
  }
}
Esempio n. 9
0
void __attribute__((interrupt("IRQ"))) systickHandler(void) {
	if (current_on_percent != target_on_percent) {
		setPin(1, 1);
		if (target_on_percent > 50) {
			target_on_percent = 50;
		}
		if (target_on_percent < current_on_percent) {
			current_on_percent -= 1;
			usicBufferedSendCh0("-\r\n");
		} else if (target_on_percent > current_on_percent) {
			current_on_percent += 1;
			usicBufferedSendCh0("+\r\n");
		}
		if (!invert_output) {
			ccuSetPeriodCompare(0, 99, 100 - current_on_percent);
			ccuSetPeriodCompare(1, 99, current_on_percent);
		} else {
			ccuSetPeriodCompare(0, 99, current_on_percent);
			ccuSetPeriodCompare(1, 99, 100 - current_on_percent);
		}
	} else {
		clearPin(1, 1);
	}
}
Esempio n. 10
0
void setup(){
//   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); // 0 bits for preemption, 4 bits for subpriority
  /* Set up interrupt controller: 2 bits for priority (0-3),
   * 2 bits for sub-priority (0-3). Priorities control which
   * interrupts are allowed to preempt one another.
   */
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  /* Increase SysTick priority to be higher than USB interrupt
   * priority. USB code stalls inside interrupt and we can't let
   * this throw off the SysTick timer.
   */
  NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(NVIC_PriorityGroup_2, SYSTICK_PRIORITY, SYSTICK_SUBPRIORITY));
  NVIC_SetPriority(DMA1_Stream3_IRQn, NVIC_EncodePriority(NVIC_PriorityGroup_2, 0, 0));
  NVIC_SetPriority(DMA1_Stream4_IRQn, NVIC_EncodePriority(NVIC_PriorityGroup_2, 0, 0));
  NVIC_SetPriority(SPI2_IRQn, NVIC_EncodePriority(NVIC_PriorityGroup_2, 1, 0));
  NVIC_SetPriority(ADC_IRQn, NVIC_EncodePriority(NVIC_PriorityGroup_2, 2, 0));

  ledSetup();
  setLed(RED);

  /* check if we need to DFU boot */
  configureDigitalInput(SWITCH_B_PORT, SWITCH_B_PIN, GPIO_PuPd_UP);
  if(isPushButtonPressed())
    jump_to_bootloader();

  adcSetup();
  clockSetup();
  setupSwitchA(footSwitchCallback);
  setupSwitchB(pushButtonCallback);

  settings.init();
  midi.init(MIDI_CHANNEL);
  patches.init();

#ifdef EXPRESSION_PEDAL
#ifndef OWLMODULAR
  setupExpressionPedal();
#endif
#endif

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); // DEBUG
  configureDigitalOutput(GPIOB, GPIO_Pin_1); // PB1, DEBUG LED
  debugClear();

#ifdef DEBUG_AUDIO
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); // DEBUG
  configureDigitalOutput(GPIOA, GPIO_Pin_7); // PA7 DEBUG
  configureDigitalOutput(GPIOC, GPIO_Pin_5); // PC5 DEBUG
  clearPin(GPIOC, GPIO_Pin_5); // DEBUG
  clearPin(GPIOA, GPIO_Pin_7); // DEBUG
#endif /* DEBUG_AUDIO */
	
  usb_init();

#if SERIAL_PORT == 1
  setupSerialPort1(115200);
#elif SERIAL_PORT == 2
  setupSerialPort2(115200); // expression pedal
#warning expression pedal jack configured as serial port
#ifdef EXPRESSION_PEDAL
#error invalid configuration
#endif
#endif

#ifdef OWLMODULAR
  configureDigitalInput(GPIOB, GPIO_Pin_6, GPIO_PuPd_NOPULL);  // PB6 OWL Modular digital input
  configureDigitalOutput(GPIOB, GPIO_Pin_7);  // PB7 OWL Modular digital output
  setPin(GPIOB, GPIO_Pin_7); // PB7 OWL Modular digital output
#endif

  codec.setup();
  codec.init(settings);

  printString("startup\n");
  updateBypassMode();

  codec.start();
}
Esempio n. 11
0
void ledSetup(){
  RCC_AHB1PeriphClockCmd(LED_CLOCK, ENABLE);
  configureDigitalOutput(LED_PORT, LED_RED|LED_GREEN);
  clearPin(LED_PORT, LED_RED|LED_GREEN);
}
Esempio n. 12
0
void Gpio::SetPinState (unsigned char pin , unsigned char state)
{
	if (state) setPin(pin);
	else clearPin(pin);
}
Esempio n. 13
0
static void buzzer_stop() {
   gptStopTimer(&BUZZER_GPT);
   clearPin(BUZZER);
//   gptStop(&AFSK_TONEGEN_GPT);
}
Esempio n. 14
0
void Gpio::SetPinState (uint8_t pin , uint8_t state)
{
  if (state)setPin (pin);
  else clearPin (pin);  
}
Esempio n. 15
0
File: main.c Progetto: mpue/AVRUart
int main(void) {

	setPin(DDRC,4);

	char buffer[4];


    /*
     *  Initialize UART library, pass baudrate and AVR cpu clock
     *  with the macro
     *  UART_BAUD_SELECT() (normal speed mode )
     *  or
     *  UART_BAUD_SELECT_DOUBLE_SPEED() ( double speed mode)
     */
    uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) );

    /*
     * now enable interrupt, since UART library is interrupt controlled
     */
    sei();

    unsigned int c;


    uart_puts("Ready.\r\n");

	while(1) {

        /*
         * Get received character from ringbuffer
         * uart_getc() returns in the lower byte the received character and
         * in the higher byte (bitmask) the last receive error
         * UART_NO_DATA is returned when no data is available.
         *
         */
        c = uart_getc();

        if ( c & UART_NO_DATA )
        {
            /*
             * no data available from UART
             */
        }
        else
        {
            /*
             * new data available from UART
             * check for Frame or Overrun error
             */
            if ( c & UART_FRAME_ERROR )
            {
                /* Framing Error detected, i.e no stop bit detected */
                uart_puts_P("UART Frame Error: ");
            }
            if ( c & UART_OVERRUN_ERROR )
            {
                /*
                 * Overrun, a character already present in the UART UDR register was
                 * not read by the interrupt handler before the next character arrived,
                 * one or more received characters have been dropped
                 */
                uart_puts_P("UART Overrun Error: ");
            }
            if ( c & UART_BUFFER_OVERFLOW )
            {
                /*
                 * We are not reading the receive buffer fast enough,
                 * one or more received character have been dropped
                 */
                uart_puts_P("Buffer overflow error: ");
            }
            /*
             * send received character back
             */

            // PORTC ^= 1 << PINC4;

            if ((unsigned char)c == 'n') {
            	setPin(PORTC,4);
            	uart_puts("On.\r\n");
            }
            else if ((unsigned char)c ==  'm') {
            	clearPin(PORTC,4);
            	uart_puts("Off.\r\n");
            }

            // uart_putc( (unsigned char)c );

        }
	}


}