mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-30 15:52:12 +01:00
OP-1477 - Add pios_ubx_ddc driver to handle i2c comms with UBlox GPS
This commit is contained in:
parent
71af403c9d
commit
f2a0daac5c
115
flight/pios/common/pios_ubx_dcc.c
Normal file
115
flight/pios/common/pios_ubx_dcc.c
Normal file
@ -0,0 +1,115 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pios_ubx_dcc.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
|
||||
* @brief PIOS UBlox I2C(DDC) driver
|
||||
* --
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <pios_i2c.h>
|
||||
#include <pios_helpers.h>
|
||||
#define GPS_I2C_ADDRESS (0x42 << 1)
|
||||
#define GPS_I2C_STREAM_REG 0xFF
|
||||
#define GPS_I2C_STREAM_SIZE_HIGH_REG 0xFD
|
||||
#define GPS_I2C_STREAM_SIZE_LOW_REG 0xFE
|
||||
|
||||
int32_t PIOS_UBX_DDC_GetAvailableBytes(uint32_t i2c_id)
|
||||
{
|
||||
uint8_t tmp[2];
|
||||
const uint8_t addr_buffer[1] = { GPS_I2C_STREAM_SIZE_HIGH_REG };
|
||||
struct pios_i2c_txn txn_list[] = {
|
||||
{
|
||||
.info = __func__,
|
||||
.addr = GPS_I2C_ADDRESS,
|
||||
.rw = PIOS_I2C_TXN_WRITE,
|
||||
.len = 1,
|
||||
.buf = (uint8_t *)addr_buffer,
|
||||
}
|
||||
,
|
||||
{
|
||||
.info = __func__,
|
||||
.addr = GPS_I2C_ADDRESS,
|
||||
.rw = PIOS_I2C_TXN_READ,
|
||||
.len = 2,
|
||||
.buf = tmp,
|
||||
}
|
||||
};
|
||||
|
||||
if (PIOS_I2C_Transfer(i2c_id, txn_list, NELEMENTS(txn_list)) != 0) {
|
||||
return -1;
|
||||
}
|
||||
return (tmp[0] << 8) | tmp[1];
|
||||
}
|
||||
|
||||
int32_t PIOS_UBX_DDC_ReadData(uint32_t i2c_id, uint8_t *buffer, uint8_t size)
|
||||
{
|
||||
const uint8_t addr_buffer[1] = { GPS_I2C_STREAM_REG };
|
||||
const struct pios_i2c_txn txn_list[] = {
|
||||
{
|
||||
.info = __func__,
|
||||
.addr = GPS_I2C_ADDRESS,
|
||||
.rw = PIOS_I2C_TXN_WRITE,
|
||||
.len = 1,
|
||||
.buf = (uint8_t *)addr_buffer,
|
||||
}
|
||||
,
|
||||
{
|
||||
.info = __func__,
|
||||
.addr = GPS_I2C_ADDRESS,
|
||||
.rw = PIOS_I2C_TXN_READ,
|
||||
.len = size,
|
||||
.buf = buffer,
|
||||
}
|
||||
};
|
||||
|
||||
if (PIOS_I2C_Transfer(i2c_id, txn_list, NELEMENTS(txn_list)) != 0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t PIOS_UBX_DDC_WriteData(const uint32_t i2c_id, const uint8_t *buffer, const uint8_t size)
|
||||
{
|
||||
const uint8_t addr_buffer[1] = { GPS_I2C_STREAM_REG };
|
||||
const struct pios_i2c_txn txn_list[] = {
|
||||
{
|
||||
.info = __func__,
|
||||
.addr = GPS_I2C_ADDRESS,
|
||||
.rw = PIOS_I2C_TXN_WRITE,
|
||||
.len = 1,
|
||||
.buf = (uint8_t *)addr_buffer,
|
||||
}
|
||||
,
|
||||
{
|
||||
.info = __func__,
|
||||
.addr = GPS_I2C_ADDRESS,
|
||||
.rw = PIOS_I2C_TXN_WRITE,
|
||||
.len = size,
|
||||
.buf = (uint8_t *)buffer,
|
||||
}
|
||||
};
|
||||
|
||||
if (PIOS_I2C_Transfer(i2c_id, txn_list, NELEMENTS(txn_list)) != 0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
33
flight/pios/inc/pios_ubx_ddc.h
Normal file
33
flight/pios/inc/pios_ubx_ddc.h
Normal file
@ -0,0 +1,33 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pios_ubx_dcc.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
|
||||
* @brief PIOS UBlox I2C(DDC) driver
|
||||
* --
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef PIOS_UBX_DDC_H_
|
||||
#define PIOS_UBX_DDC_H_
|
||||
|
||||
int32_t PIOS_UBX_DDC_GetAvailableBytes(const uint32_t i2c_id);
|
||||
int32_t PIOS_UBX_DDC_ReadData(const uint32_t i2c_id, uint8_t *buffer, uint8_t size);
|
||||
int32_t PIOS_UBX_DDC_WriteData(const uint32_t i2c_id, const uint8_t *buffer, const uint8_t size);
|
||||
|
||||
#endif /* PIOS_UBX_DDC_H_ */
|
Loading…
x
Reference in New Issue
Block a user