Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / flight / pios / common / pios_ubx_dcc.c
blob2b9a9747179a14d3e32b9ce132a139356a81436f
1 /**
2 ******************************************************************************
4 * @file pios_ubx_dcc.c
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
6 * @brief PIOS UBlox I2C(DDC) driver
7 * --
8 * @see The GNU Public License (GPL) Version 3
10 *****************************************************************************/
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <stdint.h>
28 #include <pios_i2c.h>
29 #include <pios_helpers.h>
30 #define GPS_I2C_ADDRESS 0x42
31 #define GPS_I2C_STREAM_REG 0xFF
32 #define GPS_I2C_STREAM_SIZE_HIGH_REG 0xFD
33 #define GPS_I2C_STREAM_SIZE_LOW_REG 0xFE
35 int32_t PIOS_UBX_DDC_GetAvailableBytes(uint32_t i2c_id)
37 uint8_t tmp[2];
38 const uint8_t addr_buffer[1] = { GPS_I2C_STREAM_SIZE_HIGH_REG };
39 struct pios_i2c_txn txn_list[] = {
41 .info = __func__,
42 .addr = GPS_I2C_ADDRESS,
43 .rw = PIOS_I2C_TXN_WRITE,
44 .len = 1,
45 .buf = (uint8_t *)addr_buffer,
49 .info = __func__,
50 .addr = GPS_I2C_ADDRESS,
51 .rw = PIOS_I2C_TXN_READ,
52 .len = 2,
53 .buf = tmp,
57 if (PIOS_I2C_Transfer(i2c_id, txn_list, NELEMENTS(txn_list)) != 0) {
58 return -1;
60 return (tmp[0] << 8) | tmp[1];
63 int32_t PIOS_UBX_DDC_ReadData(uint32_t i2c_id, uint8_t *buffer, uint8_t size)
65 const uint8_t addr_buffer[1] = { GPS_I2C_STREAM_REG };
66 const struct pios_i2c_txn txn_list[] = {
68 .info = __func__,
69 .addr = GPS_I2C_ADDRESS,
70 .rw = PIOS_I2C_TXN_WRITE,
71 .len = 1,
72 .buf = (uint8_t *)addr_buffer,
76 .info = __func__,
77 .addr = GPS_I2C_ADDRESS,
78 .rw = PIOS_I2C_TXN_READ,
79 .len = size,
80 .buf = buffer,
84 if (PIOS_I2C_Transfer(i2c_id, txn_list, NELEMENTS(txn_list)) != 0) {
85 return -1;
87 return 0;
90 int32_t PIOS_UBX_DDC_WriteData(const uint32_t i2c_id, const uint8_t *buffer, const uint8_t size)
92 const uint8_t addr_buffer[1] = { GPS_I2C_STREAM_REG };
93 const struct pios_i2c_txn txn_list[] = {
95 .info = __func__,
96 .addr = GPS_I2C_ADDRESS,
97 .rw = PIOS_I2C_TXN_WRITE,
98 .len = 1,
99 .buf = (uint8_t *)addr_buffer,
103 .info = __func__,
104 .addr = GPS_I2C_ADDRESS,
105 .rw = PIOS_I2C_TXN_WRITE,
106 .len = size,
107 .buf = (uint8_t *)buffer,
111 if (PIOS_I2C_Transfer(i2c_id, txn_list, NELEMENTS(txn_list)) != 0) {
112 return -1;
114 return 0;