Skip to content

Commit 999226a

Browse files
Merge pull request #4 from GeorgeYakovlev/master
Modify Parse library to support both Zero and Yun
2 parents 2fc5fd5 + e099c2f commit 999226a

35 files changed

+1364
-101
lines changed
File renamed without changes.

examples/setup/Setup.ino renamed to examples/Arduino Yun/setup/Setup.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <Bridge.h>
22

3-
String revision = "1.0.2-1_ar71xx";
4-
String location = "https://raw.githubusercontent.com/ParsePlatform/parse-embedded-sdks/1.0.2/yun/linux_package/";
3+
String revision = "1.0.3-1_ar71xx";
4+
String location = "https://raw.githubusercontent.com/ParsePlatform/parse-embedded-sdks/1.0.3/yun/linux_package/";
55

66
void downloadPackage(String file) {
77
Serial.println("Download: " + location + file + revision + ".ipk");
File renamed without changes.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <SPI.h>
2+
#include <WiFi101.h>
3+
#include <Parse.h>
4+
5+
char ssid[] = ""; // your network SSID (name)
6+
char pass[] = ""; // your network password (use for WPA, or use as key for WEP)
7+
8+
int status = WL_IDLE_STATUS;
9+
10+
void setup() {
11+
//Initialize serial and wait for port to open:
12+
Serial.begin(115200);
13+
while (!Serial) {
14+
; // wait for serial port to connect. Needed for Leonardo only
15+
}
16+
17+
// check for the presence of the shield:
18+
if (WiFi.status() == WL_NO_SHIELD) {
19+
Serial.println("WiFi shield not present");
20+
// don't continue:
21+
while (true);
22+
}
23+
24+
// attempt to connect to Wifi network:
25+
while (status != WL_CONNECTED) {
26+
Serial.print("Attempting to connect to SSID: ");
27+
Serial.println(ssid);
28+
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
29+
status = WiFi.begin(ssid, pass);
30+
// wait 10 seconds for connection:
31+
delay(10000);
32+
}
33+
34+
}
35+
36+
void loop() {
37+
38+
}

library.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name=Parse Arduino SDK
2-
version=1.0.2
2+
version=1.0.3
33
author=Parse, LLC.
44
maintainer=Parse, LLC.
55
sentence=A library that provides access to Parse
6-
paragraph=Provides convenience methods to access the REST API on Parse.com from Arduino
7-
url=https://github.com/ParsePlatform/Parse-SDK-Arduino
8-
architectures=avr
6+
paragraph=Provides convenience methods to access the REST API on Parse.com from Arduino.
7+
url=https://github.com/ParsePlatform/parse-embedded-sdks
8+
architectures=avr,samd
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
Copyright (c) 2015 Arduino LLC. 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+
#if defined (ARDUINO_SAMD_ZERO)
20+
21+
#include "FlashStorage.h"
22+
23+
static const uint32_t pageSizes[] = { 8, 16, 32, 64, 128, 256, 512, 1024 };
24+
25+
FlashClass::FlashClass(const void *flash_addr, uint32_t size) :
26+
PAGE_SIZE(pageSizes[NVMCTRL->PARAM.bit.PSZ]),
27+
PAGES(NVMCTRL->PARAM.bit.NVMP),
28+
MAX_FLASH(PAGE_SIZE * PAGES),
29+
ROW_SIZE(PAGE_SIZE * 4),
30+
flash_address((volatile void *)flash_addr),
31+
flash_size(size)
32+
{
33+
}
34+
35+
static inline uint32_t read_unaligned_uint32(const void *data)
36+
{
37+
union {
38+
uint32_t u32;
39+
uint8_t u8[4];
40+
} res;
41+
const uint8_t *d = (const uint8_t *)data;
42+
res.u8[0] = d[0];
43+
res.u8[1] = d[1];
44+
res.u8[2] = d[2];
45+
res.u8[3] = d[3];
46+
return res.u32;
47+
}
48+
49+
void FlashClass::write(const volatile void *flash_ptr, const void *data, uint32_t size)
50+
{
51+
// Calculate data boundaries
52+
size = (size + 3) / 4;
53+
volatile uint32_t *dst_addr = (volatile uint32_t *)flash_ptr;
54+
const uint8_t *src_addr = (uint8_t *)data;
55+
56+
// Disable automatic page write
57+
NVMCTRL->CTRLB.bit.MANW = 1;
58+
59+
// Do writes in pages
60+
while (size) {
61+
// Execute "PBC" Page Buffer Clear
62+
NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_PBC;
63+
while (NVMCTRL->INTFLAG.bit.READY == 0) { }
64+
65+
// Fill page buffer
66+
uint32_t i;
67+
for (i=0; i<(PAGE_SIZE/4) && size; i++) {
68+
*dst_addr = read_unaligned_uint32(src_addr);
69+
src_addr += 4;
70+
dst_addr++;
71+
size--;
72+
}
73+
74+
// Execute "WP" Write Page
75+
NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_WP;
76+
while (NVMCTRL->INTFLAG.bit.READY == 0) { }
77+
}
78+
}
79+
80+
void FlashClass::erase(const volatile void *flash_ptr, uint32_t size)
81+
{
82+
const uint8_t *ptr = (const uint8_t *)flash_ptr;
83+
while (size > ROW_SIZE) {
84+
erase(ptr);
85+
ptr += ROW_SIZE;
86+
size -= ROW_SIZE;
87+
}
88+
erase(ptr);
89+
}
90+
91+
void FlashClass::erase(const volatile void *flash_ptr)
92+
{
93+
NVMCTRL->ADDR.reg = ((uint32_t)flash_ptr) / 2;
94+
NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_ER;
95+
while (!NVMCTRL->INTFLAG.bit.READY) { }
96+
}
97+
98+
void FlashClass::read(const volatile void *flash_ptr, void *data, uint32_t size)
99+
{
100+
memcpy(data, (const void *)flash_ptr, size);
101+
}
102+
103+
#endif // defined (ARDUINO_SAMD_ZERO)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
Copyright (c) 2015 Arduino LLC. 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+
#pragma once
20+
21+
#include <Arduino.h>
22+
23+
// Concatenate after macro expansion
24+
#define PPCAT_NX(A, B) A ## B
25+
#define PPCAT(A, B) PPCAT_NX(A, B)
26+
27+
#define Flash(name, size) \
28+
__attribute__((__aligned__(256))) \
29+
static const uint8_t PPCAT(_data,name)[(size+255)/256*256] = { }; \
30+
FlashClass name(PPCAT(_data,name), size);
31+
32+
#define FlashStorage(name, T) \
33+
__attribute__((__aligned__(256))) \
34+
static const uint8_t PPCAT(_data,name)[(sizeof(T)+255)/256*256] = { }; \
35+
FlashStorageClass<T> name(PPCAT(_data,name));
36+
37+
class FlashClass {
38+
public:
39+
FlashClass(const void *flash_addr = NULL, uint32_t size = 0);
40+
41+
void write(const void *data) { write(flash_address, data, flash_size); }
42+
void erase() { erase(flash_address, flash_size); }
43+
void read(void *data) { read(flash_address, data, flash_size); }
44+
45+
void write(const volatile void *flash_ptr, const void *data, uint32_t size);
46+
void erase(const volatile void *flash_ptr, uint32_t size);
47+
void read(const volatile void *flash_ptr, void *data, uint32_t size);
48+
49+
private:
50+
void erase(const volatile void *flash_ptr);
51+
52+
const uint32_t PAGE_SIZE, PAGES, MAX_FLASH, ROW_SIZE;
53+
const volatile void *flash_address;
54+
const uint32_t flash_size;
55+
};
56+
57+
template<class T>
58+
class FlashStorageClass {
59+
public:
60+
FlashStorageClass(const void *flash_addr) : flash(flash_addr, sizeof(T)) { };
61+
62+
// Write data into flash memory.
63+
// Compiler is able to optimize parameter copy.
64+
inline void write(T data) { flash.erase(); flash.write(&data); }
65+
66+
// Read data from flash into variable.
67+
inline void read(T *data) { flash.read(data); }
68+
69+
// Overloaded version of read.
70+
// Compiler is able to optimize copy-on-return.
71+
inline T read() { T data; read(&data); return data; }
72+
73+
private:
74+
FlashClass flash;
75+
};
76+

src/internal/ConnectionClient.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef __CONNECTION_CLIENT_H__
2+
#define __CONNECTION_CLIENT_H__
3+
4+
5+
#include <Arduino.h>
6+
7+
#ifdef ARDUINO_SAMD_ZERO
8+
9+
#include <WiFi101.h>
10+
typedef WiFiClient ConnectionClient;
11+
12+
#elif ARDUINO_AVR_YUN
13+
14+
#include <Bridge.h>
15+
typedef Process ConnectionClient;
16+
17+
#endif
18+
19+
#endif //__CONNECTION_CLIENT_H__

0 commit comments

Comments
 (0)