Skip to content

Commit 1812a60

Browse files
committed
Merge branch 'master' into core-ble
2 parents b674be7 + dc4fdf2 commit 1812a60

File tree

11 files changed

+338
-21
lines changed

11 files changed

+338
-21
lines changed

docs/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ This is a record of the major changes between versions of the SparkFun Arduino A
55

66
Each log entry will use the version number of the release that contains the changes listed. Newest version at the top of the file (just below this line)
77

8+
1.0.13
9+
===================
10+
- merged PR #61
11+
812
1.0.12
913
===================
1014
- fixed redefinition of ADC symbols in redboard_artemis_nano

libraries/EEPROM/examples/Example2_AllFunctions/Example2_AllFunctions.ino

+12-7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717
#include <EEPROM.h>
1818

19+
// Give a default if the variant does not define one.
20+
#ifndef A0
21+
#define A0 0
22+
#endif
23+
1924
void setup()
2025
{
2126
Serial.begin(9600);
@@ -39,7 +44,7 @@ void setup()
3944
Serial.println("8 bit tests");
4045
byte myValue1 = 200;
4146
byte myValue2 = 23;
42-
randomLocation = random(0, FLASH_EEPROM_SIZE);
47+
randomLocation = random(0, AP3_FLASH_EEPROM_SIZE);
4348

4449
startTime = millis();
4550
EEPROM.write(randomLocation, myValue1); //(location, data)
@@ -61,7 +66,7 @@ void setup()
6166
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
6267
uint16_t myValue3 = 3411;
6368
int16_t myValue4 = -366;
64-
randomLocation = random(0, FLASH_EEPROM_SIZE);
69+
randomLocation = random(0, AP3_FLASH_EEPROM_SIZE);
6570

6671
EEPROM.put(randomLocation, myValue3);
6772
EEPROM.put(randomLocation + 2, myValue4);
@@ -82,7 +87,7 @@ void setup()
8287
Serial.printf("Size of int: %d\n", sizeof(int));
8388
int myValue5 = -245000;
8489
unsigned int myValue6 = 400123;
85-
randomLocation = random(0, FLASH_EEPROM_SIZE);
90+
randomLocation = random(0, AP3_FLASH_EEPROM_SIZE);
8691

8792
EEPROM.put(randomLocation, myValue5);
8893
EEPROM.put(randomLocation + 4, myValue6);
@@ -99,7 +104,7 @@ void setup()
99104
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
100105
int32_t myValue7 = -341002;
101106
uint32_t myValue8 = 241544;
102-
randomLocation = random(0, FLASH_EEPROM_SIZE);
107+
randomLocation = random(0, AP3_FLASH_EEPROM_SIZE);
103108

104109
EEPROM.update(randomLocation, myValue7);
105110
EEPROM.update(randomLocation + 4, myValue8);
@@ -117,7 +122,7 @@ void setup()
117122
Serial.printf("Size of float: %d\n", sizeof(float));
118123
float myValue9 = -7.35;
119124
float myValue10 = 5.22;
120-
randomLocation = random(0, FLASH_EEPROM_SIZE);
125+
randomLocation = random(0, AP3_FLASH_EEPROM_SIZE);
121126

122127
EEPROM.update(randomLocation, myValue9);
123128
EEPROM.update(randomLocation + 4, myValue10);
@@ -138,7 +143,7 @@ void setup()
138143
Serial.printf("Size of double: %d\n", sizeof(double));
139144
double myValue11 = -290.3485723409857;
140145
double myValue12 = 384.95734987;
141-
randomLocation = random(0, FLASH_EEPROM_SIZE);
146+
randomLocation = random(0, AP3_FLASH_EEPROM_SIZE);
142147

143148
EEPROM.update(randomLocation, myValue11);
144149
EEPROM.update(randomLocation + 8, myValue12);
@@ -157,7 +162,7 @@ void setup()
157162
{
158163
if (x % 32 == 0)
159164
Serial.println();
160-
Serial.printf("0x%08X ", *(uint32_t *)(FLASH_EEPROM_START + x));
165+
Serial.printf("0x%08X ", *(uint32_t *)(AP3_FLASH_EEPROM_START + x));
161166
}
162167
Serial.println();
163168
}

libraries/EEPROM/src/EEPROM.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ void ap3_EEPROM::get(uint16_t eepromLocation, double &dataToGet)
113113
double lf;
114114
uint32_t b[2];
115115
} temp;
116-
temp.b[1] = *(uint32_t *)(AP3_FLASH_EEPROM_START + eepromLocation); //LSB;
117-
temp.b[0] = *(uint32_t *)(AP3_FLASH_EEPROM_START + eepromLocation + 4) << 32; //MSB;
116+
temp.b[1] = *(uint32_t *)(AP3_FLASH_EEPROM_START + eepromLocation); //LSB;
117+
temp.b[0] = *(uint32_t *)(AP3_FLASH_EEPROM_START + eepromLocation + 4); //MSB;
118118
dataToGet = temp.lf;
119119
}
120120

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* Author: Nathan Seidle
2+
Created: Septempter 27th, 2019
3+
License: MIT. See SparkFun Arduino Apollo3 Project for more information
4+
5+
This example demonstrates how to initialize and read from the on board RTC.
6+
Most SparkFun Artemis boards have the necessary external 32kHz crystal to
7+
enable the RTC. If you are using the Artemis module bare you will either
8+
need an external 32kHz xtal or use the internal LFRC. Read the datasheet
9+
section 12.1 for more information.
10+
11+
This example is based on the Ambiq SDK EVB2 RTC example.
12+
*/
13+
14+
#include "RTC.h" //Include RTC library included with the Aruino_Apollo3 core
15+
APM3_RTC myRTC; //Create instance of RTC class
16+
17+
void setup()
18+
{
19+
Serial.begin(115200);
20+
Serial.println("SparkFun RTC Example");
21+
22+
myRTC.setToCompilerTime(); //Easily set RTC using the system __DATE__ and __TIME__ macros from compiler
23+
//myRTC.setTime(7, 28, 51, 0, 21, 10, 15); //Manually set RTC back to the future: Oct 21st, 2015 at 7:28.51 AM
24+
}
25+
26+
void loop()
27+
{
28+
myRTC.getTime();
29+
30+
Serial.printf("It is now ");
31+
Serial.printf("%d:", myRTC.hour);
32+
Serial.printf("%02d:", myRTC.minute);
33+
Serial.printf("%02d.", myRTC.seconds);
34+
Serial.printf("%02d", myRTC.hundredths);
35+
36+
Serial.printf(" %02d/", myRTC.month);
37+
Serial.printf("%02d/", myRTC.dayOfMonth);
38+
Serial.printf("%02d", myRTC.year);
39+
40+
Serial.printf(" Day of week: %d =", myRTC.weekday);
41+
Serial.printf(" %s", myRTC.textWeekday);
42+
43+
Serial.println();
44+
45+
delay(1000);
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/* Author: Nathan Seidle
2+
Created: Septempter 27th, 2019
3+
License: MIT. See SparkFun Arduino Apollo3 Project for more information
4+
5+
This example demonstrates how to put the core to sleep for a number of
6+
milliseconds before waking and printing the current time/date. This
7+
is helpful for checking power consumption of the core while RTC+CT6 are running.
8+
*/
9+
10+
#include "RTC.h" //Include RTC library included with the Aruino_Apollo3 core
11+
APM3_RTC myRTC; //Create instance of RTC class
12+
13+
uint32_t msToSleep = 2000; //This is the user editable number of ms to sleep between RTC checks
14+
#define TIMER_FREQ 3000000L //Counter/Timer 6 will use the HFRC oscillator of 3MHz
15+
uint32_t sysTicksToSleep = msToSleep * (TIMER_FREQ / 1000);
16+
17+
void setup()
18+
{
19+
Serial.begin(115200);
20+
Serial.println("SparkFun RTC Example");
21+
22+
myRTC.setToCompilerTime(); //Easily set RTC using the system __DATE__ and __TIME__ macros from compiler
23+
//myRTC.setTime(7, 28, 51, 0, 21, 10, 15); //Manually set RTC back to the future: Oct 21st, 2015 at 7:28.51 AM
24+
25+
setupWakeTimer();
26+
}
27+
28+
void loop()
29+
{
30+
myRTC.getTime();
31+
32+
Serial.printf("It is now ");
33+
Serial.printf("%d:", myRTC.hour);
34+
Serial.printf("%02d:", myRTC.minute);
35+
Serial.printf("%02d.", myRTC.seconds);
36+
Serial.printf("%02d", myRTC.hundredths);
37+
38+
Serial.printf(" %02d/", myRTC.month);
39+
Serial.printf("%02d/", myRTC.dayOfMonth);
40+
Serial.printf("%02d", myRTC.year);
41+
42+
Serial.printf(" Day of week: %d =", myRTC.weekday);
43+
Serial.printf(" %s", myRTC.textWeekday);
44+
45+
Serial.println();
46+
47+
am_hal_sysctrl_sleep(AM_HAL_SYSCTRL_SLEEP_DEEP); //Sleepy time
48+
}
49+
50+
//We use counter/timer 6 for this example but 0 to 7 are available
51+
//CT 7 is used for Software Serial. All CTs are used for Servo.
52+
void setupWakeTimer()
53+
{
54+
//Clear compare interrupt
55+
am_hal_stimer_int_clear(AM_HAL_STIMER_INT_COMPAREG); //Use CT6
56+
57+
am_hal_stimer_int_enable(AM_HAL_STIMER_INT_COMPAREG); // Enable C/T G=6
58+
59+
//Don't change from 3MHz system timer, but enable G timer
60+
am_hal_stimer_config(AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE);
61+
am_hal_stimer_config(AM_HAL_STIMER_HFRC_3MHZ | AM_HAL_STIMER_CFG_COMPARE_G_ENABLE);
62+
63+
//Setup ISR to trigger when the number of ms have elapsed
64+
am_hal_stimer_compare_delta_set(6, sysTicksToSleep);
65+
66+
//Enable the timer interrupt in the NVIC.
67+
NVIC_EnableIRQ(STIMER_CMPR6_IRQn);
68+
}
69+
70+
//Called once number of milliseconds has passed
71+
extern "C" void am_stimer_cmpr6_isr(void)
72+
{
73+
uint32_t ui32Status = am_hal_stimer_int_status_get(false);
74+
if (ui32Status & AM_HAL_STIMER_INT_COMPAREG)
75+
{
76+
am_hal_stimer_int_clear(AM_HAL_STIMER_INT_COMPAREG);
77+
78+
//Reset compare value. ISR will trigger when the number of ms have elapsed
79+
am_hal_stimer_compare_delta_set(6, sysTicksToSleep);
80+
}
81+
}

libraries/RTC/keywords.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#######################################
2+
# Syntax Coloring Map
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
RTC KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
15+
getTime KEYWORD2
16+
setTime KEYWORD2
17+
setTimeToCompiler KEYWORD2
18+
19+
#######################################
20+
# Constants (LITERAL1)
21+
#######################################

libraries/RTC/library.properties

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=RTC
2+
version=1.0
3+
author=SparkFun Electronics
4+
maintainer=SparkFun Electronics <sparkfun.com>
5+
sentence=Real Time Clock (RTC)) library for the SparkFun Artemis
6+
paragraph=Enables the setting and reading of the RTC hardware built into Apollo based modules like the Artemis. Many SparkFun Artemis carrier boards have a built in 32kHz crystals. This library enables the reading of the current date and time.
7+
category=Timing
8+
url=
9+
architectures=apollo3

libraries/RTC/src/RTC.cpp

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
This example is based on the Ambiq SDK EVB2 RTC example.
3+
*/
4+
5+
#include "RTC.h"
6+
7+
am_hal_rtc_time_t hal_time;
8+
9+
// String arrays to index Days and Months with the values returned by the RTC.
10+
char const *pcWeekday[] =
11+
{
12+
"Sunday",
13+
"Monday",
14+
"Tuesday",
15+
"Wednesday",
16+
"Thursday",
17+
"Friday",
18+
"Saturday",
19+
"Invalid day"};
20+
21+
char const *pcMonth[] =
22+
{
23+
"January",
24+
"February",
25+
"March",
26+
"April",
27+
"May",
28+
"June",
29+
"July",
30+
"August",
31+
"September",
32+
"October",
33+
"November",
34+
"December",
35+
"Invalid month"};
36+
37+
//Constructor
38+
APM3_RTC::APM3_RTC()
39+
{
40+
// Enable the XT for the RTC.
41+
am_hal_clkgen_control(AM_HAL_CLKGEN_CONTROL_XTAL_START, 0);
42+
43+
// Select XT for RTC clock source
44+
am_hal_rtc_osc_select(AM_HAL_RTC_OSC_XT);
45+
46+
// Enable the RTC.
47+
am_hal_rtc_osc_enable();
48+
}
49+
50+
void APM3_RTC::setTime(uint8_t hour, uint8_t min, uint8_t sec, uint8_t hund, uint8_t dayOfMonth, uint8_t month, uint16_t year)
51+
{
52+
hal_time.ui32Hour = hour;
53+
hal_time.ui32Minute = min;
54+
hal_time.ui32Second = sec;
55+
hal_time.ui32Hundredths = hund;
56+
57+
hal_time.ui32DayOfMonth = dayOfMonth;
58+
hal_time.ui32Month = month - 1; //HAL is expecting 0 to 11 months
59+
hal_time.ui32Year = year;
60+
hal_time.ui32Century = 0;
61+
62+
hal_time.ui32Weekday = am_util_time_computeDayofWeek(2000 + year, month + 1, dayOfMonth);
63+
64+
am_hal_rtc_time_set(&hal_time); //Initialize the RTC with this date/time
65+
}
66+
67+
//Takes the time from the last build and uses it as the current time
68+
//Works well as an arduino sketch
69+
void APM3_RTC::setToCompilerTime()
70+
{
71+
//Get the current date/time from the compiler
72+
//Alternatively, you can set these values manually
73+
hal_time.ui32Hour = toVal(&__TIME__[0]);
74+
hal_time.ui32Minute = toVal(&__TIME__[3]);
75+
hal_time.ui32Second = toVal(&__TIME__[6]);
76+
hal_time.ui32Hundredths = 00;
77+
hal_time.ui32Weekday = am_util_time_computeDayofWeek(2000 + toVal(&__DATE__[9]), mthToIndex(&__DATE__[0]) + 1, toVal(&__DATE__[4]));
78+
hal_time.ui32DayOfMonth = toVal(&__DATE__[4]);
79+
hal_time.ui32Month = mthToIndex(&__DATE__[0]);
80+
hal_time.ui32Year = toVal(&__DATE__[9]);
81+
hal_time.ui32Century = 0;
82+
83+
am_hal_rtc_time_set(&hal_time); //Initialize the RTC with this date/time
84+
}
85+
86+
void APM3_RTC::getTime()
87+
{
88+
am_hal_rtc_time_get(&hal_time);
89+
90+
hour = hal_time.ui32Hour;
91+
minute = hal_time.ui32Minute;
92+
seconds = hal_time.ui32Second;
93+
hundredths = hal_time.ui32Hundredths;
94+
95+
month = hal_time.ui32Month + 1; //Convert from 0-11 to 1-12
96+
dayOfMonth = hal_time.ui32DayOfMonth;
97+
year = hal_time.ui32Year;
98+
99+
weekday = hal_time.ui32Weekday;
100+
textWeekday = pcWeekday[hal_time.ui32Weekday]; //Given a number (day of week) return the string that represents the name
101+
}
102+
103+
// mthToIndex() converts a string indicating a month to an index value.
104+
// The return value is a value 0-12, with 0-11 indicating the month given
105+
// by the string, and 12 indicating that the string is not a month.
106+
int APM3_RTC::mthToIndex(char const *pcMon)
107+
{
108+
int idx;
109+
for (idx = 0; idx < 12; idx++)
110+
{
111+
if (am_util_string_strnicmp(pcMonth[idx], pcMon, 3) == 0)
112+
return idx;
113+
}
114+
return 12; //Error
115+
}
116+
117+
// toVal() converts a string to an ASCII value.
118+
int APM3_RTC::toVal(char const *pcAsciiStr)
119+
{
120+
int iRetVal = 0;
121+
iRetVal += pcAsciiStr[1] - '0';
122+
iRetVal += pcAsciiStr[0] == ' ' ? 0 : (pcAsciiStr[0] - '0') * 10;
123+
return iRetVal;
124+
}

0 commit comments

Comments
 (0)