Esempio n. 1
0
void GSetDir (Environment *env){

	if(env->motors[0].deltaSteps >= 0) bcm2835_gpio_clr(X_DIR);
	else {bcm2835_gpio_set(X_DIR);env->motors[0].deltaSteps*=-1;}
	if(env->motors[1].deltaSteps >= 0) bcm2835_gpio_clr(Y_DIR);
	else {bcm2835_gpio_set(Y_DIR);env->motors[1].deltaSteps*=-1;}
	if(env->motors[2].deltaSteps >= 0) bcm2835_gpio_clr(Z_DIR);
	else {bcm2835_gpio_set(Z_DIR);env->motors[2].deltaSteps*=-1;}
}
Esempio n. 2
0
void _reset(void) {
	bcm2835_gpio_fsel(D_C, BCM2835_GPIO_FSEL_OUTP); // D/C
	bcm2835_gpio_fsel(RES, BCM2835_GPIO_FSEL_OUTP); // Reset
	bcm2835_gpio_set(D_C);

	bcm2835_gpio_clr(RES);   // Reset
	bcm2835_delay(100);
	bcm2835_gpio_set(RES);   // Reset off
	bcm2835_delay(100);
}
Esempio n. 3
0
void motorStart(int direction)
{
  if(direction)
  { // Forward
    bcm2835_gpio_set(MOTOR_A);
    bcm2835_gpio_clr(MOTOR_B);
  } else { // Backward
    bcm2835_gpio_set(MOTOR_B);
    bcm2835_gpio_clr(MOTOR_A);
  }
}
Esempio n. 4
0
const void setFakeOutput(bool red, bool yellow, bool green) {
  #ifdef BUILD_RPI
  if (red)    bcm2835_gpio_set(RPI_GPIO_RED);
  else        bcm2835_gpio_clr(RPI_GPIO_RED);
  
  if (yellow) bcm2835_gpio_set(RPI_GPIO_YELLOW);
  else        bcm2835_gpio_clr(RPI_GPIO_YELLOW);
  
  if (green)  bcm2835_gpio_set(RPI_GPIO_GREEN);
  else        bcm2835_gpio_clr(RPI_GPIO_GREEN);
  #endif
  return;
}
Esempio n. 5
0
void GStepper(Environment *env)
{
	// X Axis
    if(env->motors[0].step)	bcm2835_gpio_set(X_STEP);
    if(env->motors[1].step)	bcm2835_gpio_set(Y_STEP);
    if(env->motors[2].step)	bcm2835_gpio_set(Z_STEP);
	bcm2835_delayMicroseconds (200);
	bcm2835_gpio_clr(X_STEP);
    bcm2835_gpio_clr(Y_STEP);
    bcm2835_gpio_clr(Z_STEP);
    bcm2835_delayMicroseconds (200);

}
Esempio n. 6
0
//--------------------------------------------------------------------------------------------------
// Name:    	SpiPutc
// Function:  	Emulate SPI on GPIO (Bitbanging)
//            
// Parameter: 	Databyte to send
// Return:      -
//--------------------------------------------------------------------------------------------------
void SpiPutc(unsigned char d)
{
	int i,n;
	
	for(i=0;i<8;i++)
	{
		if(d & 0x80)	bcm2835_gpio_set(PIN_LCD_MOSI);		// MOSI = 1
			else		bcm2835_gpio_clr(PIN_LCD_MOSI);		// MOSI = 0
		d <<= 1;
		
		for(n=0;n<4;n++) bcm2835_gpio_clr(PIN_LCD_SCLK); 	// CLK = 0
		for(n=0;n<4;n++) bcm2835_gpio_set(PIN_LCD_SCLK);	// CLK = 1
	}
}
Esempio n. 7
0
void write_1602(unsigned char cmd)
{
	data_1602(cmd);
	bcm2835_gpio_set(RS_1602);
	bcm2835_gpio_clr(RW_1602);
	bcm2835_gpio_clr(EN_1602);
	/*gpio_set_value(RS_1602, 1);
	gpio_set_value(RW_1602, 0);
	gpio_set_value(EN_1602, 0);*/
	udelay(200);
	bcm2835_gpio_set(EN_1602);
	//gpio_set_value(EN_1602, 1);
	udelay(200);
}
Esempio n. 8
0
const void setFakeSignal(bool signal) {
  #ifdef BUILD_RPI
  if (signal)   bcm2835_gpio_set(RPI_GPIO_SIGNAL);
  else          bcm2835_gpio_clr(RPI_GPIO_SIGNAL);
  #endif
  return;
}
void lcdscreentimer::switchPower( bool switcherAutoState, bool switcherManuState )
{
  bool update = false;

  if( switcherAutoState!=m_lastSwitcherAutoState )
  {
    m_lastSwitcherAutoState = switcherAutoState;
    update = true;
  }
  if( switcherManuState!=m_lastSwitcherManuState )
  {
    m_lastSwitcherManuState = switcherManuState;
    update = true;
  }

  if( update )
  {
    bool state = m_lastSwitcherAutoState || m_lastSwitcherManuState;
    myprintf("switching %s!\n",state ? "On" : "Off");
    //QMessageBox::warning(0,"",state ? "On" : "Off");
#ifndef QT_EMULATION
    if( state )
    {
      bcm2835_gpio_clr(PIN_SWITCHER_OUT);
    }
    else
    {
      bcm2835_gpio_set(PIN_SWITCHER_OUT);
    }
#endif
  }
}
Esempio n. 10
0
// Set the state of an output
void bcm2835_gpio_write(uint8_t pin, uint8_t on)
{
    if (on)
	bcm2835_gpio_set(pin);
    else
	bcm2835_gpio_clr(pin);
}
Esempio n. 11
0
//--------------------------------------------------------------------------------------------------
// Name:    	SpiPutc
// Function:  	Emulate SPI on GPIO (Bitbanging)
//            
// Parameter: 	Databyte to send
// Return:      -
//--------------------------------------------------------------------------------------------------
void SpiPutc(unsigned char d)
{
#ifdef QT_EMULATION
  return; // QT-Simul!
#endif
  int i,n;

  for(i=0;i<8;i++)
  {
    if(d & 0x80)	bcm2835_gpio_set(PIN_LCD_MOSI);		// MOSI = 1
    else		bcm2835_gpio_clr(PIN_LCD_MOSI);		// MOSI = 0
    d <<= 1;

    for(n=0;n<4;n++) bcm2835_gpio_clr(PIN_LCD_SCLK); 	// CLK = 0
    for(n=0;n<4;n++) bcm2835_gpio_set(PIN_LCD_SCLK);	// CLK = 1
  }
}
Esempio n. 12
0
//--------------------------------------------------------------------------------------------------
// Name:    	SetBacklight
// Function:  	Hintergrundbeleuchtung
//            
// Parameter: 	0=Off 1=On
// Return:      -
//--------------------------------------------------------------------------------------------------
void SetBacklight(uint8 light)
{
#ifdef QT_EMULATION
  Qt_SetBacklight(light);
  return; // QT-Simul!
#endif
  if(light)	bcm2835_gpio_set(PIN_LCD_BACKLIGHT);
  else	bcm2835_gpio_clr(PIN_LCD_BACKLIGHT)	;
}
Esempio n. 13
0
static void set_shaker_on(int nr)
{
  
  
  if(shaker_block)  {
    return;
  }
  else  {
    time_t akt_time = time(NULL);
    if(difftime(akt_time, shaker_block_time) < DEF_SHAKER_BLOCK_TIME_SEC )
      return;
  }
  
  shaker_block |= nr;
  
  switch (nr)
  {
    case SHAKER_NUM1:
      
#ifdef USE_PORTEXPANDER  
      mcp23s17_set_pin(PORT_A, PIN0);
#else
      bcm2835_gpio_set(SHAKER1);
#endif
      break;
    case SHAKER_NUM2:
#ifdef USE_PORTEXPANDER  
      mcp23s17_set_pin(PORT_A, PIN1);
#else
      bcm2835_gpio_set(SHAKER2);
#endif
      break;
    case SHAKER_NUM1_NUM2:
#ifdef USE_PORTEXPANDER  
      mcp23s17_set_pin(PORT_A, PIN0);
      mcp23s17_set_pin(PORT_A, PIN1);
#else
      bcm2835_gpio_set(SHAKER1);
      bcm2835_gpio_set(SHAKER2);
#endif
      break;
  }

}
Esempio n. 14
0
void dmx_data_send(const uint8_t *data, const uint16_t length)
{
	BCM2835_PL011->LCRH = PL011_LCRH_WLEN8 | PL011_LCRH_STP2 | PL011_LCRH_BRK;
	// DEBUG
	bcm2835_gpio_clr(ANALYZER_CH1); // IDLE
	bcm2835_gpio_set(ANALYZER_CH2); // BREAK
	bcm2835_gpio_clr(ANALYZER_CH3);	// DATA
	bcm2835_gpio_clr(ANALYZER_CH4); // MAB
	udelay(88);						// Break Time
	BCM2835_PL011->LCRH = PL011_LCRH_WLEN8 | PL011_LCRH_STP2;
	// DEBUG
	bcm2835_gpio_clr(ANALYZER_CH1); // IDLE
	bcm2835_gpio_clr(ANALYZER_CH2); // BREAK
	bcm2835_gpio_clr(ANALYZER_CH3);	// DATA
	bcm2835_gpio_set(ANALYZER_CH4); // MAB
	udelay(8);						// Mark After Break
	// DEBUG
	bcm2835_gpio_clr(ANALYZER_CH1); // IDLE
	bcm2835_gpio_clr(ANALYZER_CH2); // BREAK
	bcm2835_gpio_set(ANALYZER_CH3);	// DATA
	bcm2835_gpio_clr(ANALYZER_CH4); // MAB
	uint16_t i =0;
	BCM2835_PL011->DR = 0;
	for (i = 0; i < length; i++)
	{
		while (1)
		{
			if ((BCM2835_PL011->FR & 0x20) == 0)
				break;
		}
		BCM2835_PL011->DR = data[i];
	}
	// DEBUG
	bcm2835_gpio_clr(ANALYZER_CH1); // IDLE
	bcm2835_gpio_clr(ANALYZER_CH2); // BREAK
	bcm2835_gpio_clr(ANALYZER_CH3);	// DATA
	bcm2835_gpio_clr(ANALYZER_CH4); // MAB
	while (1)
	{
		if ((BCM2835_PL011->FR & 0x20) == 0)
			break;
	}
	udelay(44);
}
Esempio n. 15
0
void command_1602(unsigned char cmd)
{
	data_1602(cmd);
	bcm2835_gpio_clr(RS_1602);
	bcm2835_gpio_clr(RW_1602);
	bcm2835_gpio_clr(EN_1602);
	udelay(200);
	bcm2835_gpio_set(EN_1602);
	udelay(200);
}
Esempio n. 16
0
static PyObject *
PyBCM2835_gpio_set(PyObject *self, PyObject *args)
{
	int pin;

	if (!PyArg_ParseTuple(args,"i",&pin)) {
		return NULL;
	}

	bcm2835_gpio_set(pin);

	Py_RETURN_NONE;
}
Esempio n. 17
0
static int __init leds_init(void)
{
    int ret;

    ret = misc_register(&misc);

    bcm2835_gpio_fsel(PIN,BCM2835_GPIO_FSEL_OUTP);

    bcm2835_gpio_set(PIN);

    printk("leds init.\n");

    return ret;
}
Esempio n. 18
0
int notmain(unsigned int earlypc) {
#ifdef ENABLE_FRAMEBUFFER
	fb_init();

	printf("Compiled on %s at %s\n", __DATE__, __TIME__);
	printf("DMX512 Sender\n");
#endif

#ifdef BW_I2C_UI
#endif

	led_init();
	led_set(1);

	bcm2835_gpio_fsel(ANALYZER_CH1, BCM2835_GPIO_FSEL_OUTP); // IDLE
	bcm2835_gpio_fsel(ANALYZER_CH2, BCM2835_GPIO_FSEL_OUTP); // BREAK
	bcm2835_gpio_fsel(ANALYZER_CH3, BCM2835_GPIO_FSEL_OUTP); // DATA
	bcm2835_gpio_fsel(ANALYZER_CH4, BCM2835_GPIO_FSEL_OUTP); // MAB

	bcm2835_gpio_set(ANALYZER_CH1); // IDLE
	bcm2835_gpio_clr(ANALYZER_CH2);	// BREAK
	bcm2835_gpio_clr(ANALYZER_CH3); // DATA
	bcm2835_gpio_clr(ANALYZER_CH4);	// MAB

	bcm2835_pl011_dmx512_begin();
	bcm2835_gpio_fsel(18, BCM2835_GPIO_FSEL_OUTP);
	bcm2835_gpio_set(18);

	events_init();

	for (;;) {
		events_check();
	}

	return (0);
}
Esempio n. 19
0
uint8_t SlushMotor::SPIXfer(uint8_t data) {
	char dataPacket[1];

	dataPacket[0] = (char) data;

	bcm2835_spi_chipSelect(BCM2835_SPI_CS_NONE);
	bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_64);
	bcm2835_spi_setDataMode(BCM2835_SPI_MODE3);

	bcm2835_gpio_clr(m_nSpiChipSelect);
	bcm2835_spi_transfern(dataPacket, 1);
	bcm2835_gpio_set(m_nSpiChipSelect);

	return (uint8_t) dataPacket[0];
}
Esempio n. 20
0
// Writes an number of bytes to SPI
void spi_uart_tx(char c) {
	volatile uint32_t* paddr = bcm2835_spi0 + BCM2835_SPI0_CS/4;
	volatile uint32_t* fifo = bcm2835_spi0 + BCM2835_SPI0_FIFO/4;
	
	bcm2835_gpio_fsel(RPI_GPIO_P1_19, BCM2835_GPIO_FSEL_ALT0);
	
	//BUG: The start bit is always 1.5 periods long, probably unfixable
	
	// This is Polled transfer as per section 10.6.1
	// BUG ALERT: what happens if we get interupted in this section, and someone else
	// accesses a different peripheral?
	
	// Clear TX and RX fifos
	bcm2835_peri_set_bits(paddr, BCM2835_SPI0_CS_CLEAR, BCM2835_SPI0_CS_CLEAR);
	
	// Set TA = 1
	bcm2835_peri_set_bits(paddr, BCM2835_SPI0_CS_TA, BCM2835_SPI0_CS_TA);
	
		// Maybe wait for TXD
		while (!(bcm2835_peri_read(paddr) & BCM2835_SPI0_CS_TXD))
			;
		
		// Write to FIFO, no barrier
		bcm2835_peri_write_nb(fifo, reverse_bits(c));
		
		// Read from FIFO to prevent stalling
		while (bcm2835_peri_read(paddr) & BCM2835_SPI0_CS_RXD)
			(void) bcm2835_peri_read_nb(fifo);
// 		bcm2835_gpio_fsel(RPI_GPIO_P1_19, BCM2835_GPIO_FSEL_ALT0);
	
	// Wait for DONE to be set
	while (!(bcm2835_peri_read_nb(paddr) & BCM2835_SPI0_CS_DONE)) {
// 		while (bcm2835_peri_read(paddr) & BCM2835_SPI0_CS_RXD)
// 			(void) bcm2835_peri_read_nb(fifo);
	}
	
// 	bcm2835_delayMicroseconds(10);
	
	// Set TA = 0, and also set the barrier
	bcm2835_peri_set_bits(paddr, 0, BCM2835_SPI0_CS_TA);
	
	//TODO: THe program might be interrupted in here, corrupting the character.
	
	bcm2835_gpio_fsel(RPI_GPIO_P1_19, BCM2835_GPIO_FSEL_OUTP); // MOSI
	bcm2835_gpio_set(RPI_GPIO_P1_19); //idle high
	bcm2835_gpio_set_pud(RPI_GPIO_P1_19,BCM2835_GPIO_PUD_UP);
	bcm2835_delayMicroseconds(40);
}
Esempio n. 21
0
static void write_port(void *arg, long period)
{
  int n;

  for (n = 0; n < npins; n++) {
    if (exclude_map & RTAPI_BIT(n)) 
      continue;
    if (dir_map & RTAPI_BIT(n)) {
      if (*(port_data[n])) { 
	bcm2835_gpio_set(gpios[n]);
      } else {
	bcm2835_gpio_clr(gpios[n]);
      }
    }
  }
}
Esempio n. 22
0
static int leds_ioctl(struct file *filp,unsigned int cmd, unsigned long arg)
{
    switch(cmd)
    {
	case 0:
	    bcm2835_gpio_clr(PIN);
	    printk("LED OFF\n");
	    break;
	case 1:
	    bcm2835_gpio_set(PIN);
	    printk("LED ON\n");
	    break;
	default:
	    return -EINVAL;
    }
    return 0;
}
Esempio n. 23
0
void data_1602(unsigned char data_v)
{
	if(data_v & 0x01)	bcm2835_gpio_set(D0_1602);
	else				bcm2835_gpio_clr(D0_1602);
	if(data_v & 0x02)	bcm2835_gpio_set(D1_1602);
	else				bcm2835_gpio_clr(D1_1602);
	if(data_v & 0x04)	bcm2835_gpio_set(D2_1602);
	else				bcm2835_gpio_clr(D2_1602);
	if(data_v & 0x08)	bcm2835_gpio_set(D3_1602);
	else				bcm2835_gpio_clr(D3_1602);
	if(data_v & 0x10)	bcm2835_gpio_set(D4_1602);
	else				bcm2835_gpio_clr(D4_1602);
	if(data_v & 0x20)	bcm2835_gpio_set(D5_1602);
	else				bcm2835_gpio_clr(D5_1602);
	if(data_v & 0x40)	bcm2835_gpio_set(D6_1602);
	else				bcm2835_gpio_clr(D6_1602);
	if(data_v & 0x80)	bcm2835_gpio_set(D7_1602);
	else				bcm2835_gpio_clr(D7_1602);	
	
}
Esempio n. 24
0
int max98306_set_volume(int value) {

	int volume;
	int gain_setting,gain_prime_setting;

	/*
				GAIN		GAIN_PRIME
		0 = shutdown
		1 =  6dB	FLOATING	FLOATING
		2 =  9dB	FLOATING	HIGH
		3 = 12dB	HIGH		FLOATING
		4 = 15dB	FLOATING	LOW
		5 = 18dB	LOW		FLOATING
	*/

	if (value<0) volume=0;
	else if (value>5) volume=5;
	else volume=value;

	if (volume==0) {
		max98306_disable();
		return 0;
	}

	/* in case we had been disabled */
	max98306_enable();

	switch(volume) {
		case 1:	/*  6dB	FLOATING	FLOATING	*/
			gain_setting=GAIN_FLOAT;
			gain_prime_setting=GAIN_FLOAT;
			break;
		case 2: /*  9dB	FLOATING	HIGH		*/
			gain_setting=GAIN_FLOAT;
			gain_prime_setting=GAIN_HIGH;
			break;
		case 3: /* 12dB	HIGH		FLOATING	*/
			gain_setting=GAIN_HIGH;
			gain_prime_setting=GAIN_FLOAT;
			break;
		case 4: /* 15dB	FLOATING	LOW		*/
			gain_setting=GAIN_FLOAT;
			gain_prime_setting=GAIN_LOW;
			break;
		case 5: /* 18dB	LOW		FLOATING	*/
			gain_setting=GAIN_LOW;
			gain_prime_setting=GAIN_FLOAT;
			break;
		default:
			fprintf(stderr,"Unknown volume %d\n",volume);
			return -1;
	}

	/* Set GAIN value */
	if (gain_setting==GAIN_FLOAT) {
		/* Set float by setting !OE high*/
		bcm2835_gpio_set(GAIN_GPIO_EN);
	}
	else {
		bcm2835_gpio_clr(GAIN_GPIO_EN);
		if (gain_setting==GAIN_HIGH) {
			bcm2835_gpio_set(GAIN_GPIO);
		}
		else {
			bcm2835_gpio_clr(GAIN_GPIO);
		}
	}

	/* Set GAIN_PRIME value */
	if (gain_prime_setting==GAIN_FLOAT) {
		/* Set float by setting !OE high*/
		bcm2835_gpio_set(GAIN_PRIME_GPIO_EN);
	}
	else {
		bcm2835_gpio_clr(GAIN_PRIME_GPIO_EN);
		if (gain_prime_setting==GAIN_HIGH) {
			bcm2835_gpio_set(GAIN_PRIME_GPIO);
		}
		else {
			bcm2835_gpio_clr(GAIN_PRIME_GPIO);
		}

	}

	return 0;
}
Esempio n. 25
0
int max98306_enable(void) {

	 bcm2835_gpio_set(SHUTDOWN_GPIO);

	return 0;
}
Esempio n. 26
0
//--------------------------------------------------------------------------------------------------
// Name:    	SetBacklight
// Function:  	Hintergrundbeleuchtung
//            
// Parameter: 	0=Off 1=On
// Return:      -
//--------------------------------------------------------------------------------------------------
void SetBacklight(uint8 light)
{
	if(light)	bcm2835_gpio_set(PIN_LCD_BACKLIGHT);
		else	bcm2835_gpio_clr(PIN_LCD_BACKLIGHT)	;
}
Esempio n. 27
0
void SparkFunDmx::ReadConfigFiles(void) {
	DEBUG_ENTRY;

	m_bIsSpiCsSet = false;
	m_bIsResetSet = false;
	m_bIsBusyPinSet = false;

	ReadConfigFile configfile(SparkFunDmx::staticCallbackFunction, this);

	if (configfile.Read("sparkfun.txt")) {
#ifndef NDEBUG
		printf("\'sparkfun.txt\' (global settings):\n");

		if (m_bIsSpiCsSet) {
			printf("\tSPI CS : %d\n", m_nSpiCs);
		}

		if (m_bIsResetSet) {
			printf("\tReset pin: %d\n", m_nResetPin);
		}

		if (m_bIsBusyPinSet) {
			printf("\tBusy pin: %d\n", m_nBusyPin);
		}
#endif
	}

	if (!m_bIsResetSet) {
		m_nResetPin = GPIO_RESET_OUT;
		m_bIsResetSet = true;
#ifndef NDEBUG
		printf("\tReset pin: %d\n", m_nResetPin);
#endif
	}

	if (m_bIsBusyPinSet) {
		bcm2835_gpio_fsel(m_nBusyPin, BCM2835_GPIO_FSEL_INPT);
	}

	bcm2835_gpio_fsel(m_nResetPin, BCM2835_GPIO_FSEL_OUTP);
	bcm2835_gpio_set(m_nResetPin);

	bcm2835_gpio_clr(m_nResetPin);
	udelay(10000);
	bcm2835_gpio_set(m_nResetPin);
	udelay(10000);

	bcm2835_spi_begin();

	char fileName[] = "motor%.txt";

	for (int i = 0; i < SPARKFUN_DMX_MAX_MOTORS; i++) {

		fileName[5] = (char) i + '0';

		m_bIsPositionSet = false;

		if (configfile.Read(fileName)) {
#ifndef NDEBUG
			printf("Motor %d:\n", i);
#endif
			if (m_bIsPositionSet && m_bIsSpiCsSet) {
#ifndef NDEBUG
				printf("\t%s=%d\n", SPARKFUN_PARAMS_POSITION, m_nPosition);
				printf("\t%s=%d\n", SPARKFUN_PARAMS_SPI_CS, m_nSpiCs);
				printf("\t%s=%d\n", SPARKFUN_PARAMS_RESET_PIN, m_nResetPin);
				if(m_bIsBusyPinSet) {
					printf("\t%s=%d\n", SPARKFUN_PARAMS_BUSY_PIN, m_nBusyPin);
				}
				printf("\t-----------------------------\n");
				printf("\t%s=%d (DMX footprint=%d)\n", PARAMS_DMX_MODE, m_nDmxMode, L6470DmxModes::GetDmxFootPrintMode(m_nDmxMode));
				printf("\t%s=%d\n", PARAMS_DMX_START_ADDRESS, m_nDmxStartAddressMode);
				printf("\t=============================\n");
#endif
				if ((m_nDmxStartAddressMode <= DMX_MAX_CHANNELS) && (L6470DmxModes::GetDmxFootPrintMode(m_nDmxMode) != 0)) {

					if (m_bIsBusyPinSet) {
						m_pAutoDriver[i] = new AutoDriver(m_nPosition, m_nSpiCs, m_nResetPin, m_nBusyPin);
					} else {
						m_pAutoDriver[i] = new AutoDriver(m_nPosition, m_nSpiCs, m_nResetPin);
					}

					assert(m_pAutoDriver[i] != 0);

					if (m_pAutoDriver[i] != 0) {
						if (m_pAutoDriver[i]->IsConnected()) {
							m_pAutoDriver[i]->setMotorNumber(i);
							m_pAutoDriver[i]->Dump();

							m_pMotorParams[i] = new MotorParams(fileName);
							assert(m_pMotorParams[i] != 0);
							m_pMotorParams[i]->Dump();
							m_pMotorParams[i]->Set(m_pAutoDriver[i]);

							L6470Params l6470Params(fileName);
							l6470Params.Dump();
							l6470Params.Set(m_pAutoDriver[i]);

							m_pAutoDriver[i]->Dump();

							m_pModeParams[i] = new ModeParams(fileName);
							assert(m_pModeParams[i] != 0);
							m_pModeParams[i]->Dump();

							m_pL6470DmxModes[i] = new L6470DmxModes((TL6470DmxModes) m_nDmxMode, m_nDmxStartAddressMode, m_pAutoDriver[i], m_pMotorParams[i], m_pModeParams[i]);
							assert(m_pL6470DmxModes[i] != 0);

							if (m_pL6470DmxModes[i] != 0) {
								if (m_nDmxStartAddress == DMX_ADDRESS_INVALID) {
									m_nDmxStartAddress = m_pL6470DmxModes[i]->GetDmxStartAddress();
									m_nDmxFootprint = m_pL6470DmxModes[i]->GetDmxFootPrint();
								} else {
									const uint16_t nDmxChannelLastCurrent = m_nDmxStartAddress + m_nDmxFootprint;
									m_nDmxStartAddress = MIN(m_nDmxStartAddress, m_pL6470DmxModes[i]->GetDmxStartAddress());

									const uint16_t nDmxChannelLastNew = m_nDmxStartAddressMode + m_pL6470DmxModes[i]->GetDmxFootPrint();
									m_nDmxFootprint = MAX(nDmxChannelLastCurrent, nDmxChannelLastNew) - m_nDmxStartAddress;
								}
#ifndef NDEBUG
								printf("DMX Mode: %d, DMX Start Address: %d\n", m_pL6470DmxModes[i]->GetMode(), m_pL6470DmxModes[i]->GetDmxStartAddress());
								printf("DMX Start Address:%d, DMX Footprint:%d\n", (int) m_nDmxStartAddress, (int) m_nDmxFootprint);
#endif
							}
						} else {
							delete m_pAutoDriver[i];
							m_pAutoDriver[i] = 0;
							printf("Communication issues; check SPI configuration and cables\n");
						}
					} else {
						printf("Internal error!\n");
					}
				}
			} else {
				if(!m_bIsPositionSet) {
					printf("Missing %s=\n", SPARKFUN_PARAMS_POSITION);
				}
				if(!m_bIsSpiCsSet) {
					printf("Missing %s=\n", SPARKFUN_PARAMS_SPI_CS);
				}
			}
#ifndef NDEBUG
			printf("Motor %d: --------- end ---------\n", i);
#endif
		} else {
#ifndef NDEBUG
			printf("Configuration file : %s not found\n", fileName);
#endif
		}
	}

	for (int i = 0; i < SPARKFUN_DMX_MAX_MOTORS; i++) {
		if (m_pL6470DmxModes[i] != 0) {
			m_pL6470DmxModes[i]->InitSwitch();
		}
	}

	for (int i = 0; i < SPARKFUN_DMX_MAX_MOTORS; i++) {
		if (m_pAutoDriver[i] != 0) {
			while (m_pAutoDriver[i]->busyCheck())
				;
		}
	}

	for (int i = 0; i < SPARKFUN_DMX_MAX_MOTORS; i++) {
		if (m_pL6470DmxModes[i] != 0) {
			m_pL6470DmxModes[i]->InitPos();
		}
	}

#ifndef NDEBUG
	printf("Motors connected : %d\n", (int) AutoDriver::getNumBoards());
#endif
	DEBUG_EXIT;
}
//void bcm2835_gpio_set(uint8_t pin);
/// Call bcm2835_gpio_set with 1 parameter
/// \par            Refer
/// \par            Modify
void ope_gpio_set(void)
{
    get_byte_code();
    bcm2835_gpio_set( *((uint8_t *)(buff+1)) );
}
Esempio n. 29
0
void motorStop()
{
  // Stop motor
  bcm2835_gpio_set(MOTOR_A);
  bcm2835_gpio_set(MOTOR_B);
}
Esempio n. 30
0
int main(int argc, char **argv)
{

    int i;

    if (!bcm2835_init())
        return 1;

    // Set the pins to be an output
    bcm2835_gpio_fsel(PIN0, BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_fsel(PIN1, BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_fsel(PIN2, BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_fsel(PIN3, BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_fsel(PIN4, BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_fsel(PIN5, BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_fsel(PIN6, BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_fsel(PIN7, BCM2835_GPIO_FSEL_OUTP);

    while(1)
    {
        bcm2835_gpio_set(PIN0);
        bcm2835_delay(500);
        bcm2835_gpio_clr(PIN0);
        bcm2835_delay(500);

        bcm2835_gpio_set(PIN1);
        bcm2835_delay(500);
        bcm2835_gpio_clr(PIN1);
        bcm2835_delay(500);
        bcm2835_gpio_set(PIN2);
        bcm2835_delay(500);
        bcm2835_gpio_clr(PIN2);
        bcm2835_delay(500);

        bcm2835_gpio_set(PIN3);
        bcm2835_delay(500);
        bcm2835_gpio_clr(PIN3);
        bcm2835_delay(500);

        bcm2835_gpio_set(PIN4);
        bcm2835_delay(500);
        bcm2835_gpio_clr(PIN4);
        bcm2835_delay(500);

        bcm2835_gpio_set(PIN5);
        bcm2835_delay(500);
        bcm2835_gpio_clr(PIN5);
        bcm2835_delay(500);

        bcm2835_gpio_set(PIN6);
        bcm2835_delay(500);
        bcm2835_gpio_clr(PIN6);
        bcm2835_delay(500);

        bcm2835_gpio_set(PIN7);
        bcm2835_delay(500);
        bcm2835_gpio_clr(PIN7);
        bcm2835_delay(500);
    }

    bcm2835_close();
    return 0;
}