aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile62
-rw-r--r--README5
-rw-r--r--core/binary.h539
-rw-r--r--libmaple/nvic.c15
-rw-r--r--libmaple/nvic.h6
-rw-r--r--wirish/Print.cpp (renamed from core/Print.cpp)6
-rw-r--r--wirish/Print.h (renamed from core/Print.h)0
-rw-r--r--wirish/WProgram.h (renamed from core/WProgram.h)0
-rw-r--r--wirish/bits.h (renamed from core/bits.h)0
-rw-r--r--wirish/comm/HardwareSPI.cpp138
-rw-r--r--wirish/comm/HardwareSPI.h57
-rw-r--r--wirish/comm/HardwareSerial.cpp (renamed from core/comm/HardwareSerial.cpp)2
-rw-r--r--wirish/comm/HardwareSerial.h (renamed from core/comm/HardwareSerial.h)0
-rw-r--r--wirish/comm/HardwareUsb.cpp (renamed from core/comm/HardwareUsb.cpp)2
-rw-r--r--wirish/comm/HardwareUsb.h (renamed from core/comm/HardwareUsb.h)0
-rw-r--r--wirish/ext_interrupts.c (renamed from core/ext_interrupts.c)2
-rw-r--r--wirish/ext_interrupts.h (renamed from core/ext_interrupts.h)0
-rw-r--r--wirish/io.h (renamed from core/io.h)0
-rw-r--r--wirish/main.cxx (renamed from core/main.cxx)0
-rw-r--r--wirish/pwm.c (renamed from core/pwm.c)4
-rw-r--r--wirish/pwm.h (renamed from core/pwm.h)0
-rw-r--r--wirish/time.c (renamed from core/time.c)0
-rw-r--r--wirish/time.h (renamed from core/time.h)0
-rw-r--r--wirish/wirish.c (renamed from core/wiring.c)20
-rw-r--r--wirish/wirish.h (renamed from core/wiring.h)33
-rw-r--r--wirish/wirish_analog.c (renamed from core/wiring_analog.c)4
-rw-r--r--wirish/wirish_digital.c (renamed from core/wiring_digital.c)4
-rw-r--r--wirish/wirish_math.cpp (renamed from core/wiring_math.cpp)0
-rw-r--r--wirish/wirish_math.h (renamed from core/wiring_math.h)26
-rw-r--r--wirish/wirish_shift.c (renamed from core/wiring_shift.c)2
30 files changed, 291 insertions, 636 deletions
diff --git a/Makefile b/Makefile
index e7df3a5..875e458 100644
--- a/Makefile
+++ b/Makefile
@@ -27,14 +27,14 @@ BUILD_PATH = build
LIB_PATH = libmaple
OUTDIRS = $(BUILD_PATH)/$(LIB_PATH)\
- $(BUILD_PATH)/core \
- $(BUILD_PATH)/core/comm
+ $(BUILD_PATH)/wirish \
+ $(BUILD_PATH)/wirish/comm
INCLUDES = -I$(LIB_PATH) \
-I./ \
- -Icore \
- -Icore/comm
+ -Iwirish \
+ -Iwirish/comm
# default is to upload to flash
#DEFFLAGS = VECT_TAB_BASE
@@ -57,33 +57,33 @@ ODFLAGS = -S
# main source file
MAIN=main.c
-CSRC = libmaple/systick.c \
- libmaple/timers.c \
- libmaple/adc.c \
- libmaple/syscalls.c \
- libmaple/exc.c \
- libmaple/exti.c \
- libmaple/gpio.c \
- libmaple/nvic.c \
- libmaple/usart.c \
- libmaple/util.c \
- libmaple/usb.c \
- libmaple/rcc.c \
- libmaple/flash.c \
- libmaple/spi.c \
- core/wiring.c \
- core/wiring_shift.c \
- core/wiring_analog.c \
- core/time.c \
- core/pwm.c \
- core/ext_interrupts.c \
- core/wiring_digital.c
-
-CPPSRC = core/wiring_math.cpp \
- core/Print.cpp \
- core/comm/HardwareSerial.cpp \
- core/comm/HardwareUsb.cpp \
- core/comm/HardwareSPI.cpp \
+CSRC = libmaple/systick.c \
+ libmaple/timers.c \
+ libmaple/adc.c \
+ libmaple/syscalls.c \
+ libmaple/exc.c \
+ libmaple/exti.c \
+ libmaple/gpio.c \
+ libmaple/nvic.c \
+ libmaple/usart.c \
+ libmaple/util.c \
+ libmaple/usb.c \
+ libmaple/rcc.c \
+ libmaple/flash.c \
+ libmaple/spi.c \
+ wirish/wirish.c \
+ wirish/wirish_shift.c \
+ wirish/wirish_analog.c \
+ wirish/time.c \
+ wirish/pwm.c \
+ wirish/ext_interrupts.c \
+ wirish/wirish_digital.c
+
+CPPSRC = wirish/wirish_math.cpp \
+ wirish/Print.cpp \
+ wirish/comm/HardwareSerial.cpp \
+ wirish/comm/HardwareUsb.cpp \
+ wirish/comm/HardwareSPI.cpp \
main.cpp
# i really have no idea what i'm doing
diff --git a/README b/README
index f3bb334..9638a6b 100644
--- a/README
+++ b/README
@@ -31,9 +31,10 @@ libmaple Repo Layout
Lowest level definitions, routines, macros, and functions. This is the meat
of the library.
-/core/
+/wirish/
Extra wrappers and functionality around the lower level code which is
- useful for programming in the IDE.
+ useful for programming in the IDE. Files in here implement the "Wirish"
+ language, an Arduino "Wiring"-like language.
/examples/
What it sounds like. Copy these to /main.cpp to compile them.
diff --git a/core/binary.h b/core/binary.h
deleted file mode 100644
index e4882fc..0000000
--- a/core/binary.h
+++ /dev/null
@@ -1,539 +0,0 @@
-/* *****************************************************************************
- * The MIT License
- *
- * Copyright (c) 2010 LeafLabs LLC.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- * ****************************************************************************/
-
-#ifndef Binary_h
-#define Binary_h
-
-#define B0 0
-#define B00 0
-#define B000 0
-#define B0000 0
-#define B00000 0
-#define B000000 0
-#define B0000000 0
-#define B00000000 0
-#define B1 1
-#define B01 1
-#define B001 1
-#define B0001 1
-#define B00001 1
-#define B000001 1
-#define B0000001 1
-#define B00000001 1
-#define B10 2
-#define B010 2
-#define B0010 2
-#define B00010 2
-#define B000010 2
-#define B0000010 2
-#define B00000010 2
-#define B11 3
-#define B011 3
-#define B0011 3
-#define B00011 3
-#define B000011 3
-#define B0000011 3
-#define B00000011 3
-#define B100 4
-#define B0100 4
-#define B00100 4
-#define B000100 4
-#define B0000100 4
-#define B00000100 4
-#define B101 5
-#define B0101 5
-#define B00101 5
-#define B000101 5
-#define B0000101 5
-#define B00000101 5
-#define B110 6
-#define B0110 6
-#define B00110 6
-#define B000110 6
-#define B0000110 6
-#define B00000110 6
-#define B111 7
-#define B0111 7
-#define B00111 7
-#define B000111 7
-#define B0000111 7
-#define B00000111 7
-#define B1000 8
-#define B01000 8
-#define B001000 8
-#define B0001000 8
-#define B00001000 8
-#define B1001 9
-#define B01001 9
-#define B001001 9
-#define B0001001 9
-#define B00001001 9
-#define B1010 10
-#define B01010 10
-#define B001010 10
-#define B0001010 10
-#define B00001010 10
-#define B1011 11
-#define B01011 11
-#define B001011 11
-#define B0001011 11
-#define B00001011 11
-#define B1100 12
-#define B01100 12
-#define B001100 12
-#define B0001100 12
-#define B00001100 12
-#define B1101 13
-#define B01101 13
-#define B001101 13
-#define B0001101 13
-#define B00001101 13
-#define B1110 14
-#define B01110 14
-#define B001110 14
-#define B0001110 14
-#define B00001110 14
-#define B1111 15
-#define B01111 15
-#define B001111 15
-#define B0001111 15
-#define B00001111 15
-#define B10000 16
-#define B010000 16
-#define B0010000 16
-#define B00010000 16
-#define B10001 17
-#define B010001 17
-#define B0010001 17
-#define B00010001 17
-#define B10010 18
-#define B010010 18
-#define B0010010 18
-#define B00010010 18
-#define B10011 19
-#define B010011 19
-#define B0010011 19
-#define B00010011 19
-#define B10100 20
-#define B010100 20
-#define B0010100 20
-#define B00010100 20
-#define B10101 21
-#define B010101 21
-#define B0010101 21
-#define B00010101 21
-#define B10110 22
-#define B010110 22
-#define B0010110 22
-#define B00010110 22
-#define B10111 23
-#define B010111 23
-#define B0010111 23
-#define B00010111 23
-#define B11000 24
-#define B011000 24
-#define B0011000 24
-#define B00011000 24
-#define B11001 25
-#define B011001 25
-#define B0011001 25
-#define B00011001 25
-#define B11010 26
-#define B011010 26
-#define B0011010 26
-#define B00011010 26
-#define B11011 27
-#define B011011 27
-#define B0011011 27
-#define B00011011 27
-#define B11100 28
-#define B011100 28
-#define B0011100 28
-#define B00011100 28
-#define B11101 29
-#define B011101 29
-#define B0011101 29
-#define B00011101 29
-#define B11110 30
-#define B011110 30
-#define B0011110 30
-#define B00011110 30
-#define B11111 31
-#define B011111 31
-#define B0011111 31
-#define B00011111 31
-#define B100000 32
-#define B0100000 32
-#define B00100000 32
-#define B100001 33
-#define B0100001 33
-#define B00100001 33
-#define B100010 34
-#define B0100010 34
-#define B00100010 34
-#define B100011 35
-#define B0100011 35
-#define B00100011 35
-#define B100100 36
-#define B0100100 36
-#define B00100100 36
-#define B100101 37
-#define B0100101 37
-#define B00100101 37
-#define B100110 38
-#define B0100110 38
-#define B00100110 38
-#define B100111 39
-#define B0100111 39
-#define B00100111 39
-#define B101000 40
-#define B0101000 40
-#define B00101000 40
-#define B101001 41
-#define B0101001 41
-#define B00101001 41
-#define B101010 42
-#define B0101010 42
-#define B00101010 42
-#define B101011 43
-#define B0101011 43
-#define B00101011 43
-#define B101100 44
-#define B0101100 44
-#define B00101100 44
-#define B101101 45
-#define B0101101 45
-#define B00101101 45
-#define B101110 46
-#define B0101110 46
-#define B00101110 46
-#define B101111 47
-#define B0101111 47
-#define B00101111 47
-#define B110000 48
-#define B0110000 48
-#define B00110000 48
-#define B110001 49
-#define B0110001 49
-#define B00110001 49
-#define B110010 50
-#define B0110010 50
-#define B00110010 50
-#define B110011 51
-#define B0110011 51
-#define B00110011 51
-#define B110100 52
-#define B0110100 52
-#define B00110100 52
-#define B110101 53
-#define B0110101 53
-#define B00110101 53
-#define B110110 54
-#define B0110110 54
-#define B00110110 54
-#define B110111 55
-#define B0110111 55
-#define B00110111 55
-#define B111000 56
-#define B0111000 56
-#define B00111000 56
-#define B111001 57
-#define B0111001 57
-#define B00111001 57
-#define B111010 58
-#define B0111010 58
-#define B00111010 58
-#define B111011 59
-#define B0111011 59
-#define B00111011 59
-#define B111100 60
-#define B0111100 60
-#define B00111100 60
-#define B111101 61
-#define B0111101 61
-#define B00111101 61
-#define B111110 62
-#define B0111110 62
-#define B00111110 62
-#define B111111 63
-#define B0111111 63
-#define B00111111 63
-#define B1000000 64
-#define B01000000 64
-#define B1000001 65
-#define B01000001 65
-#define B1000010 66
-#define B01000010 66
-#define B1000011 67
-#define B01000011 67
-#define B1000100 68
-#define B01000100 68
-#define B1000101 69
-#define B01000101 69
-#define B1000110 70
-#define B01000110 70
-#define B1000111 71
-#define B01000111 71
-#define B1001000 72
-#define B01001000 72
-#define B1001001 73
-#define B01001001 73
-#define B1001010 74
-#define B01001010 74
-#define B1001011 75
-#define B01001011 75
-#define B1001100 76
-#define B01001100 76
-#define B1001101 77
-#define B01001101 77
-#define B1001110 78
-#define B01001110 78
-#define B1001111 79
-#define B01001111 79
-#define B1010000 80
-#define B01010000 80
-#define B1010001 81
-#define B01010001 81
-#define B1010010 82
-#define B01010010 82
-#define B1010011 83
-#define B01010011 83
-#define B1010100 84
-#define B01010100 84
-#define B1010101 85
-#define B01010101 85
-#define B1010110 86
-#define B01010110 86
-#define B1010111 87
-#define B01010111 87
-#define B1011000 88
-#define B01011000 88
-#define B1011001 89
-#define B01011001 89
-#define B1011010 90
-#define B01011010 90
-#define B1011011 91
-#define B01011011 91
-#define B1011100 92
-#define B01011100 92
-#define B1011101 93
-#define B01011101 93
-#define B1011110 94
-#define B01011110 94
-#define B1011111 95
-#define B01011111 95
-#define B1100000 96
-#define B01100000 96
-#define B1100001 97
-#define B01100001 97
-#define B1100010 98
-#define B01100010 98
-#define B1100011 99
-#define B01100011 99
-#define B1100100 100
-#define B01100100 100
-#define B1100101 101
-#define B01100101 101
-#define B1100110 102
-#define B01100110 102
-#define B1100111 103
-#define B01100111 103
-#define B1101000 104
-#define B01101000 104
-#define B1101001 105
-#define B01101001 105
-#define B1101010 106
-#define B01101010 106
-#define B1101011 107
-#define B01101011 107
-#define B1101100 108
-#define B01101100 108
-#define B1101101 109
-#define B01101101 109
-#define B1101110 110
-#define B01101110 110
-#define B1101111 111
-#define B01101111 111
-#define B1110000 112
-#define B01110000 112
-#define B1110001 113
-#define B01110001 113
-#define B1110010 114
-#define B01110010 114
-#define B1110011 115
-#define B01110011 115
-#define B1110100 116
-#define B01110100 116
-#define B1110101 117
-#define B01110101 117
-#define B1110110 118
-#define B01110110 118
-#define B1110111 119
-#define B01110111 119
-#define B1111000 120
-#define B01111000 120
-#define B1111001 121
-#define B01111001 121
-#define B1111010 122
-#define B01111010 122
-#define B1111011 123
-#define B01111011 123
-#define B1111100 124
-#define B01111100 124
-#define B1111101 125
-#define B01111101 125
-#define B1111110 126
-#define B01111110 126
-#define B1111111 127
-#define B01111111 127
-#define B10000000 128
-#define B10000001 129
-#define B10000010 130
-#define B10000011 131
-#define B10000100 132
-#define B10000101 133
-#define B10000110 134
-#define B10000111 135
-#define B10001000 136
-#define B10001001 137
-#define B10001010 138
-#define B10001011 139
-#define B10001100 140
-#define B10001101 141
-#define B10001110 142
-#define B10001111 143
-#define B10010000 144
-#define B10010001 145
-#define B10010010 146
-#define B10010011 147
-#define B10010100 148
-#define B10010101 149
-#define B10010110 150
-#define B10010111 151
-#define B10011000 152
-#define B10011001 153
-#define B10011010 154
-#define B10011011 155
-#define B10011100 156
-#define B10011101 157
-#define B10011110 158
-#define B10011111 159
-#define B10100000 160
-#define B10100001 161
-#define B10100010 162
-#define B10100011 163
-#define B10100100 164
-#define B10100101 165
-#define B10100110 166
-#define B10100111 167
-#define B10101000 168
-#define B10101001 169
-#define B10101010 170
-#define B10101011 171
-#define B10101100 172
-#define B10101101 173
-#define B10101110 174
-#define B10101111 175
-#define B10110000 176
-#define B10110001 177
-#define B10110010 178
-#define B10110011 179
-#define B10110100 180
-#define B10110101 181
-#define B10110110 182
-#define B10110111 183
-#define B10111000 184
-#define B10111001 185
-#define B10111010 186
-#define B10111011 187
-#define B10111100 188
-#define B10111101 189
-#define B10111110 190
-#define B10111111 191
-#define B11000000 192
-#define B11000001 193
-#define B11000010 194
-#define B11000011 195
-#define B11000100 196
-#define B11000101 197
-#define B11000110 198
-#define B11000111 199
-#define B11001000 200
-#define B11001001 201
-#define B11001010 202
-#define B11001011 203
-#define B11001100 204
-#define B11001101 205
-#define B11001110 206
-#define B11001111 207
-#define B11010000 208
-#define B11010001 209
-#define B11010010 210
-#define B11010011 211
-#define B11010100 212
-#define B11010101 213
-#define B11010110 214
-#define B11010111 215
-#define B11011000 216
-#define B11011001 217
-#define B11011010 218
-#define B11011011 219
-#define B11011100 220
-#define B11011101 221
-#define B11011110 222
-#define B11011111 223
-#define B11100000 224
-#define B11100001 225
-#define B11100010 226
-#define B11100011 227
-#define B11100100 228
-#define B11100101 229
-#define B11100110 230
-#define B11100111 231
-#define B11101000 232
-#define B11101001 233
-#define B11101010 234
-#define B11101011 235
-#define B11101100 236
-#define B11101101 237
-#define B11101110 238
-#define B11101111 239
-#define B11110000 240
-#define B11110001 241
-#define B11110010 242
-#define B11110011 243
-#define B11110100 244
-#define B11110101 245
-#define B11110110 246
-#define B11110111 247
-#define B11111000 248
-#define B11111001 249
-#define B11111010 250
-#define B11111011 251
-#define B11111100 252
-#define B11111101 253
-#define B11111110 254
-#define B11111111 255
-
-#endif
diff --git a/libmaple/nvic.c b/libmaple/nvic.c
index 91e572e..6603d42 100644
--- a/libmaple/nvic.c
+++ b/libmaple/nvic.c
@@ -64,3 +64,18 @@ void nvic_enable_interrupt(uint32 n) {
}
+
+/**
+ * @brief Initialice the NVIC at address addr
+ * @param addr Address to set the vector table at
+ */
+void nvic_init(void) {
+#ifdef VECT_TAB_ROM
+ nvic_set_vector_table(USER_ADDR_ROM, 0x0);
+#elif defined VECT_TAB_RAM
+ nvic_set_vector_table(USER_ADDR_RAM, 0x0);
+#else // VECT_TAB_BASE
+ /* Set the Vector Table base location at 0x08000000 */
+ nvic_set_vector_table(((uint32)0x08000000), 0x0);
+#endif
+}
diff --git a/libmaple/nvic.h b/libmaple/nvic.h
index e785018..a9f32d6 100644
--- a/libmaple/nvic.h
+++ b/libmaple/nvic.h
@@ -54,10 +54,15 @@
#define NVIC_NR_INTERRUPTS 60
+/* Where to put code */
+#define USER_ADDR_ROM 0x08005000
+#define USER_ADDR_RAM 0x20000C00
+
#ifdef __cplusplus
extern "C"{
#endif
+void nvic_init(void);
void nvic_disable_interrupts(void);
void nvic_enable_interrupt(uint32);
@@ -65,6 +70,5 @@ void nvic_enable_interrupt(uint32);
}
#endif
-
#endif
diff --git a/core/Print.cpp b/wirish/Print.cpp
index da461ae..5a1bc93 100644
--- a/core/Print.cpp
+++ b/wirish/Print.cpp
@@ -19,11 +19,7 @@
Modified 23 November 2006 by David A. Mellis
*/
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-#include "wiring.h"
-
+#include "wirish.h"
#include "Print.h"
// Public Methods //////////////////////////////////////////////////////////////
diff --git a/core/Print.h b/wirish/Print.h
index b2f8647..b2f8647 100644
--- a/core/Print.h
+++ b/wirish/Print.h
diff --git a/core/WProgram.h b/wirish/WProgram.h
index 7653bb6..7653bb6 100644
--- a/core/WProgram.h
+++ b/wirish/WProgram.h
diff --git a/core/bits.h b/wirish/bits.h
index 7ebea80..7ebea80 100644
--- a/core/bits.h
+++ b/wirish/bits.h
diff --git a/wirish/comm/HardwareSPI.cpp b/wirish/comm/HardwareSPI.cpp
new file mode 100644
index 0000000..49dad71
--- /dev/null
+++ b/wirish/comm/HardwareSPI.cpp
@@ -0,0 +1,138 @@
+/* *****************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2010 Perry Hung.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * ****************************************************************************/
+
+/**
+ * @brief HardwareSPI "wiring-like" api for SPI
+ */
+
+/* NOTES:
+ *
+ * Speeds:
+ * -----------------------------------
+ * Interface num: SPI1 SPI2
+ * Bus APB2 APB1
+ * -----------------------------------
+ * Prescaler Frequencies
+ * -----------------------------------
+ * 2: N/A 18 000 000
+ * 4: 18 000 000 9 000 000
+ * 8: 9 000 000 4 500 000
+ * 16: 4 500 000 2 250 000
+ * 32: 2 250 000 1 125 000
+ * 64: 1 125 000 562 500
+ * 128: 562 500 281 250
+ * 256: 281 250 140 625
+ *
+ * TODO: Do the complementary PWM outputs mess up SPI2?
+ * */
+
+#include "wirish.h"
+#include "spi.h"
+#include "HardwareSPI.h"
+
+static const uint32 prescaleFactors[MAX_SPI_FREQS] = {
+ SPI_PRESCALE_2, // SPI_18MHZ
+ SPI_PRESCALE_4, // SPI_9MHZ
+ SPI_PRESCALE_8, // SPI_4_5MHZ
+ SPI_PRESCALE_16, // SPI_2_25MHZ
+ SPI_PRESCALE_32, // SPI_1_125MHZ
+ SPI_PRESCALE_64, // SPI_562_500KHZ
+ SPI_PRESCALE_128, // SPI_281_250KHZ
+ SPI_PRESCALE_256, // SPI_140_625KHZ
+};
+
+/**
+ * @brief Initialize a SPI peripheral
+ * @param freq frequency to run at, must one of the following values:
+ * - SPI_18MHZ
+ * - SPI_9MHZ
+ * - SPI_4_5MHZ
+ * - SPI_2_25MHZ
+ * - SPI_1_125MHZ
+ * - SPI_562_500KHZ
+ * - SPI_281_250KHZ
+ * - SPI_140_625KHZ
+ * @param endianness endianness of the data frame, must be either LSBFIRST
+ * or MSBFIRST
+ * @param mode SPI standard CPOL and CPHA levels
+ */
+void HardwareSPI::begin(SPIFrequency freq, uint32 endianness, uint32 mode) {
+ uint32 spi_num = this->spi_num;
+ uint32 high_speed = 0;
+ uint32 index;
+ uint32 prescale;
+
+ if ((freq >= MAX_SPI_FREQS) ||
+ !((endianness == LSBFIRST) ||
+ (endianness == MSBFIRST)) ||
+ (mode >= 4)) {
+ return;
+ }
+
+ if (spi_num == 1) {
+ /* SPI1 is too fast for 140625 */
+ if (freq == SPI_140_625KHZ) {
+ return;
+ }
+
+ /* Turn off PWM on shared pins */
+ timers_disable_channel(3, 2);
+ timers_disable_channel(3, 1);
+ }
+
+ endianness = (endianness == LSBFIRST) ? SPI_LSBFIRST : SPI_MSBFIRST;
+ prescale = (spi_num == 1) ? prescaleFactors[freq + 1] : prescaleFactors[freq];
+
+ spi_init(spi_num, prescale, endianness, 0);
+}
+
+/**
+ * @brief Initialize a SPI peripheral with a default speed of 1.125 MHZ, MSBFIRST,
+ * mode 0
+ * @param mode SPI standard CPOL and CPHA levels
+ */
+void HardwareSPI::begin(void) {
+ begin(SPI_1_125MHZ, MSBFIRST, 0);
+}
+
+/**
+ * @brief send a byte out the spi peripheral
+ * @param data byte to send
+ */
+void HardwareSPI::send(uint8 data) {
+ spi_tx(this->spi_num, data);
+}
+
+
+/**
+ * @brief read a byte from the spi peripheral
+ * @return byte in the buffer
+ */
+uint8 HardwareSPI::recv(void) {
+ return spi_rx(this->spi_num);
+}
+
+HardwareSPI::HardwareSPI(uint32 spi_num) {
+ this->spi_num = spi_num;
+}
diff --git a/wirish/comm/HardwareSPI.h b/wirish/comm/HardwareSPI.h
new file mode 100644
index 0000000..b974334
--- /dev/null
+++ b/wirish/comm/HardwareSPI.h
@@ -0,0 +1,57 @@
+/* *****************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2010 Perry Hung.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * ****************************************************************************/
+
+/**
+ * @brief HardwareSPI definitions
+ */
+
+#ifndef _HARDWARESPI_H_
+#define _HARDWARESPI_H_
+
+typedef enum SPIFrequency {
+ SPI_18MHZ = 0,
+ SPI_9MHZ = 1,
+ SPI_4_5MHZ = 2,
+ SPI_2_25MHZ = 3,
+ SPI_1_125MHZ = 4,
+ SPI_562_500KHZ = 5,
+ SPI_281_250KHZ = 6,
+ SPI_140_625KHZ = 7,
+ MAX_SPI_FREQS = 8,
+} SPIFrequency;
+
+class HardwareSPI {
+ private:
+ uint32 spi_num;
+
+ public:
+ HardwareSPI(uint32 spi_num);
+ void begin(void);
+ void begin(SPIFrequency freq, uint32 endianness, uint32 mode);
+ void send(uint8 data);
+ uint8 recv(void);
+};
+
+#endif
+
diff --git a/core/comm/HardwareSerial.cpp b/wirish/comm/HardwareSerial.cpp
index 42c5d61..3e855ea 100644
--- a/core/comm/HardwareSerial.cpp
+++ b/wirish/comm/HardwareSerial.cpp
@@ -28,7 +28,7 @@
* @brief Wiring-like serial api
*/
-#include "wiring.h"
+#include "wirish.h"
#include "HardwareSerial.h"
#include "usart.h"
#include "gpio.h"
diff --git a/core/comm/HardwareSerial.h b/wirish/comm/HardwareSerial.h
index a488244..a488244 100644
--- a/core/comm/HardwareSerial.h
+++ b/wirish/comm/HardwareSerial.h
diff --git a/core/comm/HardwareUsb.cpp b/wirish/comm/HardwareUsb.cpp
index 2012c2e..4398e96 100644
--- a/core/comm/HardwareUsb.cpp
+++ b/wirish/comm/HardwareUsb.cpp
@@ -26,7 +26,7 @@
* @brief Wiring like serial api to USB virtual COM
*/
-#include "wiring.h"
+#include "wirish.h"
#include "HardwareUsb.h"
#include "bootVect.h"
#include "usb.h"
diff --git a/core/comm/HardwareUsb.h b/wirish/comm/HardwareUsb.h
index ee13f40..ee13f40 100644
--- a/core/comm/HardwareUsb.h
+++ b/wirish/comm/HardwareUsb.h
diff --git a/core/ext_interrupts.c b/wirish/ext_interrupts.c
index bbe861d..54b8be9 100644
--- a/core/ext_interrupts.c
+++ b/wirish/ext_interrupts.c
@@ -28,7 +28,7 @@
* @brief Wiring-like interface for external interrupts
*/
-#include "wiring.h"
+#include "wirish.h"
#include "exti.h"
#include "ext_interrupts.h"
diff --git a/core/ext_interrupts.h b/wirish/ext_interrupts.h
index fc69a15..fc69a15 100644
--- a/core/ext_interrupts.h
+++ b/wirish/ext_interrupts.h
diff --git a/core/io.h b/wirish/io.h
index fff551c..fff551c 100644
--- a/core/io.h
+++ b/wirish/io.h
diff --git a/core/main.cxx b/wirish/main.cxx
index 440d464..440d464 100644
--- a/core/main.cxx
+++ b/wirish/main.cxx
diff --git a/core/pwm.c b/wirish/pwm.c
index 8e58d01..40715b5 100644
--- a/core/pwm.c
+++ b/wirish/pwm.c
@@ -23,12 +23,10 @@
* ****************************************************************************/
/**
- * @file pwm.c
- *
* @brief
*/
-#include "wiring.h"
+#include "wirish.h"
#include "timers.h"
#include "io.h"
#include "pwm.h"
diff --git a/core/pwm.h b/wirish/pwm.h
index 4f69751..4f69751 100644
--- a/core/pwm.h
+++ b/wirish/pwm.h
diff --git a/core/time.c b/wirish/time.c
index 69e962c..69e962c 100644
--- a/core/time.c
+++ b/wirish/time.c
diff --git a/core/time.h b/wirish/time.h
index 9e5536b..9e5536b 100644
--- a/core/time.h
+++ b/wirish/time.h
diff --git a/core/wiring.c b/wirish/wirish.c
index 803b571..5102124 100644
--- a/core/wiring.c
+++ b/wirish/wirish.c
@@ -23,17 +23,14 @@
* ****************************************************************************/
/**
- * @file wiring.c
- *
- * @brief
+ * @brief Maple board bring up
*/
-#include "wiring.h"
+#include "wirish.h"
#include "rcc.h"
#include "systick.h"
#include "gpio.h"
-
-void nvic_init(void);
+#include "nvic.h"
void init(void) {
rcc_init();
@@ -47,13 +44,4 @@ void init(void) {
timer_init(4, 1);
}
-void nvic_init(void) {
-#ifdef VECT_TAB_ROM
- nvic_set_vector_table(USER_ADDR_ROM, 0x0);
-#elif defined VECT_TAB_RAM
- nvic_set_vector_table(USER_ADDR_RAM, 0x0);
-#else // VECT_TAB_BASE
- /* Set the Vector Table base location at 0x08000000 */
- nvic_set_vector_table(((uint32)0x08000000), 0x0);
-#endif
-}
+
diff --git a/core/wiring.h b/wirish/wirish.h
index 8360ce6..5129c26 100644
--- a/core/wiring.h
+++ b/wirish/wirish.h
@@ -21,14 +21,19 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* ****************************************************************************/
+/**
+ * @brief Main include file for the Wirish core.
+ *
+ * Includes various Arduino wiring macros and bit defines
+ */
+
-#ifndef _WIRING_H_
-#define _WIRING_H_
+#ifndef _WIRISH_H_
+#define _WIRISH_H_
#include "libmaple.h"
#include "timers.h"
#include "io.h"
-#include "binary.h"
#include "bits.h"
#include "time.h"
#include "pwm.h"
@@ -41,38 +46,34 @@ extern "C"{
#define MAPLE 1
#define NR_MAPLE_PINS 39 // temporary
+/* Arduino wiring macros and bit defines */
#define HIGH 0x1
#define LOW 0x0
#define true 0x1
#define false 0x0
-#define SERIAL 0x0
-#define DISPLAY 0x1
-
#define LSBFIRST 0
#define MSBFIRST 1
#define USER_ADDR_ROM 0x08005000
#define USER_ADDR_RAM 0x20000C00
-#define lowByte(w) ((w) & 0xff)
-#define highByte(w) ((w) >> 8)
-#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
-#define bitSet(value, bit) ((value) |= (1UL << (bit)))
-#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
-#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
-#define bit(b) (1UL << (b))
-
+#define lowByte(w) ((w) & 0xff)
+#define highByte(w) ((w) >> 8)
+#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
+#define bitSet(value, bit) ((value) |= (1UL << (bit)))
+#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
+#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : \
+ bitClear(value, bit))
+#define bit(b) (1UL << (b))
typedef uint8 boolean;
typedef uint8 byte;
void init(void);
-unsigned long pulseIn(uint8 pin, uint8 state, unsigned long timeout);
void shiftOut(uint8 dataPin, uint8 clockPin, uint8 bitOrder, byte val);
-
#ifdef __cplusplus
} // extern "C"
#endif
diff --git a/core/wiring_analog.c b/wirish/wirish_analog.c
index da41025..f4c1204 100644
--- a/core/wiring_analog.c
+++ b/wirish/wirish_analog.c
@@ -23,13 +23,11 @@
* ****************************************************************************/
/**
- * @file wiring_analog.c
- *
* @brief
*/
#include "libmaple.h"
-#include "wiring.h"
+#include "wirish.h"
#include "io.h"
extern const PinMapping PIN_MAP[NR_MAPLE_PINS];
diff --git a/core/wiring_digital.c b/wirish/wirish_digital.c
index 52cc652..33217b6 100644
--- a/core/wiring_digital.c
+++ b/wirish/wirish_digital.c
@@ -23,12 +23,10 @@
* ****************************************************************************/
/**
- * @file wiring_digital.c
- *
* @brief
*/
-#include "wiring.h"
+#include "wirish.h"
#include "io.h"
#define ADC0 0
diff --git a/core/wiring_math.cpp b/wirish/wirish_math.cpp
index 0d907c4..0d907c4 100644
--- a/core/wiring_math.cpp
+++ b/wirish/wirish_math.cpp
diff --git a/core/wiring_math.h b/wirish/wirish_math.h
index b8fa710..19f3892 100644
--- a/core/wiring_math.h
+++ b/wirish/wirish_math.h
@@ -32,25 +32,25 @@ long random(long);
long random(long, long);
long map(long, long, long, long, long);
-#define PI 3.1415926535897932384626433832795
-#define HALF_PI 1.5707963267948966192313216916398
-#define TWO_PI 6.283185307179586476925286766559
-#define DEG_TO_RAD 0.017453292519943295769236907684886
-#define RAD_TO_DEG 57.295779513082320876798154814105
-
-#define min(a,b) ((a)<(b)?(a):(b))
-#define max(a,b) ((a)>(b)?(a):(b))
+#define PI 3.1415926535897932384626433832795
+#define HALF_PI 1.5707963267948966192313216916398
+#define TWO_PI 6.283185307179586476925286766559
+#define DEG_TO_RAD 0.017453292519943295769236907684886
+#define RAD_TO_DEG 57.295779513082320876798154814105
+
+#define min(a,b) ((a)<(b)?(a):(b))
+#define max(a,b) ((a)>(b)?(a):(b))
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
-#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
-#define radians(deg) ((deg)*DEG_TO_RAD)
-#define degrees(rad) ((rad)*RAD_TO_DEG)
-#define sq(x) ((x)*(x))
+#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
+#define radians(deg) ((deg)*DEG_TO_RAD)
+#define degrees(rad) ((rad)*RAD_TO_DEG)
+#define sq(x) ((x)*(x))
/* undefine stdlib's abs if encountered */
#ifdef abs
#undef abs
#endif
-#define abs(x) (((x) > 0) ? (x) : -(unsigned)(x))
+#define abs(x) (((x) > 0) ? (x) : -(unsigned)(x))
#endif
diff --git a/core/wiring_shift.c b/wirish/wirish_shift.c
index a2487e7..884b560 100644
--- a/core/wiring_shift.c
+++ b/wirish/wirish_shift.c
@@ -22,7 +22,7 @@
$Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
*/
-#include "wiring.h"
+#include "wirish.h"
void shiftOut(uint8 dataPin, uint8 clockPin, uint8 bitOrder, uint8 val)
{