Example #1
0
int tca_tco_pwm_ctrl(unsigned tco_ch, unsigned uGPIO, unsigned int max_cnt, unsigned int level_cnt)
{
	unsigned uFGPIO;
	volatile PTIMERN pTIMER = IO_TCO_GetBaseAddr(tco_ch);

	printf("tco:%d, GPIO(G:%d, Num:%d) max:%d level:%d TCOaddr:0x%p \n", tco_ch, (uGPIO>>5), (uGPIO &0x1F), max_cnt, level_cnt, pTIMER);
	if(pTIMER == NULL)
		return -1;
	
	gpio_config(uGPIO, GPIO_OUTPUT);

	if(max_cnt <= level_cnt)	{
		gpio_config(uGPIO, GPIO_OUTPUT | GPIO_FN0);
		gpio_set(uGPIO, 1);
	}
	else if(level_cnt == 0) {
		gpio_config(uGPIO, GPIO_OUTPUT | GPIO_FN0);
		gpio_set(uGPIO, 0);
	}
	else 	{
		pTIMER->TREF = max_cnt;
		pTIMER->TCFG	= 0x105;	
		pTIMER->TMREF = level_cnt;
		pTIMER->TCFG	= 0x105;
		uFGPIO = IO_TCO_GetGpioFunc(tco_ch, uGPIO);
		gpio_config(uGPIO, GPIO_OUTPUT | uFGPIO);
	}
}
Example #2
0
void gpio_keypad_init(struct gpio_keypad_info *kpinfo)
{
	int key_count;
	int output_val;
	int output_cfg;
	int i;
	int len;

	ASSERT(kpinfo->keymap && kpinfo->input_gpios && kpinfo->output_gpios);
	key_count = kpinfo->ninputs * kpinfo->noutputs;

	len = sizeof(struct gpio_kp) + (sizeof(unsigned long) *	BITMAP_NUM_WORDS(key_count));
	keypad = malloc(len);
	ASSERT(keypad);

	memset(keypad, 0, len);
	keypad->keypad_info = kpinfo;

	output_val = (!!(kpinfo->flags & GPIOKPF_ACTIVE_HIGH))^(!!(kpinfo->flags & GPIOKPF_DRIVE_INACTIVE));
	output_cfg = kpinfo->flags & GPIOKPF_DRIVE_INACTIVE ? GPIO_OUTPUT : 0;
	for (i = 0; i < kpinfo->noutputs; i++) {
		gpio_set(kpinfo->output_gpios[i], output_val);
		gpio_config(kpinfo->output_gpios[i], output_cfg);
	}
	for (i = 0; i < kpinfo->ninputs; i++) {
		gpio_config(kpinfo->input_gpios[i], GPIO_INPUT);
	}
	keypad->current_output = kpinfo->noutputs;
	
	timer_initialize(&keypad->timer);
	timer_set_oneshot(&keypad->timer, 0, gpio_keypad_timer_func, NULL);
}
Example #3
0
static void setup_gpios()
{
    // Input:
    //     4: Joy #2 Pot x
    //
    // Output:
    //     5: Joy #1 Pot X
    //    21: Joy #1 Pot X

    // Output: 5 (LED) and 21
    gpio_config_t io_conf;
    io_conf.intr_type = GPIO_INTR_DISABLE;
    io_conf.mode = GPIO_MODE_OUTPUT;
    io_conf.pin_bit_mask = ((1ULL << GPIO_NUM_21) | (1ULL << GPIO_NUM_5));
    io_conf.pull_down_en = false;
    io_conf.pull_up_en = false;
    ESP_ERROR_CHECK( gpio_config(&io_conf) );

    // Input: read POT X
    io_conf.intr_type = GPIO_INTR_POSEDGE;
    io_conf.mode = GPIO_MODE_INPUT;
    io_conf.pin_bit_mask = 1ULL << GPIO_NUM_18;
    io_conf.pull_down_en = false;
    io_conf.pull_up_en = true;
    ESP_ERROR_CHECK( gpio_config(&io_conf) );

    // install gpio isr service
    ESP_ERROR_CHECK( gpio_install_isr_service(0) );

    //hook isr handler for specific gpio pin
    ESP_ERROR_CHECK( gpio_isr_handler_add(GPIO_NUM_18, gpio_isr_handler_up, (void*) GPIO_NUM_18) );

 //   ESP_ERROR_CHECK( gpio_isr_register(gpio_isr_handler_up, (void*) GPIO_NUM_4, 0, NULL) );
}
Example #4
0
int lcd_init(lcd_t *lcd, ssp_port_t ssp_port, pin_t cs, pin_t rs, pin_t rw, pin_t e)
{
    lcd->ssp = ssp_port.ssp;
    lcd->cs = cs;
    lcd->rs = rs;
    lcd->rw = rw;
    lcd->e = e;
    //lcd->type = COM8BITS;

    gpio_config(cs, pin_dir_write, pull_up);
    gpio_set(cs, 1);
    gpio_config(rs, pin_dir_write, pull_down);
    gpio_set(rs, 0);
    gpio_config(rw, pin_dir_write, pull_down);
    gpio_set(rw, 0);
    gpio_config(e, pin_dir_write, pull_down);    
    gpio_set(e, 0);

    ssp_config(ssp_port, 8 * 1000 * 1000);

    delay(lcd, 1000);

    lcd_clear_display(lcd);
    lcd_return_home(lcd);
    lcd_set_display(lcd,1, 1, 1);

    return 1;
}
Example #5
0
File: init.c Project: XRobinHe/lk
void target_early_init(void)
{
    GPIO_InitTypeDef gpio_init;

    __HAL_RCC_GPIOE_CLK_ENABLE();
    __HAL_RCC_GPIOD_CLK_ENABLE();
    __HAL_RCC_GPIOJ_CLK_ENABLE();

#if DEBUG_UART == 3
    // configure usart 3 pins.
    gpio_config(GPIO_USART3_TX, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF7_USART3) | GPIO_PULLUP);
    gpio_config(GPIO_USART3_RX, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF7_USART3) | GPIO_PULLUP);
#else
#error need to configure gpio pins for debug uart
#endif

    gpio_init.Mode    = GPIO_MODE_OUTPUT_PP;
    gpio_init.Pull    = GPIO_NOPULL;
    gpio_init.Speed   = GPIO_SPEED_LOW;

    gpio_init.Pin  = GPIO_TO_PIN_MASK(GPIO_LED108) | GPIO_TO_PIN_MASK(GPIO_LED109) |
                     GPIO_TO_PIN_MASK(GPIO_LED110) | GPIO_TO_PIN_MASK(GPIO_LED111);
    HAL_GPIO_Init(GPIOE, &gpio_init);

    gpio_init.Pin  = GPIO_TO_PIN_MASK(GPIO_LED112) | GPIO_TO_PIN_MASK(GPIO_LED113);
    HAL_GPIO_Init(GPIOD, &gpio_init);

    gpio_init.Pin  = GPIO_TO_PIN_MASK(GPIO_LED114) | GPIO_TO_PIN_MASK(GPIO_LED115);
    HAL_GPIO_Init(GPIOJ, &gpio_init);

    // Initialize the switches GPIOs for interrupt on raising edge. In order
    // to use stm32_EXTI15_10_IRQ() handler needs to be provided and EXTI15_10_IRQn
    // needs to be enabled.
    gpio_init.Mode   = GPIO_MODE_INPUT;
    gpio_init.Pull   = GPIO_NOPULL;
    gpio_init.Speed  = GPIO_SPEED_FAST;
    gpio_init.Mode   = GPIO_MODE_IT_RISING;

    gpio_init.Pin  =  GPIO_TO_PIN_MASK(GPIO_SW100) | GPIO_TO_PIN_MASK(GPIO_SW101) |
                      GPIO_TO_PIN_MASK(GPIO_SW102) | GPIO_TO_PIN_MASK(GPIO_SW103);
    HAL_GPIO_Init(GPIOJ, &gpio_init);

#if ENABLE_SENSORBUS
    // Initialize Sensor bus (accelerometer / gyroscope / nrf51 spi bus
    sensor_bus_init_early();
#endif

    // now that the uart gpios are configured, enable the debug uart.
    stm32_debug_early_init();

    // default all the debug leds to off
    target_set_debug_led(0, false);
    target_set_debug_led(1, false);
    target_set_debug_led(2, false);
    target_set_debug_led(3, false);
}
Example #6
0
static enum handler_return
gpio_keypad_timer_func(struct timer *timer, time_t now, void *arg)
{
    struct gpio_kp *kp = keypad;
    struct gpio_keypad_info *kpinfo = kp->keypad_info;
    int polarity = !!(kpinfo->flags & GPIOKPF_ACTIVE_HIGH);
    int out;
    int gpio;

    out = kp->current_output;
    if (out == kpinfo->noutputs) {
        out = 0;
        kp->some_keys_pressed = 0;
    } else {
        check_output(kp, out, polarity);
        out++;
    }

    kp->current_output = out;
    if (out < kpinfo->noutputs) {
        gpio = kpinfo->output_gpios[out];
        if (kpinfo->flags & GPIOKPF_DRIVE_INACTIVE)
            gpio_set(gpio, polarity);
        else
            gpio_config(gpio, polarity ? GPIO_OUTPUT : 0);
        timer_set_oneshot(timer, kpinfo->settle_time,
        gpio_keypad_timer_func, NULL);
        goto done;
    }

    if (/*!kp->use_irq*/ 1 || kp->some_keys_pressed) {
        event_signal(&kp->full_scan, false);
        timer_set_oneshot(timer, kpinfo->poll_time,
        gpio_keypad_timer_func, NULL);
        goto done;
    }

#if 0
    /* No keys are pressed, reenable interrupt */
    for (out = 0; out < kpinfo->noutputs; out++) {
        if (gpio_keypad_flags & GPIOKPF_DRIVE_INACTIVE)
            gpio_set(kpinfo->output_gpios[out], polarity);
        else
            gpio_config(kpinfo->output_gpios[out], polarity ? GPIO_OUTPUT : 0);
    }
    for (in = 0; in < kpinfo->ninputs; in++)
        enable_irq(gpio_to_irq(kpinfo->input_gpios[in]));
    return INT_RESCHEDULE;
#endif

done:
    return INT_RESCHEDULE;
}
Example #7
0
File: init.c Project: DuChunDar/lk
void target_early_init(void)
{
#if DEBUG_UART == 1
    /* configure usart 1 pins */
    gpio_config(GPIO_USART1_TX, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF7_USART1) | GPIO_PULLUP);
    gpio_config(GPIO_USART1_RX, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF7_USART1) | GPIO_PULLUP);
#else
#error need to configure gpio pins for debug uart
#endif

    /* now that the uart gpios are configured, enable the debug uart */
    stm32_debug_early_init();
}
Example #8
0
/*********************************************************************
 * Configure LCD GPIO Pins and Initialize LCD
 *
 * Note:
 *	The LCD units vary in their ideal setting for Vop. Here the
 *	default value used is 0xBF, if the arg vop is <= 0. Good
 *	values vary from about 0xB0 all the way up to 0xE0.
 *
 * Hints:
 *	1. If you see a matrix of dark pixels, your Vop is too high.
 *	2. If you see faint or no pixels, increase Vop.
 *	3. For inverse video, readjust Vop to suit.
 *	4. Type '+' or '-' to try different Vop values. Press
 *	   + or - repeatedly until the contrast improves.
 *
 *********************************************************************/
void
lcd_init(int vop) {
	if ( vop > 0 )
		lcd_vop = vop;		/* Use this new value */

	/* No outputs yet.. */
	gpio_config(lcd_ce,Input);
	gpio_config(lcd_res,Input);
	gpio_config(lcd_d_c,Input);
	gpio_config(lcd_sdin,Input);
	gpio_config(lcd_sclk,Input);

	/* Configure all pins as high */
	gpio_write(lcd_ce,1);
	gpio_write(lcd_res,1);
	gpio_write(lcd_d_c,1);
	gpio_write(lcd_sdin,1);
	gpio_write(lcd_sclk,1);

	/* Now assert outputs */
	gpio_config(lcd_ce,Output);
	gpio_config(lcd_res,Output);
	gpio_config(lcd_d_c,Output);
	gpio_config(lcd_sdin,Output);
	gpio_config(lcd_sclk,Output);

	lcd(LCD_Command);	/* Command mode */

	gpio_write(lcd_res,0);	/* Apply /RESET */
	gpio_read(lcd_res);	/* Delay a little */
	gpio_read(lcd_res);	/* Delay a little */
	gpio_read(lcd_res);	/* Delay a little */

	gpio_write(lcd_res,1);	/* Deactivate /RESET */
	gpio_read(lcd_res);	/* Delay a little more */
	gpio_read(lcd_res);	/* Delay a little */
	gpio_read(lcd_res);	/* Delay a little */

	lcd_wr_byte(0x21);	/* Chip Active, Extended instructions enabled */
	lcd_wr_byte(lcd_vop);	/* Set Vop level */
	lcd_wr_byte(0x04);	/* Set TC */
	lcd_wr_byte(0x14);	/* Set Bias */
	lcd_wr_byte(0x20);	/* Chip Active, Extended instructions disabled */
	lcd_wr_byte(0x0C);	/* Set normal mode (adjust Vop if using inverse video) */
	lcd(LCD_Unselect);

	lcd_clear();		/* Clear screen */
}
Example #9
0
/*!
    \brief      main function
    \param[in]  none
    \param[out] none
    \retval     none
*/
int main(void)
{
    can_parameter_struct            can_init_parameter;
    can_filter_parameter_struct     can_filter_parameter;

    receive_flag = RESET;
    /* configure Tamper key */
    gd_eval_keyinit(KEY_TAMPER, KEY_MODE_GPIO);
    /* configure GPIO */
    gpio_config();
    /* configure USART */
    gd_eval_COMinit(EVAL_COM2);
    /* configure NVIC */
    nvic_config();
    /* configure leds */
    led_config();
    /* set all leds off */
    gd_eval_ledoff(LED1);
    gd_eval_ledoff(LED2);
    gd_eval_ledoff(LED3);
    gd_eval_ledoff(LED4);
    /* initialize CAN */
    can_networking_init(can_init_parameter, can_filter_parameter);
    /* enable phy */
#ifdef CAN0_USED 
    can_phy_enable(CANX);
#endif
    /* enable CAN receive FIFO0 not empty interrupt */
    can_interrupt_enable(CANX, CAN_INTEN_RFNEIE0);
    
    /* initialize transmit message */
    transmit_message.can_tx_sfid = 0x321;
    transmit_message.can_tx_efid = 0x01;
    transmit_message.can_tx_ft = CAN_FT_DATA;
    transmit_message.can_tx_ff = CAN_FF_STANDARD;
    transmit_message.can_tx_dlen = 1;
    printf("please press the Tamper key to transmit data!\r\n");
    while(1){
        /* waiting for the Tamper key pressed */
        while(0 == gd_eval_keygetstate(KEY_TAMPER)){
            /* if transmit_number is 0x10, set it to 0x00 */
            if(transmit_number == 0x10){
                transmit_number = 0x00;
            }else{
                transmit_message.can_tx_data[0] = transmit_number++;
                printf("transmit data: %x\r\n", transmit_message.can_tx_data[0]);
                /* transmit message */
                can_transmit_message(CANX, &transmit_message);
                delay();
                /* waiting for Tamper key up */
                while(0 == gd_eval_keygetstate(KEY_TAMPER));
            }
        }
        if(SET == receive_flag){
            gd_eval_ledtoggle(LED1);
            receive_flag = RESET;
            printf("recive data: %x\r\n", receive_message.can_rx_data[0]);
        }
    } 
}
Example #10
0
File: init.c Project: skabet/lk
void target_early_init(void)
{
#if DEBUG_UART == 1
    /* configure usart 1 pins */
    gpio_config(GPIO_USART1_TX, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF7_USART1) | GPIO_PULLUP);
    gpio_config(GPIO_USART1_RX, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF7_USART1) | GPIO_PULLUP);
#else
#error need to configure gpio pins for debug uart
#endif

    /* now that the uart gpios are configured, enable the debug uart */
    stm32_debug_early_init();

    /* The lcd framebuffer starts at the base of SDRAM */
    BSP_LCD_Init(SDRAM_BASE);
}
Example #11
0
static void hdp_disable(struct hdmi_connector *hdmi_connector)
{
	struct hdmi *hdmi = hdmi_connector->hdmi;
	const struct hdmi_platform_config *config = hdmi->config;
	struct device *dev = &hdmi->pdev->dev;
	int i, ret = 0;

	/* Disable HPD interrupt */
	hdmi_write(hdmi, REG_HDMI_HPD_INT_CTRL, 0);

	msm_hdmi_set_mode(hdmi, false);

	enable_hpd_clocks(hdmi, false);
	pm_runtime_put_autosuspend(dev);

	ret = gpio_config(hdmi, false);
	if (ret)
		dev_warn(dev, "failed to unconfigure GPIOs: %d\n", ret);

	ret = pinctrl_pm_select_sleep_state(dev);
	if (ret)
		dev_warn(dev, "pinctrl state chg failed: %d\n", ret);

	for (i = 0; i < config->hpd_reg_cnt; i++) {
		ret = regulator_disable(hdmi->hpd_regs[i]);
		if (ret)
			dev_warn(dev, "failed to disable hpd regulator: %s (%d)\n",
					config->hpd_reg_names[i], ret);
	}
}
Example #12
0
/**@brief Function for application main entry.
 */
int main(void)
{
    gpio_config();

    bool success = nrf6350_lcd_init();
    APP_ERROR_CHECK_BOOL(success);
    success = nrf6350_lcd_write_string("    BLE ANCS    ", MAX_CHARACTERS_PER_LINE, LCD_UPPER_LINE, 0);
    APP_ERROR_CHECK_BOOL(success);

    // Initialize.
    leds_init();
    timers_init();
    gpiote_init();
    buttons_init();
    ble_stack_init();    
    bond_manager_init();
    gap_params_init();
    service_add();    
    advertising_init();
    conn_params_init();
    sec_params_init();
    radio_notification_init();
    
    // Start execution.
    advertising_start();

    // Enter main loop.
    for (;;)
    {
        power_manage();
    }

}
Example #13
0
/*!
    \brief      main function
    \param[in]  none
    \param[out] none
    \retval     none
*/
int main(void)
{
    gpio_config(); 
    timer_config();

    while (1);
}
Example #14
0
/**
 * main function
 * @return int return type required by ANSI/ISO standard.
 */
int main(void)
{
  gpio_config();

  //Initialize the LCD display
  if (!nrf6350_lcd_init())
  {
    show_error();
  }

  // Clear the display and print a welcome message
  if (!nrf6350_lcd_write_string("    RF TEST     ", MAX_CHARACTERS_PER_LINE, LCD_UPPER_LINE, 0))
  {
    show_error();
  }
  
  if (!nrf6350_lcd_write_string("   SCROLL DOWN  ", MAX_CHARACTERS_PER_LINE, LCD_LOWER_LINE, 0))
  {
    show_error();
  }

  // Init peripherals needed by radio
  radio_init();

  wait_for_joystick_movement();     // so that the test title is visible on display until joystick status is changed

  menu_help_testrun_when_idle();  // This function will never return
}
Example #15
0
int wasp_mem_config(void){
	unsigned int reg32;

	wasp_ddr_initial_config(CFG_DDR_REFRESH_VAL);

	/* Take WMAC out of reset */
	reg32 = ar7240_reg_rd(AR7240_RESET);
	reg32 = reg32 & ~AR7240_RESET_WMAC;
	
	ar7240_reg_wr_nf(AR7240_RESET, reg32);

	/* Switching regulator settings */
	ar7240_reg_wr_nf(0x18116c40, 0x633c8176); /* AR_PHY_PMU1 */
	ar7240_reg_wr_nf(0x18116c44, 0x10380000); /* AR_PHY_PMU2 */

	//wasp_usb_initial_config();

	gpio_config();

	/* Needed here not to mess with Ethernet clocks */
	ath_set_tuning_caps();
	
	// return memory size
	return(ar7240_ddr_find_size());
}
Example #16
0
File: debug.c Project: 0xBADCA7/lk
/* Ideally this would be generic, but different platforms have varying manners of handling gpio
 * numbers / banks etc. Nvidia uses A-F, ST uses # and ports, Xilinx uses #s and banks. Etc.
 */
static int cmd_gpio(int argc, const cmd_args *argv)
{
    if (argc == 4 && !strcmp(argv[1].str,"set")) {
        unsigned int gpio = argv[2].u;
        unsigned int value = argv[3].u;

        gpio_set(gpio, value);
    } else if (argc == 3 && !strcmp(argv[1].str,"get")) {
        unsigned int gpio = argv[2].u;

        printf("gpio %u: %d\n", gpio, gpio_get(gpio));
    } else if (argc >= 3 && !strcmp(argv[1].str,"cfg")) {
        unsigned int gpio = argv[2].u;
        unsigned int flags = 0;

        for (int i = 3; i < argc; i++) {
            flags |= get_flag_value(argv[i].str);
        }

        gpio_config(gpio, flags);
    } else {
        printf("gpio set <gpio #> <value>\n");
        printf("gpio get <gpio #>\n");
        printf("gpio cfg <gpio #> [flags: ");
        for (unsigned int i = 0; i < countof(gpio_flag_labels); i++) {
            printf("%s ", gpio_flag_labels[i].label);
        }
        putchar(']');
        putchar('\n');
    }

    return 0;
}
Example #17
0
static int component_detect(void)
{
	int ret = true;

	#if defined(DISPLAY_STB_AUTO_DETECT)
		#if defined(BOARD_TCC880X_STB_DEMO)
			gpio_config(GPIO_PORTF|26, GPIO_FN0 | GPIO_INPUT); /* VE_DET */
			ret = gpio_get(GPIO_PORTF|26)? false : true;
		#elif defined(TARGET_TCC8920ST_EVM)
			gpio_config(GPIO_PORTB|29, GPIO_FN0 | GPIO_INPUT); /* VE_DET */
			ret = gpio_get(GPIO_PORTB|29)? false : true;
		#endif
	#endif

	return ret;
}
Example #18
0
//--------------
//main loop
int main(void)
{

	int i=0;
	for(i=0;i<100000ul;i++);


	rcc_config();
	nvic_config();
	gpio_config();
	usart_config();
	USART_puts(USART1, "USART BT initialization complete!\r\n"); // just send a message to indicate that it works

	MPU6050_I2C_Init();
	MPU6050_Initialize();
	if( MPU6050_TestConnection() == 1){
	    // connection success
		USART_puts(USART1, "I2C IMU connection initialization complete!\r\n");
	}else{
	    // connection failed
		USART_puts(USART1, "I2C initialization failed!\r\n");
	}

	//sysTick_Config_Mod(SysTick_CLKSource_HCLK_Div8, 10500000ul); // interruption every 1/2sec from systick
	sysTick_Config_Mod(SysTick_CLKSource_HCLK_Div8, 840000ul); // interruption every 0.04sec from systick


    while(1)
    {

    }
}
Example #19
0
static int hdp_disable(struct hdmi_connector *hdmi_connector)
{
	struct hdmi *hdmi = hdmi_connector->hdmi;
	struct drm_device *dev = hdmi_connector->base.dev;
	int ret = 0;

	/* Disable HPD interrupt */
	hdmi_write(hdmi, REG_HDMI_HPD_INT_CTRL, 0);

	hdmi_set_mode(hdmi, false);

	if (hdmi->mpp0)
		ret = regulator_disable(hdmi->mpp0);
	if (!ret)
		ret = regulator_disable(hdmi->mvs);
	if (ret) {
		dev_err(dev->dev, "failed to enable regulators: %d\n", ret);
		goto fail;
	}

	clk_disable_unprepare(hdmi->clk);
	clk_disable_unprepare(hdmi->m_pclk);
	clk_disable_unprepare(hdmi->s_pclk);

	ret = gpio_config(hdmi, false);
	if (ret) {
		dev_err(dev->dev, "failed to unconfigure GPIOs: %d\n", ret);
		goto fail;
	}

	return 0;

fail:
	return ret;
}
Example #20
0
/* FUNCTION *******************************************************************
* Initialise I2C for slave device access on the backplane
*
*******************************************************************************/
int bp_i2c_init (void)
{
    vSemaphoreCreateBinary(bp_i2c_in_use);

    if (bp_i2c_in_use == NULL)
    {
        DEBUG_PRINTF((DEBUG_UART, "cannot create BP I2C semaphore!"));
        while (1);
    }
    /* BP_I2C_EN on PMCH enable I2C analog switch to backplane */
    gpio_config(PORT0,PIN30,GPIO_OUTPUT,GPIO_CLR);

    /* Set the I2C output frequency to 100 kHz and duty cycle 1:1 */
    BP_I2CSCLH = IPMB_SCLH;
    BP_I2CSCLL = IPMB_SCLL;

    /* Set I2C bus address */
    BP_I2CADR = I2C_GENERAL_CALL_EN;

    /* Set I2C to master mode */
    BP_I2CCONSET = EN;

    /* Clear I2C interrupt bit */
    BP_I2CCONCLR = SIC;

    /* set interrupt vector entry */
    set_isr_handler(BP_I2C_IRQ,(void *)bp_i2c_isr,BP_IRQ_PRIO);

    /* enable the interrupt for BP_I2C */
    VICIntEnable = (1<<BP_I2C_IRQ);

    return E_OK;
}
Example #21
0
static int hdp_disable(struct hdmi_connector *hdmi_connector)
{
	struct hdmi *hdmi = hdmi_connector->hdmi;
	const struct hdmi_platform_config *config = hdmi->config;
	struct drm_device *dev = hdmi_connector->base.dev;
	int i, ret = 0;

	/* Disable HPD interrupt */
	hdmi_write(hdmi, REG_HDMI_HPD_INT_CTRL, 0);

	hdmi_set_mode(hdmi, false);

	for (i = 0; i < config->hpd_reg_cnt; i++) {
		ret = regulator_disable(hdmi->hpd_regs[i]);
		if (ret) {
			dev_err(dev->dev, "failed to disable hpd regulator: %s (%d)\n",
					config->hpd_reg_names[i], ret);
			goto fail;
		}
	}

	for (i = 0; i < config->hpd_clk_cnt; i++)
		clk_disable_unprepare(hdmi->hpd_clks[i]);

	ret = gpio_config(hdmi, false);
	if (ret) {
		dev_err(dev->dev, "failed to unconfigure GPIOs: %d\n", ret);
		goto fail;
	}

	return 0;

fail:
	return ret;
}
Example #22
0
void ICACHE_FLASH_ATTR ir_remote_init(uint16 gpio_pin_num, bool invert_logic_level)
{
	_gpio_pin_num = gpio_pin_num;

	_logic_low = invert_logic_level;
	_logic_high = !_logic_low;
	_pwm_lvl = _logic_low;

	GPIO_ConfigTypeDef gpioCfg;
	gpioCfg.GPIO_Pin = BIT(_gpio_pin_num);
	gpioCfg.GPIO_Mode = GPIO_Mode_Output;
	gpioCfg.GPIO_Pullup = GPIO_PullUp_DIS;
	gpio_config(&gpioCfg);

	GPIO_OUTPUT_SET(_gpio_pin_num, _logic_low);

	portENTER_CRITICAL();
	_xt_isr_attach(ETS_FRC_TIMER1_INUM, pwm_tim1_intr_handler);
	TM1_EDGE_INT_ENABLE();
	_xt_isr_unmask((1 << ETS_FRC_TIMER1_INUM));

	CLEAR_PERI_REG_MASK(FRC1_INT_ADDRESS, FRC1_INT_CLR_MASK);
	WRITE_PERI_REG(FRC1_CTRL_ADDRESS, CLOCK_DIV_256 | FRC1_ENABLE_TIMER | TM_EDGE_INT);
	WRITE_PERI_REG(FRC1_LOAD_ADDRESS, 0);
	portEXIT_CRITICAL();
}
Example #23
0
/*!
    \brief      main routine
    \param[in]  none
    \param[out] none
    \retval     none
*/
int main(void)
{
    /* system clocks configuration */
    rcu_config();

    /* GPIO configuration */
    gpio_config();

    /* USB device configuration */
    usbd_core_init(&usb_device_dev);

    /* NVIC configuration */
    nvic_config();

    /* enabled USB pull-up */
    gpio_bit_set(USB_PULLUP, USB_PULLUP_PIN);

    /* now the usb device is connected */
    usb_device_dev.status = USBD_CONNECTED;

    while (1)
    {
        if (USBD_CONFIGURED == usb_device_dev.status) {
            cdc_acm_data_receive(&usb_device_dev);
            if (0 != receive_length) {
                if (1 == packet_sent) {
                    cdc_acm_data_send(&usb_device_dev, receive_length);
                    receive_length = 0;
                }
            }
        }
    }
}
static void check_output(struct gpio_kp *kp, int out, int polarity)
{
	struct gpio_keypad_info *kpinfo = kp->keypad_info;
	int key_index;
	int in;
	int gpio;
	int changed = 0;

	key_index = out * kpinfo->ninputs;
	for (in = 0; in < kpinfo->ninputs; in++, key_index++) {
		gpio = kpinfo->input_gpios[in];
		changed = 0;
		if (gpio_get(gpio) ^ !polarity) {
			if (kp->some_keys_pressed < 3)
				kp->some_keys_pressed++;
			changed = !bitmap_set(kp->keys_pressed, key_index);
		} else {
			changed = bitmap_clear(kp->keys_pressed, key_index);
		}
		if (changed) {
			int state = bitmap_test(kp->keys_pressed, key_index);
			keys_post_event(kpinfo->keymap[key_index], state);
		}
	}

	/* sets up the right state for the next poll cycle */
	gpio = kpinfo->output_gpios[out];
	if (kpinfo->flags & GPIOKPF_DRIVE_INACTIVE)
		gpio_set(gpio, !polarity);
	else
		gpio_config(gpio, GPIO_INPUT);
}
Example #25
0
static int hpd_enable(struct hdmi_connector *hdmi_connector)
{
	struct hdmi *hdmi = hdmi_connector->hdmi;
	const struct hdmi_platform_config *config = hdmi->config;
	struct drm_device *dev = hdmi_connector->base.dev;
	struct hdmi_phy *phy = hdmi->phy;
	uint32_t hpd_ctrl;
	int i, ret;

	ret = gpio_config(hdmi, true);
	if (ret) {
		dev_err(dev->dev, "failed to configure GPIOs: %d\n", ret);
		goto fail;
	}

	for (i = 0; i < config->hpd_clk_cnt; i++) {
		ret = clk_prepare_enable(hdmi->hpd_clks[i]);
		if (ret) {
			dev_err(dev->dev, "failed to enable hpd clk: %s (%d)\n",
					config->hpd_clk_names[i], ret);
			goto fail;
		}
	}

	for (i = 0; i < config->hpd_reg_cnt; i++) {
		ret = regulator_enable(hdmi->hpd_regs[i]);
		if (ret) {
			dev_err(dev->dev, "failed to enable hpd regulator: %s (%d)\n",
					config->hpd_reg_names[i], ret);
			goto fail;
		}
	}

	hdmi_set_mode(hdmi, false);
	phy->funcs->reset(phy);
	hdmi_set_mode(hdmi, true);

	hdmi_write(hdmi, REG_HDMI_USEC_REFTIMER, 0x0001001b);

	/* enable HPD events: */
	hdmi_write(hdmi, REG_HDMI_HPD_INT_CTRL,
			HDMI_HPD_INT_CTRL_INT_CONNECT |
			HDMI_HPD_INT_CTRL_INT_EN);

	/* set timeout to 4.1ms (max) for hardware debounce */
	hpd_ctrl = hdmi_read(hdmi, REG_HDMI_HPD_CTRL);
	hpd_ctrl |= HDMI_HPD_CTRL_TIMEOUT(0x1fff);

	/* Toggle HPD circuit to trigger HPD sense */
	hdmi_write(hdmi, REG_HDMI_HPD_CTRL,
			~HDMI_HPD_CTRL_ENABLE & hpd_ctrl);
	hdmi_write(hdmi, REG_HDMI_HPD_CTRL,
			HDMI_HPD_CTRL_ENABLE | hpd_ctrl);

	return 0;

fail:
	return ret;
}
Example #26
0
File: main.c Project: nvll/lpc
int main(void)
{
    SystemInit();
    uart_init();
    puts("kernel alive");

    gpio_config(GPIO(2, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7), GPIO_OUTPUT);
    gpio_config(GPIO(3, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3), GPIO_OUTPUT);

    SysTick_Config(1000000);

    uint32_t value = 0;
    while (1) {
        spin(1000);
        led_set_binary(value++);
    }
}
Example #27
0
/*!
    \brief      main function
    \param[in]  none
    \param[out] none
    \retval     none
*/
int main(void)
{
    gpio_config(); 
    gd_eval_ledinit(LED1);
    timer_config();

    while (1);
}
Example #28
0
File: init.c Project: DSKIM3/lk
void target_early_init(void)
{
	/* configure the usart3 pins */
	GPIO_PinRemapConfig(GPIO_FullRemap_USART3, ENABLE);

	gpio_config(GPIO(GPIO_PORT_D, 8), GPIO_STM32_AF);
	gpio_config(GPIO(GPIO_PORT_D, 9), GPIO_INPUT);

	stm32_debug_early_init();

	/* configure some status leds */
	gpio_set(GPIO_LED0, 0);
	gpio_set(GPIO_LED1, 0);

	gpio_config(GPIO_LED0, GPIO_OUTPUT);
	gpio_config(GPIO_LED1, GPIO_OUTPUT);
}
static void gpio_callback_update(GtkWidget *widget, gpointer data[])
{
    int pin_number = atoi(gtk_entry_get_text(data[0]));
    gpio_config(pin_number, 0);
    int state = gpio_read(pin_number);
    char state_string[5];
    sprintf(state_string, "%s", (state == 0) ? "Low" : "High");
    gtk_label_set_text(data[1], state_string);
}
Example #30
0
/**
 * main function
 * \return 0. int return type required by ANSI/ISO standard.
 */
int main(void)
{
  gpio_config();
  lfclk_config();
  rtc_config();
  NRF_RTC0->TASKS_START = 1;
  while (true)
  {
  }
}