Ejemplo n.º 1
0
/**************************************************************************//**
 * @brief  Main function
 * Main is called from __iar_program_start, see assembly startup file
 *****************************************************************************/
int main(void)
{  
  /* Initialize chip */
  CHIP_Init();
  
  /* Enable clock for GPIO module */
  CMU_ClockEnable(cmuClock_GPIO, true);

  /* Configure PD with alternate drive strength of 20mA */
  GPIO_DriveModeSet(gpioPortD, gpioDriveModeHigh);
  
  /* Configure PC12 as input with filter*/
  GPIO_PinModeSet(gpioPortC, 12, gpioModeInput, 0);
  
  /* Configure PD8 as push pull output */
  GPIO_PinModeSet(gpioPortD, 8, gpioModePushPullDrive, 0);
  
  while(1)
  {
    /* If PC12 is high, drive high PD8, else drive low */
    if(GPIO_PinInGet(gpioPortC, 12)) 
      GPIO_PinOutSet(gpioPortD, 8);   /* Drive high PD8 */ 
    else 
      GPIO_PinOutClear(gpioPortD, 8); /* Drive low PD8 */
  }
  
 
}
Ejemplo n.º 2
0
void initGPIO()
{
	  CMU_ClockEnable(cmuClock_GPIO, true);                           // enable GPIO peripheral clock

	  GPIO_PinModeSet(GPS_PORT, FIX, gpioModeInput, 0);    // set FIX pin as input (no filter)
	  GPIO_PinModeSet(GPS_PORT, ENABLE, gpioModePushPull, 0);    // set ENABLE pin as output, initialize low

	  GPIO_PinModeSet(LED_PORT, LED0_PIN, gpioModePushPull, 0);       // configure LED0 pin as push-pull output with standard drive strength
	  GPIO_PinModeSet(LED_PORT, LED1_PIN, gpioModePushPull, 0);  // configure LED1 pin as push-pull output with alternate drive strength
	  GPIO_PinModeSet(EXT_LED, RED_LED, gpioModePushPull, 0);  // configure LED1 pin as push-pull output with alternate drive strength
	  GPIO_PinModeSet(EXT_LED, YEL_LED, gpioModePushPull, 0);  // configure LED1 pin as push-pull output with alternate drive strength
	  GPIO_PinModeSet(EXT_LED, GRE_LED, gpioModePushPull, 0);  // configure LED1 pin as push-pull output with alternate drive strength
	  GPIO_DriveModeSet(LED_PORT, gpioDriveModeLowest);               // set alternate drive strength to lowest setting (0.5mA)
	  GPIO_PinOutClear(LED_PORT, LED0_PIN);                             // turn on LED0
	  GPIO_PinOutSet(LED_PORT, LED1_PIN);                             // turn on LED1
	  GPIO_PinOutClear(EXT_LED, RED_LED);
	  GPIO_PinOutClear(EXT_LED, YEL_LED);                           // turn on LED1
	  GPIO_PinOutClear(EXT_LED, GRE_LED);

	  GPIO_PinModeSet(BUT_PORT, LEFT_BUT, gpioModeInputPull, 1);		//configure left button as input with pull-up enabled
	  GPIO_PinModeSet(BUT_PORT, RIGHT_BUT, gpioModeInputPull, 1);		//'' but with right button

	  NVIC_EnableIRQ(GPIO_ODD_IRQn);	//enable gpio_even interrupt vector in nvic
	  GPIO_IntConfig(GPS_PORT, FIX, true, false, true);		//configure FIX pin interrupt on rising
}
Ejemplo n.º 3
0
/**************************************************************************//**
 * @brief  Setup the GPIO
 *****************************************************************************/
void setupGPIO(void)
{
  /* Configure the drive strength of the ports for the light sensor. */
  GPIO_DriveModeSet(LIGHTSENSE_EXCITE_PORT, gpioDriveModeStandard);
  GPIO_DriveModeSet(LIGHTSENSE_SENSOR_PORT, gpioDriveModeStandard);

  /* Initialize the 2 GPIO pins of the light sensor setup. */
  GPIO_PinModeSet(LIGHTSENSE_EXCITE_PORT, LIGHTSENSE_EXCITE_PIN, gpioModePushPull, 0);
  GPIO_PinModeSet(LIGHTSENSE_SENSOR_PORT, LIGHTSENSE_SENSOR_PIN, gpioModeDisabled, 0);

  /* Enable push button 0 pin as input. */
  GPIO_PinModeSet(LIGHTSENSE_BUTTON0_PORT, LIGHTSENSE_BUTTON0_PIN,  gpioModeInput, 0);
  /* Enable interrupts for that pin. */
  GPIO_IntConfig(LIGHTSENSE_BUTTON0_PORT, LIGHTSENSE_BUTTON0_PIN, false, true, true);
  /* Enable GPIO_EVEN interrupt vector in NVIC. */
  NVIC_EnableIRQ(GPIO_ODD_IRQn);
}
Ejemplo n.º 4
0
/**************************************************************************//**
 * @brief  Setup the GPIO
 *****************************************************************************/
void CAPLESENSE_setupGPIO(void)
{
  /* Configure the drive strength of the ports for the light sensor. */
  GPIO_DriveModeSet(CAPLESENSE_SLIDER_PORT0, gpioDriveModeStandard);

  /* Initialize the 4 GPIO pins of the touch slider for using them as LESENSE
   * scan channels for capacitive sensing. */
  GPIO_PinModeSet(CAPLESENSE_SLIDER_PORT0, CAPLESENSE_SLIDER0_PIN, gpioModeDisabled, 0);
  GPIO_PinModeSet(CAPLESENSE_SLIDER_PORT0, CAPLESENSE_SLIDER1_PIN, gpioModeDisabled, 0);
  GPIO_PinModeSet(CAPLESENSE_SLIDER_PORT0, CAPLESENSE_SLIDER2_PIN, gpioModeDisabled, 0);
  GPIO_PinModeSet(CAPLESENSE_SLIDER_PORT0, CAPLESENSE_SLIDER3_PIN, gpioModeDisabled, 0);
}
Ejemplo n.º 5
0
void testInitIO()
{
  CMU_ClockEnable(cmuClock_GPIO, true);

/*
 * Button.
 */
  GPIO_PinModeSet(gpioPortA, 1, gpioModeInputPullFilter, 0); 

/*
 * Led.
 */
  GPIO_PinModeSet(gpioPortA, 0, gpioModePushPullDrive, 0);
  GPIO_DriveModeSet(gpioPortA, gpioDriveModeHigh);
}
Ejemplo n.º 6
0
int gpio_init(gpio_t pin, gpio_mode_t mode)
{
    /* check for valid pin */
    if (pin == GPIO_UNDEF) {
        return -1;
    }

    /* enable clocks */
    CMU_ClockEnable(cmuClock_HFPER, true);
    CMU_ClockEnable(cmuClock_GPIO, true);

    /* configure pin */
    GPIO_PinModeSet(_port_num(pin), _pin_num(pin), mode >> 1, mode & 0x1);
#ifdef _SILICON_LABS_32B_PLATFORM_1
    GPIO_DriveModeSet(_port_num(pin), gpioDriveModeStandard);
#endif

    return 0;
}
Ejemplo n.º 7
0
Archivo: main.c Proyecto: x893/OpenBLT
/************************************************************************************//**
** \brief     Initializes the microcontroller.
** \return    none.
**
****************************************************************************************/
static void Init(void)
{
  /* initialize the system and its clocks */
  SystemInit();
  /* handle chip errate workarounds */
  CHIP_Init();
  /* enable the low frequency crystal oscillator */
  CMU_OscillatorEnable(cmuOsc_LFXO, true, true);
  /* turn on clocking of all the modules */
  CMU->HFCORECLKEN0 |= 0x0F;
  CMU->HFPERCLKEN0 |= 0xFFFF;
  /* disable clocking of the modules that are not in use */
  CMU_ClockEnable(cmuClock_AES, false);
  CMU_ClockEnable(cmuClock_DMA, false);
  CMU_ClockEnable(cmuClock_EBI, false);
  CMU_ClockEnable(cmuClock_PRS, false);
  CMU_ClockEnable(cmuClock_USART0, false);
  CMU_ClockEnable(cmuClock_USART1, false);
  CMU_ClockEnable(cmuClock_USART2, false);
  CMU_ClockEnable(cmuClock_UART0, false);
  CMU_ClockEnable(cmuClock_ACMP0, false);
  CMU_ClockEnable(cmuClock_ACMP1, false);
  CMU_ClockEnable(cmuClock_DAC0, false);
  CMU_ClockEnable(cmuClock_ADC0, false);
  CMU_ClockEnable(cmuClock_I2C0, false);
  CMU_ClockEnable(cmuClock_VCMP, false);
#if (BOOT_COM_UART_ENABLE > 0)
  /* enable power to U2 (RS232_PWR_E) */
  GPIO_PinModeSet(gpioPortB, 9, gpioModePushPullDrive, 1);
  /* set port B outputs to drive up to 20 mA */
  GPIO_DriveModeSet(gpioPortB, gpioDriveModeHigh);
#endif
  /* init the led driver */
  LedInit();
  /* init the timer driver */
  TimerInit();
  /* enable IRQ's, because they were initially disabled by the bootloader */
  IrqInterruptEnable();
} /*** end of Init ***/
Ejemplo n.º 8
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
	/* Chip errata */
	CHIP_Init();

	// Turn on the peripheral clocks
	CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);
	CMU_ClockEnable(cmuClock_GPIO, true);
	CMU_ClockEnable(cmuClock_USART1, true);

	Ecode_t result;

	// Initialize DMA.
	result = DMADRV_Init();
	if (result != ECODE_EMDRV_DMADRV_OK)
	{
		DEBUG_BREAK
	}

	// Request a DMA channel.
	result = DMADRV_AllocateChannel( &dma_channel, NULL );
	if (result != ECODE_EMDRV_DMADRV_OK)
	{
		DEBUG_BREAK
	}

	// Configure the USART peripheral
	USART_InitSync_TypeDef init = USART_INITSYNC_DEFAULT;
	init.baudrate = 50000;
	init.msbf = true;		// MSB first, per the TLC5940 spec
	USART_InitSync(USART1, &init);

	// Route the peripheral to the GPIO block
	USART1->ROUTE = USART_ROUTE_TXPEN | 		// US1_TX
			        USART_ROUTE_CLKPEN | 		// US1_CLK
			        USART_ROUTE_LOCATION_LOC1;	// Location #1

	// Configure both the USART and control pins in GPIO
	GPIO_DriveModeSet(gpioPortD, gpioDriveModeLowest);
	GPIO_PinModeSet(CONTROL_PORT, SIN_PIN, gpioModePushPullDrive, 0);
	GPIO_PinModeSet(CONTROL_PORT, SCLK_PIN, gpioModePushPullDrive, 0);
	GPIO_PinModeSet(CONTROL_PORT, XLAT_PIN, gpioModePushPullDrive, 0);
	GPIO_PinModeSet(CONTROL_PORT, VPRG_PIN, gpioModePushPullDrive, 0);
	GPIO_PinModeSet(CONTROL_PORT, BLANK_PIN, gpioModePushPullDrive, 0);
	GPIO_PinModeSet(CONTROL_PORT, GSCLK_PIN, gpioModePushPullDrive, 0);

	// Start with DC Data
	stream.mode = DOT_CORRECTION_MODE;
	for (int i=0; i<MAX_CHANNELS; i++)
	{
//	      stream.channel[i].dot_correction = 0b100001;		// Test pattern
//	      stream.channel[i].grayscale = 0b100000000001;		// Test pattern
		stream.channel[i].dot_correction = 0xF; //MAX_DOT_CORRECTION;
		stream.channel[i].grayscale = 0; //MAX_GRAYSCALE;
	}

	// Write the DC Data
	write_serial_stream();

	//all_white();
	//rgb_display();
	yellow_purple();

	int count = 0;
	while (1)
	{
		if (count %2)
		{
			GPIO_PinOutSet(CONTROL_PORT, GSCLK_PIN);
		}
		else
		{
			GPIO_PinOutClear(CONTROL_PORT, GSCLK_PIN);
		}
		count++;

		if (count > 4096)
		{
			GPIO_PinOutSet(CONTROL_PORT, BLANK_PIN);
			for (volatile int i=0; i < 10; i++)
					;
			GPIO_PinOutClear(CONTROL_PORT, BLANK_PIN);
			count = 0;
		}

		for (volatile int i=0; i < 10; i++)
			;
	}
}