Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
mcp355x.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2011 Gautier Hattenberger
3 *
4 * This file is part of paparazzi.
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, write to
18 * the Free Software Foundation, 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
26
27#include "peripherals/mcp355x.h"
28#include "mcu_periph/spi.h"
29
33
35
36void mcp355x_init(void)
37{
39 mcp355x_data = 0;
40
41 mcp355x_spi_trans.input_length = 4;
43 mcp355x_spi_trans.output_length = 0;
44 mcp355x_spi_trans.output_buf = NULL;
45 mcp355x_spi_trans.slave_idx = SPI_SLAVE0;
47
53}
54
55void mcp355x_read(void)
56{
58}
59
60void mcp355x_event(void)
61{
62 if (mcp355x_spi_trans.status == SPITransSuccess) {
63 if ((mcp355x_spi_trans.input_buf[0] >> 4) == 0) {
65 ((uint32_t)mcp355x_spi_trans.input_buf[0] << 17) |
66 ((uint32_t)mcp355x_spi_trans.input_buf[1] << 9) |
67 ((uint32_t)mcp355x_spi_trans.input_buf[2] << 1) |
68 (mcp355x_spi_trans.input_buf[3] >> 7));
70 }
72 }
73 if (mcp355x_spi_trans.status == SPITransFailed) {
75 }
76}
77
#define SPI_SLAVE0
Definition spi.h:189
bool spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit SPI transaction.
Definition spi_arch.c:548
struct spi_periph spi1
Definition spi.c:46
@ SPICphaEdge1
CPHA = 0.
Definition spi.h:70
@ SPITransFailed
Definition spi.h:96
@ SPITransSuccess
Definition spi.h:95
@ SPITransDone
Definition spi.h:97
@ SPICpolIdleLow
CPOL = 0.
Definition spi.h:79
@ SPISelect
slave is selected before transaction but not unselected
Definition spi.h:60
@ SPIMSBFirst
Definition spi.h:108
@ SPIDiv64
Definition spi.h:121
@ SPIDss8bit
Definition spi.h:86
SPI transaction structure.
Definition spi.h:144
int32_t mcp355x_data
Definition mcp355x.c:31
void mcp355x_event(void)
Definition mcp355x.c:60
void mcp355x_init(void)
Definition mcp355x.c:36
void mcp355x_read(void)
Definition mcp355x.c:55
bool mcp355x_data_available
Definition mcp355x.c:30
uint8_t mcp355x_val[4]
Definition mcp355x.c:32
struct spi_transaction mcp355x_spi_trans
Definition mcp355x.c:34
Architecture independent SPI (Serial Peripheral Interface) API.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.