Added L3GD20 shared SPI switch,
Minor indent fixes. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9045 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
92c4f97fa4
commit
e080a1b8b6
|
@ -101,8 +101,8 @@
|
||||||
* @brief L3GD20 Power Mode
|
* @brief L3GD20 Power Mode
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
L3GD20_PM_POWER_DOWN = 0x00, /**< Power down enabled. */
|
L3GD20_PM_POWER_DOWN = 0x00, /**< Power down enabled. */
|
||||||
L3GD20_PM_SLEEP_NORMAL = 0x08 /**< Normal operation mode. */
|
L3GD20_PM_SLEEP_NORMAL = 0x08 /**< Normal operation mode. */
|
||||||
}l3gd20_pm_t;
|
}l3gd20_pm_t;
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -199,9 +199,11 @@ static msg_t read_raw(void *ip, int32_t axes[L3GD20_NUMBER_OF_AXES]) {
|
||||||
#if L3GD20_USE_SPI
|
#if L3GD20_USE_SPI
|
||||||
osalDbgAssert((((L3GD20Driver *)ip)->config->spip->state == SPI_READY),
|
osalDbgAssert((((L3GD20Driver *)ip)->config->spip->state == SPI_READY),
|
||||||
"read_raw(), channel not ready");
|
"read_raw(), channel not ready");
|
||||||
|
#if L3GD20_SHARED_SPI
|
||||||
spiAcquireBus(((L3GD20Driver *)ip)->config->spip);
|
spiAcquireBus(((L3GD20Driver *)ip)->config->spip);
|
||||||
spiStart(((L3GD20Driver *)ip)->config->spip,
|
spiStart(((L3GD20Driver *)ip)->config->spip,
|
||||||
((L3GD20Driver *)ip)->config->spicfg);
|
((L3GD20Driver *)ip)->config->spicfg);
|
||||||
|
#endif /* L3GD20_SHARED_SPI */
|
||||||
if(((L3GD20Driver *)ip)->config->axesenabling & L3GD20_AE_X){
|
if(((L3GD20Driver *)ip)->config->axesenabling & L3GD20_AE_X){
|
||||||
axes[0] = (int16_t)(l3gd20SPIReadRegister(((L3GD20Driver *)ip)->config->spip,
|
axes[0] = (int16_t)(l3gd20SPIReadRegister(((L3GD20Driver *)ip)->config->spip,
|
||||||
L3GD20_AD_OUT_X_L));
|
L3GD20_AD_OUT_X_L));
|
||||||
|
@ -223,7 +225,9 @@ static msg_t read_raw(void *ip, int32_t axes[L3GD20_NUMBER_OF_AXES]) {
|
||||||
L3GD20_AD_OUT_Y_H) << 8);
|
L3GD20_AD_OUT_Y_H) << 8);
|
||||||
axes[2] -= ((L3GD20Driver *)ip)->bias[2];
|
axes[2] -= ((L3GD20Driver *)ip)->bias[2];
|
||||||
}
|
}
|
||||||
|
#if L3GD20_SHARED_SPI
|
||||||
spiReleaseBus(((L3GD20Driver *)ip)->config->spip);
|
spiReleaseBus(((L3GD20Driver *)ip)->config->spip);
|
||||||
|
#endif /* L3GD20_SHARED_SPI */
|
||||||
#endif
|
#endif
|
||||||
return MSG_OK;
|
return MSG_OK;
|
||||||
}
|
}
|
||||||
|
@ -326,8 +330,10 @@ void l3gd20Start(L3GD20Driver *devp, const L3GD20Config *config) {
|
||||||
|
|
||||||
devp->config = config;
|
devp->config = config;
|
||||||
|
|
||||||
#if (L3GD20_USE_SPI)
|
#if L3GD20_USE_SPI
|
||||||
|
#if L3GD20_SHARED_SPI
|
||||||
spiAcquireBus((devp)->config->spip);
|
spiAcquireBus((devp)->config->spip);
|
||||||
|
#endif /* L3GD20_SHARED_SPI */
|
||||||
spiStart((devp)->config->spip,
|
spiStart((devp)->config->spip,
|
||||||
(devp)->config->spicfg);
|
(devp)->config->spicfg);
|
||||||
l3gd20SPIWriteRegister(devp->config->spip, L3GD20_AD_CTRL_REG1,
|
l3gd20SPIWriteRegister(devp->config->spip, L3GD20_AD_CTRL_REG1,
|
||||||
|
@ -338,7 +344,9 @@ void l3gd20Start(L3GD20Driver *devp, const L3GD20Config *config) {
|
||||||
devp->config->fullscale |
|
devp->config->fullscale |
|
||||||
devp->config->blockdataupdate |
|
devp->config->blockdataupdate |
|
||||||
devp->config->endianness);
|
devp->config->endianness);
|
||||||
|
#if L3GD20_SHARED_SPI
|
||||||
spiReleaseBus((devp)->config->spip);
|
spiReleaseBus((devp)->config->spip);
|
||||||
|
#endif /* L3GD20_SHARED_SPI */
|
||||||
#endif /* L3GD20_USE_SPI */
|
#endif /* L3GD20_USE_SPI */
|
||||||
|
|
||||||
/* Storing sensitivity information according to full scale value */
|
/* Storing sensitivity information according to full scale value */
|
||||||
|
@ -372,13 +380,17 @@ void l3gd20Stop(L3GD20Driver *devp) {
|
||||||
|
|
||||||
#if (L3GD20_USE_SPI)
|
#if (L3GD20_USE_SPI)
|
||||||
if (devp->state == L3GD20_STOP) {
|
if (devp->state == L3GD20_STOP) {
|
||||||
|
#if L3GD20_SHARED_SPI
|
||||||
spiAcquireBus((devp)->config->spip);
|
spiAcquireBus((devp)->config->spip);
|
||||||
spiStart((devp)->config->spip,
|
spiStart((devp)->config->spip,
|
||||||
(devp)->config->spicfg);
|
(devp)->config->spicfg);
|
||||||
|
#endif /* L3GD20_SHARED_SPI */
|
||||||
l3gd20SPIWriteRegister(devp->config->spip, L3GD20_AD_CTRL_REG1,
|
l3gd20SPIWriteRegister(devp->config->spip, L3GD20_AD_CTRL_REG1,
|
||||||
L3GD20_PM_POWER_DOWN | L3GD20_AE_DISABLED);
|
L3GD20_PM_POWER_DOWN | L3GD20_AE_DISABLED);
|
||||||
spiStop((devp)->config->spip);
|
spiStop((devp)->config->spip);
|
||||||
|
#if L3GD20_SHARED_SPI
|
||||||
spiReleaseBus((devp)->config->spip);
|
spiReleaseBus((devp)->config->spip);
|
||||||
|
#endif /* L3GD20_SHARED_SPI */
|
||||||
}
|
}
|
||||||
#endif /* L3GD20_USE_SPI */
|
#endif /* L3GD20_USE_SPI */
|
||||||
devp->state = L3GD20_STOP;
|
devp->state = L3GD20_STOP;
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @brief L3GD20 SPI interface selector.
|
* @brief L3GD20 SPI interface switch.
|
||||||
* @details If set to @p TRUE the support for SPI is included.
|
* @details If set to @p TRUE the support for SPI is included.
|
||||||
* @note The default is @p TRUE.
|
* @note The default is @p TRUE.
|
||||||
*/
|
*/
|
||||||
|
@ -57,7 +57,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief L3GD20 I2C interface selector.
|
* @brief L3GD20 I2C interface switch.
|
||||||
* @details If set to @p TRUE the support for I2C is included.
|
* @details If set to @p TRUE the support for I2C is included.
|
||||||
* @note The default is @p FALSE.
|
* @note The default is @p FALSE.
|
||||||
*/
|
*/
|
||||||
|
@ -65,6 +65,16 @@
|
||||||
#define L3GD20_USE_I2C FALSE
|
#define L3GD20_USE_I2C FALSE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief L3GD20 shared SPI switch.
|
||||||
|
* @details If set to @p TRUE the device acquires SPI bus ownership
|
||||||
|
* on each transaction.
|
||||||
|
* @note The default is @p FALSE. Requires SPI_USE_MUTUAL_EXCLUSION
|
||||||
|
*/
|
||||||
|
#if !defined(L3GD20_SHARED_SPI) || defined(__DOXYGEN__)
|
||||||
|
#define L3GD20_SHARED_SPI FALSE
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Number of acquisitions for bias removal
|
* @brief Number of acquisitions for bias removal
|
||||||
* @details This is the number of acquisitions performed to compute the
|
* @details This is the number of acquisitions performed to compute the
|
||||||
|
@ -87,8 +97,8 @@
|
||||||
/* Derived constants and error checks. */
|
/* Derived constants and error checks. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
#if L3GD20_USE_SPI && L3GD20_USE_I2C
|
#if !(L3GD20_USE_SPI ^ L3GD20_USE_I2C)
|
||||||
#error "L3GD20_USE_SPI and L3GD20_USE_I2C cannot be both true"
|
#error "L3GD20_USE_SPI and L3GD20_USE_I2C cannot be both true or both false"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if L3GD20_USE_SPI && !HAL_USE_SPI
|
#if L3GD20_USE_SPI && !HAL_USE_SPI
|
||||||
|
@ -99,6 +109,10 @@
|
||||||
#error "L3GD20_USE_I2C requires HAL_USE_I2C"
|
#error "L3GD20_USE_I2C requires HAL_USE_I2C"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if L3GD20_SHARED_SPI && !SPI_USE_MUTUAL_EXCLUSION
|
||||||
|
#error "L3GD20_SHARED_SPI requires SPI_USE_MUTUAL_EXCLUSION"
|
||||||
|
#endif
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Driver data structures and types. */
|
/* Driver data structures and types. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -111,9 +125,9 @@
|
||||||
* @brief L3GD20 full scale
|
* @brief L3GD20 full scale
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
L3GD20_FS_250DPS = 0x00, /**< Full scale 250 degree per second. */
|
L3GD20_FS_250DPS = 0x00, /**< Full scale 250 degree per second. */
|
||||||
L3GD20_FS_500DPS = 0x10, /**< Full scale 500 degree per second. */
|
L3GD20_FS_500DPS = 0x10, /**< Full scale 500 degree per second. */
|
||||||
L3GD20_FS_2000DPS = 0x20 /**< Full scale 2000 degree per second. */
|
L3GD20_FS_2000DPS = 0x20 /**< Full scale 2000 degree per second. */
|
||||||
}l3gd20_fs_t;
|
}l3gd20_fs_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -46,7 +46,7 @@ static L3GD20Config l3gd20cfg = {
|
||||||
&SPID2, /* Pointer to SPI Driver */
|
&SPID2, /* Pointer to SPI Driver */
|
||||||
&spicfg, /* Pointer to SPI Configuration */
|
&spicfg, /* Pointer to SPI Configuration */
|
||||||
L3GD20_FS_250DPS, /* Full scale value */
|
L3GD20_FS_250DPS, /* Full scale value */
|
||||||
L3GD20_ODR_760HZ_FC_100, /* Output data rate */
|
L3GD20_ODR_760HZ_FC_30, /* Output data rate */
|
||||||
L3GD20_AE_XYZ, /* Enabled axes */
|
L3GD20_AE_XYZ, /* Enabled axes */
|
||||||
L3GD20_BDU_BLOCKED, /* Block data update */
|
L3GD20_BDU_BLOCKED, /* Block data update */
|
||||||
L3GD20_END_LITTLE /* Endianness */
|
L3GD20_END_LITTLE /* Endianness */
|
||||||
|
|
Loading…
Reference in New Issue