示例#1
0
文件: gpio.c 项目: bigneilm/gratis
void GPIO_mode(GPIO_pin_type pin, GPIO_mode_type mode) {

	// ignore unimplemented pins
	if (pin < 0 || pin >= SIZE_OF_ARRAY(gpio_info) || NULL == gpio_info[pin].name) {
		return;
	}

	switch (mode) {
	default:
	case GPIO_INPUT:
		if (gpio_info[pin].fd < 0 && !GPIO_enable(pin)) {
			return;
		}
		write_file(gpio_info[pin].direction, DIRECTION_in "\n", CONST_STRLEN(DIRECTION_in "\n"));
		write_file(gpio_info[pin].active_low, "0\n", 2);
		write_file(gpio_info[pin].state, STATE_rxEnable_pullNone "\n", CONST_STRLEN(STATE_rxEnable_pullNone "\n"));
		break;

	case GPIO_OUTPUT:
		if (gpio_info[pin].fd < 0 && !GPIO_enable(pin)) {
			return;
		}
		write_file(gpio_info[pin].direction, DIRECTION_out "\n", CONST_STRLEN(DIRECTION_out "\n"));
		write_file(gpio_info[pin].active_low, "0\n", 2);
		write_file(gpio_info[pin].state, STATE_rxDisable_pullNone "\n", CONST_STRLEN(STATE_rxDisable_pullNone "\n"));
		break;

	case GPIO_PWM:  // only certain pins allowed
		switch (pin) {
		case GPIO_P9_14:    // EHRPWM1A
			PWM_enable(0, "P9_14");
			break;
		case GPIO_P9_16:    // EHRPWM1B
			PWM_enable(1, "P9_16");
			break;
		case GPIO_P8_19:    // EHRPWM2A
			PWM_enable(2, "P8_19");
			break;
		case GPIO_P8_13:    // EHRPWM2B
			PWM_enable(3, "P8_13");
			break;
		default:
			break;
		}
		break;
	}
}
示例#2
0
void GPIO_mode(GPIO_pin_type pin, GPIO_mode_type mode) {
	int bank = (pin >> 8) & 0xff;
	int pin32 = pin & 0xff;
	if (bank < 0 || bank > 3 || pin32 < 0 || pin32 > 31) {
		return;
	}
	if (NULL == gpio_map[bank]) {
		return;
	}

	volatile uint32_t *oe = &gpio_map[bank][GPIO_OE];

	switch (mode) {
	default:
	case GPIO_INPUT:
		*oe |= 1 << pin32;
		break;
	case GPIO_OUTPUT:
		*oe &= ~(1 << pin32);
		break;
	case GPIO_PWM:  // only certain pins allowed
		switch (pin) {
		case GPIO_P9_14:    // EHRPWM1A
			PWM_enable(0, "P9_14");
			break;
		case GPIO_P9_16:    // EHRPWM1B
			PWM_enable(1, "P9_16");
			break;
		case GPIO_P8_19:    // EHRPWM2A
			PWM_enable(2, "P8_19");
			break;
		case GPIO_P8_13:    // EHRPWM2B
			PWM_enable(3, "P8_13");
			break;
		default:
			break;
		}
		break;
	}
}
示例#3
0
void wheel3(int pwm){
//REQUIRES: pwm_init() has been called
//          Takes a number from -255 to 255 where 0 is stopped and 
//          255 is full speed ahead
//EFFECTS: Modifies the speed of wheel3
	if (pwm == 0){
		PWM_disable(&motors, PWM_5);
		PWM_disable(&motors, PWM_6);
	}
	else if (pwm > 0){
		PWM_set_duty_cycle(&motors, PWM_5, pwm);
		PWM_enable(&motors, PWM_5);
		PWM_disable(&motors, PWM_6);
	}
	else {
		pwm = pwm * -1;
		PWM_set_duty_cycle(&motors, PWM_6, pwm);
		PWM_enable(&motors, PWM_6);
		PWM_disable(&motors, PWM_5);
	}
	return;
}
示例#4
0
void main(){
	WDT_DISABLE;
	BC16MSET;
	
	PWM_enable(PWM0, SMCLK, UP, BIT0, 0xff);
	
	P1DIR = 0xff;
	P1SEL = 0xff;
	
	unsigned int i;
	while (1){
		i++;
		PWM_setter(PWM0, 1, 100 + (SPWM_DATA[(i << 2) & 1023]>>9), POUT);
		//PWM_setter(PWM0, 1, 0x80, POUT);
	}
	
	
	_BIS_SR(CPUOFF);
}
示例#5
0
文件: gpio.c 项目: RavenB/gratis
void GPIO_mode(GPIO_pin_type pin, GPIO_mode_type mode) {

	// ignore unimplemented pins
	if (pin < 0 || pin >= SIZE_OF_ARRAY(gpio_info) || NULL == gpio_info[pin].name) {
		return;
	}

	switch (mode) {
	default:
	case GPIO_INPUT:
		if (gpio_info[pin].fd < 0 && !GPIO_enable(pin)) {
			return;
		}
		write_pin_file(GPIO_DIRECTION, pin, GPIO_DIRECTION_in "\n", CONST_STRLEN(GPIO_DIRECTION_in "\n"));
		write_pin_file(GPIO_ACTIVE_LOW, pin, "0\n", 2);
		write_pin_file(GPIO_EDGE, pin, GPIO_EDGE_none "\n", CONST_STRLEN(GPIO_EDGE_none "\n"));
		//write_pin_file(GPIO_STATE, pin, STATE_rxEnable_pullNone "\n", CONST_STRLEN(STATE_rxEnable_pullNone "\n"));
		break;

	case GPIO_OUTPUT:
		if (gpio_info[pin].fd < 0 && !GPIO_enable(pin)) {
			return;
		}
		write_pin_file(GPIO_DIRECTION, pin, GPIO_DIRECTION_out "\n", CONST_STRLEN(GPIO_DIRECTION_out "\n"));
		write_pin_file(GPIO_ACTIVE_LOW, pin, "0\n", 2);
		write_pin_file(GPIO_EDGE, pin, GPIO_EDGE_none "\n", CONST_STRLEN(GPIO_EDGE_none "\n"));
		//write_pin_file(GPIO_STATE, pin, STATE_rxDisable_pullNone "\n", CONST_STRLEN(STATE_rxDisable_pullNone "\n"));
		break;

	case GPIO_PWM:  // only certain pins allowed
		if (gpio_info[pin].fd < 0 && !PWM_enable(pin)) {
			return;
		}
		break;
	}
}
示例#6
0
// Set the PWM pulse width
void PWM_width(uint16_t width) {
  PWM_disable();
  // Timer counter match value for pulse width (sec 18.7.7)
  LPC_TMR16B0->MR0 = LPC_TMR16B0->MR1 - width;
  PWM_enable();
}