From 0bdca93ef724c929727f74311140c7612372fb77 Mon Sep 17 00:00:00 2001 From: Thomas Pietrzak Date: Fri, 18 Oct 2013 21:16:55 +0000 Subject: [PATCH] Initial commit git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@115 47cf9a05-e0a8-4ed5-9e9b-101a649bc004 --- multitouchglove.c | 160 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 multitouchglove.c diff --git a/multitouchglove.c b/multitouchglove.c new file mode 100644 index 0000000..91ce6e2 --- /dev/null +++ b/multitouchglove.c @@ -0,0 +1,160 @@ +#include +#include +#include +#include + +//#include + +#include +#include +#include +#include + +#include +#include + +#define LSM_I2C_Speed 400000 + +#if 0//LSM303DLHC geomagnetic module is talking on I2C2 +void initMagneto() +{ + //enable GPIO clocks + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE); + RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE); + + // SCL => PB10 + // SDA => PB11 + GPIO_InitTypeDef i2cpinsdef; + i2cpinsdef.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; + i2cpinsdef.GPIO_Speed = GPIO_Speed_50MHz; + i2cpinsdef.GPIO_Mode = GPIO_Mode_AF_OD; + GPIO_Init(GPIOB, &i2cpinsdef); + + // Connect I2C1 pins to AF + GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_I2C1); // SCL + GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_I2C1); // SDA + + I2C_InitTypeDef i2cdef; + i2cdef.I2C_ClockSpeed = LSM_I2C_Speed; + i2cdef.I2C_Mode = I2C_Mode_I2C; + i2cdef.I2C_DutyCycle = I2C_DutyCycle_2; + i2cdef.I2C_OwnAddress1 = 0x00; + i2cdef.I2C_Ack = I2C_Ack_Enable; + i2cdef.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; + I2C_Init(I2Cx, &i2cdef); + I2C_Cmd(I2Cx, ENABLE); +} +#endif + +void initLed() +{ + //set Pin22 (PA4) to output mode + GPIO_InitTypeDef pin22def; + pin22def.GPIO_Pin = GPIO_Pin_4; + pin22def.GPIO_Speed = GPIO_Speed_50MHz; + pin22def.GPIO_Mode = GPIO_Mode_Out_PP; + GPIO_Init(GPIOA, &pin22def); +} + +void initGyro() +{ + L3GInit L3GInitStructure; + + /* Fill the gyro structure */ + L3GInitStructure.xPowerMode = L3G_NORMAL_SLEEP_MODE; + L3GInitStructure.xOutputDataRate = L3G_ODR_190_HZ_CUTOFF_12_5; + L3GInitStructure.xEnabledAxes = L3G_ALL_AXES_EN; + L3GInitStructure.xFullScale = L3G_FS_500_DPS; + L3GInitStructure.xDataUpdate = L3G_BLOCK_UPDATE; + L3GInitStructure.xEndianness = L3G_BIG_ENDIAN; + + /* Configure the gyro main parameters */ + L3gd20Config(&L3GInitStructure); +} + +void getGyroInfo() +{ + L3GInit L3GInitStructure; + + L3gd20GetInfo(&L3GInitStructure); + + printf("Power mode: %02x\n", L3GInitStructure.xPowerMode); + printf("Output data rate: %02x\n", L3GInitStructure.xOutputDataRate); + printf("Enabled axes: %02x\n", L3GInitStructure.xEnabledAxes); + printf("Full scale: %02x\n", L3GInitStructure.xFullScale); + printf("Data update: %02x\n", L3GInitStructure.xDataUpdate); + printf("Endianness: %02x\n", L3GInitStructure.xEndianness); +} + +void setLed() +{ + GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_SET); +} + +void resetLed() +{ + GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_RESET); +} + +static void blinkerTask(void *p) +{ + printf("Start blinker task\n"); + while (1) + { + setLed(); + vTaskDelay(1357); + resetLed(); + vTaskDelay(1357); + } +} + +static void gyroTask(void *p) +{ + printf("Start gyro task\n"); + float *values = (float *) malloc(3 * sizeof(float)); + if (values == NULL) + return; + while (1) + { +// printf("Read raw angles\n"); + L3gxReadAngRate(values); + printf("x=%.4f y=%.4f z=%.4f\n", values[0], values[1], values[2]); +// printf("x=%d y=%d z=%d\r", (int)values[0], (int)values[1], (int)values[2]); + vTaskDelay(1000); + } + free(values); +} + +int main() +{ + init_malloc_wrapper(); + printf("Init led\n"); + initLed(); + printf("Init SPI 2\n"); + spi_init(2); + printf("Init Gyro\n"); + initGyro(); + + getGyroInfo(); + + printf("Start blinkerTask\n"); + //start a task + xTaskCreate(blinkerTask, (const signed char *)NULL, configMINIMAL_STACK_SIZE, (void *)NULL, tskIDLE_PRIORITY, NULL); + + printf("Start gyroTask\n"); + //start a task + xTaskCreate(gyroTask, (const signed char *)NULL, configMINIMAL_STACK_SIZE, (void *)NULL, tskIDLE_PRIORITY, NULL); + + //start task scheduler + vTaskStartScheduler(); + + return 0; +} + +/* while(1) + { + setLed(); + sleep(1000); + resetLed(); + sleep(1000); + }*/ -- 2.30.2