Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
humid_pcap01.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Norman Wildmann, 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 #include "led.h"
32 #include "mcu_periph/sys_time.h"
33 #include "mcu_periph/i2c.h"
34 #include "mcu_periph/uart.h"
35 #include "messages.h"
38 #ifdef PCAP01_LOAD_FIRMWARE
39 #include "modules/meteo/humid_pcap01_firmware.h"
40 #endif
41 
42 
46 
47 #ifndef PCAP01_I2C_DEV
48 #define PCAP01_I2C_DEV i2c0
49 #endif
50 
52 {
54 
55  pcap01_trans.buf[0] = 0x90+(unsigned char)(s_add>>8);
56  pcap01_trans.buf[1] = (unsigned char)(s_add);
57  pcap01_trans.buf[2] = data;
59 }
60 
62 {
64 
65  pcap01_trans.buf[0] = 0x10+(unsigned char)(s_add>>8);
66  pcap01_trans.buf[1] = (unsigned char)(s_add);
69 
70  return pcap01_trans.buf[0];
71 }
85  void PCAP01_Control(uint8_t control)
86 {
88 
89  pcap01_trans.buf[0] = control;
90  pcap01_trans.buf[1] = 0;
91  pcap01_trans.buf[2] = 0;
92  pcap01_trans.buf[3] = 0;
94 }
95 
97  {
99 
100  pcap01_trans.buf[0] = PCAP01_WRITE_REG + reg;
101  pcap01_trans.buf[1] = (unsigned char) (value>>16);
102  pcap01_trans.buf[2] = (unsigned char) (value>>8);
103  pcap01_trans.buf[3] = (unsigned char) (value);
105  }
106 
107 #ifdef PCAP01_LOAD_FIRMWARE
108 void writePCAP01_firmware(void)
109 {
110  int i = 0;
111  char testbyte = 44;
112  uint16_t testaddress = 71;
113  // Hard reset
115  sys_time_usleep(50000);
116  //write testbyte
117  writePCAP01_SRAM(testbyte, testaddress);
118 
119  //check testbyte
120  if (readPCAP01_SRAM(testaddress) != testbyte)
121  return;
122  else
123  {
124 LED_ON(3);
125  //Hard reset
127  //write firmware
128  for (i = 0;i< sizeof(firmware); i++)
129  {
130  writePCAP01_SRAM(firmware[i],i);
131  }
132  //fill with ffs
133  for (;i< 4029; i++)
134  {
135  writePCAP01_SRAM(0xff,i);
136  }
137  i++;
138 #ifdef PCAP01_200HZ
139  //write end bytes of sram
140  writePCAP01_SRAM(0x04,i++);
141  writePCAP01_SRAM(0x01,i++);
142  writePCAP01_SRAM(0x01,i++);
143 #endif
144 #ifdef PCAP01_STANDARD
145  //write end bytes of sram
146  writePCAP01_SRAM(0x02,i++);
147  writePCAP01_SRAM(0x01,i++);
148  writePCAP01_SRAM(0x03,i++);
149 #endif
150  }
151 }
152 #endif // PCAP01_LOAD_FIRMWARE
153 
154 void pcap01_init(void) {
156  pcap01Value.status = PCAP01_IDLE;
157 #ifdef PCAP01_LOAD_FIRMWARE
159 #endif
182  sys_time_usleep(500000);
184 }
185 
187  {
188  uint16_t byte1 = 0x40 | reg;
189  pcap01_trans.buf[0] = byte1;
191  }
192 
199 void pcap01_periodic(void)
200 {
201  pcap01Value.status = PCAP01_GET_HUMID;
202 #ifdef PCAP01_STANDARD
204 #endif
205 #ifdef PCAP01_200HZ
207 #endif
208 }
209 
210 void pcap01_event(void)
211 {
212  float humidity;
213  float temperature;
214 
216  switch (pcap01Value.status) {
217 
218  case PCAP01_GET_HUMID:
219  pcap01Value.C_ratio = pcap01_trans.buf[0] << 16;
220  pcap01Value.C_ratio |= (pcap01_trans.buf[1] << 8);
221  pcap01Value.C_ratio |= pcap01_trans.buf[2];
222  pcap01Value.status = PCAP01_GET_TEMP;
223 #ifdef PCAP01_STANDARD
225 #endif
226 #ifdef PCAP01_200HZ
228 #endif
229  break;
230 
231  case PCAP01_GET_TEMP:
232  pcap01Value.R_ratio = pcap01_trans.buf[0] << 16;
233  pcap01Value.R_ratio |= (pcap01_trans.buf[1] << 8);
234  pcap01Value.R_ratio |= pcap01_trans.buf[2];
235  humidity = pcap01Value.C_ratio * (-0.0023959245437) + 516.4124438673063;
236  temperature = pcap01Value.R_ratio * 61.927 - 259.74;
237  DOWNLINK_SEND_PCAP01_STATUS(DefaultChannel, DefaultDevice,
238  &pcap01Value.C_ratio,
239  &pcap01Value.R_ratio,
240  &humidity,
241  &temperature);
243  pcap01Value.status = PCAP01_IDLE;
244  break;
245 
246  default:
248  break;
249  }
250  }
251 }
#define PCAP01_GET_TEMP
Definition: humid_pcap01.h:54
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
#define PCAP01_REG0_VALUE
Definition: humid_pcap01.h:93
void writePCAP01_SRAM(uint8_t data, uint16_t s_add)
Definition: humid_pcap01.c:51
transaction successfully finished by I2C driver
Definition: i2c.h:57
#define PCAP01_REG15_VALUE
Definition: humid_pcap01.h:108
uint16_t value
Definition: adc_arch.c:585
#define PCAP01_REG11
Definition: humid_pcap01.h:80
void PCAP01_Control(uint8_t control)
PCAP01_Control.
Definition: humid_pcap01.c:85
I2C transaction structure.
Definition: i2c.h:93
#define PCAP01_REG13_VALUE
Definition: humid_pcap01.h:106
#define PCAP01_REG19
Definition: humid_pcap01.h:88
static void sys_time_usleep(uint32_t us)
Busy wait, in microseconds.
Definition: sys_time_arch.h:85
#define PCAP01_REG8
Definition: humid_pcap01.h:77
#define PCAP01_REG11_VALUE
Definition: humid_pcap01.h:104
#define LED_ON(i)
Definition: led_hw.h:28
void pcap01readRegister(uint8_t reg)
Definition: humid_pcap01.c:186
#define PCAP01_START
Definition: humid_pcap01.h:59
#define PCAP01_REG9_VALUE
Definition: humid_pcap01.h:102
#define PCAP01_REG4
Definition: humid_pcap01.h:73
#define PCAP01_REG17_VALUE
Definition: humid_pcap01.h:110
bool_t i2c_transceive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len_w, uint16_t len_r)
Submit a write/read transaction.
Definition: i2c.c:258
struct i2c_transaction pcap01_trans
Definition: humid_pcap01.c:44
void pcap01_event(void)
Definition: humid_pcap01.c:210
#define PCAP01_REG6
Definition: humid_pcap01.h:75
#define PCAP01_REG7_VALUE
Definition: humid_pcap01.h:100
#define PCAP01_REG5_VALUE
Definition: humid_pcap01.h:98
#define PCAP01_IN_RESET
Definition: humid_pcap01.h:58
#define PCAP01_REG7
Definition: humid_pcap01.h:76
#define PCAP01_REG1
Definition: humid_pcap01.h:70
ACAM Picocap Single-chip Solution for Capacitance Measurement.
#define PCAP01_REG18_VALUE
Definition: humid_pcap01.h:111
transaction set to done by user level
Definition: i2c.h:59
Architecture independent timing functions.
PCAP01VALUE pcap01Value
Definition: humid_pcap01.c:45
#define PCAP01_I2C_DEV
Definition: humid_pcap01.c:48
bool_t 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:238
unsigned long uint32_t
Definition: types.h:18
void writePCAP01_firmware(void)
#define PCAP01_REG5
Definition: humid_pcap01.h:74
void pcap01writeRegister(uint8_t reg, uint32_t value)
Definition: humid_pcap01.c:96
uint8_t pcap01_meas_started
Definition: humid_pcap01.c:43
#define PCAP01_REG8_VALUE
Definition: humid_pcap01.h:101
#define PCAP01_REG19_VALUE
Definition: humid_pcap01.h:112
#define PCAP01_PU_RESET
Definition: humid_pcap01.h:57
uint32_t C_ratio
Definition: humid_pcap01.h:44
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
#define PCAP01_ADDR
Definition: humid_pcap01.h:50
#define PCAP01_REG3_VALUE
Definition: humid_pcap01.h:96
#define PCAP01_REG18
Definition: humid_pcap01.h:87
#define PCAP01_REG16_VALUE
Definition: humid_pcap01.h:109
#define PCAP01_REG12_VALUE
Definition: humid_pcap01.h:105
uint32_t status
Definition: humid_pcap01.h:47
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
#define PCAP01_REG10
Definition: humid_pcap01.h:79
uint8_t readPCAP01_SRAM(uint16_t s_add)
Definition: humid_pcap01.c:61
unsigned char uint8_t
Definition: types.h:14
#define PCAP01_REG15
Definition: humid_pcap01.h:84
#define PCAP01_GET_HUMID
Definition: humid_pcap01.h:53
#define PCAP01_WRITE_REG
Definition: humid_pcap01.h:62
#define PCAP01_REG2_VALUE
Definition: humid_pcap01.h:95
uint32_t R_ratio
Definition: humid_pcap01.h:43
#define PCAP01_REG14
Definition: humid_pcap01.h:83
#define PCAP01_REG0
Definition: humid_pcap01.h:69
#define PCAP01_REG12
Definition: humid_pcap01.h:81
arch independent LED (Light Emitting Diodes) API
#define PCAP01_REG16
Definition: humid_pcap01.h:85
void pcap01_periodic(void)
pcap01_readData
Definition: humid_pcap01.c:199
#define PCAP01_REG13
Definition: humid_pcap01.h:82
#define PCAP01_REG20
Definition: humid_pcap01.h:89
#define PCAP01_REG6_VALUE
Definition: humid_pcap01.h:99
#define PCAP01_REG20_VALUE
Definition: humid_pcap01.h:113
void pcap01_init(void)
Definition: humid_pcap01.c:154
#define PCAP01_REG10_VALUE
Definition: humid_pcap01.h:103
#define PCAP01_REG14_VALUE
Definition: humid_pcap01.h:107
#define PCAP01_REG4_VALUE
Definition: humid_pcap01.h:97
#define PCAP01_REG17
Definition: humid_pcap01.h:86
#define PCAP01_REG3
Definition: humid_pcap01.h:72
#define PCAP01_REG2
Definition: humid_pcap01.h:71
transaction is pending in queue
Definition: i2c.h:55
#define PCAP01_IDLE
Definition: humid_pcap01.h:52
#define PCAP01_REG9
Definition: humid_pcap01.h:78
#define PCAP01_REG1_VALUE
Definition: humid_pcap01.h:94
Architecture independent I2C (Inter-Integrated Circuit Bus) API.