Пример #1
0
void
mcp23x17::setup( uint8_t pin, uint8_t mode, uint8_t pull_mode ) {

	// Enable/disable pull-up control on the GPIO pin
	if ( mode == INPUT )
		setPullUpDown( pin, pull_mode );

	uint8_t reg = pin / 8;

	// Update the local register
	utils::set_bit( m_states, reg, pin % 8, mode ? 0 : 1 );

	// Set the mode of the GPIO pin
	send( IODIR + reg, m_states[ reg ] );
}
Пример #2
0
void
gpio::setup( uint8_t pin, PinMode mode, PullMode pud_mode ) {

	// Enable/disable pull-up/down control on the GPIO pin
	if ( mode == INPUT ) setPullUpDown( pin, pud_mode );

	// Calculate the bit position
	uint8_t shift = ( pin % 10 ) * 3;

	// Get GPIO controller register
	volatile uint32_t &reg = *( m_gpio + GPFSEL0 + ( pin / 10 ) );

	// Sets the GPIO pin mode
	// 000 = Input
	// 001 = Output
	reg = ( reg & ~( 7 << shift ) ) | ( (uint32_t) mode << shift );
}
Пример #3
0
void pinMode(int pin,int mode){
	vu32_t *res;

	// GPFSEL select
	if(0 <= pin && pin <= 9){
		res = GPFSEL0;
	}else if (pin <= 19)
	{
		res = GPFSEL1;
	}else if (pin <= 29)
	{
		res = GPFSEL2;
	}else if (pin <= 39)
	{
		res = GPFSEL3;
	}else if (pin <= 49)
	{
		res = GPFSEL4;
	}else if (pin <= 53)
	{
		res = GPFSEL5;
	}else{
		// pin missmuch
		return;
	}

	// mode set
	switch(mode){
		case INPUT:
			*res &= GPFSEL_MASK_IN(pin);
			break;
		case INPUT_PULLUP:
			setPullUpDown(pin,INPUT_PULLUP);
			*res &= GPFSEL_MASK_IN(pin);
			break;
		case INPUT_PULLDOWN:
			setPullUpDown(pin,INPUT_PULLDOWN);
			*res &= GPFSEL_MASK_IN(pin);
			break;
		case OUTPUT:
			*res |= GPFSEL_MASK_OUT(pin);
			break;
		case ALT0:
			*res |= GPFSEL_MASK_ALT0(pin);
			break;
		case ALT1:
			*res |= GPFSEL_MASK_ALT1(pin);
			break;
		case ALT2:
			*res |= GPFSEL_MASK_ALT2(pin);
			break;
		case ALT3:
			*res |= GPFSEL_MASK_ALT3(pin);
			break;
		case ALT4:
			*res |= GPFSEL_MASK_ALT4(pin);
			break;
		case ALT5:
			*res |= GPFSEL_MASK_ALT5(pin);
			break;
		default:
			// error!
			;
	}
	return;
}