Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
hmc58xx.c
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (C) 2011 Gautier Hattenberger
4  *
5  * This file is part of paparazzi.
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, write to
19  * the Free Software Foundation, 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22 
23 /* Driver for HMC5843 and HMC5883
24  */
25 
26 #include "peripherals/hmc58xx.h"
27 #include "std.h"
28 
29 #define HMC_CONF_UNINIT 0
30 #define HMC_CONF_CRA 1
31 #define HMC_CONF_CRB 2
32 #define HMC_CONF_MODE 3
33 #define HMC_CONF_DONE 4
34 
35 
36 // Data ready flag
37 volatile bool_t hmc58xx_data_available;
38 // Data vector
40 // I2C transaction structure
42 // Init flag
45 
46 // TODO IRQ handling
47 
48 void hmc58xx_init(void)
49 {
54 }
55 
56 // Configuration function called once before normal use
57 static void hmc58xx_send_config(void)
58 {
59  switch (hmc58xx_init_status) {
60  case HMC_CONF_CRA:
65  break;
66  case HMC_CONF_CRB:
71  break;
72  case HMC_CONF_MODE:
77  break;
78  case HMC_CONF_DONE:
81  break;
82  default:
83  break;
84  }
85 }
86 
87 // Configure
89 {
94  }
95  }
96 }
97 
98 // Normal reading
99 void hmc58xx_read(void)
100 {
104  }
105 }
106 
107 #define Int16FromBuf(_buf,_idx) ((int16_t)((_buf[_idx]<<8) | _buf[_idx+1]))
108 
109 void hmc58xx_event(void)
110 {
111  if (hmc58xx_initialized) {
114  }
121  }
122  }
123  else if (!hmc58xx_initialized && hmc58xx_init_status != HMC_CONF_UNINIT) { // Configuring
127  }
131  hmc58xx_send_config(); // Retry config (TODO max retry)
132  }
133  }
134 }
135 
struct Int16Vect3 hmc58xx_data
Definition: hmc58xx.c:39
#define I2CTransmit(_p, _t, _s_addr, _len)
Definition: i2c.h:148
#define HMC58XX_I2C_DEVICE
Definition: hmc58xx.h:70
#define HMC_CONF_DONE
Definition: hmc58xx.c:33
#define HMC_CONF_MODE
Definition: hmc58xx.c:32
static void hmc58xx_send_config(void)
Definition: hmc58xx.c:57
void hmc58xx_configure(void)
Definition: hmc58xx.c:88
#define HMC58XX_ADDR
Definition: hmc58xx.h:34
#define HMC58XX_CRB
Definition: hmc58xx.h:66
#define HMC58XX_MD
Definition: hmc58xx.h:62
void hmc58xx_event(void)
Definition: hmc58xx.c:109
uint8_t slave_addr
Definition: i2c.h:43
void hmc58xx_init(void)
Definition: hmc58xx.c:48
#define FALSE
Definition: imu_chimu.h:141
#define HMC_CONF_CRB
Definition: hmc58xx.c:31
#define HMC58XX_CRA
Definition: hmc58xx.h:65
uint8_t hmc58xx_init_status
Definition: hmc58xx.c:44
#define HMC_CONF_UNINIT
Definition: hmc58xx.c:29
enum I2CTransactionStatus status
Definition: i2c.h:47
#define HMC58XX_REG_CFGA
Definition: hmc58xx.h:37
#define TRUE
Definition: imu_chimu.h:144
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:46
volatile bool_t hmc58xx_data_available
Definition: hmc58xx.c:37
unsigned char uint8_t
Definition: types.h:14
#define I2CTransceive(_p, _t, _s_addr, _len_w, _len_r)
Definition: i2c.h:156
#define HMC58XX_REG_DATXM
Definition: hmc58xx.h:40
void hmc58xx_read(void)
Definition: hmc58xx.c:99
struct i2c_transaction hmc58xx_i2c_trans
Definition: hmc58xx.c:41
#define HMC_CONF_CRA
Definition: hmc58xx.c:30
#define Int16FromBuf(_buf, _idx)
Definition: hmc58xx.c:107
#define HMC58XX_REG_MODE
Definition: hmc58xx.h:39
bool_t hmc58xx_initialized
Definition: hmc58xx.c:43
#define HMC58XX_REG_CFGB
Definition: hmc58xx.h:38