123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #include <stdlib.h>
- #include <math.h>
- #include "ch.h"
- #include "hal.h"
- #include "lis3.h"
- #include "fake.h"
- static float acc[3];
- static THD_WORKING_AREA(PollAccelThreadWA, 256);
- static THD_FUNCTION(PollAccelThread, arg) {
- (void)arg;
- chRegSetThreadName("PollAccel");
- while (true) {
- osalThreadSleepMilliseconds(32);
- lis3GetAcc(acc);
- }
- }
- static THD_WORKING_AREA(PollFakeThreadWA, 256);
- static THD_FUNCTION(PollFakeThread, arg) {
- (void)arg;
- chRegSetThreadName("PollFake");
- while (true) {
- osalThreadSleepMilliseconds(16);
- request_fake();
- }
- }
- static const I2CConfig i2cfg1 = {
- OPMODE_I2C,
- 400000,
- FAST_DUTY_CYCLE_2,
- };
- int main(void) {
- halInit();
- chSysInit();
- i2cStart(&I2CD1, &i2cfg1);
- lis3Start();
-
- chThdCreateStatic(PollAccelThreadWA,
- sizeof(PollAccelThreadWA),
- NORMALPRIO,
- PollAccelThread,
- NULL);
-
- chThdCreateStatic(PollFakeThreadWA,
- sizeof(PollFakeThreadWA),
- NORMALPRIO,
- PollFakeThread,
- NULL);
-
- while (true) {
- if (sqrtf(acc[0]*acc[0] + acc[1]*acc[1]) > 0.5)
- palClearPad(IOPORT3, GPIOC_LED);
- else
- palSetPad(IOPORT3, GPIOC_LED);
- osalThreadSleepMilliseconds(20);
- }
- return 0;
- }
|