-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
high_speed_logger_spi_link.c
78 lines (64 loc) · 3.19 KB
/
high_speed_logger_spi_link.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Copyright (C) 2005-2013 The Paparazzi Team
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#include "high_speed_logger_spi_link.h"
#include "subsystems/imu.h"
#include "mcu_periph/spi.h"
struct high_speed_logger_spi_link_data high_speed_logger_spi_link_data;
struct spi_transaction high_speed_logger_spi_link_transaction;
static volatile bool_t high_speed_logger_spi_link_ready = TRUE;
static void high_speed_logger_spi_link_trans_cb( struct spi_transaction *trans );
void high_speed_logger_spi_link_init(void) {
high_speed_logger_spi_link_data.id = 0;
high_speed_logger_spi_link_transaction.select = SPISelectUnselect;
high_speed_logger_spi_link_transaction.cpol = SPICpolIdleHigh;
high_speed_logger_spi_link_transaction.cpha = SPICphaEdge2;
high_speed_logger_spi_link_transaction.dss = SPIDss8bit;
high_speed_logger_spi_link_transaction.bitorder = SPIMSBFirst;
high_speed_logger_spi_link_transaction.cdiv = SPIDiv64;
high_speed_logger_spi_link_transaction.slave_idx = HIGH_SPEED_LOGGER_SPI_LINK_SLAVE_NUMBER;
high_speed_logger_spi_link_transaction.output_length = sizeof(high_speed_logger_spi_link_data);
high_speed_logger_spi_link_transaction.output_buf = (uint8_t*) &high_speed_logger_spi_link_data;
high_speed_logger_spi_link_transaction.input_length = 0;
high_speed_logger_spi_link_transaction.input_buf = NULL;
high_speed_logger_spi_link_transaction.after_cb = high_speed_logger_spi_link_trans_cb;
}
void high_speed_logger_spi_link_periodic(void)
{
if (high_speed_logger_spi_link_ready)
{
high_speed_logger_spi_link_ready = FALSE;
high_speed_logger_spi_link_data.gyro_p = imu.gyro_unscaled.p;
high_speed_logger_spi_link_data.gyro_q = imu.gyro_unscaled.q;
high_speed_logger_spi_link_data.gyro_r = imu.gyro_unscaled.r;
high_speed_logger_spi_link_data.acc_x = imu.accel_unscaled.x;
high_speed_logger_spi_link_data.acc_y = imu.accel_unscaled.y;
high_speed_logger_spi_link_data.acc_z = imu.accel_unscaled.z;
high_speed_logger_spi_link_data.mag_x = imu.mag_unscaled.x;
high_speed_logger_spi_link_data.mag_y = imu.mag_unscaled.x;
high_speed_logger_spi_link_data.mag_z = imu.mag_unscaled.x;
spi_submit(&(HIGH_SPEED_LOGGER_SPI_LINK_DEVICE), &high_speed_logger_spi_link_transaction);
}
high_speed_logger_spi_link_data.id++;
}
static void high_speed_logger_spi_link_trans_cb( struct spi_transaction *trans ) {
high_speed_logger_spi_link_ready = TRUE;
}