Ejemplo n.º 1
0
/**
 * @brief Set the default register settings
 * @return 0 if successful, -1 if not
 */
static int32_t PIOS_BMA180_Config() 
{
	/*
	0x35 = 0x81  //smp-skip = 1 for less interrupts
	0x33 = 0x81  //shadow-dis = 1, update MSB and LSB synchronously
	0x27 = 0x01  //dis-i2c
	0x21 = 0x02  //new_data_int = 1
	 */
		
	PIOS_DELAY_WaituS(20);

	if(PIOS_BMA180_Validate(dev) != 0) 
		return -1;

	while(PIOS_BMA180_EnableEeprom() != 0);
	while(PIOS_BMA180_SetReg(BMA_RESET, BMA_RESET_CODE) != 0);
	while(PIOS_BMA180_SetReg(BMA_OFFSET_LSB1, 0x81) != 0);
	while(PIOS_BMA180_SetReg(BMA_GAIN_Y, 0x81) != 0);
	while(PIOS_BMA180_SetReg(BMA_CTRREG3, 0xFF) != 0);
	while(PIOS_BMA180_SelectBW(dev->cfg->bandwidth) != 0);
	while(PIOS_BMA180_SetRange(dev->cfg->range) != 0);
	while(PIOS_BMA180_DisableEeprom() != 0);

	return 0;
}
Ejemplo n.º 2
0
int32_t PIOS_USB_Reenumerate()
{
    /* Force USB reset and power-down (this will also release the USB pins for direct GPIO control) */
    _SetCNTR(CNTR_FRES | CNTR_PDWN);

    /* Using a "dirty" method to force a re-enumeration: */
    /* Force DPM (Pin PA12) low for ca. 10 mS before USB Tranceiver will be enabled */
    /* This overrules the external Pull-Up at PA12, and at least Windows & MacOS will enumerate again */
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_StructInit(&GPIO_InitStructure);
    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_12;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    PIOS_DELAY_WaitmS(50);

    /* Release power-down, still hold reset */
    _SetCNTR(CNTR_PDWN);
    PIOS_DELAY_WaituS(5);

    /* CNTR_FRES = 0 */
    _SetCNTR(0);

    /* Clear pending interrupts */
    _SetISTR(0);

    /* Configure USB clock */
    /* USBCLK = PLLCLK / 1.5 */
    RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
    /* Enable USB clock */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);

    return 0;
}
Ejemplo n.º 3
0
/**
* Trigger sonar sensor
*/
void PIOS_HCSR04_Trigger(void)
{
	CapCounter=0;
	PIOS_HCSR04_TRIG_GPIO_PORT->BSRR = PIOS_HCSR04_TRIG_PIN;
	PIOS_DELAY_WaituS(15);
	PIOS_HCSR04_TRIG_GPIO_PORT->BRR = PIOS_HCSR04_TRIG_PIN;
	TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE);
}
Ejemplo n.º 4
0
/**
 * Waits for a specific number of mS
 *
 * Example:<BR>
 * \code
 *   // Wait for 500 mS
 *   PIOS_DELAY_Wait_mS(500);
 * \endcode
 * \param[in] mS delay (1..65535 milliseconds)
 * \return < 0 on errors
 */
int32_t PIOS_DELAY_WaitmS(uint32_t mS)
{
	while (mS--) {
		PIOS_DELAY_WaituS(1000);
	}

	/* No error */
	return 0;
}
Ejemplo n.º 5
0
/**
* Waits for a specific number of mS<BR>
* Example:<BR>
* \code
*   // Wait for 500 mS
*   PIOS_DELAY_Wait_mS(500);
* \endcode
* \param[in] mS delay (1..65535 milliseconds)
* \return < 0 on errors
*/
int32_t PIOS_DELAY_WaitmS(uint16_t mS)
{
	for(int i = 0; i < mS; i++) {
		PIOS_DELAY_WaituS(1000);
	}

	/* No error */
	return 0;
}
Ejemplo n.º 6
0
/**
 * @brief Initialize the flash object setting FS
 * @return 0 if success, -1 if failure
 */
int32_t PIOS_FLASHFS_Init()
{

	// Check for valid object table or create one
	uint32_t object_table_magic;
	uint32_t magic_fail_count = 0;
	bool magic_good = false;

	while(!magic_good) {
		if (PIOS_Flash_W25X_ReadData(0, (uint8_t *)&object_table_magic, sizeof(object_table_magic)) != 0)
			return -1;
		if(object_table_magic != OBJECT_TABLE_MAGIC) {
			if(magic_fail_count++ > MAX_BADMAGIC) {
				PIOS_FLASHFS_ClearObjectTableHeader();
				PIOS_LED_Toggle(LED1);
				magic_fail_count = 0;
				magic_good = true;
			} else {
				PIOS_DELAY_WaituS(1000);
			}

		}
		else {
			magic_good = true;
		}

	}

	int32_t addr = OBJECT_TABLE_START;
	struct objectHeader header;
	numObjects = 0;

	// Loop through header area while objects detect to count how many saved
	while(addr < OBJECT_TABLE_END) {
		// Read the instance data
		if (PIOS_Flash_W25X_ReadData(addr, (uint8_t *)&header, sizeof(header)) != 0)
			return -1;

		// Counting number of valid headers
		if(header.objMagic != OBJ_MAGIC)
			break;

		numObjects++;
		addr += sizeof(header);
	}

	return 0;
}
Ejemplo n.º 7
0
/**
 * @brief Initialize with good default settings
 * @returns 0 for success, -1 for failure
 */
int32_t PIOS_BMA180_Init(uint32_t spi_id, uint32_t slave_num, const struct pios_bma180_cfg * cfg)
{	
	dev = PIOS_BMA180_alloc();
	if(dev == NULL)
		return -1;
		
	dev->spi_id = spi_id;
	dev->slave_num = slave_num;
	dev->cfg = cfg;
	
	if(PIOS_BMA180_Config() < 0)
		return -1;
	PIOS_DELAY_WaituS(50);
	
	PIOS_EXTI_Init(dev->cfg->exti_cfg);

	while(PIOS_BMA180_EnableIrq() != 0);
	
	return 0;
}