1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers: update to new periph_spi API

This commit is contained in:
Marian Buschsieweke 2021-02-01 14:25:22 +01:00
parent f04b522601
commit 732cbd969c
No known key found for this signature in database
GPG Key ID: 61F64C6599B1539F
17 changed files with 43 additions and 103 deletions

View File

@ -48,9 +48,9 @@
#define AT225XXXX_SET_BUF_SIZE (64)
#endif
static inline int getbus(const at25xxx_t *dev)
static inline void getbus(const at25xxx_t *dev)
{
return spi_acquire(dev->params.spi, dev->params.cs_pin, SPI_MODE_0, dev->params.spi_clk);
spi_acquire(dev->params.spi, dev->params.cs_pin, SPI_MODE_0, dev->params.spi_clk);
}
static inline uint32_t _pos(uint8_t cmd, uint32_t pos)
@ -254,10 +254,11 @@ int at25xxx_init(at25xxx_t *dev, const at25xxx_params_t *params)
gpio_set(dev->params.hold_pin);
}
/* check if the SPI configuration is valid */
if (getbus(dev) != SPI_OK) {
return -1;
if (!IS_ACTIVE(NDEBUG)) {
/* if assertions are on, trigger an assert on incorrect SPI settings
* right on initialization to ease debugging */
getbus(dev);
spi_release(dev->params.spi);
}
spi_release(dev->params.spi);
return 0;
}

View File

@ -89,14 +89,11 @@ static int _init(netdev_t *netdev)
gpio_set(dev->params.reset_pin);
gpio_init_int(dev->params.int_pin, GPIO_IN, GPIO_RISING, _irq_handler, dev);
/* Intentionally check if bus can be acquired,
since getbus() drops the return value */
if (spi_acquire(dev->params.spi, dev->params.cs_pin, SPI_MODE_0,
dev->params.spi_clk) < 0) {
DEBUG("[at86rf2xx] error: unable to acquire SPI bus\n");
return -EIO;
/* Intentionally check if bus can be acquired, if assertions are on */
if (!IS_ACTIVE(NDEBUG)) {
spi_acquire(dev->params.spi, dev->params.cs_pin, SPI_MODE_0, dev->params.spi_clk);
spi_release(dev->params.spi);
}
spi_release(dev->params.spi);
#endif
/* reset hardware into a defined state */

View File

@ -156,9 +156,7 @@ static void _irq_handler(void *arg)
static void _getbus(const ata8520e_t *dev)
{
if (spi_acquire(SPIDEV, CSPIN, SPI_MODE_0, dev->params.spi_clk) < 0) {
DEBUG("[ata8520e] ERROR: Cannot acquire SPI bus!\n");
}
spi_acquire(SPIDEV, CSPIN, SPI_MODE_0, dev->params.spi_clk);
}
static void _spi_transfer_byte(const ata8520e_t *dev, bool cont, uint8_t out)

View File

@ -50,9 +50,7 @@
#ifdef BMX280_USE_SPI /* using SPI mode */
static inline int _acquire(const bmx280_t *dev)
{
if (spi_acquire(BUS, CS, MODE, CLK) != SPI_OK) {
return BMX280_ERR_BUS;
}
spi_acquire(BUS, CS, MODE, CLK);
return BMX280_OK;
}

View File

@ -57,9 +57,7 @@ int cc110x_apply_config(cc110x_t *dev, const cc110x_config_t *conf,
return -ERANGE;
}
if (cc110x_acquire(dev) != SPI_OK) {
return -EIO;
}
cc110x_acquire(dev);
gpio_irq_disable(dev->params.gdo0);
gpio_irq_disable(dev->params.gdo2);
@ -107,9 +105,7 @@ int cc110x_set_tx_power(cc110x_t *dev, cc110x_tx_power_t power)
return -ERANGE;
}
if (cc110x_acquire(dev) != SPI_OK) {
return -EIO;
}
cc110x_acquire(dev);
switch (dev->state) {
case CC110X_STATE_IDLE:
@ -134,9 +130,7 @@ int cc110x_set_channel(cc110x_t *dev, uint8_t channel)
return -EINVAL;
}
if (cc110x_acquire(dev) != SPI_OK) {
return -EIO;
}
cc110x_acquire(dev);
if ((channel >= CC110X_MAX_CHANNELS) || (dev->channels->map[channel] == 0xff)) {
/* Channel out of range or not supported in current channel map */

View File

@ -67,9 +67,7 @@ int cc110x_recalibrate(cc110x_t *dev)
/* Re-acquire SPI interface in order to check if calibration
* succeeded
*/
if (cc110x_acquire(dev) != SPI_OK) {
return -EIO;
}
cc110x_acquire(dev);
} while (cc110x_state_from_status(cc110x_status(dev)) != CC110X_STATE_IDLE);
get_calibration_data(dev);
@ -84,9 +82,7 @@ int cc110x_full_calibration(cc110x_t *dev)
return -EINVAL;
}
if (cc110x_acquire(dev) != SPI_OK) {
return -EIO;
}
cc110x_acquire(dev);
switch (dev->state) {
case CC110X_STATE_IDLE:

View File

@ -39,9 +39,7 @@ int cc110x_power_on_and_acquire(cc110x_t *dev)
gpio_set(cs);
spi_init_cs(dev->params.spi, dev->params.cs);
if (cc110x_acquire(dev) != SPI_OK) {
return -EIO;
}
cc110x_acquire(dev);
while (cc110x_state_from_status(cc110x_status(dev)) != CC110X_STATE_IDLE) {
cc110x_cmd(dev, CC110X_STROBE_IDLE);

View File

@ -354,11 +354,7 @@ static int cc110x_recv(netdev_t *netdev, void *buf, size_t len, void *info)
/* Call to cc110x_enter_rx_mode() will clear dev->buf.len, so back up it first */
int size = dev->buf.len;
if (cc110x_acquire(dev) != SPI_OK) {
DEBUG("[cc110x] netdev_driver_t::recv(): cc110x_acquire() "
"failed\n");
return -EIO;
}
cc110x_acquire(dev);
/* Copy RX info on last frame (if requested) */
if (info != NULL) {
@ -396,10 +392,7 @@ static int cc110x_send(netdev_t *netdev, const iolist_t *iolist)
/* assert that cc110x_send was called with valid parameters */
assert(netdev && iolist && (iolist->iol_len == sizeof(cc1xxx_l2hdr_t)));
if (cc110x_acquire(dev) != SPI_OK) {
DEBUG("[cc110x] netdev_driver_t::send(): cc110x_acquire() failed\n");
return -1;
}
cc110x_acquire(dev);
switch (dev->state) {
case CC110X_STATE_FSTXON:
@ -503,9 +496,7 @@ static int cc110x_send(netdev_t *netdev, const iolist_t *iolist)
*/
static int cc110x_get_promiscuous_mode(cc110x_t *dev, netopt_enable_t *dest)
{
if (cc110x_acquire(dev) != SPI_OK) {
return -EIO;
}
cc110x_acquire(dev);
uint8_t pktctrl1;
cc110x_read(dev, CC110X_REG_PKTCTRL1, &pktctrl1);
@ -598,9 +589,7 @@ static int cc110x_get(netdev_t *netdev, netopt_t opt,
*/
static int cc110x_set_addr(cc110x_t *dev, uint8_t addr)
{
if (cc110x_acquire(dev) != SPI_OK) {
return -EIO;
}
cc110x_acquire(dev);
dev->addr = addr;
cc110x_write(dev, CC110X_REG_ADDR, addr);
@ -618,9 +607,7 @@ static int cc110x_set_addr(cc110x_t *dev, uint8_t addr)
*/
static int cc110x_set_promiscuous_mode(cc110x_t *dev, netopt_enable_t enable)
{
if (cc110x_acquire(dev) != SPI_OK) {
return -EIO;
}
cc110x_acquire(dev);
uint8_t pktctrl1 = CC110X_PKTCTRL1_VALUE;
if (enable == NETOPT_ENABLE) {

View File

@ -280,10 +280,7 @@ void cc110x_isr(netdev_t *netdev)
*/
netdev_event_t post_isr_event = NETDEV_NO_EVENT;
if (cc110x_acquire(dev) != SPI_OK) {
DEBUG("[cc110x] ISR: CRITICAL ERROR: Couldn't acquire device\n");
return;
}
cc110x_acquire(dev);
/* Disable IRQs in a coarse manner, instead of doing so any time the
* IOCFGx configuration registers are changed. (This should be less

View File

@ -29,20 +29,15 @@ extern "C" {
#endif
/**
* @brief Acquire the SPI interface of the transceiver and configure it
*
* @retval SPI_OK Success
* @retval SPI_NOMODE SPI mode 0 not supported by MCU
* @retval SPI_NOCLK SPI clock given in @ref cc110x_params_t is not supported
* @brief Acquire the SPI interface of the transceiver
*
* @pre When first acquiring the device either after boot or after having put
* the device to sleep mode, use @ref cc110x_power_on_and_acquire
* instead. Subsequently, this function should be used (it is faster).
*/
static inline int cc110x_acquire(cc110x_t *dev)
static inline void cc110x_acquire(cc110x_t *dev)
{
return spi_acquire(dev->params.spi, dev->params.cs, SPI_MODE_0,
dev->params.spi_clk);
spi_acquire(dev->params.spi, dev->params.cs, SPI_MODE_0, dev->params.spi_clk);
}
/**

View File

@ -74,21 +74,11 @@ int kw2xrf_spi_init(kw2xrf_t *dev)
(unsigned)SPIDEV, res);
return 1;
}
/* verify SPI params */
res = spi_acquire(SPIDEV, CSPIN, SPIMODE, SPICLK);
if (res == SPI_NOMODE) {
LOG_ERROR("[kw2xrf_spi] given SPI mode is not supported");
return 1;
/* verify SPI params, if assertions are on */
if (!IS_ACTIVE(NDEBUG)) {
spi_acquire(SPIDEV, CSPIN, SPIMODE, SPICLK);
spi_release(SPIDEV);
}
else if (res == SPI_NOCLK) {
LOG_ERROR("[kw2xrf_spi] targeted clock speed is not supported");
return 1;
}
else if (res != SPI_OK) {
LOG_ERROR("[kw2xrf_spi] unable to acquire bus with given parameters");
return 1;
}
spi_release(SPIDEV);
DEBUG("[kw2xrf_spi] SPI_DEV(%u) initialized: mode: %u, clk: %u, cs_pin: %u\n",
(unsigned)SPIDEV, (unsigned)SPIMODE, (unsigned)SPICLK, (unsigned)CSPIN);

View File

@ -58,7 +58,8 @@ static int _init_bus(const lis2dh12_t *dev)
static int _acquire(const lis2dh12_t *dev)
{
return spi_acquire(BUS, BUS_CS, BUS_MODE, BUS_CLK);
spi_acquire(BUS, BUS_CS, BUS_MODE, BUS_CLK);
return BUS_OK;
}
static void _release(const lis2dh12_t *dev)

View File

@ -83,12 +83,11 @@ int nrf24l01p_init(nrf24l01p_t *dev, spi_t spi, gpio_t ce, gpio_t cs, gpio_t irq
/* Init IRQ pin */
gpio_init_int(dev->irq, GPIO_IN_PU, GPIO_FALLING, nrf24l01p_rx_cb, dev);
/* Test the SPI connection */
if (spi_acquire(dev->spi, dev->cs, SPI_MODE, SPI_CLK) != SPI_OK) {
DEBUG("error: unable to acquire SPI bus with given params\n");
return -1;
/* Test the SPI connection, if assertions are on */
if (!IS_ACTIVE(NDEBUG)) {
spi_acquire(dev->spi, dev->cs, SPI_MODE, SPI_CLK);
spi_release(dev->spi);
}
spi_release(dev->spi);
xtimer_spin(DELAY_AFTER_FUNC_TICKS);

View File

@ -105,17 +105,13 @@ extern "C" {
* @brief Acquire the SPI bus of the transceiver
*
* @param[in] dev NRF24L01+ device handle
*
* @return @see spi_acquire
*/
int nrf24l01p_ng_acquire(nrf24l01p_ng_t *dev);
void nrf24l01p_ng_acquire(nrf24l01p_ng_t *dev);
/**
* @brief Release the SPI bus of the transceiver
*
* @param[in] dev NRF24L01+ device handle
*
* @return @see spi_release
*/
void nrf24l01p_ng_release(nrf24l01p_ng_t *dev);

View File

@ -74,10 +74,9 @@ static void _nrf24l01p_ng_copy_and_swap_bytes(uint8_t* dst, const uint8_t* src,
}
}
int nrf24l01p_ng_acquire(nrf24l01p_ng_t *dev)
void nrf24l01p_ng_acquire(nrf24l01p_ng_t *dev)
{
return spi_acquire(dev->params.spi, dev->params.pin_cs, SPI_MODE_0,
dev->params.spi_clk);
spi_acquire(dev->params.spi, dev->params.pin_cs, SPI_MODE_0, dev->params.spi_clk);
}
void nrf24l01p_ng_release(nrf24l01p_ng_t *dev)

View File

@ -177,10 +177,7 @@ static int _init(netdev_t *netdev)
return -EIO;
}
gpio_clear(dev->params.pin_ce);
if (nrf24l01p_ng_acquire(dev) < 0) {
DEBUG_PUTS("[nrf24l01p_ng] _init(): nrf24l01p_ng_acquire() failed");
return -EIO;
}
nrf24l01p_ng_acquire(dev);
if (dev->state != NRF24L01P_NG_STATE_POWER_DOWN) {
nrf24l01p_ng_transition_to_power_down(dev);
}

View File

@ -104,10 +104,7 @@ static void print_state(cc110x_t *dev)
uint8_t virtual_channel;
/* Get all required data and release device */
if (cc110x_acquire(dev) != SPI_OK) {
puts("Failed to acquire CC1100/CC1101 transceiver");
return;
}
cc110x_acquire(dev);
if (dev->state == CC110X_STATE_OFF) {
cc110x_release(dev);