Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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
uint16_t
unsigned short uint16_t
Definition: types.h:16
gps_i2c_write_cfg
@ gps_i2c_write_cfg
send a config msg and get reply
Definition: gps_ubx_i2c.h:56
GpsUbxI2C::baudrate
int baudrate
baudrate, unused
Definition: gps_ubx_i2c.h:77
GpsUbxI2C::read_state
GpsI2CReadState read_state
Definition: gps_ubx_i2c.h:63
GpsUbxI2C::tx_buf_idx
uint16_t tx_buf_idx
tx buf index
Definition: gps_ubx_i2c.h:71
GpsI2CWriteState
GpsI2CWriteState
write states
Definition: gps_ubx_i2c.h:52
GpsUbxI2C::trans
struct i2c_transaction trans
i2c transaction
Definition: gps_ubx_i2c.h:75
GpsUbxI2C::rx_buf
uint8_t rx_buf[GPS_I2C_BUF_SIZE]
receive buffer
Definition: gps_ubx_i2c.h:66
I2CTransFailed
@ I2CTransFailed
transaction failed
Definition: i2c.h:58
GpsUbxi2cEvent
static void GpsUbxi2cEvent(void)
i2c event
Definition: gps_ubx_i2c.h:101
I2CTransSuccess
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition: i2c.h:57
gps_ubx_i2c_init
void gps_ubx_i2c_init(void)
init function
Definition: gps_ubx_i2c.c:97
std.h
GpsUbxI2C::tx_buf
uint8_t tx_buf[GPS_I2C_BUF_SIZE]
transmit buffer
Definition: gps_ubx_i2c.h:67
GpsUbxI2C::rx_buf_idx
uint16_t rx_buf_idx
rx buf index
Definition: gps_ubx_i2c.h:70
GpsUbxI2C::tx_rdy
bool tx_rdy
are we ready to transmit
Definition: gps_ubx_i2c.h:73
gps_i2c_write_standby
@ gps_i2c_write_standby
wait for gps_ubx to read buffer or ucenter to transmit
Definition: gps_ubx_i2c.h:54
GpsUbxI2C::device
struct link_device device
ppz link device
Definition: gps_ubx_i2c.h:79
gps_i2c_tx_is_ready
bool gps_i2c_tx_is_ready(void)
is driver ready to send a message
Definition: gps_ubx_i2c.c:155
uint8_t
unsigned char uint8_t
Definition: types.h:14
gps_i2c_read_data
@ gps_i2c_read_data
read data from ubx buffer
Definition: gps_ubx_i2c.h:47
GpsI2CReadState
GpsI2CReadState
read states
Definition: gps_ubx_i2c.h:43
i2c_transaction::status
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
GpsUbxI2C
ubx_i2c state
Definition: gps_ubx_i2c.h:61
i2c_transaction
I2C transaction structure.
Definition: i2c.h:93
gps_i2c
struct GpsUbxI2C gps_i2c
Definition: gps_ubx_i2c.c:50
GpsUbxI2C::write_state
GpsI2CWriteState write_state
Definition: gps_ubx_i2c.h:64
gps_ubx_i2c_read_event
void gps_ubx_i2c_read_event(void)
handle message reception
Definition: gps_ubx_i2c.c:209
I2CTransDone
@ I2CTransDone
transaction set to done by user level
Definition: i2c.h:59
GpsUbxI2C::rx_buf_avail
uint16_t rx_buf_avail
how many bytes are waiting to be read
Definition: gps_ubx_i2c.h:69
gps_i2c_read_standby
@ gps_i2c_read_standby
dont read anything
Definition: gps_ubx_i2c.h:45
gps_i2c_read_sizeof
@ gps_i2c_read_sizeof
read size of ubx buffer
Definition: gps_ubx_i2c.h:46
gps_i2c_write_request_size
@ gps_i2c_write_request_size
request size of ubx buffer
Definition: gps_ubx_i2c.h:55
i2c.h
gps_ubx_i2c_periodic
void gps_ubx_i2c_periodic(void)
handle message sending
Definition: gps_ubx_i2c.c:170
GPS_I2C_BUF_SIZE
#define GPS_I2C_BUF_SIZE
Definition: gps_ubx_i2c.h:39
gps_i2c_begin
void gps_i2c_begin(void)
config is done, begin reading messages
Definition: gps_ubx_i2c.c:160