spidev_linux.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Frank Hessel <frank@fhessel.de>
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 
61 #ifndef SPIDEV_LINUX_H
62 #define SPIDEV_LINUX_H
63 
64 #if defined(__linux__) || defined(DOXYGEN) /* Linux-only */
65 
66 #include "periph/spi.h"
67 
68 #include "mutex.h"
69 #include "periph_conf.h"
70 
71 #ifdef __cplusplus
72 extern "C" {
73 #endif
74 
78 enum {
81 };
82 
88 typedef struct spidev_linux_conf {
92 
98 typedef struct spidev_linux_state {
102  int fd[SPI_MAXCS];
104 
114 int spidev_linux_setup(spi_t bus, unsigned cs_id, const char *name);
115 
120 
121 #ifdef __cplusplus
122 }
123 #endif
124 
125 #else
126 /* Create the error in the header file as spi.c will be compiled to late to show it */
127 #ifdef MODULE_PERIPH_SPIDEV_LINUX
128 #error "MODULE periph_spidev_linux is only available on Linux"
129 #endif
130 #endif /* defined(__linux__) || defined(DOXYGEN) */
131 
132 #endif /* SPIDEV_LINUX_H */
Peripheral MCU configuration for the Zigduino board.
#define SPI_MAXCS
Maximum amount of chip select lines per bus.
Definition: periph_conf.h:115
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:80
@ SPI_SETUP_OK
parameters are sound
Definition: spidev_linux.h:79
Mutex for thread synchronization.
Low-level SPI peripheral driver interface definition.
Mutex structure.
Definition: mutex.h:146
Static runtime configuration for SPI port + CS line.
Definition: spidev_linux.h:88
char * device_filename[SPI_MAXCS]
Filename for a specific SPI device + CS line (like /dev/spidev0.0)
Definition: spidev_linux.h:90
Dynamic runtime state for SPI port + CS line.
Definition: spidev_linux.h:98
int fd[SPI_MAXCS]
File descriptors for each CS line on the bus.
Definition: spidev_linux.h:102
mutex_t lock
Mutex for the whole bus (all CS lines)
Definition: spidev_linux.h:100