Example #1
0
static void
init(void)
{
        /* set modes before to enable the port */
        gpio_dir(PROG_BUTTON, GPIO_INPUT);
        pin_mode(PROG_BUTTON, PIN_MODE_PULLUP);
        gpio_dir(TARGET_RESET, GPIO_INPUT);
        gpio_dir(TARGET_LED, GPIO_INPUT);

        /* set digital debounce/filter */
        pin_physport_from_pin(PROG_BUTTON)->dfcr.cs = PORT_CS_LPO;
        pin_physport_from_pin(PROG_BUTTON)->dfwr.filt = 31;

        /* button interrupt */
        pin_physport_from_pin(PROG_BUTTON)->dfer |= 1 << pin_physpin_from_pin(PROG_BUTTON);
        pin_physport_from_pin(PROG_BUTTON)->pcr[pin_physpin_from_pin(PROG_BUTTON)].irqc = PCR_IRQC_INT_FALLING;

        /* reset interrupt */
        pin_physport_from_pin(TARGET_RESET)->pcr[pin_physpin_from_pin(TARGET_RESET)].irqc = PCR_IRQC_INT_RISING;

        /* LED interrupt */
        pin_physport_from_pin(TARGET_LED)->pcr[pin_physpin_from_pin(TARGET_LED)].irqc = PCR_IRQC_INT_FALLING;

        int_enable(IRQ_PORTD);

        gpio_dir(LED_SUCCESS, GPIO_OUTPUT);
        gpio_dir(LED_FAIL, GPIO_OUTPUT);

        timeout_init();
}
Example #2
0
FTVOID ft9xx_spi_init (FTU8 spi_type, FTU32 spi_div)
{
	/* limitation check */
	if (spi_type == 0 || spi_type == 3 || spi_type > 4) {
		FTPRINT("\nSPI type error");
		return;	
	} else if (spi_type == 4 && spi_div < 8) {
		FTPRINT("\nQSPI div too small");
		return;	
	}

	/* receive dummy byte */
	if (spi_type != 1) {
		spi_dummy = 2;
	} else {
		spi_dummy = 1;
	}

	/* basic SPI init */
	sys_enable(sys_device_spi_master);
	/* in order to use the SPI in multiple way (not only for EVE)
	   do not use FT900 integrated CS (pad_spim_ss0),
	   do the CS action by GPIO in other place */
	gpio_function(FT9XX_SPI_SCK, pad_spim_sck);
	gpio_function(FT9XX_SPI_MOSI, pad_spim_mosi);
	gpio_function(FT9XX_SPI_MISO, pad_spim_miso);

	gpio_dir(FT9XX_SPI_SCK, pad_dir_output);
	gpio_dir(FT9XX_SPI_MOSI, pad_dir_output);
	gpio_dir(FT9XX_SPI_MISO, pad_dir_input);

	/* QSPI init */
	if (spi_type == 4) {
		gpio_function(FT9XX_SPI_MOSI_2, pad_spim_io2);
		gpio_function(FT9XX_SPI_MOSI_3, pad_spim_io3);
		gpio_dir(FT9XX_SPI_MOSI_2, pad_dir_output);
		gpio_dir(FT9XX_SPI_MOSI_3, pad_dir_output);
	}

	/* enable SPI: host, mode0, speed */
	spi_init(SPIM, spi_dir_master, spi_mode_0, spi_div);

	/* DSPI, QSPI setting */
	if (spi_type != 1) {
		spi_option(SPIM,spi_option_fifo_size,64);
		spi_option(SPIM,spi_option_fifo,1);
		spi_option(SPIM,spi_option_fifo_receive_trigger,1);
	}

	/* spi bus width */
	spi_option(SPIM,spi_option_bus_width,spi_type);

	/* set all output pins HIGH */
	if (spi_type == 4) {
		gpio_write(FT9XX_SPI_MOSI_2, 1);
		gpio_write(FT9XX_SPI_MOSI_3, 1);
	}
	gpio_write(FT9XX_SPI_SCK, 1);
	gpio_write(FT9XX_SPI_MOSI, 1);
}
Example #3
0
FTVOID ft9xx_init (FTVOID)
{
	interrupt_enable_globally();

	/* set and pull HIGH the PD pin of EVE */
	gpio_function(FT9XX_PD, pad_gpio43);
	gpio_dir(FT9XX_PD, pad_dir_output);
	gpio_write(FT9XX_PD, 1);	

	/* connect a LED in this GPIO to see 
	 * if the MCU run here */
	gpio_function(FT9XX_TST, pad_gpio54);
	gpio_dir(FT9XX_TST, pad_dir_output);
	gpio_write(FT9XX_TST, 1);

	/* set all the possible functional GPIO to HIGH
	   for better initial status*/
	gpio_function(FT9XX_ILI9488_CS, pad_gpio33);
	gpio_function(FT9XX_SPI_CS_P, pad_gpio28);
	gpio_function(FT9XX_ILI9488_DCX, pad_gpio34);

	gpio_dir(FT9XX_ILI9488_CS, pad_dir_output);
	gpio_dir(FT9XX_SPI_CS_P, pad_dir_output);
	gpio_dir(FT9XX_ILI9488_DCX, pad_dir_output);

	gpio_write(FT9XX_ILI9488_CS, 1);
	gpio_write(FT9XX_SPI_CS_P, 1);
	gpio_write(FT9XX_ILI9488_DCX, 1);

    ft9xx_int_timer();
}
Example #4
0
/*******************************************************************************
**函    数: IIC_InitPort
**功    能: IIC接口初始化
**参    数: void
**返    回: void
*******************************************************************************/
void IIC_InitPort(void)
{                        

    
    printf("\n BL5372 IIC Port Init");
    // Init IIC_1_SCL_PIN
      gpio_init(&gpio_iic_1_scl, IIC_1_SCL_PIN);
      gpio_dir(&gpio_iic_1_scl, PIN_OUTPUT);    // Direction: Output
      gpio_mode(&gpio_iic_1_scl, PullNone);     // No pull
      
      gpio_write(&gpio_iic_1_scl, 1);


      // Init IIC_1_SDA_PIN
      gpio_init(&gpio_iic_1_sda, IIC_1_SDA_PIN);
      gpio_dir(&gpio_iic_1_sda, PIN_OUTPUT);    // Direction: Output
      gpio_mode(&gpio_iic_1_sda, PullNone);     // No pull
    
      gpio_write(&gpio_iic_1_sda, 1);
      
      SDA_OUT();
      SCL_OUT();
      SCL1;
      SDA1;
}
Example #5
0
static int f7188x_gpio_direction_out(struct gpio_chip *chip,
				     unsigned offset, int value)
{
	int err;
	struct f7188x_gpio_bank *bank =
		container_of(chip, struct f7188x_gpio_bank, chip);
	struct f7188x_sio *sio = bank->data->sio;
	u8 dir, data_out;

	err = superio_enter(sio->addr);
	if (err)
		return err;
	superio_select(sio->addr, SIO_LD_GPIO);

	data_out = superio_inb(sio->addr, gpio_data_out(bank->regbase));
	if (value)
		data_out |= (1 << offset);
	else
		data_out &= ~(1 << offset);
	superio_outb(sio->addr, gpio_data_out(bank->regbase), data_out);

	dir = superio_inb(sio->addr, gpio_dir(bank->regbase));
	dir |= (1 << offset);
	superio_outb(sio->addr, gpio_dir(bank->regbase), dir);

	superio_exit(sio->addr);

	return 0;
}
Example #6
0
//int main_app(IN u16 argc, IN u8 *argv[])
void main(void)
{
    gpio_t gpio_led;
    gpio_t gpio_btn;

    // Init LED control pin
    gpio_init(&gpio_led, GPIO_LED_PIN);
    gpio_dir(&gpio_led, PIN_OUTPUT);    // Direction: Output
    gpio_mode(&gpio_led, PullNone);     // No pull

    // Initial Push Button pin
    gpio_init(&gpio_btn, GPIO_PUSHBT_PIN);
    gpio_dir(&gpio_btn, PIN_INPUT);     // Direction: Input
    gpio_mode(&gpio_btn, PullUp);       // Pull-High

    while(1){
        if (gpio_read(&gpio_btn)) {
            // turn off LED
            gpio_write(&gpio_led, 0);
        }
        else {
            // turn on LED
            gpio_write(&gpio_led, 1);
        }
    }
}
Example #7
0
/* Private methods for acting on bits */
static inline void set_w1_gpio(int gpio, int value)
{
    gpio_dir(gpio, GPIO_DIR_IN, 0);
    udelay(5); /* input for 5usec (recover prev bit) */
    gpio_dir(gpio, GPIO_DIR_OUT, 0); /* output low */
    udelay(value ? 1 : 60);
    gpio_dir(gpio, GPIO_DIR_IN, 0); /* input again */
    udelay(value ? 60 : 1);
}
Example #8
0
static void
enable_power(void)
{
        /* pull CS low */
        gpio_write(EZPORT_CS, 0);
        gpio_dir(EZPORT_CS, GPIO_OUTPUT);

        /* enable power */
        gpio_write(EZPORT_POWER, 0);
        gpio_dir(EZPORT_POWER, GPIO_OUTPUT);
}
Example #9
0
static inline int get_w1_gpio(int gpio)
{
    int ret;

    gpio_dir(gpio, 1, 0); /* output low */
    udelay(1);
    gpio_dir(gpio, GPIO_DIR_IN, 0); /* input (pull up) */
    udelay(9);
    ret = gpio_get(gpio);
    udelay(60);
    return ret;
}
Example #10
0
File: gpio.c Project: ttajmaje/mbed
static inline void _gpio_init_out(gpio_t* gpio, PinName pin, PinMode mode, int value)
{
    gpio_init(gpio, pin);
    if (pin != NC) {
        gpio_write(gpio, value);
        if(mode == OpenDrain)
            gpio_dir(gpio, PIN_OUTPUT_OD);
        else{
            gpio_dir(gpio, PIN_OUTPUT);
        }
        gpio_mode(gpio, mode);
    }
}
Example #11
0
/* Public methods follow */
static int w1_gpio_reset(struct w1_bus *bus)
{
	int ret;

	gpio_dir_af(bus->detail, 0, 0, 0); /* input, novalue, af = 0 */
	gpio_dir(bus->detail, 1, 0); /* low pulse */
	udelay(480);
	gpio_dir(bus->detail, 0, 0); /* input */
	udelay(100);
	ret = !gpio_get(bus->detail); /* 0 == present */
	udelay(480);
	if (!gpio_get(bus->detail))
		return 0; /* stuck low: not present */
	return ret;
}
Example #12
0
/* Public methods follow */
static int w1_gpio_reset(struct w1_bus *bus)
{
    int ret;

    gpio_dir_af(bus->detail, GPIO_DIR_IN, 0, GPIO_AF_GPIO);
    gpio_dir(bus->detail, GPIO_DIR_OUT, 0);
    udelay(480); /* low pulse */
    gpio_dir(bus->detail, GPIO_DIR_IN, 0);
    udelay(100);
    ret = !gpio_get(bus->detail); /* 0 == present */
    udelay(480);
    if (!gpio_get(bus->detail))
        return 0; /* stuck low: not present */
    return ret;
}
Example #13
0
int is_update_image_enable(gpio_t *gpio_uart_update_eable)
{

	HAL_GPIO_PIN  GPIO_Pin;
    u32 active_state;
//	gpio_t gpio_uart_update_eable;
	int ret = 0;
#if 0
    GPIO_Pin.pin_name = 0xC4;
	//low active
	GPIO_Pin.pin_mode = DIN_PULL_HIGH;
	active_state = GPIO_PIN_LOW;
	
    HAL_GPIO_Init(&GPIO_Pin);
	
    if (HAL_GPIO_ReadPin(&GPIO_Pin) == active_state)
    	ret = 0;
	else
		ret = 1;
	
   	HAL_GPIO_DeInit(&GPIO_Pin);
#else
	gpio_init(gpio_uart_update_eable, PIN_NAME);
	gpio_dir(gpio_uart_update_eable, PIN_INPUT);     // Direction: Input
	gpio_mode(gpio_uart_update_eable, PullUp);       // Pull-High
//	ret = gpio_read(&gpio_uart_update_eable);
#endif

	return ret;
}
Example #14
0
SPIFram::SPIFram(PinName cs) {
  gpio_init(&csPin, cs);
  gpio_dir(&csPin, PIN_OUTPUT);
  gpio_mode(&csPin, PullNone);
  gpio_write(&csPin, 1);
  CHIP_DESELECT
}
Example #15
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{

	gpio_init(&gpio_reset, GPIO_RESET);
	gpio_mode(&gpio_reset, PullUp);
	gpio_dir(&gpio_reset, PIN_OUTPUT);

	gpio_init(&gpio_cs, GPIO_CS);
	gpio_mode(&gpio_cs, PullUp);
	gpio_dir(&gpio_cs, PIN_OUTPUT);
	
    spi_init(&spi0_master, SPI0_MOSI, SPI0_MISO, SPI0_SCLK, SPI0_CS);
	spi_format(&spi0_master, 8, 3, 0);
	spi_frequency(&spi0_master, 800000);
	
	do
	{
		SPI_PL7223_Reset();
		SPI_PL7223_Read(&Read_Data_PL7223[0],0x3860,1);//DSP version :20130322 ver02, 0x3860=0x04
                                                                 //DSP version :20141009 ver01, 0x3860=0x03
	}while( ((Read_Data_PL7223[0]) != 0x04) && ((Read_Data_PL7223[0]) != 0x03) );
	
	SPI_PL7223_DELY(120000);
	SPI_PL7223_RelayControl(0);		// OFF
	SPI_PL7223_DELY(120000);
	
	do{
	// As below is read DSP buffer process every time (144 byte)
	SPI__PL7223_Read_Status();
	SPI_PL7223_Read(&Read_Data_PL7223[0],0x3000,144); // 0x3000~0x308F     //144 byte
	SPI_PL7223_Read(&Read_Data_PL7223[144],0x3809,2); // Sample_cnt0
	SPI_PL7223_Masurement();
	
	SPI_PL7223_DELY(600000);
	SPI_PL7223_RelayControl(1);		// ON
	SPI_PL7223_DELY(120000);
	
	SPI__PL7223_Read_Status();
	SPI_PL7223_Read(&Read_Data_PL7223[0],0x3000,144); // 0x3000~0x308F     //144 byte
	SPI_PL7223_Read(&Read_Data_PL7223[144],0x3809,2); // Sample_cnt0
	SPI_PL7223_Masurement();
	
	SPI_PL7223_DELY(600000);
	SPI_PL7223_RelayControl(0);		// OFF
	SPI_PL7223_DELY(120000);
	}while(1);
}
Example #16
0
static inline void _gpio_init_in(gpio_t* gpio, PinName pin, PinMode mode)
{
    gpio_init(gpio, pin);
    if (pin != NC) {
        gpio_dir(gpio, PIN_INPUT);
        gpio_mode(gpio, mode);
    }
}
Example #17
0
static inline void _gpio_init_out(gpio_t* gpio, PinName pin, PinMode mode, int value)
{
    gpio_init(gpio, pin);
    if (pin != NC) {
        gpio_write(gpio, value);
        gpio_dir(gpio, PIN_OUTPUT);
        gpio_mode(gpio, mode);
    }
}
Example #18
0
unsigned char i2c_write(unsigned char data){//ok
	unsigned char m;
	for (m = 0x80; m != 0; m >>= 1) {
		if (m & data)	gpio_write(SDA,1);
		else 		gpio_write(SDA,0);
		gpio_write(SCL,1);
		usleep(i2c_sleep);
		gpio_write(SCL,0);
	}
	gpio_dir(SDA,0);
	gpio_write(SDA,1);
	gpio_write(SCL,1);
	unsigned char isOK = gpio_read(SDA);
	gpio_write(SCL,0);
	gpio_dir(SDA,1);
	gpio_write(SDA,0);
	return isOK == 0;
}
Example #19
0
static int spi_open(struct bathos_pipe *pipe)
{
	/* Enable SPI (in slave mode) and its interrupt */
	SPCR = (1 << SPE);
	SPCR |= (1 << SPIE);
	spi_data.bufrx = bathos_alloc_buffer(SPI_BUF_SIZE);
	spi_data.buftx = bathos_alloc_buffer(SPI_BUF_SIZE);
	gpio_dir(SPI_INTERRUPT_PIN, 1, 0);
	return 0;
}
Example #20
0
int gpio_dir_af(int gpio, int output, int value, int afnum)
{
	if (gpio > GPIO_MAX || gpio < 0)
		return -1;

	if (afnum < 2) { /* if weird bit, swap AF0 and AF1 */
		int port = GPIO_PORT(gpio);
		int bit = GPIO_BIT(gpio);
		if (gpio_weird[port] & (1 << bit))
			afnum ^= 1;
	}
	/* First set dir to prevent glitches when moving to AF0 */
	gpio_dir(gpio, output, value);
	writel(afnum | 0x80, /* This 0x80 for "digital mode" */
	       0x40044000 + gpio_addr[gpio]);
	/* Finally, dir again to force value when moving to gpio-out */
	gpio_dir(gpio, output, value);
	return 0;
}
Example #21
0
void uartadapter_gpio_init()
{
    	gpio_init(&gpio_led, UA_GPIO_IRQ_PIN);
    	gpio_dir(&gpio_led, PIN_INPUT);    // Direction: Output
    	gpio_mode(&gpio_led, PullNone);     // No pull
    	
    	gpio_irq_init(&gpio_btn, UA_GPIO_IRQ_PIN, uartadapter_gpio_irq, (uint32_t)(&gpio_led));
    	gpio_irq_set(&gpio_btn, IRQ_FALL, 1);   // Falling Edge Trigger
    	gpio_irq_enable(&gpio_btn);
}
Example #22
0
void
nrf_interrupt(void *cbdata)
{
	gpio_write(NRF_CE, 0); // go to standby-1
	static struct nrf_transaction_t trans = {
		.cmd = NRF_CMD_NOP,
		.tx_len = 0,
		.rx_len = 0
	};
	send_command(&trans, handle_status, &trans); // nop it to get the status register
}

PIN_DEFINE_CALLBACK(NRF_IRQ, PIN_CHANGE_FALLING, nrf_interrupt, NULL);

void
nrf_init(void)
{
	nrf_ctx.state = 0;
	nrf_ctx.channel = 42;
	nrf_ctx.data_rate = NRF_DATA_RATE_1MBPS;
	nrf_ctx.power = NRF_TX_POWER_0DBM;
	nrf_ctx.crc_len = NRF_CRC_ENC_2_BYTES;
	nrf_ctx.ard = 0;
	nrf_ctx.arc = 3;
	nrf_ctx.power_save = 0;
	nrf_ctx.dynamic_payload = 0;
	nrf_ctx.dirty = 1;

	spi_init();

	pin_mode(NRF_CSN, PIN_MODE_MUX_ALT2);
	pin_mode(NRF_SCK, PIN_MODE_MUX_ALT2);
	pin_mode(NRF_MOSI, PIN_MODE_MUX_ALT2);
	pin_mode(NRF_MISO, PIN_MODE_MUX_ALT2);

	gpio_dir(NRF_CE, GPIO_OUTPUT);
	gpio_write(NRF_CE, 0);

	gpio_dir(NRF_IRQ, GPIO_INPUT);

	pin_change_init();
}
Example #23
0
static int f7188x_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
{
	int err;
	struct f7188x_gpio_bank *bank = gpiochip_get_data(chip);
	struct f7188x_sio *sio = bank->data->sio;
	u8 dir;

	err = superio_enter(sio->addr);
	if (err)
		return err;
	superio_select(sio->addr, SIO_LD_GPIO);

	dir = superio_inb(sio->addr, gpio_dir(bank->regbase));
	dir &= ~(1 << offset);
	superio_outb(sio->addr, gpio_dir(bank->regbase), dir);

	superio_exit(sio->addr);

	return 0;
}
Example #24
0
unsigned char i2c_read(unsigned char ack){//ok
	unsigned char b = 0;
	gpio_dir(SDA,0);
	gpio_write(SDA,1);
	unsigned char i;
	for (i = 0; i < 8; i++) {
		b <<= 1;
		usleep(i2c_sleep);
		gpio_write(SCL,1);
		if (gpio_read(SDA)) b |= 1;
		gpio_write(SCL,0);
	}
	gpio_write(SDA,0);
	gpio_dir(SDA,1);
	if (ack)	gpio_write(SDA,1); 
	else 		gpio_write(SDA,0);
	gpio_write(SCL,1);
	usleep(i2c_sleep);
	gpio_write(SCL,0);
	gpio_write(SDA,0);
	return b;
}
Example #25
0
/* In boot.S there is a loop of spidy_step */
void spidy_step(void *unused)
{
	/* Wait till next beginning */
	while (regs[REG_TMR32B1PC] >= 30)
		;

	/* up motor i, frameIndex != 9 && != 19 */
	if (portNow >= 0)
		gpio_dir(used_gpio[portNow], 1, 1);

	/* down motor i-1 if it's > 52 deg, frameIndex != 0 && != 10 */
	if (portLast >= 0) {
		if (motors[portLast] > DEGREELIMIT) {
			waitTime = TIMEDEG * (motors[portLast] - DEGREELIMIT);
			while (regs[REG_TMR32B1PC] < waitTime)
				;
			gpio_dir(used_gpio[portLast], 1, 0);
		}
	} else {
		/* acquiring buffer */
		if (getBuffer()) {
			saveBuffer();
			putc(CHAR_MREADY);	/* to get next burst */
		}
	}

	/* down motor i if it's <= 52 deg, frameIndex != 9 && != 19 */
	if (portNow >= 0) {
		if (motors[portNow] <= DEGREELIMIT) {
			waitTime = (TIMEDEG * (motors[portNow])) + TIME090;
			while(regs[REG_TMR32B1PC] < waitTime)
				;
			gpio_dir(used_gpio[portNow], 1, 0);
		}
	}
	/* setup next motor */
	setPort();
}
Example #26
0
void
config_pins()
{
        // REMOTE_EN pin
        pin_mode(PIN_PTD3, PIN_MODE_MUX_GPIO);
        gpio_dir(PIN_PTD3, GPIO_OUTPUT);

        // UART
        pin_mode(PIN_PTA1, PIN_MODE_MUX_ALT2);
        pin_mode(PIN_PTA2, PIN_MODE_MUX_ALT2);

        // for I2C devices
        i2c_init(I2C_RATE_100);
        PORTB.pcr[pin_physpin_from_pin(PIN_PTB0)].raw = ((struct PCR_t) {.mux=2,.ode=1}).raw;
Example #27
0
void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
    if(pin == NC) return;

    obj->pin = pin;
    obj->mask = gpio_set(pin);

#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
    LPC_GPIO_TypeDef *port_reg = (LPC_GPIO_TypeDef *) ((int)pin & ~0x1F);

    obj->reg_set = &port_reg->FIOSET;
    obj->reg_clr = &port_reg->FIOCLR;
    obj->reg_in  = &port_reg->FIOPIN;
    obj->reg_dir = &port_reg->FIODIR;

#elif defined(TARGET_LPC11U24)
    unsigned int port = (unsigned int)pin >> PORT_SHIFT;

    obj->reg_set = &LPC_GPIO->SET[port];
    obj->reg_clr = &LPC_GPIO->CLR[port];
    obj->reg_in  = &LPC_GPIO->PIN[port];
    obj->reg_dir = &LPC_GPIO->DIR[port];
#elif  defined(TARGET_LPC11Cxx)
    int gpionum = ((int) pin) >> 5;
    int pinnum = ((int) pin) & 0x1f;
    LPC_GPIO_TypeDef* lpc = 0;
    switch(gpionum) {
      case 0: lpc = LPC_GPIO0; break;
      case 1: lpc = LPC_GPIO1; break;
      case 2: lpc = LPC_GPIO2; break;
      case 3: lpc = LPC_GPIO3; break;
      default: {
        extern void abort(void); abort();
      }
    }
    obj->reg_dir = &lpc->DIR;
    obj->reg_set = &lpc->MASKED_ACCESS[1<<pinnum];
    // TODO(bracz) this is not strictly speaking true. You have to write 0 here
    // to clear the pin state.
    obj->reg_clr = &lpc->MASKED_ACCESS[1<<pinnum];
    obj->reg_in = &lpc->DATA;
#else
#error CPU undefined.
#endif

    gpio_dir(obj, direction);
    switch (direction) {
        case PIN_OUTPUT: pin_mode(pin, PullNone); break;
        case PIN_INPUT : pin_mode(pin, PullDown); break;
    }
}
Example #28
0
void led_init(void)
{	
	// activate port f
	sysctrl(rcgc2, port_f);
	// output mode
	gpio_dir(port_f) |= pins;
	// regular gpio port
	gpio_afsel(port_f) &= ~pins;
	// 2ma current
	gpio_dr2r(port_f) |= pins;
	// digital mode
	gpio_den(port_f) |= pins;
	// clear all pins
	gpio_data(port_f) &= ~pins;
}
void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
    if(pin == NC) return;

    obj->pin = pin;
    obj->mask = (1ul<<pin);

    obj->reg_set = &NRF_GPIO->OUTSET;
    obj->reg_clr = &NRF_GPIO->OUTCLR;
    obj->reg_in  = &NRF_GPIO->IN;
    obj->reg_dir = &NRF_GPIO->DIR;

    gpio_dir(obj, direction);
    switch (direction) {
        case PIN_OUTPUT: pin_mode(pin, PullNone); break;
        case PIN_INPUT : pin_mode(pin, PullUp); break;
    }
}
Example #30
0
void digitalChangeDir( uint32_t ulPin, uint8_t direction)
{
    gpio_t *pGpio_t;
    u32 RegValue;

    if ( ulPin < 0 || ulPin > TOTAL_GPIO_PIN_NUM )
    {
        return;
    }

    if ( g_APinDescription[ulPin].ulPinType != PIO_GPIO )
    {
        return;
    }

    pGpio_t = (gpio_t *)gpio_pin_struct[ulPin];

    gpio_dir( pGpio_t, direction );
}