Paparazzi UAS  v5.12_stable-4-g9b43e9b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
gps_ubx_i2c.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 ENAC, Pascal Brisset, Michel Gorraz,Gautier Hattenberger,
3  * 2016 Michael Sierra <sierramichael.a@gmail.com>
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 
32 #ifndef GPS_UBX_I2C_H
33 #define GPS_UBX_I2C_H
34 
35 #include "std.h"
36 #include "mcu_periph/i2c.h"
37 #include "pprzlink/pprzlink_device.h"
38 
39 #define GPS_I2C_BUF_SIZE 255
40 
43 typedef enum GpsI2CReadState
44 {
49 
52 typedef enum GpsI2CWriteState
53 {
58 
61 struct GpsUbxI2C
62 {
65 
68 
72 
73  bool tx_rdy;
74 
76 
77  int baudrate;
78 
79  struct link_device device;
80 };
81 
82 extern struct GpsUbxI2C gps_i2c;
85 extern void gps_ubx_i2c_init(void);
88 extern void gps_ubx_i2c_periodic(void);
91 extern void gps_ubx_i2c_read_event(void);
94 extern bool gps_i2c_tx_is_ready(void);
97 extern void gps_i2c_begin(void);
98 
101 static inline void GpsUbxi2cEvent(void)
102 {
105  } else if (gps_i2c.trans.status == I2CTransFailed) {
106  // if transaction failed, mark as done so can be retried
108  }
109 }
110 
111 #endif // GPS_UBX_I2C_H
unsigned short uint16_t
Definition: types.h:16
#define GPS_I2C_BUF_SIZE
Definition: gps_ubx_i2c.h:39
uint16_t tx_buf_idx
tx buf index
Definition: gps_ubx_i2c.h:71
GpsI2CWriteState
write states
Definition: gps_ubx_i2c.h:52
transaction successfully finished by I2C driver
Definition: i2c.h:57
request size of ubx buffer
Definition: gps_ubx_i2c.h:55
void gps_i2c_begin(void)
config is done, begin reading messages
Definition: gps_ubx_i2c.c:159
GpsI2CReadState read_state
Definition: gps_ubx_i2c.h:63
wait for gps_ubx to read buffer or ucenter to transmit
Definition: gps_ubx_i2c.h:54
struct i2c_transaction trans
i2c transaction
Definition: gps_ubx_i2c.h:75
static void GpsUbxi2cEvent(void)
i2c event
Definition: gps_ubx_i2c.h:101
uint8_t tx_buf[GPS_I2C_BUF_SIZE]
transmit buffer
Definition: gps_ubx_i2c.h:67
uint16_t rx_buf_idx
rx buf index
Definition: gps_ubx_i2c.h:70
void gps_ubx_i2c_init(void)
init function
Definition: gps_ubx_i2c.c:96
uint8_t rx_buf[GPS_I2C_BUF_SIZE]
receive buffer
Definition: gps_ubx_i2c.h:66
bool gps_i2c_tx_is_ready(void)
is driver ready to send a message
Definition: gps_ubx_i2c.c:154
send a config msg and get reply
Definition: gps_ubx_i2c.h:56
transaction set to done by user level
Definition: i2c.h:59
GpsI2CReadState
read states
Definition: gps_ubx_i2c.h:43
transaction failed
Definition: i2c.h:58
bool tx_rdy
are we ready to transmit
Definition: gps_ubx_i2c.h:73
I2C transaction structure.
Definition: i2c.h:93
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
dont read anything
Definition: gps_ubx_i2c.h:45
struct link_device device
ppz link device
Definition: gps_ubx_i2c.h:79
read size of ubx buffer
Definition: gps_ubx_i2c.h:46
uint16_t rx_buf_avail
how many bytes are waiting to be read
Definition: gps_ubx_i2c.h:69
unsigned char uint8_t
Definition: types.h:14
ubx_i2c state
Definition: gps_ubx_i2c.h:61
void gps_ubx_i2c_periodic(void)
handle message sending
Definition: gps_ubx_i2c.c:169
struct GpsUbxI2C gps_i2c
Definition: gps_ubx_i2c.c:49
GpsI2CWriteState write_state
Definition: gps_ubx_i2c.h:64
int baudrate
baudrate, unused
Definition: gps_ubx_i2c.h:77
void gps_ubx_i2c_read_event(void)
handle message reception
Definition: gps_ubx_i2c.c:208
read data from ubx buffer
Definition: gps_ubx_i2c.h:47
Architecture independent I2C (Inter-Integrated Circuit Bus) API.