spidev_linux.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2019 Frank Hessel <frank@fhessel.de>
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
61 #if defined(__linux__) || defined(DOXYGEN) /* Linux-only */
62 
63 #include "periph/spi.h"
64 
65 #include "mutex.h"
66 #include "periph_conf.h"
67 
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71 
75 enum {
78 };
79 
85 typedef struct spidev_linux_conf {
89 
95 typedef struct spidev_linux_state {
99  int fd[SPI_MAXCS];
101 
111 int spidev_linux_setup(spi_t bus, unsigned cs_id, const char *name);
112 
117 
118 #ifdef __cplusplus
119 }
120 #endif
121 
122 #else
123 /* Create the error in the header file as spi.c will be compiled to late to show it */
124 #ifdef MODULE_PERIPH_SPIDEV_LINUX
125 #error "MODULE periph_spidev_linux is only available on Linux"
126 #endif
127 #endif /* defined(__linux__) || defined(DOXYGEN) */
128 
Peripheral MCU configuration for the Zigduino board.
#define SPI_MAXCS
Maximum amount of chip select lines per bus.
Definition: periph_conf.h:112
int spidev_linux_setup(spi_t bus, unsigned cs_id, const char *name)
register /dev/spidev* device to be used for SPI
struct spidev_linux_state spidev_linux_state_t
Dynamic runtime state for SPI port + CS line.
struct spidev_linux_conf spidev_linux_conf_t
Static runtime configuration for SPI port + CS line.
void spidev_linux_teardown(void)
Close open SPI file descriptors.
@ SPI_SETUP_INVALID
invalid params or duplicate definition
Definition: spidev_linux.h:77
@ SPI_SETUP_OK
parameters are sound
Definition: spidev_linux.h:76
Mutex for thread synchronization.
Low-level SPI peripheral driver interface definition.
Mutex structure.
Definition: mutex.h:39
Static runtime configuration for SPI port + CS line.
Definition: spidev_linux.h:85
char * device_filename[SPI_MAXCS]
Filename for a specific SPI device + CS line (like /dev/spidev0.0)
Definition: spidev_linux.h:87
Dynamic runtime state for SPI port + CS line.
Definition: spidev_linux.h:95
int fd[SPI_MAXCS]
File descriptors for each CS line on the bus.
Definition: spidev_linux.h:99
mutex_t lock
Mutex for the whole bus (all CS lines)
Definition: spidev_linux.h:97