8000 Merge branch 'master' of https://github.com/sparkfun/Arduino_Apollo3 · EmbeddedMan/Arduino_Apollo3@fa15508 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fa15508

Browse files
committed
2 parents cd83dc0 + 3d20391 commit fa15508

File tree

5 files changed

+129
-33
lines changed

5 files changed

+129
-33
lines changed

cores/arduino/ard_sup/Arduino.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ enum BitOrder
9494
#include "ap3_debugging.h"
9595
#include "ap3_uart.h"
9696
#include "ap3_analog.h"
97+
#include "WMath.h"
9798

9899
#include "variant.h"
99100

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Copyright (c) 2014 Arduino. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
extern "C" {
20+
#include "stdlib.h"
21+
#include "stdint.h"
22+
}
23+
#include "WMath.h"
24+
25+
extern void randomSeed( uint32_t dwSeed )
26+
{
27+
if ( dwSeed != 0 )
28+
{
29+
srand( dwSeed ) ;
30+
}
31+
}
32+
33+
extern long random( long howbig )
34+
{
35+
if ( howbig == 0 )
36+
{
37+
return 0 ;
38+
}
39+
40+
return rand() % howbig;
41+
}
42+
43+
extern long random( long howsmall, long howbig )
44+
{
45+
if (howsmall >= howbig)
46+
{
47+
return howsmall;
48+
}
49+
50+
long diff = howbig - howsmall;
51+
52+
return random(diff) + howsmall;
53+
}
54+
55+
extern long map(long x, long in_min, long in_max, long out_min, long out_max)
56+
{
57+
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
58+
}
59+
60+
extern uint16_t makeWord( uint16_t w )
61+
{
62+
return w ;
63+
}
64+
65+
extern uint16_t makeWord( uint8_t h, uint8_t l )
66+
{
67+
return (h << 8) | l ;
68+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Copyright (c) 2014 Arduino. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#ifndef _WIRING_MATH_
20+
#define _WIRING_MATH_
21+
22+
extern long random( long ) ;
23+
extern long random( long, long ) ;
24+
extern void randomSeed( uint32_t dwSeed ) ;
25+
extern long map( long, long, long, long, long ) ;
26+
27+
extern uint16_t makeWord( uint16_t w ) ;
28+
extern uint16_t makeWord( uint8_t h, uint8_t l ) ;
29+
30+
#define word(...) makeWord(__VA_ARGS__)
31+
32+
33+
#endif /* _WIRING_MATH_ */

variants/SparkFun_Artemis/config/variant.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ SOFTWARE.
2222

2323
#include "variant.h"
2424

25-
// This is the actual pinmap.
25+
// This is the actual pinmap.
2626
// For a variant pin X the corresponding Apollo3 pad Y is stored in ap3_variant_pinmap[X]
2727
// X [0, (AP3_VARIANT_NUM_PINS - 1)]
2828
// Y [0, 49]
@@ -86,12 +86,9 @@ const ap3_gpio_pad_t ap3_variant_pinmap[AP3_VARIANT_NUM_PINS] = {
8686

8787
// Uart Definitions
8888
//Serial(instance, RX, TX)
89-
//
90-
// Commented out because we don't know which pins should be used on the Artemis module
91-
//
92-
// Uart Serial(0, 23, 22); // Declares a Uart object called Serial using instance 0 of Apollo3 UART peripherals with RX on variant pin 23 and TX on pin 24 (note, you specify *pins* not Apollo3 pads. This uses the variant's pin map to determine the Apollo3 pad)
93-
// Uart Serial1(1, 0, 1); // Declares a Uart object called Serial1 using instance 1 of Apollo3 UART peripherals with RX on pin 0 and TX on pin 1 (note, you specify *pins* not Apollo3 pads. This uses the variant's pin map to determine the Apollo3 pad)
94-
89+
//We default Serial to 22/23 but can be moved to any TX0/RX0 pin
90+
Uart Serial(0, 23, 22); // Declares a Uart object called Serial using instance 0 of Apollo3 UART peripherals with RX on variant pin 23 and TX on pin 24 (note, you specify *pins* not Apollo3 pads. This uses the variant's pin map to determine the Apollo3 pad)
91+
// Uart Serial1(1, 0, 1); // Declares a Uart object called Serial1 using instance 1 of Apollo3 UART peripherals with RX on pin 0 and TX on pin 1 (note, you specify *pins* not Apollo3 pads. This uses the variant's pin map to determine the Apollo3 pad)
9592

9693
// Pin aliasing using the const uint8_t approach
9794
//
@@ -102,7 +99,6 @@ const ap3_gpio_pad_t ap3_variant_pinmap[AP3_VARIANT_NUM_PINS] = {
10299
// const uint8_t A4 = 20;
103100
// const uint8_t A5 = 21;
104101

105-
106102
// Indirect pinmap example
107103
//
108104
// const ap3_gpio_pad_t ap3_variant_pinmap[AP3_VARIANT_NUM_PINS] = {

variants/SparkFun_Artemis/config/variant.h

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,21 @@ explained so that this file can serve as a starting point for creating new varia
3232
3333
*/
3434

35-
3635
#ifndef _AP3_VARIANT_H_
3736
#define _AP3_VARIANT_H_
3837

3938
#include "Arduino.h"
4039

41-
// In the Apollo3 Arduino core *pins* refer to the connections that can be accessed
40+
// In the Apollo3 Arduino core *pins* refer to the connections that can be accessed
4241
// via Arduino code. This may be, for example, an exposed connection that the user could
43-
// utilize directly or it may be a connection to an onboard sensor.
44-
//
42+
// utilize directly or it may be a connection to an onboard sensor.
43+
//
4544
// *pads* on the other hand refer directly to the pad numbers of the Apollo3 microcontroller
4645
//
4746
// When developing a variant you might connect *pin* x of your board to *pad* y on the
4847
// Apollo3. When a user asks to write to *pin* x the core will use a map to determine which
49-
// *pad* to control.
50-
//
48+
// *pad* to control.
49+
//
5150
// AP3_VARIANT_NUM_PINS determines the size of this map and its value must be N+1 where N
5251
// is the largest _pin_id_ of your variant. Let's try an example:
5352
//
@@ -67,25 +66,25 @@ extern const ap3_gpio_pad_t ap3_variant_pinmap[AP3_VARIANT_NUM_PINS];
6766

6867
// Uart declarations
6968
// - "HardwareSerial" is the class that is built into Arduino to allow "Serial.print()"
70-
// and related functions to work.
69+
// and related functions to work.
7170
// - The "Uart" class inherits from HardwareSerial and contains Apollo3-specific code
7271
// - Declaring your Uart objects here makes them available in any Arduino code and you
7372
// can give them extra descriptive names
74-
// - The maximum number of Uarts is 2 (instances 0 and 1)
73+
// - The maximum number of Uarts is 2 (instances 0 and 1)
7574
//
7675
// In this case the declarations are commented out because we don't know which pins of
7776
// the Artemis module you would like to use
7877
class Uart; // Forward declaration of Uart class
79-
// extern Uart Serial;
78+
extern Uart Serial;
8079
// extern Uart Serial1;
8180

8281
// A note about IOMaster peripherals:
8382
// - IOMaster peripherals are used to provide either SPI or I2C communications. The pads
8483
// of the Apollo3 that a given IOMaster [0,5] use are not configurable
8584

8685
// Wire defines
87-
// - Wire is the I2C class for Arduino.
88-
// - Wire is handled differently than HardwareSerial/Uart because Wire is a library that
86+
// - Wire is the I2C class for Arduino.
87+
// - Wire is handled differently than HardwareSerial/Uart because Wire is a library that
8988
// you have to include manually (saves space if you won't be using I2C)
9089
// - In this case we rely on communication between the variant.h file and the Wire library
9190
// through the use of #define statements
@@ -107,7 +106,7 @@ class Uart; // Forward declaration of Uart class
107106
#define AP3_Wire5_IOM 5 // Secify that Wire5 uses IOMaster instance 5
108107
// This is also a convenient location to provide some aliased names for certain Wire objects
109108
// For example: (examples commented out because they aren't real)
110-
//
109+
//
111110
// #define WireQwiic Wire // Giving Wire an alias of "WireQwiic" to indicat that it is the I2C controller for the Qwiic bus
112111
// #define WireAccel Wire1 // Useful if the variant has an onboard accelerometer connected to the Wire1 bus
113112

@@ -121,19 +120,18 @@ class Uart; // Forward declaration of Uart class
121120
// you need to specify two settings:
122121
// - - AP3_SPI_IOM - which IOMaster peripher the SPI object will use
123122
// - - AP3_SPI_DUP - which duplex mode the SPI object will use (full duplex is the most common, ap3_spi_tx_only and ap3_spi_rx_only are the other options )
124-
#define AP3_SPI_IOM 0
125-
#define AP3_SPI_DUP ap3_spi_full_duplex
126-
#define AP3_SPI1_IOM 1
127-
#define AP3_SPI1_DUP ap3_spi_full_duplex
128-
#define AP3_SPI2_IOM 2
129-
#define AP3_SPI2_DUP ap3_spi_full_duplex
130-
#define AP3_SPI3_IOM 3
131-
#define AP3_SPI3_DUP ap3_spi_full_duplex
132-
#define AP3_SPI4_IOM 4
133-
#define AP3_SPI4_DUP ap3_spi_full_duplex
134-
#define AP3_SPI5_IOM 5
135-
#define AP3_SPI5_DUP ap3_spi_full_duplex
136-
123+
#define AP3_SPI_IOM 0
124+
#define AP3_SPI_DUP ap3_spi_full_duplex
125+
#define AP3_SPI1_IOM 1
126+
#define AP3_SPI1_DUP ap3_spi_full_duplex
127+
#define AP3_SPI2_IOM 2
128+
#define AP3_SPI2_DUP ap3_spi_full_duplex
129+
#define AP3_SPI3_IOM 3
130+
#define AP3_SPI3_DUP ap3_spi_full_duplex
131+
#define AP3_SPI4_IOM 4
132+
#define AP3_SPI4_DUP ap3_spi_full_duplex
133+
#define AP3_SPI5_IOM 5
134+
#define AP3_SPI5_DUP ap3_spi_full_duplex
137135

138136
// Additional Pin Aliasing
139137
// - It is required that every pin is accessible by a number between 0 and (AP3_VARIANT_NUM_PINS - 1)

0 commit comments

Comments
 (0)
0