forked from zephyrproject-rtos/gsoc-2022-arduino-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSPI.h
67 lines (54 loc) · 1.61 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
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* Copyright (c) 2024 Ayush Singh <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <Arduino.h>
#include <api/HardwareSPI.h>
#include <zephyr/drivers/spi.h>
#define SPR0 0
#define SPR1 1
#define CPHA 2
#define CPOL 3
#define MSTR 4
#define DORD 5
#define SPE 6
#define SPIE 7
/* Count the number of GPIOs for limit of number of interrupts */
#define INTERRUPT_HELPER(n, p, i) 1
#define INTERRUPT_COUNT \
DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), digital_pin_gpios, \
INTERRUPT_HELPER, (+))
namespace arduino {
class ZephyrSPI : public HardwareSPI {
public:
ZephyrSPI(const struct device *spi);
virtual uint8_t transfer(uint8_t data);
virtual uint16_t transfer16(uint16_t data);
virtual void transfer(void *buf, size_t count);
// Transaction Functions
virtual void usingInterrupt(int interruptNumber);
virtual void notUsingInterrupt(int interruptNumber);
virtual void beginTransaction(SPISettings settings);
virtual void endTransaction(void);
// SPI Configuration methods
virtual void attachInterrupt();
virtual void detachInterrupt();
virtual void begin();
virtual void end();
private:
const struct device *spi_dev;
struct spi_config config;
int interrupt[INTERRUPT_COUNT];
size_t interrupt_pos = 0;
};
} // namespace arduino
extern arduino::ZephyrSPI SPI;
/* Serial Peripheral Control Register */
extern uint8_t SPCR;
using arduino::SPI_MODE0;
using arduino::SPI_MODE1;
using arduino::SPI_MODE2;
using arduino::SPI_MODE3;
using arduino::SPISettings;