Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
wind_gfi.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010 Martin Mueller
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 */
22
31
32#include "mcu_periph/i2c.h"
33#include "led.h"
34#include "mcu_periph/uart.h"
35#include "pprzlink/messages.h"
37
39
40#ifndef ZERO_OFFSET_DEGREES
41#define ZERO_OFFSET_DEGREES 45.
42#endif
43
44#ifndef PCF_I2C_DEV
45#define PCF_I2C_DEV i2c0
46#endif
47
48/* PCF8575 address can be set through A0..A2, starting at 0x40 */
49
50#ifndef PCF_SLAVE_ADDR
51#define PCF_SLAVE_ADDR 0x40
52#endif
53
56
62
64{
65 /* OE low, SEL high (for low data) */
66 pcf_trans.buf[0] = 0xFF;
67 pcf_trans.buf[1] = 0xBF;
70}
71
73{
75
79 } else if (pcf_status == PCF_READ_LSB) {
80 /* read lower byte direction info */
82
83 /* OE low, SEL low (for high data) */
84 pcf_trans.buf[0] = 0xFF;
85 pcf_trans.buf[1] = 0x3F;
88 } else if (pcf_status == PCF_SET_OE_MSB) {
91 } else if (pcf_status == PCF_READ_MSB) {
92 float fpcf_direction;
93
94 /* read higher byte direction info */
95 pcf_direction |= pcf_trans.buf[0] << 8;
96
97 /* OE high, SEL high */
98 pcf_trans.buf[0] = 0xFF;
99 pcf_trans.buf[1] = 0xFF;
102
103 /* 2048 digits per 360 degrees */
104 fpcf_direction = fmod((pcf_direction * (360. / 2048.)) + ZERO_OFFSET_DEGREES, 360.);
105
107 } else if (pcf_status == PCF_IDLE) {
109 }
110 }
111}
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition i2c.h:122
enum I2CTransactionStatus status
Transaction status.
Definition i2c.h:126
bool i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Submit a write only transaction.
Definition i2c.c:202
bool i2c_receive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
Submit a read only transaction.
Definition i2c.c:212
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition i2c.h:57
@ I2CTransDone
transaction set to done by user level
Definition i2c.h:59
I2C transaction structure.
Definition i2c.h:93
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
arch independent LED (Light Emitting Diodes) API
uint16_t foo
Definition main_demo5.c:58
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
void wind_gfi_periodic(void)
Definition wind_gfi.c:63
void wind_gfi_event(void)
Definition wind_gfi.c:72
#define ZERO_OFFSET_DEGREES
Definition wind_gfi.c:41
uint32_t pcf_direction
Definition wind_gfi.c:54
#define PCF_I2C_DEV
Definition wind_gfi.c:45
uint8_t pcf_status
Definition wind_gfi.c:55
struct i2c_transaction pcf_trans
Definition wind_gfi.c:38
void wind_gfi_init(void)
Definition wind_gfi.c:57
#define PCF_SLAVE_ADDR
Definition wind_gfi.c:51
@ PCF_SET_OE_MSB
Definition wind_gfi.h:10
@ PCF_IDLE
Definition wind_gfi.h:7
@ PCF_READ_MSB
Definition wind_gfi.h:11
@ PCF_SET_OE_LSB
Definition wind_gfi.h:8
@ PCF_READ_LSB
Definition wind_gfi.h:9