Ejemplo n.º 1
0
int main(void) {
	int i;

	init();
	output_speed(0, 50);
	output_speed(1, 50);

	while (1) {
		flash(LED_M0_R);
		flash(LED_M0_B);
		flash(LED_M1_R);
		flash(LED_M1_B);

		output_enable(0);
		output_direction(0, DIR_FWD);
		delay(DELAY*2);
		output_direction(0, DIR_REV);
		delay(DELAY*2);
		output_disable(0);
		delay(DELAY);

		output_enable(1);
		output_direction(1, DIR_FWD);
		delay(DELAY*2);
		output_direction(1, DIR_REV);
		delay(DELAY*2);
		output_disable(1);
		delay(DELAY);
	}

	return 0;
}
int main(int argc, char **argv) {
	setvbuf(stdout, NULL, _IONBF, 0); // needed to print to the command line

	int x;
	int a;

	// initialise the servo pi on I2C address 0x40 with the Output Enable pin enabled.
	// Check the returned value to ensure the Servo Pi initialised correctly

	a = servopi_init(0x40, 1);
	if (a != 0) {
		if (a == 1) {
			printf("Error enabling GPIO Pin");
		}
		if (a == 2) {
			printf("Error setting GPIO Pin direction");
		}
		return (0);
	}

	//Set PWM frequency to 60 Hz and enable the output
	set_pwm_freq(60, 0x40);
	output_enable();

	while (1) {
		set_pwm(1, 0, servoMin, 0x40); // set the pwm width to servoMin
		usleep(500000); // sleep 0.5 seconds
		set_pwm(1, 0, servoMed, 0x40); // set the pwm width to servoMed
		usleep(500000); // sleep 0.5 seconds
		set_pwm(1, 0, servoMax, 0x40); // set the pwm width to servoMax
		usleep(500000); // sleep 0.5 seconds
	}

	return (0);
}
Ejemplo n.º 3
0
void read_lock(uint8_t *lock)
{
	load_command(appc_read_fuse_n_lock_bits);
	output_enable();
	reset_bs2();
	set_byte_high();
	*lock = data_in();
	output_disable();
}
Ejemplo n.º 4
0
void read_cali(uint8_t *cali)
{
	load_command(appc_read_sig_bytes_n_cali_byte);

	load_address_low_byte(0);
	output_enable();
	set_byte_high();
	*cali = data_in();
	output_disable();
}
Ejemplo n.º 5
0
int pd_set_power_supply_ready(int port)
{
	/* fault condition not cleared : do not turn on power */
	if ((fault != FAULT_OK) || discharge_is_enabled())
		return EC_ERROR_INVAL;

	output_enable();
	/* Over-current monitoring */
	adc_enable_watchdog(ADC_CH_A_SENSE, MAX_CURRENT_FAST, 0);

	return EC_SUCCESS; /* we are ready */
}
Ejemplo n.º 6
0
uint8_t read_eeprom(uint16_t addr)
{
	uint8_t data;

	load_command(appc_read_eeprom);
	load_address_high_byte(addr >> 8);
	load_address_low_byte(addr & 0xFF);
	output_enable();
	set_byte_low();
	data = data_in();
	output_disable();

	return data;
}
Ejemplo n.º 7
0
void read_sign(uint8_t *msb, uint8_t *csb, uint8_t *lsb)
{
	load_command(appc_read_sig_bytes_n_cali_byte);
	//load_address_high_byte(0); // TODO

	load_address_low_byte(0);
	output_enable();
	set_byte_low();
	*msb = data_in();
	output_disable();

	load_address_low_byte(1);
	output_enable();
	set_byte_low();
	*csb = data_in();
	output_disable();

	load_address_low_byte(2);
	output_enable();
	set_byte_low();
	*lsb = data_in();
	output_disable();
}
Ejemplo n.º 8
0
void read_fuse(uint8_t *efuse, uint8_t *hfuse, uint8_t *lfuse)
{
	load_command(appc_read_fuse_n_lock_bits);
	output_enable();
	reset_bs2();
	set_byte_low();
	*lfuse = data_in();
	set_bs2();
	set_byte_high();
	*hfuse = data_in();
	set_bs2();
	set_byte_low();
	*efuse = data_in();
	output_disable();
}
Ejemplo n.º 9
0
uint16_t read_pgm_mem_word(uint16_t waddr)
{
	uint16_t word;

	load_command(appc_read_flash);
	load_address_high_byte(waddr >> 8);
	load_address_low_byte(waddr & 0xFF);
	output_enable();
	set_byte_low();
	word = data_in();
	set_byte_high();
	word |= data_in() << 8;
	output_disable();

	return word;
}
Ejemplo n.º 10
0
int main(int argc, char **argv) {
	setvbuf(stdout, NULL, _IONBF, 0); // needed to print to the command line

	int x;
	int a;

	// initialise the servo pi on I2C address 0x40 with the Output Enable pin enabled.
	// Check the returned value to ensure the Servo Pi initialised correctly

	a = servopi_init(0x40, 1);
	if (a != 0){
		if (a == 1){
			printf("Error enabling GPIO Pin");
		}
		if (a == 2){
			printf("Error setting GPIO Pin direction");
		}
		return (0);
	}

	//Set PWM frequency to 1 Khz and enable the output
	set_pwm_freq(1000, 0x40);
	output_enable();



	while (1) {
		for (x = 1; x <= 4095; x = x + 5) {
			set_pwm(1, 0, x, 0x40); // set the pwm width to x
		}

		for (x = 4095; x >= 0; x = x - 5) {
			set_pwm(1, 0, x, 0x40); // set the pwm width to x
		}

	}

	return (0);
}
Ejemplo n.º 11
0
//
// set pixel at (x, y) to val (1 = on, 0 = off)
//
//	note:  top left is (0, 0) and bottom right is (4, 4).
//
void setpixel(uint8_t x, uint8_t y, uint8_t val)
{
	uint8_t n, b;
	uint8_t hi, lo;
	
	//n = x + 5*y;
	n = x + (y<<2) + y;		// equivalent to "n = x + 5*y" but avoids mult operation (attiny doesn't have MUL!)
	
	b = LEDS[n];			// get hi,lo nibbles from LED lookup table
	hi = UNPACKH(b);
	lo = UNPACKL(b);

	
	// enable/disable the high pin
	switch (hi) {
	case A:
		if (val) {
			output_enable(A_LINE);
			output_high(A_LINE);
		} else {
			output_low(A_LINE);
			output_disable(A_LINE);
		}
		break;
		
	case B:
		if (val) {
			output_enable(B_LINE);
			output_high(B_LINE);
		} else {
			output_low(B_LINE);
			output_disable(B_LINE);
		}
		break;
		
	case C:
		if (val) {
			output_enable(C_LINE);
			output_high(C_LINE);
		} else {
			output_low(C_LINE);
			output_disable(C_LINE);
		}
		break;
		
	case D:
		if (val) {
			output_enable(D_LINE);
			output_high(D_LINE);
		} else {
			output_low(D_LINE);
			output_disable(D_LINE);
		}
		break;
		
	case E:
		if (val) {
			output_enable(E_LINE);
			output_high(E_LINE);
		} else {
			output_low(E_LINE);
			output_disable(E_LINE);
		}
		break;
		
	case F:
		if (val) {
			output_enable(F_LINE);
			//output_high(F_LINE);
			output_low(F_LINE);			// XXX hack for V0.9 board - F_LINE is ALWAYS low
		} else {
			//output_low(F_LINE);
			output_disable(F_LINE);
		}
		break;
		
	}


	// low pin
	switch (lo) {
	case A:
		if (val) {
			output_enable(A_LINE);
			output_low(A_LINE);
		} else {
			output_disable(A_LINE);
		}
		break;
		
	case B:
		if (val) {
			output_enable(B_LINE);
			output_low(B_LINE);
		} else {
			output_disable(B_LINE);
		}
		break;
		
	case C:
		if (val) {
			output_enable(C_LINE);
			output_low(C_LINE);
		} else {
			output_disable(C_LINE);
		}
		break;
		
	case D:
		if (val) {
			output_enable(D_LINE);
			output_low(D_LINE);
		} else {
			output_disable(D_LINE);
		}
		break;
		
	case E:
		if (val) {
			output_enable(E_LINE);
			output_low(E_LINE);
		} else {
			output_disable(E_LINE);
		}
		break;
#ifdef NOTDEF
	// note: this case does not occur!
	case F:
		if (val) {
			output_enable(F_LINE);
			output_low(F_LINE);
		} else {
			output_disable(F_LINE);
		}
		break;
#endif		
	}
}