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 
62 #ifndef SPIDEV_LINUX_H
63 #define SPIDEV_LINUX_H
64 
65 #if defined(__linux__) || defined(DOXYGEN) /* Linux-only */
66 
67 #include "periph/spi.h"
68 
69 #include "mutex.h"
70 #include "periph_conf.h"
71 
72 #ifdef __cplusplus
73 extern "C" {
74 #endif
75 
79 enum {
82 };
83 
89 typedef struct spidev_linux_conf {
93 
99 typedef struct spidev_linux_state {
103  int fd[SPI_MAXCS];
105 
115 int spidev_linux_setup(spi_t bus, unsigned cs_id, const char *name);
116 
120 void spidev_linux_teardown(void);
121 
122 #ifdef __cplusplus
123 }
124 #endif
125 
126 #else
127 /* Create the error in the header file as spi.c will be compiled to late to show it */
128 #ifdef MODULE_PERIPH_SPIDEV_LINUX
129 #error "MODULE periph_spidev_linux is only available on Linux"
130 #endif
131 #endif /* defined(__linux__) || defined(DOXYGEN) */
132 
133 #endif /* SPIDEV_LINUX_H */
134 
spidev_linux_conf::device_filename
char * device_filename[SPI_MAXCS]
Filename for a specific SPI device + CS line (like /dev/spidev0.0)
Definition: spidev_linux.h:91
spidev_linux_conf
Static runtime configuration for SPI port + CS line.
Definition: spidev_linux.h:89
spidev_linux_state::fd
int fd[SPI_MAXCS]
File descriptors for each CS line on the bus.
Definition: spidev_linux.h:103
SPI_SETUP_OK
@ SPI_SETUP_OK
parameters are sound
Definition: spidev_linux.h:80
periph_conf.h
Native CPU peripheral configuration.
spidev_linux_state::lock
mutex_t lock
Mutex for the whole bus (all CS lines)
Definition: spidev_linux.h:101
SPI_SETUP_INVALID
@ SPI_SETUP_INVALID
invalid params or duplicate definition
Definition: spidev_linux.h:81
spi.h
Low-level SPI peripheral driver interface definition.
spidev_linux_state_t
struct spidev_linux_state spidev_linux_state_t
Dynamic runtime state for SPI port + CS line.
spidev_linux_conf_t
struct spidev_linux_conf spidev_linux_conf_t
Static runtime configuration for SPI port + CS line.
SPI_MAXCS
#define SPI_MAXCS
Maximum amount of chip select lines per bus.
Definition: periph_conf.h:102
spidev_linux_state
Dynamic runtime state for SPI port + CS line.
Definition: spidev_linux.h:99
mutex.h
Mutex for thread synchronization.
spidev_linux_teardown
void spidev_linux_teardown(void)
Close open SPI file descriptors.
spidev_linux_setup
int spidev_linux_setup(spi_t bus, unsigned cs_id, const char *name)
register /dev/spidev* device to be used for SPI
mutex_t
Mutex structure.
Definition: mutex.h:120
spi_t
unsigned int spi_t
Default type for SPI devices.
Definition: spi.h:118