24
24
#include " ap3_iomaster.h"
25
25
26
26
// Give a warning if the variant did not define these symbols:
27
- #ifndef SS
28
- #warning "variant has no definition for pin number 'SS'"
29
- #endif // SS
30
27
#ifndef MOSI
31
28
#warning "variant has no definition for pin number 'MOSI'"
32
- #endif // MOSI
29
+ #endif // MOSI
33
30
#ifndef MISO
34
31
#warning "variant has no definition for pin number 'MISO'"
35
- #endif // MISO
36
- #ifndef CLK
37
- #warning "variant has no definition for pin number 'CLK '"
38
- #endif // CLK
32
+ #endif // MISO
33
+ #ifndef SCK
34
+ #warning "variant has no definition for pin number 'SCK '"
35
+ #endif // SCK
39
36
40
37
// SPI_HAS_TRANSACTION means SPI has
41
38
// - beginTransaction()
52
49
#define SPI_MODE2 AM_HAL_IOM_SPI_MODE_2
53
50
#define SPI_MODE3 AM_HAL_IOM_SPI_MODE_3
54
51
55
- typedef enum {
52
+ typedef enum
53
+ {
56
54
ap3_spi_tx_only = 1 ,
57
55
ap3_spi_rx_only = 2 ,
58
56
ap3_spi_full_duplex = 3 ,
59
- }ap3_spi_duplex_e;
60
-
61
- class SPISettings {
62
- public:
63
- SPISettings (uint32_t clock, BitOrder bitOrder, uint8_t dataMode) {
64
- if (__builtin_constant_p (clock )) {
57
+ } ap3_spi_duplex_e;
58
+
59
+ class SPISettings
60
+ {
61
+ public:
62
+ SPISettings (uint32_t clock, BitOrder bitOrder, uint8_t dataMode)
63
+ {
64
+ if (__builtin_constant_p (clock ))
65
+ {
65
66
init_AlwaysInline (clock , bitOrder, dataMode);
66
- } else {
67
+ }
68
+ else
69
+ {
67
70
init_MightInline (clock , bitOrder, dataMode);
68
71
}
69
72
}
70
73
71
74
// Default speed set to 4MHz, SPI mode set to MODE 0 and Bit order set to MSB first.
72
- SPISettings () {
73
- init_AlwaysInline (4000000 , MSBFIRST, SPI_MODE0);
75
+ SPISettings ()
76
+ {
77
+ init_AlwaysInline (4000000 , MSBFIRST, SPI_MODE0);
74
78
}
75
79
76
- private:
77
- public: // temporary
78
- void init_MightInline (uint32_t clock, BitOrder bitOrder, uint8_t dataMode) {
80
+ private:
81
+ public: // temporary
82
+ void init_MightInline (uint32_t clock, BitOrder bitOrder, uint8_t dataMode)
83
+ {
79
84
init_AlwaysInline (clock , bitOrder, dataMode);
80
85
}
81
86
82
- void init_AlwaysInline (uint32_t clock, BitOrder bitOrder, uint8_t dataMode) __attribute__((__always_inline__)) {
87
+ void init_AlwaysInline (uint32_t clock, BitOrder bitOrder, uint8_t dataMode) __attribute__((__always_inline__))
88
+ {
83
89
this ->clockFreq = clock ;
84
90
this ->bitOrder = bitOrder;
85
91
this ->dataMode = (am_hal_iom_spi_mode_e)dataMode;
@@ -92,8 +98,9 @@ class SPISettings {
92
98
friend class SPIClass ;
93
99
};
94
100
95
- class SPIClass : public IOMaster {
96
- public:
101
+ class SPIClass : public IOMaster
102
+ {
103
+ public:
97
104
SPIClass (uint8_t iom_instance);
98
105
SPIClass (uint8_t iom_instance, ap3_spi_duplex_e duplex);
99
106
@@ -122,7 +129,7 @@ class SPIClass : public IOMaster {
122
129
123
130
private:
124
131
void config (SPISettings settings);
125
- void _transfer (void * buf_out = NULL , void * buf_in = NULL , size_t count = 0 );
132
+ void _transfer (void * buf_out = NULL , void * buf_in = NULL , size_t count = 0 );
126
133
127
134
// Bit Order (need a better way to handle this)
128
135
BitOrder _order;
@@ -131,9 +138,9 @@ class SPIClass : public IOMaster {
131
138
ap3_spi_duplex_e _duplex;
132
139
133
140
// Pads (for reference)
134
- ap3_gpio_pin_t _padSCLK;
135
- ap3_gpio_pin_t _padMOSI;
136
- ap3_gpio_pin_t _padMISO;
141
+ ap3_gpio_pin_t _padSCLK;
142
+ ap3_gpio_pin_t _padMOSI;
143
+ ap3_gpio_pin_t _padMISO;
137
144
138
145
// SERCOM *_p_sercom;
139
146
// uint8_t _uc_pinMiso;
@@ -150,34 +157,34 @@ class SPIClass : public IOMaster {
150
157
};
151
158
152
159
#if SPI_INTERFACES_COUNT > 0
153
- extern SPIClass SPI;
160
+ extern SPIClass SPI;
154
161
#endif
155
162
#if SPI_INTERFACES_COUNT > 1
156
- extern SPIClass SPI1;
163
+ extern SPIClass SPI1;
157
164
#endif
158
165
#if SPI_INTERFACES_COUNT > 2
159
- extern SPIClass SPI2;
166
+ extern SPIClass SPI2;
160
167
#endif
161
168
#if SPI_INTERFACES_COUNT > 3
162
- extern SPIClass SPI3;
169
+ extern SPIClass SPI3;
163
170
#endif
164
171
#if SPI_INTERFACES_COUNT > 4
165
- extern SPIClass SPI4;
172
+ extern SPIClass SPI4;
166
173
#endif
167
174
#if SPI_INTERFACES_COUNT > 5
168
- extern SPIClass SPI5;
175
+ extern SPIClass SPI5;
169
176
#endif
170
177
171
178
// For compatibility with sketches designed for AVR @ 16 MHz
172
179
// New programs should use SPI.beginTransaction to set the SPI clock
173
180
#if F_CPU == 48000000
174
- #define SPI_CLOCK_DIV2 6
175
- #define SPI_CLOCK_DIV4 12
176
- #define SPI_CLOCK_DIV8 24
177
- #define SPI_CLOCK_DIV16 48
178
- #define SPI_CLOCK_DIV32 96
179
- #define SPI_CLOCK_DIV64 192
180
- #define SPI_CLOCK_DIV128 255
181
+ #define SPI_CLOCK_DIV2 6
182
+ #define SPI_CLOCK_DIV4 12
183
+ #define SPI_CLOCK_DIV8 24
184
+ #define SPI_CLOCK_DIV16 48
185
+ #define SPI_CLOCK_DIV32 96
186
+ #define SPI_CLOCK_DIV64 192
187
+ #define SPI_CLOCK_DIV128 255
181
188
#endif
182
189
183
190
#endif
0 commit comments