Пример #1
0
int main(void) {	
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	/* Init ONEWIRE port on PB4 pin */
	TM_OneWire_Init(&OW, GPIOB, GPIO_PIN_4);
	
	/* Check if any device is connected */
	if (TM_OneWire_First(&OW)) {
		/* Set LED GREEN */
		TM_DISCO_LedOn(LED_GREEN);
		
		/* Search for next devices */
		do {
			/* Read ROM from device */
			//TM_OneWire_GetFullROM(&OW, &array_8_bytes[0]);
		} while (TM_OneWire_Next(&OW));
	} else {
		/* Set LED RED */
		TM_DISCO_LedOn(LED_RED);
	}
	
	while (1) {

	}
}
Пример #2
0
int main(void) {
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize leds on board */
	TM_DISCO_LedInit();
	
	/* Initialize button */
	TM_DISCO_ButtonInit();
	
	/* Disable watchdog when we are in debug mode */
	DBGMCU->APB1FZ |= DBGMCU_IWDG_STOP;
	
	/* Initialize watchdog timer */
	/* Set timeout to 1s */
	/* If we are in debug mode, watchdog won't start even if we enable it */
	if (TM_WATCHDOG_Init(TM_WATCHDOG_Timeout_1s)) {
		/* System was reset by watchdog */
		TM_DISCO_LedOn(LED_RED);
	} else {
		/* System was not reset by watchdog */
		TM_DISCO_LedOn(LED_GREEN);
	}
	
	while (1) {
		/* If button is pressed, do nothing and system will be reset after 1 second */
		while (TM_DISCO_ButtonPressed());
		
		/* Reset watchdog */
		TM_WATCHDOG_Reset();
	}
}
Пример #3
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	/* Init USART, Pins not initialized yet, 921600 bauds */
	TM_USART_Init(USART6, TM_USART_PinsPack_Custom, 921600);
	
	/* Put test string */
	TM_USART_Puts(USART6, "Hello world\n");
	
	while (1) {
		/* Check if anything received */
		while (!TM_USART_BufferEmpty(USART6)) {
			/* Send data back from buffer */
			TM_USART_Putc(USART6, TM_USART_Getc(USART6));
		}
	}
}
Пример #4
0
int main(void) {
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize leds on board */
	TM_DISCO_LedInit();
	
	/* Initialize button */
	TM_DISCO_ButtonInit();
	
	/* Initialize watchdog timer */
	/* Set timeout to 1s */
	if (TM_WATCHDOG_Init(TM_WATCHDOG_Timeout_1s)) {
		/* System was reset by watchdog */
		TM_DISCO_LedOn(LED_RED);
	} else {
		/* System was not reset by watchdog */
		TM_DISCO_LedOn(LED_GREEN);
	}
	
	while (1) {
		/* If button is pressed, do nothing and system will be reset after 1 second */
		while (TM_DISCO_ButtonPressed());
		
		/* Reset watchdog */
		TM_WATCHDOG_Reset();
	}
}
Пример #5
0
int main(void) {
	//Initialize system
	SystemInit();
	//Initialize delay
	TM_DELAY_Init();
	//Initialize leds on board
	TM_DISCO_LedInit();
	//Initialize button
	TM_DISCO_ButtonInit();
	//Initialize watchdog timer
	//Set timeout to 1s
	if (TM_WATCHDOG_Init(TM_WATCHDOG_Timeout_1s)) {
		//System was reset by watchdog
		TM_DISCO_LedOn(LED_RED);
	} else {
		//System was not reset by watchdog
		TM_DISCO_LedOn(LED_GREEN);
	}
	
	while (1) {
		//if button is pressed, do nothing and system will be reset after 1 second
		while (TM_DISCO_ButtonPressed());
		
		//Reset watchdog
		TM_WATCHDOG_Reset();
	}
}
Пример #6
0
int main(void) {
    /* Init system clock for maximum system speed */
    TM_RCC_InitSystem();

    /* Init HAL layer */
    HAL_Init();

    /* Init leds */
    TM_DISCO_LedInit();

    /* Init button */
    TM_DISCO_ButtonInit();

    /* Initialize USART, TX: PB6, RX: PB7 */
    TM_USART_Init(USART1, TM_USART_PinsPack_2, 115200);

    /* Initialize NRF24L01+ on channel 15 and 32bytes of payload */
    /* By default 2Mbps data rate and 0dBm output power */
    /* NRF24L01 goes to RX mode by default */
    TM_NRF24L01_Init(15, 32);

    /* Set RF settings, Data rate to 2Mbps, Output power to -18dBm */
    TM_NRF24L01_SetRF(TM_NRF24L01_DataRate_2M, TM_NRF24L01_OutputPower_M18dBm);

    /* Set my address, 5 bytes */
    TM_NRF24L01_SetMyAddress(MyAddress);

    /* Set TX address, 5 bytes */
    TM_NRF24L01_SetTxAddress(TxAddress);

    while (1) {
        /* If data is ready on NRF24L01+ */
        if (TM_NRF24L01_DataReady()) {
            /* Get data from NRF24L01+ */
            TM_NRF24L01_GetData(dataIn);

            /* Start send */
            TM_DISCO_LedOn(LED_GREEN);

            /* Send it back, automatically goes to TX mode */
            TM_NRF24L01_Transmit(dataIn);

            /* Wait for data to be sent */
            do {
                /* Wait till sending */
                transmissionStatus = TM_NRF24L01_GetTransmissionStatus();
            } while (transmissionStatus == TM_NRF24L01_Transmit_Status_Sending);

            /* Send done */
            TM_DISCO_LedOff(LED_GREEN);

            /* Go back to RX mode */
            TM_NRF24L01_PowerUpRx();
        }
    }
}
Пример #7
0
int main(void) {
	uint16_t values[2] = {0, 0};
	
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	/* Init DAC channel 1 = PA4 */
	TM_DAC_Init(TM_DAC_Channel_1);
	
	/* Init DAC channel 2 = PA5 */
	TM_DAC_Init(TM_DAC_Channel_2);
	
	while (1) {
		/* Toggle ALL leds */
		if (TM_DELAY_Time() > 200) {	
			/* Toggle leds */
			TM_DISCO_LedToggle(LED_ALL);
		}
		
		/* Increase channel 1 value */
		values[0]++;
		
		/* Decrease channel 2 value */
		values[1]--;
		
		/* Check if channel 1 is overflowed 12 bit and set it to zero */
		if (values[0] > 0x0FFF) {
			values[0] = 0;
		}
		
		/* Check if channel 2 is less than zero (overflow to 0xFFFF) and set to to max 12 bit value */
		if (values[1] > 0x0FFF) {
			values[1] = 0x0FFF;
		}
		
		/* Set DAC channel 1 = PA4 */
		TM_DAC_SetValue(TM_DAC_Channel_1, values[0]);
		
		/* Set DAC channel 2 = PA5 */
		TM_DAC_SetValue(TM_DAC_Channel_2, values[1]);
		
		/* Delay 1ms */
		Delayms(1);
	}
}
Пример #8
0
int main(void) {	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initiaize button */
	TM_DISCO_ButtonInit();
	
	/* Initialize Leds */
	TM_DISCO_LedInit();
	
	/* Initialize USART, TX: PB10, RX: PB11 */
	TM_USART_Init(USART3, TM_USART_PinsPack_1, 115200);
	
	/* Initialize RTC with internal 32768Hz clock */
	/* It's not very accurate */
	if (!TM_RTC_Init(TM_RTC_ClockSource_Internal)) {
		/* RTC was first time initialized */
		/* Do your stuff here */
		/* eg. set default time */
	}
	
	/* Set wakeup interrupt every 125 ms */
	TM_RTC_Interrupts(TM_RTC_Int_125ms);
	
	while (1) {
		/* If button pressed */
		if (TM_DISCO_ButtonPressed()) {
			
			/* Subseconds are ignored when writing new time */
			
			datatime.hours = 0;
			datatime.minutes = 59;
			datatime.seconds = 55;
			datatime.year = 14;
			datatime.month = 6;
			datatime.date = 30;
			datatime.day = 6;
			
			/* Set new time */
			TM_RTC_SetDateTime(&datatime, TM_RTC_Format_BIN);
		}
	}
}
Пример #9
0
int main(void) {
	__IO uint32_t i;
	
	/* CPU load structure */
	TM_CPULOAD_t CPU_LOAD;
	
	/* Init CPU load monitor */
	TM_CPULOAD_Init(&CPU_LOAD);
	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize leds on board */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	/* Init USART2, TX: PA2, RX: PA3, 921600 bauds */
	TM_USART_Init(USART2, TM_USART_PinsPack_1, 921600);
	
	while (1) {
		/* Check if CPU LOAD variable is updated */
		if (CPU_LOAD.Updated) {
			/* Print to user */
			printf("W: %u; S: %u; Load: %5.2f\n", CPU_LOAD.WCNT, CPU_LOAD.SCNT, CPU_LOAD.Load);
		}
		
		/* Toggle leds */
		TM_DISCO_LedToggle(LED_ALL);
		
		/* If button pressed, do some useless counting */
		if (TM_DISCO_ButtonPressed()) {
			/* Count something to waste some time before entering to sleep mode */
			i = 0;
			while (i++ < 0x1FFF);
		}
		
		/* Go low power mode, sleep mode until interrupt, measure CPU load */
		TM_CPULOAD_GoToSleepMode(&CPU_LOAD, TM_LOWPOWERMODE_SleepUntilInterrupt);
	}
}
Пример #10
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize leds on board */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	/* Init USART6, TX: PC6, 921600 baud */
	TM_USART_Init(USART6, TM_USART_PinsPack_1, 921600);
	
	/* Get system reset source and clear flags after read */
	printf("System reset source: %d\n", (uint8_t)TM_GENERAL_GetResetSource(1));
	
	/* Get system reset source and clear flags after read */
	/* You should see number which corresponds to "None", because we cleared flags in statement above */
	printf("System reset source: %d\n", (uint8_t)TM_GENERAL_GetResetSource(1));
	
	/* Get system core and PCLK1 (Peripheral Clock 1, APB1) clocks */
	printf("System core clock: %u Hz; PCLK1 clock: %u Hz\n", 
		TM_GENERAL_GetClockSpeed(TM_GENERAL_Clock_SYSCLK),
		TM_GENERAL_GetClockSpeed(TM_GENERAL_Clock_PCLK1)
	);
	
	while (1) {
		/* If button pressed */
		if (TM_DISCO_ButtonOnPressed()) {
			/* Send to USER */
			printf("Software reset will happen in a moment\n");
			/* Wait a little */
			Delayms(500);
			/* Perform system software reset */
			TM_GENERAL_SystemReset();
		}
	}
}
Пример #11
0
int main(void) {	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initiaize button */
	TM_DISCO_ButtonInit();
	
	/* Initialize Leds */
	TM_DISCO_LedInit();
	
	/* Initialize RTC with internal 32768Hz clock */
	/* It's not very accurate */
	if (!TM_RTC_Init(TM_RTC_ClockSource_Internal)) {
		/* RTC was first time initialized */
		/* Do your stuff here */
		/* eg. set default time */
		
		/* Write data to backup register 4 */
		TM_RTC_WriteBackupRegister(4, 0x1244);
		
		/* Turn on RED led = Write operation */
		TM_DISCO_LedOn(LED_RED);
	} else {
		/* Try to read data back and check if it is OK */
		if (TM_RTC_ReadBackupRegister(4) == 0x1244) {
			/* Read OK after reset, turn on GREEN led */
			TM_DISCO_LedOn(LED_GREEN);
		}
	}
	
	/* If not leds ON, try to remove power from device first so RTC will need to initialize again */
	/* If still no leds after that, then you have problems with your RTC clock */
	
	while (1) {
		/* If button pressed */
		if (TM_DISCO_ButtonPressed()) {
			/* After button press, system will reset */
			NVIC_SystemReset();
		}
	}
}
Пример #12
0
int main(void) {
	/* Initialize System */
	SystemInit();
	
	/* Initialize leds on board */
	TM_DISCO_LedInit();
	/* Initialize button on board */
	TM_DISCO_ButtonInit();
	
    while(1) {
		/* If button pressed */
    	if (TM_DISCO_ButtonPressed()) {
			/* Turn on leds */
    		TM_DISCO_LedOn(LED_RED | LED_GREEN);
    	} else {
			/* Turn off leds */
    		TM_DISCO_LedOff(LED_RED | LED_GREEN);
    	}
    }
}
Пример #13
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	while (1) {
		/* Toggle leds */
		TM_DISCO_LedToggle(LED_ALL);
		
		/* Delay 500ms */
		Delayms(500);
	}
}
Пример #14
0
int main(void) {
    TM_RCC_InitSystem();                                    /* Init system */
    HAL_Init();                                             /* Init HAL layer */
    TM_DISCO_LedInit();                                     /* Init leds */
    TM_DISCO_ButtonInit();                                  /* Init button */
    TM_DELAY_Init();                                        /* Init delay */
    TM_USART_Init(DEBUG_USART, DEBUG_USART_PP, 921600);     /* Init USART for debug purpose */

    /* Print first screen message */
    printf("ESP8266 commands parser; Compiled: %s %s\r\n", __DATE__, __TIME__);

    /* Initialize threads */
    ESP_Update_ThreadId = osThreadCreate(osThread(ESP_Update), NULL);
    ESP_Main_ThreadId = osThreadCreate(osThread(ESP_Main), NULL);

    /* Start kernel */
    osKernelStart();
    
	while (1) {

	}
}
Пример #15
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	/* For pinouts, check TM_MPU6050 library */
	
	/* Try to init MPU6050, device address is 0xD0, AD0 pin is set to low */
	if (TM_MPU6050_Init(&MPU6050, TM_MPU6050_Device_0, TM_MPU6050_Accelerometer_8G, TM_MPU6050_Gyroscope_250s) == TM_MPU6050_Result_Ok) {
		/* Green LED on */
		TM_DISCO_LedOn(LED_GREEN);
	}
	
	while (1) {
		/* Read everything from device */
		TM_MPU6050_ReadAll(&MPU6050);
		
		/* Raw data are available for use as needed */
		//MPU6050.Accelerometer_X;
		//MPU6050.Accelerometer_Y;
		//MPU6050.Accelerometer_Z;
		//MPU6050.Gyroscope_X;
		//MPU6050.Gyroscope_Y;
		//MPU6050.Gyroscope_Z;
		//MPU6050.Temperature;
		
		/* Delay a little */
		Delayms(1);
	}
}
Пример #16
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	/* Check if system reset because of IWDG */
	if (TM_IWDG_Init(TM_IWDG_Timeout_4s)) {
		/* System reset was done because of IWDG timer */
		TM_DISCO_LedOn(LED_RED);
	} else {
		/* No IWDG */
		TM_DISCO_LedOn(LED_GREEN);
	}
	
	/* If there is no LED active (F7-Discovery, Nucleo boards), */
	/* then system reset occurred because of IWDG */
	
	while (1) {
		/* Check for button */
		if (TM_DISCO_ButtonPressed()) {
			/* Wait till pressed */
			/* If pressed more than 4 seconds in a row, system will reset because of IWDG timer */
			while (TM_DISCO_ButtonPressed());
		}
		
		/* Reset watchdog */
		TM_IWDG_Reset();
	}
}
Пример #17
0
int main(void) {
	/* Initialize System */
	SystemInit();
	
	/* Initialize leds on board */
	TM_DISCO_LedInit();
	
	/* Initialize button on board */
	TM_DISCO_ButtonInit();
	
    while(1) {
		/* If button pressed, do stuff all the time button is pressed */
    	if (TM_DISCO_ButtonPressed()) {
			/* Turn on leds */
    		TM_DISCO_LedOn(LED_RED | LED_GREEN);
    	} else {
			/* Turn off leds */
    		TM_DISCO_LedOff(LED_RED | LED_GREEN);
    	}
		
		/* Do the stuff only once when button is pressed */
		if (TM_DISCO_ButtonOnPressed()) {
			/* Do here stuff only once */
			/* This function will return 0 until you release button and press it again */
			/* For example, you can send data here to USART, but only once when button is pressed */
			GPIOD->BSRRL = LED_BLUE;
		}
		
		/* Do the stuff only once when button is released */
		if (TM_DISCO_ButtonOnReleased()) {
			/* DO here stuff only once */
			/* This function will return 0 until you press button and release it again */
			GPIOD->BSRRH = LED_BLUE;
		}
    }
}
Пример #18
0
int main(void) {	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initiaize button */
	TM_DISCO_ButtonInit();
	
	/* Initialize Leds */
	TM_DISCO_LedInit();
	
	/* Initialize USART, TX: PB10, RX: PB11 */
	TM_USART_Init(USART3, TM_USART_PinsPack_1, 115200);
	
	/* Initialize RTC with internal 32768Hz clock */
	/* It's not very accurate */
	if (!TM_RTC_Init(TM_RTC_ClockSource_Internal)) {
		/* RTC was first time initialized */
		/* Do your stuff here */
		/* eg. set default time */
	}
	
	/* Set wakeup interrupt every 1 second */
	TM_RTC_Interrupts(TM_RTC_Int_1s);
	
	while (1) {
		/* If button pressed */
		if (TM_DISCO_ButtonPressed()) {
			
			/* Set new time */
			Time.hours = 21;
			Time.minutes = 11;
			Time.seconds = 00;
			Time.year = 14;
			Time.month = 10;
			Time.date = 20;
			Time.day = 1;
			
			/* Set new RTC time */
			TM_RTC_SetDateTime(&Time, TM_RTC_Format_BIN);
			
			/* Set alarm A each day 1 (Monday) in a week */
			/* Alarm will be first triggered 5 seconds later as time is configured for RTC */
			AlarmTime.hours = Time.hours;
			AlarmTime.minutes = Time.minutes;
			AlarmTime.seconds = Time.seconds + 5;
			AlarmTime.alarmtype = TM_RTC_AlarmType_DayInWeek;
			AlarmTime.day = 1;
			
			/* Set RTC alarm A, time in binary format */
			TM_RTC_SetAlarm(TM_RTC_Alarm_A, &AlarmTime, TM_RTC_Format_BIN);
			
			/* Set alarm B each 20th day in a month */
			/* Alarm will be first triggered 10 seconds later as time is configured for RTC */
			AlarmTime.hours = Time.hours;
			AlarmTime.minutes = Time.minutes;
			AlarmTime.seconds = Time.seconds + 10;
			AlarmTime.day = 20;
			AlarmTime.alarmtype = TM_RTC_AlarmType_DayInMonth;
			
			/* Set RTC alarm B, time in binary format */
			TM_RTC_SetAlarm(TM_RTC_Alarm_B, &AlarmTime, TM_RTC_Format_BIN);
		}
	}
}
Пример #19
0
int main(void) {
	uint8_t already = 0;
	
	/* Set structs for all examples */
	TM_USB_HIDDEVICE_Keyboard_t Keyboard;
	TM_USB_HIDDEVICE_Gamepad_t Gamepad1, Gamepad2;
	TM_USB_HIDDEVICE_Mouse_t Mouse;
	
	/* Initialize system */
	SystemInit();
	
	/* Initialize leds */
	TM_DISCO_LedInit();
	
	/* Initialize button */
	TM_DISCO_ButtonInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize USB HID Device */
	TM_USB_HIDDEVICE_Init();
	
	/* Set default values for mouse struct */
	TM_USB_HIDDEVICE_MouseStructInit(&Mouse);
	/* Set default values for keyboard struct */
	TM_USB_HIDDEVICE_KeyboardStructInit(&Keyboard);
	/* Set default values for gamepad structs */
	TM_USB_HIDDEVICE_GamepadStructInit(&Gamepad1);
	TM_USB_HIDDEVICE_GamepadStructInit(&Gamepad2);

	while (1) {		  
		/* If we are connected and drivers are OK */
		if (TM_USB_HIDDEVICE_GetStatus() == TM_USB_HIDDEVICE_Status_Connected) {
			/* Turn on green LED */
			TM_DISCO_LedOn(LED_GREEN);
			
/* Simple sketch start */	
			
			/* If you pressed button right now and was not already pressed */
			if (TM_DISCO_ButtonPressed() && already == 0) { /* Button on press */
				already = 1;
				
				/* Set pressed keys = WIN + R */
				Keyboard.L_GUI = TM_USB_HIDDEVICE_Button_Pressed;	/* Win button */
				Keyboard.Key1 = 0x15; 								/* R */
				/* Result = "Run" command */
				
				/* Send keyboard report */
				TM_USB_HIDDEVICE_KeyboardSend(&Keyboard);
			} else if (!TM_DISCO_ButtonPressed() && already == 1) { /* Button on release */
				already = 0;
				
				/* Release all buttons */
				Keyboard.L_GUI = TM_USB_HIDDEVICE_Button_Released;	/* No button */
				Keyboard.Key1 = 0x00; 								/* No key */
				/* Result = Released everything */
				
				/* Send keyboard report */
				TM_USB_HIDDEVICE_KeyboardSend(&Keyboard);
			}
			
/* Simple sketch end */
			
		} else {
			/* Turn off green LED */
			TM_DISCO_LedOff(LED_GREEN);
		}
	}
}
Пример #20
0
int main(void) {
	uint8_t already = 0;

	/* Set structs for all examples */
	TM_USB_HIDDEVICE_Keyboard_t Keyboard;
	TM_USB_HIDDEVICE_Gamepad_t Gamepad1, Gamepad2;
	TM_USB_HIDDEVICE_Mouse_t Mouse;

	/* Initialize system */
	SystemInit();

	//Initialize LIS302DL - acceleration sensor;...
	//... the board position determines the movement of joystick

	LIS302DL_Init1();

	/* Initialize leds */
	TM_DISCO_LedInit();

	/* Initialize button */
	TM_DISCO_ButtonInit();

	/* Initialize delay */
	TM_DELAY_Init();

	/* Initialize USB HID Device */
	TM_USB_HIDDEVICE_Init();

	/* Set default values for mouse struct */
	TM_USB_HIDDEVICE_MouseStructInit(&Mouse);
	/* Set default values for keyboard struct */
	TM_USB_HIDDEVICE_KeyboardStructInit(&Keyboard);
	/* Set default values for gamepad structs */
	TM_USB_HIDDEVICE_GamepadStructInit(&Gamepad1);
	TM_USB_HIDDEVICE_GamepadStructInit(&Gamepad2);

	//Variables
	const int8_t axis_x_min = 0; //The number represents maximum deflection of left-stick on left; Default: -128 (!The value recommended for Unity game: 0 - Unity can read only not minus numbers of axis!)
	const int8_t axis_x_max = 127; //The number represents maximum deflection of left-stick on right; Default: 127
	const int8_t axis_x_avg = (axis_x_min + axis_x_max) / 2; //The value presented center position of left stick
	const int8_t acc_x_min = -60; //Minimum (approximately) value reading from accelerometer for X-axis
	const int8_t acc_x_max = 60; //Maximum (approximately) value reading from accelerometer for X-axis
	const int8_t kx = (-axis_x_min + axis_x_max) / (-acc_x_min + acc_x_max); //Thanks to this ratio, can create universal formula on value of gamepad left-axis depends on STM-board position

		const int8_t axis_y_min = 0; //The number represents maximum deflection of left-stick on top; Default: -128 (!The value recommended for Unity game: 0 - Unity can read only not minus numbers of axis!)
		const int8_t axis_y_max = 127; //The number represents maximum deflection of left-stick on bottom; Default: 127
		const int8_t axis_y_avg = (axis_y_min + axis_y_max) / 2; //The value presented center position of left stick
		const int8_t acc_y_min = -60; //Minimum (approximately) value reading from accelerometer for Y-axis
		const int8_t acc_y_max = 60; //Maximum (approximately) value reading from accelerometer for Y-axis
		const int8_t ky = (-axis_y_min + axis_y_max) / (-acc_y_min + acc_y_max); //Thanks to this ratio, can create universal formula on value of gamepad left-axis depends on STM-board position

	while (1) {
		/* If we are connected and drivers are OK */
		if (TM_USB_HIDDEVICE_GetStatus() == TM_USB_HIDDEVICE_Status_Connected) {
			/* Turn on green LED */
			TM_DISCO_LedOn(LED_GREEN);

/* Simple sketch start */

			/* If you pressed button right now and was not already pressed */
			if (TM_DISCO_ButtonPressed() && already == 0) { /* Button on press */
				already = 1;

				/* Gamepad 1 */
				/* Simulate button 1 on gamepad 1 */
				Gamepad1.Button1 = TM_USB_HIDDEVICE_Button_Pressed;

				/* Send report for gamepad 1 */
				TM_USB_HIDDEVICE_GamepadSend(TM_USB_HIDDEVICE_Gamepad_Number_1, &Gamepad1);


			} else if (!TM_DISCO_ButtonPressed() && already == 1) { /* Button on release */
				already = 0;

				//I thought the command that is 5 lines below was sufficient but no...
				//I released blue button but computer "thought" I still pressed it.
				Gamepad1.Button1 = TM_USB_HIDDEVICE_Button_Released; //release button 1

				/* Send command to release all buttons on both gamepads */
				TM_USB_HIDDEVICE_GamepadReleaseAll(TM_USB_HIDDEVICE_Gamepad_Number_1);
			}

			// Read the board position on axes
			LIS302DL_Read(&acc_x,LIS302DL_OUT_X_ADDR,1);
			LIS302DL_Read(&acc_y,LIS302DL_OUT_Y_ADDR,1);
			LIS302DL_Read(&acc_z,LIS302DL_OUT_Z_ADDR,1);

			//The value on axis depends on board lean
			//HERE: Changing orientation of left joystick under the influence of X-axis

			/* Simulate left stick rotation */
			/* X axis */
			if (acc_x > -15 && acc_x < 15) //horizontal position of STM-board
			{
				Gamepad1.LeftXAxis = axis_x_avg;
			}
			else
			{
				if (acc_x >= acc_x_max - 10) //maximum right position --> vertical position of STM-board (USB mini-B on top of board)
				{
					Gamepad1.LeftXAxis = axis_x_max;
				}
				else
				{
					if (acc_x <= acc_x_min + 10) //maximum left position --> vertical position of STM-board (mini-jack out and USB micro-B on top )
					{
						Gamepad1.LeftXAxis = axis_x_min;
					}
					else
					{
						Gamepad1.LeftXAxis = acc_x * kx + axis_x_avg; //universal formula on left-stick position of gamepad depending on STM position
						//it seems to be sufficient (without if-conditionals); but using of "if", it ensures more stability
					}
				}
			}

			/* Y axis */
			if (acc_y > -15 && acc_y < 15) //horizontal position of STM-board
			{
				Gamepad1.LeftYAxis = axis_y_avg;
			}
			else
			{
				if (acc_y >= acc_x_max - 10) //maximum "up" position --> blue button of STM is higher than black reset-button
				{
					Gamepad1.LeftYAxis = axis_y_min;
				}
				else
				{
					if (acc_y <= acc_x_min + 10) //maximum "down" position --> black button of STM is higher than blue button
					{
						Gamepad1.LeftYAxis = axis_y_max;
					}
					else
					{
						Gamepad1.LeftYAxis = acc_y * (-ky) + axis_y_avg; //universal formula on left-stick position of gamepad depending on STM position
						//it seems to be sufficient (without if-conditionals); but using of "if", it ensures more stability
					}
				}
			}

			TM_USB_HIDDEVICE_GamepadSend(TM_USB_HIDDEVICE_Gamepad_Number_1, &Gamepad1);

/* Simple sketch end */

		} else {
			/* Turn off green LED */
			TM_DISCO_LedOff(LED_GREEN);
		}
	}
}
Пример #21
0
int main(void) {
    /* Initialize system */
    SystemInit();

    /* Init USART6, TX: PC6 for debug */
    TM_USART_Init(USART6, TM_USART_PinsPack_1, 115200);

    /* Enable watchdog, 4 seconds before timeout */
    if (TM_WATCHDOG_Init(TM_WATCHDOG_Timeout_4s)) {
        /* Report to user */
        printf("Reset occured because of Watchdog\n");
    }

    /* Initialize delay */
    TM_DELAY_Init();

    /* Initialize leds on board */
    TM_DISCO_LedInit();

    /* Initialize button */
    TM_DISCO_ButtonInit();

    /* Display to user */
    printf("Program starting..\n");

    /* Initialize ethernet peripheral */
    /* All parameters NULL, default options for MAC, static IP, gateway and netmask will be used */
    /* They are defined in tm_stm32f4_ethernet.h file */
    if (TM_ETHERNET_Init(NULL, NULL, NULL, NULL) == TM_ETHERNET_Result_Ok) {
        /* Successfully initialized */
        TM_DISCO_LedOn(LED_GREEN);
    } else {
        /* Unsuccessfull communication */
        TM_DISCO_LedOn(LED_RED);
    }

    /* Reset watchdog */
    TM_WATCHDOG_Reset();

    while (1) {
        /* Update ethernet, call this as fast as possible */
        TM_ETHERNET_Update();

        /* If DNS is not working and we don't have IP yet */
        if (MyDNS.Working == 0 && MyDNS.HaveIP == 0) {
            /* Try to start DNS */
            /* It will return error in case Ethernet is not ready yet so you have to try more than one time */
            if (TM_ETHERNETDNS_GetHostByName("stm32f4-discovery.com") == TM_ETHERNET_Result_Ok) {
                /* We started with working */
                MyDNS.Working = 1;
            }
        }

        /* On button pressed, make a new connection and if we have IP known */
        if (TM_DISCO_ButtonOnPressed() && MyDNS.HaveIP) {
            /* Try to make a new connection, port 80 */
            if (TM_ETHERNETCLIENT_Connect("stm32f4-discovery.com", MyDNS.ip[0], MyDNS.ip[1], MyDNS.ip[2], MyDNS.ip[3], 80, &requests_count) != TM_ETHERNET_Result_Ok) {
                /* Print to user */
                printf("Can not make a new connection!\n");
            }
        }

        /* Reset watchdog */
        TM_WATCHDOG_Reset();
    }
}
Пример #22
0
int main(void) {
	/* Init system */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	/* Init delay */
	TM_DELAY_Init();
	
	/* Init debug USART */
	TM_USART_Init(USART2, TM_USART_PinsPack_1, 921600);
	
	/* Display message */
	printf("ESP8266 AT commands parser\r\n");
	
	/* Init ESP module */
	while (ESP8266_Init(&ESP8266, 115200) != ESP_OK) {
		printf("Problems with initializing module!\r\n");
	}
	
	/* Set mode to STA+AP */
	while (ESP8266_SetMode(&ESP8266, ESP8266_Mode_STA_AP) != ESP_OK);
	
	/* Enable server on port 80 */
	while (ESP8266_ServerEnable(&ESP8266, 80) != ESP_OK);
	
	/* Module is connected OK */
	printf("Initialization finished!\r\n");
	
	/* Disconnect from wifi if connected */
	ESP8266_WifiDisconnect(&ESP8266);
	
#if ESP8266_USE_APSEARCH
	/* Get a list of all stations */
	ESP8266_ListWifiStations(&ESP8266);
#endif
	
	/* Wait till finishes */
	ESP8266_WaitReady(&ESP8266);
	
	/* Connect to wifi and save settings */
	ESP8266_WifiConnect(&ESP8266, "YOUR SSID", "SSID PASSWORD");
	
	/* Wait till finish */
	ESP8266_WaitReady(&ESP8266);
	
	/* Get connected devices */
	ESP8266_WifiGetConnected(&ESP8266);
	
	while (1) {
		/* Update ESP module */
		ESP8266_Update(&ESP8266);
		
		/* Check for button */
		if (TM_DISCO_ButtonOnPressed()) {
			/* Starting with connection to web */
			while (ESP8266_StartClientConnection(&ESP8266, "stm32f4_discovery", "stm32f4-discovery.com", 80, NULL));
		}
	}
}
Пример #23
0
int main(void) {
	/* Initialize system */
	SystemInit();
	
	/* Init USART6, TX: PC6 for debug */
	TM_USART_Init(USART6, TM_USART_PinsPack_1, 115200);
	
	/* Enable watchdog, 4 seconds before timeout */
	if (TM_WATCHDOG_Init(TM_WATCHDOG_Timeout_4s)) {
		/* Report to user */
		printf("Reset occured because of Watchdog\n");
	}
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize leds on board */
	TM_DISCO_LedInit();
	
	/* Initialize button */
	TM_DISCO_ButtonInit();
	
	/* Display to user */
	printf("Program starting..\n");
	
	/* Initialize RTC with internal clock if not already */
	if (!TM_RTC_Init(TM_RTC_ClockSource_Internal)) {
		/* Set default time for RTC */
		
		/* Set date and time if RTC is not initialized already */
		TM_RTC_SetDateTimeString("28.02.15.6;23:35:30");
	};
	
	/* Initialize ethernet peripheral */
	/* All parameters NULL, default options for MAC, static IP, gateway and netmask will be used */
	/* They are defined in tm_stm32f4_ethernet.h file */
	if (TM_ETHERNET_Init(NULL, NULL, NULL, NULL) == TM_ETHERNET_Result_Ok) {
		/* Successfully initialized */
		TM_DISCO_LedOn(LED_GREEN);
	} else {
		/* Unsuccessfull communication */
		TM_DISCO_LedOn(LED_RED);
	}
	
	/* Reset watchdog */
	TM_WATCHDOG_Reset();
	
	/* Initialize ethernet server if you want use it, server port 80 */
	TM_ETHERNETSERVER_Enable(80);
	
	/* Set SSI tags, we have 21 SSI tags */
	TM_ETHERNETSERVER_SetSSITags(SSI_Tags, 21);
	
	/* Set CGI tags, we have 1 CGI handler, for leds only */
	TM_ETHERNETSERVER_SetCGIHandlers(CGI_Handlers, 1);
	
	/* Read RTC clock */
	TM_RTC_GetDateTime(&RTC_Data, TM_RTC_Format_BIN);
	
	/* Print current time to USART */
	printf("Current date: %02d:%02d:%02d\n", RTC_Data.hours, RTC_Data.minutes, RTC_Data.seconds);
	
	/* Reset watchdog */
	TM_WATCHDOG_Reset();

	while (1) {
		/* Update ethernet, call this as fast as possible */
		TM_ETHERNET_Update();
		
		/* If button pressed, toggle server status */
		if (TM_DISCO_ButtonOnPressed()) {
			/* If server is enabled */
			if (TM_ETHERNETSERVER_Enabled()) {
				/* Disable it */
				TM_ETHERNETSERVER_Disable();
				/* Print to user */
				printf("Server disabled\n");
			} else {
				/* Enable it */
				TM_ETHERNETSERVER_Enable(80);
				/* Print to user */
				printf("Server enabled\n");
			}
		}
		
		/* Reset watchdog */
		TM_WATCHDOG_Reset();
	}
}