Loading...
Searching...
No Matches
soft_spi.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017 Hamburg University of Applied Sciences
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
28#ifndef SOFT_SPI_H
29#define SOFT_SPI_H
30
31#include "periph/gpio.h"
32#include "periph/spi.h"
33#include "mutex.h"
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
47#ifndef SOFT_SPI_DEV
48#define SOFT_SPI_DEV(x) (x)
49#endif
50
54#ifndef SOFT_SPI_UNDEF
55#define SOFT_SPI_UNDEF (UINT_MAX)
56#endif
57
61#ifndef SOFT_SPI_CS_UNDEF
62#define SOFT_SPI_CS_UNDEF (GPIO_UNDEF)
63#endif
69typedef unsigned int soft_spi_t;
70
75typedef gpio_t soft_spi_cs_t;
76
80enum {
85 SOFT_SPI_NOCLK = -4
86};
87
110
123
134
149
161
176
194
204
217uint8_t soft_spi_transfer_byte(soft_spi_t bus, soft_spi_cs_t cs, bool cont, uint8_t out);
218
230 const void *out, void *in, size_t len);
231
245uint8_t soft_spi_transfer_reg(soft_spi_t bus, soft_spi_cs_t cs, uint8_t reg, uint8_t out);
246
261 const void *out, void *in, size_t len);
262
263#ifdef __cplusplus
264}
265#endif
266
267#endif /* SOFT_SPI_H */
Low-level GPIO peripheral driver interface definitions.
soft_spi_mode_t
Available SPI modes, defining the configuration of clock polarity and clock phase.
Definition soft_spi.h:104
int soft_spi_init_cs(soft_spi_t bus, soft_spi_cs_t cs)
Initialize the given chip select pin.
void soft_spi_transfer_regs(soft_spi_t bus, soft_spi_cs_t cs, uint8_t reg, const void *out, void *in, size_t len)
Transfer a number of bytes to/from a given register address.
unsigned int soft_spi_t
Default type for SPI devices.
Definition soft_spi.h:69
void soft_spi_init(soft_spi_t bus)
Basic initialization of the given SPI bus.
gpio_t soft_spi_cs_t
Chip select pin type overlaps with gpio_t so it can be casted to this.
Definition soft_spi.h:75
void soft_spi_init_pins(soft_spi_t bus)
Initialize the used SPI bus pins, i.e.
void soft_spi_release(soft_spi_t bus)
Finish an ongoing SPI transaction by releasing the given SPI bus.
void soft_spi_acquire(soft_spi_t bus, soft_spi_cs_t cs, soft_spi_mode_t mode, soft_spi_clk_t clk)
Start a new SPI transaction.
uint8_t soft_spi_transfer_reg(soft_spi_t bus, soft_spi_cs_t cs, uint8_t reg, uint8_t out)
Transfer one byte to/from a given register address.
uint8_t soft_spi_transfer_byte(soft_spi_t bus, soft_spi_cs_t cs, bool cont, uint8_t out)
Transfer one byte on the given SPI bus Currently only the use of MOSI in master mode is implemented.
void soft_spi_transfer_bytes(soft_spi_t bus, soft_spi_cs_t cs, bool cont, const void *out, void *in, size_t len)
Transfer a number bytes using the given SPI bus.
soft_spi_clk_t
Available SPI clock speeds.
Definition soft_spi.h:118
@ SOFT_SPI_MODE_2
CPOL=1, CPHA=0.
Definition soft_spi.h:107
@ SOFT_SPI_MODE_3
CPOL=1, CPHA=1.
Definition soft_spi.h:108
@ SOFT_SPI_MODE_1
CPOL=0, CPHA=1.
Definition soft_spi.h:106
@ SOFT_SPI_MODE_0
CPOL=0, CPHA=0.
Definition soft_spi.h:105
@ SOFT_SPI_OK
everything went as planned
Definition soft_spi.h:81
@ SOFT_SPI_NOCLK
selected clock value is not supported
Definition soft_spi.h:85
@ SOFT_SPI_NOMODE
selected mode is not supported
Definition soft_spi.h:84
@ SOFT_SPI_NOCS
invalid chip select line specified
Definition soft_spi.h:83
@ SOFT_SPI_NODEV
invalid SPI bus specified
Definition soft_spi.h:82
@ SOFT_SPI_CLK_1MHZ
drive the SPI bus with less than 1MHz
Definition soft_spi.h:120
@ SOFT_SPI_CLK_100KHZ
drive the SPI bus with less than 100kHz
Definition soft_spi.h:119
@ SOFT_SPI_CLK_DEFAULT
drive the SPI bus with maximum speed possible
Definition soft_spi.h:121
Mutex for thread synchronization.
Low-level SPI peripheral driver interface definition.
Software SPI port descriptor.
Definition soft_spi.h:127
soft_spi_mode_t soft_spi_mode
data and clock polarity
Definition soft_spi.h:131
gpio_t clk_pin
CLK pin.
Definition soft_spi.h:130
gpio_t miso_pin
MOSI pin.
Definition soft_spi.h:128
soft_spi_clk_t soft_spi_clk
clock speed
Definition soft_spi.h:132
gpio_t mosi_pin
MOSI pin.
Definition soft_spi.h:129