-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspi.h
54 lines (39 loc) · 1.15 KB
/
spi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef _SPI_H_
#define _SPI_H_
#include "pps.h"
#include <stdint.h>
/* ************************************************************************** */
typedef struct {
pps_output_t *clockOutPin;
pps_output_t *dataOutPin;
pps_input_t dataInPin;
} spi_config_t;
// setup
extern void spi1_init(spi_config_t config);
/* -------------------------------------------------------------------------- */
#define MAX_SPI_DEVICES 4
typedef struct {
struct {
unsigned useHardware : 1;
unsigned polarity : 1;
unsigned enable : 1;
pps_output_t *pin;
} slaveSelect;
unsigned inputPolarity : 1;
unsigned outputPolarity : 1;
unsigned bmode : 1;
uint8_t width;
void (*prehook)(void);
void (*posthook)(void);
} spi_device_t;
// register a new device
// returns the deviceID for the new device
extern uint8_t spi1_register_device(spi_device_t device);
/* -------------------------------------------------------------------------- */
//
extern void spi1_write_byte(uint8_t data);
//
extern uint8_t spi1_read_byte(void);
//
extern void spi1_exchange_block(uint8_t deviceID, uint8_t *block, uint8_t size);
#endif