예제 #1
0
int main() {
	SystemInit();

	initSystick();
	initAccelerometer();
	initLeds();

	AccelerometerDataStruct dat;

	uint32_t lastTime = 0;

	while(1) {
		if (millisecondCounter > lastTime + 100) {
			readAxes(&dat);	// read sensor and store into `dat'
			setbuf(stdout, NULL);
			printf("X: %d Y: %d Z: %d\n", dat.X, dat.Y, dat.Z);	// the member variables for each direction
			lastTime = millisecondCounter;


			// Add extra logic here to light LEDs based on orientation of the board
			if(dat.X<-500){
			GPIOD->BSRRL|=(1<<12);
			GPIOD->BSRRH|=(1<<13);
			GPIOD->BSRRH|=(1<<14);
			GPIOD->BSRRH|=(1<<15);			
			}
			if(dat.Y<-500){
			GPIOD->BSRRL|=(1<<15);
			GPIOD->BSRRH|=(1<<12);
			GPIOD->BSRRH|=(1<<13);
			GPIOD->BSRRH|=(1<<14);
			}
			if(dat.Y>500){
			GPIOD->BSRRL|=(1<<13);
			GPIOD->BSRRH|=(1<<12);
			GPIOD->BSRRH|=(1<<14);
			GPIOD->BSRRH|=(1<<15);
			}
			if(dat.X>500){
			GPIOD->BSRRL|=(1<<14);
			GPIOD->BSRRH|=(1<<12);
			GPIOD->BSRRH|=(1<<13);
			GPIOD->BSRRH|=(1<<15);
			}

		}
	}
}
예제 #2
0
파일: sensors.cpp 프로젝트: cazacov/webdev
void Sensors::init(void) {
  Wire.begin();  
  initAccelerometer();
  initMagnetometer();
}
예제 #3
0
파일: hardware.cpp 프로젝트: jharvey/rusefi
void initHardware(Logging *l) {
	efiAssertVoid(CUSTOM_IH_STACK, getRemainingStack(chThdGetSelfX()) > 256, "init h");
	sharedLogger = l;
	engine_configuration_s *engineConfiguration = engine->engineConfigurationPtr;
	efiAssertVoid(CUSTOM_EC_NULL, engineConfiguration!=NULL, "engineConfiguration");
	board_configuration_s *boardConfiguration = &engineConfiguration->bc;

	printMsg(sharedLogger, "initHardware()");
	// todo: enable protection. it's disabled because it takes
	// 10 extra seconds to re-flash the chip
	//flashProtect();

	chMtxObjectInit(&spiMtx);

#if EFI_HISTOGRAMS
	/**
	 * histograms is a data structure for CPU monitor, it does not depend on configuration
	 */
	initHistogramsModule();
#endif /* EFI_HISTOGRAMS */

	/**
	 * We need the LED_ERROR pin even before we read configuration
	 */
	initPrimaryPins();

	if (hasFirmwareError()) {
		return;
	}

#if EFI_INTERNAL_FLASH

	palSetPadMode(CONFIG_RESET_SWITCH_PORT, CONFIG_RESET_SWITCH_PIN, PAL_MODE_INPUT_PULLUP);

	initFlash(sharedLogger);
	/**
	 * this call reads configuration from flash memory or sets default configuration
	 * if flash state does not look right.
	 */
	if (SHOULD_INGORE_FLASH()) {
		engineConfiguration->engineType = DEFAULT_ENGINE_TYPE;
		resetConfigurationExt(sharedLogger, engineConfiguration->engineType PASS_ENGINE_PARAMETER_SUFFIX);
		writeToFlashNow();
	} else {
		readFromFlash();
	}
#else
	engineConfiguration->engineType = DEFAULT_ENGINE_TYPE;
	resetConfigurationExt(sharedLogger, engineConfiguration->engineType PASS_ENGINE_PARAMETER_SUFFIX);
#endif /* EFI_INTERNAL_FLASH */

#if EFI_HD44780_LCD
//	initI2Cmodule();
	lcd_HD44780_init(sharedLogger);
	if (hasFirmwareError())
		return;

	lcd_HD44780_print_string(VCS_VERSION);

#endif /* EFI_HD44780_LCD */

	if (hasFirmwareError()) {
		return;
	}

#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
	initTriggerDecoder();
#endif

	bool isBoardTestMode_b;
	if (CONFIGB(boardTestModeJumperPin) != GPIO_UNASSIGNED) {
		efiSetPadMode("board test", CONFIGB(boardTestModeJumperPin),
		PAL_MODE_INPUT_PULLUP);
		isBoardTestMode_b = (!efiReadPin(CONFIGB(boardTestModeJumperPin)));

		// we can now relese this pin, it is actually used as output sometimes
		unmarkPin(CONFIGB(boardTestModeJumperPin));
	} else {
		isBoardTestMode_b = false;
	}

#if HAL_USE_ADC || defined(__DOXYGEN__)
	initAdcInputs(isBoardTestMode_b);
#endif

	if (isBoardTestMode_b) {
		// this method never returns
		initBoardTest();
	}

	initRtc();

	initOutputPins();

#if EFI_MAX_31855
	initMax31855(sharedLogger, getSpiDevice(CONFIGB(max31855spiDevice)), CONFIGB(max31855_cs));
#endif /* EFI_MAX_31855 */

#if EFI_CAN_SUPPORT
	initCan();
#endif /* EFI_CAN_SUPPORT */

//	init_adc_mcp3208(&adcState, &SPID2);
//	requestAdcValue(&adcState, 0);

#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
	// todo: figure out better startup logic
	initTriggerCentral(sharedLogger);
#endif /* EFI_SHAFT_POSITION_INPUT */

	turnOnHardware(sharedLogger);


#if HAL_USE_SPI || defined(__DOXYGEN__)
	initSpiModules(boardConfiguration);
#endif

#if EFI_HIP_9011 || defined(__DOXYGEN__)
	initHip9011(sharedLogger);
#endif /* EFI_HIP_9011 */

#if EFI_FILE_LOGGING || defined(__DOXYGEN__)
	initMmcCard();
#endif /* EFI_FILE_LOGGING */

#if EFI_MEMS || defined(__DOXYGEN__)
	initAccelerometer(PASS_ENGINE_PARAMETER_SIGNATURE);
#endif
//	initFixedLeds();


#if EFI_BOSCH_YAW || defined(__DOXYGEN__)
	initBoschYawRateSensor();
#endif /* EFI_BOSCH_YAW */

	//	initBooleanInputs();

#if EFI_UART_GPS || defined(__DOXYGEN__)
	initGps();
#endif

#if EFI_SERVO
	initServo();
#endif

#if ADC_SNIFFER || defined(__DOXYGEN__)
	initAdcDriver();
#endif

#if HAL_USE_I2C || defined(__DOXYGEN__)
	addConsoleActionII("i2c", sendI2Cbyte);
#endif


//	USBMassStorageDriver UMSD1;

//	while (true) {
//		for (int addr = 0x20; addr < 0x28; addr++) {
//			sendI2Cbyte(addr, 0);
//			int err = i2cGetErrors(&I2CD1);
//			print("I2C: err=%x from %d\r\n", err, addr);
//			chThdSleepMilliseconds(5);
//			sendI2Cbyte(addr, 255);
//			chThdSleepMilliseconds(5);
//		}
//	}

#if EFI_VEHICLE_SPEED || defined(__DOXYGEN__)
	initVehicleSpeed(sharedLogger);
#endif

#if EFI_CDM_INTEGRATION
	cdmIonInit();
#endif

#if HAL_USE_EXT || defined(__DOXYGEN__)
	initJoystick(sharedLogger);
#endif

	calcFastAdcIndexes();

	printMsg(sharedLogger, "initHardware() OK!");
}
예제 #4
0
int main(void) {
    SystemInit();
    SaLDelayInit();
    SalGclkInit();
    SaLRtcInit();
    PinConfig();
    uart_init(9600);
    //SaLTC4Init();
    sampleInit();
    adcInit();
    // UsbInit();
    // startUpTone();
    SaLBuzzerInit();



    struct IoDescriptor *UsartIoModule;
    struct IoDescriptor *UsartIoModuleUsb;

    struct AccelerometerModule myAccelerometer;

    SaLSyncUsartIo(&USART_0, &UsartIoModule);
    SaLSyncUsartIo(&USART_1, &UsartIoModuleUsb);

    initAccelerometer(&myAccelerometer);
    initBarometer();
    SaLFlashMemInit();


    volatile uint16_t ticks = 0;

    uint32_t lastTime = 0;
    //uint8_t message[255];
//     AT25SFErace4KBlock(0);
//     AT25SFWriteByte(0x00101,251);
//   volatile uint8_t byte = AT25SFGetByte(0x00101);

//     pinLow(CC1120_SLAVE_SELECT);
//     delay_ms(30);
//     pinHigh(CC1120_SLAVE_SELECT);
//     delay_ms(20);
//     pinLow(CC1120_SLAVE_SELECT);
//     delay_ms(30);
//     pinHigh(CC1120_SLAVE_SELECT);
//     delay_ms(20);

   // pinLow(CC1120_SLAVE_SELECT);
    //volatile uint8_t ccstatus = syncByte(CC1120_SCK ,CC1120_MOSI, CC1120_MISO, 0x80 | 0x30);
   // pinHigh(CC1120_SLAVE_SELECT);

    //delay_ms(200);

  //  pinLow(CC1120_SLAVE_SELECT);

    // while (pinRead(CC1120_MISO));
   // volatile uint8_t ccstatus2 = syncByte(CC1120_SCK ,CC1120_MOSI, CC1120_MISO, 0x80 | 0x3B);
   // volatile uint8_t ccstatus3 = getByte(CC1120_SCK_PIN,CC1120_MISO_PIN);
    // byteOut(CC1120_SCK_PIN,CC1120_MOSI_PIN, 0b10111101 );
  //  pinHigh(CC1120_SLAVE_SELECT);


    volatile float batt;

    //TC5->COUNT16.CTRLA.bit.ENABLE = 0;


   // TC5->COUNT16.CTRLBCLR.reg= TC_CTRLBCLR_CMD_RETRIGGER;

    while (1) {

        milliseconds = millis();

        sampleTick(); 
        batt = senseBatVolts(senseBat);
    }
}
예제 #5
0
int main(void) {
    /* Initialize the SAM system */
    SystemInit();

    SaLDelayInit();
    SalGclkInit();
    SaLRtcInit();
    // uart_init(9600);
    //SaLTC4Init();
    sampleInit();
    adcInit();

    pinOut(CC1120_SLAVE_SELECT);
    pinOut(AT25SF_SLAVE_SELECT);
    pinOut(MS5607_SLAVE_SELECT);
    pinOut(ADXL345_SLAVE_SELECT);
    // SaLPinMode(PIN_PA13,INPUT);

    // pinOut(MS5607_MOSI);
    // pinOut(MS5607_SCK);
    //pinIn(MS5607_MISO);




    pinHigh(CC1120_SLAVE_SELECT);
    pinHigh(AT25SF_SLAVE_SELECT);
    pinHigh(MS5607_SLAVE_SELECT);
    pinHigh(ADXL345_SLAVE_SELECT);



    pinOut(LedPin);
    pinHigh(LedPin);

    struct AccelerometerModule myAccelerometer;
    initAccelerometer(&myAccelerometer);
    initBarometer();
    //SaLFlashMemInit();



//     uint8_t message[255];
// // 	     AT25SFErace4KBlock(0);
// // 	     AT25SFWriteByte(0x00101,252);
// // 	   volatile uint8_t byte = AT25SFGetByte(0x00101);
//
//     pinLow(CC1120_SLAVE_SELECT);
//     volatile uint8_t ccstatus = syncByte(CC1120_SCK ,CC1120_MOSI, CC1120_MISO, 0x80 | 0x30);
//     pinHigh(CC1120_SLAVE_SELECT);
//
//     pinLow(CC1120_SLAVE_SELECT);
//
//     while (pinRead(CC1120_MISO));
//     volatile uint8_t ccstatus2 = syncByte(CC1120_SCK ,CC1120_MOSI, CC1120_MISO, 0x80 | 0x3B);
//     volatile uint8_t ccstatus3 = getByte(CC1120_SCK_PIN,CC1120_MISO_PIN);
//     // byteOut(CC1120_SCK_PIN,CC1120_MOSI_PIN, 0b10111101 );
//     pinHigh(CC1120_SLAVE_SELECT);

    volatile float batt;

    volatile float accelX;
    volatile float accelXOffset;

    for (uint8_t i = 0; i < 20; i++) {
        accelXOffset += (1.8 - (adcRead(ADXL278_ACCELX) * (3.60/2.0)/pow(2,12)))/((1.8-0.50)/70);
    }
	accelXOffset = accelXOffset / 20;

    while (1) {

        delay_ms(100);
        pinToggle(LedPin);

        sampleTick();
       // batt = senseBatVolts(senseBat);
        accelX = (1.8 - (adcRead(ADXL278_ACCELX) * (3.60/2.0)/pow(2,12)))/((1.8-0.50)/70) - accelXOffset;
       // batt = accelX;

    }
}