1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 05:12:57 +01:00

drivers/cc110x: Allow setting the default channel

This (re-)introduces the `CC110X_DEFAULT_CHANNEL` preprocessor macro to set the
default channel of the `cc110x` at compile time. The same macro has been used
in the previous version of the driver, so some users might still expect it to
work.
This commit is contained in:
Marian Buschsieweke 2019-08-21 14:33:48 +02:00
parent abd1cd51b7
commit bb739907a2
No known key found for this signature in database
GPG Key ID: 61F64C6599B1539F
3 changed files with 23 additions and 11 deletions

View File

@ -44,13 +44,18 @@ int cc110x_setup(cc110x_t *dev, const cc110x_params_t *params)
}
int cc110x_apply_config(cc110x_t *dev, const cc110x_config_t *conf,
const cc110x_chanmap_t *chanmap)
const cc110x_chanmap_t *chanmap, uint8_t channel)
{
DEBUG("[cc110x] Applying new configuration\n");
if (!dev || !chanmap) {
return -EINVAL;
}
if ((channel >= CC110X_MAX_CHANNELS) || (chanmap->map[channel] == 0xff)) {
/* Channel out of range or not supported in current channel map */
return -ERANGE;
}
if (cc110x_acquire(dev) != SPI_OK) {
return -EIO;
}
@ -72,11 +77,10 @@ int cc110x_apply_config(cc110x_t *dev, const cc110x_config_t *conf,
cc110x_write(dev, CC110X_REG_DEVIATN, conf->deviatn);
}
/* Set current channel to zero, as the new map might not support the current
* virtual channel number. cc110x_full_calibration() will tune in that
* channel after calibration.
/* We only need to store the channel, cc110x_full_calibration() will tune it
* in after calibration.
*/
dev->channel = 0;
dev->channel = channel;
dev->channels = chanmap;
cc110x_release(dev);

View File

@ -347,19 +347,18 @@ static int cc110x_init(netdev_t *netdev)
/* Apply configuration (if non-NULL) and channel map, which also calls
* cc110x_full_calibration
*/
retval = cc110x_apply_config(dev, dev->params.config, dev->params.channels);
retval = cc110x_apply_config(dev, dev->params.config, dev->params.channels,
CC110X_DEFAULT_CHANNEL);
if (retval) {
gpio_irq_disable(dev->params.gdo0);
gpio_irq_disable(dev->params.gdo2);
DEBUG("[cc110x] netdev_driver_t::init(): cc110x_apply_config() "
"failed\n");
/* Pass through received error code */
/* Pass through received error code */
return retval;
}
else {
DEBUG("[cc110x] netdev_driver_t::init(): Success\n");
}
DEBUG("[cc110x] netdev_driver_t::init(): Success\n");
return 0;
}

View File

@ -240,6 +240,13 @@ extern "C" {
#define CC110X_DEFAULT_PROTOCOL (GNRC_NETTYPE_UNDEF)
#endif
#ifndef CC110X_DEFAULT_CHANNEL
/**
* @brief The default channel to set up after initializing the device
*/
#define CC110X_DEFAULT_CHANNEL (0U)
#endif
/**
* @brief The state of the CC1100/CC1101 transceiver
*
@ -558,10 +565,12 @@ int cc110x_setup(cc110x_t *dev, const cc110x_params_t *params);
* @param dev Device descriptor of the transceiver
* @param conf Configuration to apply or `NULL` to only change channel map
* @param chanmap Channel map to apply (must be compatible with @p conf)
* @param channel The channel to tune in after applying the config
*
* @retval 0 Success
* @retval -EINVAL Called with invalid argument
* @retval -EIO Communication with the transceiver failed
* @retval -ERANGE Channel out of range or not supported by channel map
*
* @pre The application developer checked in the documentation that the
* channel map in @p chanmap is compatible with the configuration in
@ -574,7 +583,7 @@ int cc110x_setup(cc110x_t *dev, const cc110x_params_t *params);
* @ref cc110x_full_calibration is called to update it.
*/
int cc110x_apply_config(cc110x_t *dev, const cc110x_config_t *conf,
const cc110x_chanmap_t *chanmap);
const cc110x_chanmap_t *chanmap, uint8_t channel);
/**
* @brief Perform a calibration of the frequency generator for each supported