Przeglądaj źródła

added teensymac to generate unique MAC ID
first example running with arduinoOSC
moving to OSC from CNMAT to use multicast

eLandon 6 lat temu
rodzic
commit
6c4f479315

+ 29 - 0
HTequi-firmware/lib/TeensyMAC/.gitignore

@@ -0,0 +1,29 @@
+# Compiled Object files
+*.slo
+*.lo
+*.o
+*.obj
+
+# Precompiled Headers
+*.gch
+*.pch
+
+# Compiled Dynamic libraries
+*.so
+*.dylib
+*.dll
+
+# Fortran module files
+*.mod
+*.smod
+
+# Compiled Static libraries
+*.lai
+*.la
+*.a
+*.lib
+
+# Executables
+*.exe
+*.out
+*.app

+ 32 - 0
HTequi-firmware/lib/TeensyMAC/.travis.yml

@@ -0,0 +1,32 @@
+language: python
+python:
+  - "2.7"
+
+# Short duration job, use the container/without sudo image as it boots faster
+sudo: false
+# Use the latest Travis images since they are more up to date than the stable release.
+group: edge
+
+cache:
+  directories:
+    - "~/.platformio"
+
+env:
+  global:
+   # Warnings are errors
+   - PLATFORMIO_BUILD_FLAGS="-Werror"
+
+matrix:
+  fast_finish: true
+  include:
+    - env: BOARD=teensylc PLATFORMIO_CI_SRC=examples/PrintInfo
+    - env: BOARD=teensy30 PLATFORMIO_CI_SRC=examples/PrintInfo
+    - env: BOARD=teensy31 PLATFORMIO_CI_SRC=examples/PrintInfo
+    - env: BOARD=teensy35 PLATFORMIO_CI_SRC=examples/PrintInfo
+    - env: BOARD=teensy36 PLATFORMIO_CI_SRC=examples/PrintInfo
+
+install:
+  - pip install -U platformio
+
+script:
+  - platformio ci --lib="." --board=$BOARD

+ 21 - 0
HTequi-firmware/lib/TeensyMAC/LICENSE

@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2016 Frank
+
+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.

+ 8 - 0
HTequi-firmware/lib/TeensyMAC/README.md

@@ -0,0 +1,8 @@
+[![Build Status](https://travis-ci.org/FrankBoesing/TeensyMAC.svg?branch=master)](https://travis-ci.org/FrankBoesing/TeensyMAC)
+
+# TeensyMAC
+Teensy Serial# and MAC
+
+Works with Teensy LC & Teensy 3.0 .. 3.6
+
+For an example see examples/PrintInfo/PrintInfo.ino .

+ 100 - 0
HTequi-firmware/lib/TeensyMAC/TeensyMAC.cpp

@@ -0,0 +1,100 @@
+/* TeensyMAC library code is placed under the MIT license
+ * Copyright (c) 2016 Frank Bösing
+ *
+ * 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.
+ */
+
+#include "TeensyMAC.h"
+#include <Arduino.h>
+
+#define MY_SYSREGISTERFILE	((uint8_t *)0x40041000) // System Register File
+
+
+static uint32_t _getserialhw(void) {
+	uint32_t num;
+	__disable_irq();
+#if defined(HAS_KINETIS_FLASH_FTFA) || defined(HAS_KINETIS_FLASH_FTFL)
+	FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL;
+	FTFL_FCCOB0 = 0x41;
+	FTFL_FCCOB1 = 15;
+	FTFL_FSTAT = FTFL_FSTAT_CCIF;
+	while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ; // wait
+	num = *(uint32_t *)&FTFL_FCCOB7;
+#elif defined(HAS_KINETIS_FLASH_FTFE)
+	// Does not work in HSRUN mode :
+	FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL;
+	*(uint32_t *)&FTFL_FCCOB3 = 0x41070000;
+	FTFL_FSTAT = FTFL_FSTAT_CCIF;
+	while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ; // wait
+	num = *(uint32_t *)&FTFL_FCCOBB;
+#endif
+	__enable_irq();
+	return num;
+}
+
+
+#if defined(HAS_KINETIS_FLASH_FTFE) && (F_CPU > 120000000)
+extern "C" void startup_early_hook(void) {
+#if defined(KINETISK)
+  WDOG_STCTRLH = WDOG_STCTRLH_ALLOWUPDATE;
+#elif defined(KINETISL)
+  SIM_COPC = 0;  // disable the watchdog
+#endif
+ *(uint32_t*)(MY_SYSREGISTERFILE) = _getserialhw();
+}
+
+uint32_t teensySerial(void) {
+	uint32_t num;
+	num = *(uint32_t*)(MY_SYSREGISTERFILE);
+	// add extra zero to work around OS-X CDC-ACM driver bug
+	// http://forum.pjrc.com/threads/25482-Duplicate-usb-modem-number-HELP
+	if (num < 10000000) num = num * 10;
+	return num;
+}
+uint64_t teensyMAC(void) {
+	return 0x04E9E5000000ULL | (*(uint32_t*)(MY_SYSREGISTERFILE));
+}
+
+#else
+
+	uint32_t teensySerial(void) {
+	uint32_t num;
+	num = _getserialhw();
+	// add extra zero to work around OS-X CDC-ACM driver bug
+	// http://forum.pjrc.com/threads/25482-Duplicate-usb-modem-number-HELP
+	if (num < 10000000) num = num * 10;
+	return num;
+}
+uint64_t teensyMAC(void) {
+	return 0x04E9E5000000ULL | _getserialhw();
+}
+
+#endif
+
+void teensyMAC(uint8_t *macArray) {
+	uint64_t mac = teensyMAC();
+	macArray[0] = (uint8_t)((mac >> 40) & 0xFF);
+	macArray[1] = (uint8_t)((mac >> 32) & 0xFF);
+	macArray[2] = (uint8_t)((mac >> 24) & 0XFF);
+	macArray[3] = (uint8_t)((mac >> 16) & 0XFF);
+	macArray[4] = (uint8_t)((mac >> 8) & 0XFF);
+	macArray[5] = (uint8_t)(mac & 0XFF);
+}

+ 32 - 0
HTequi-firmware/lib/TeensyMAC/TeensyMAC.h

@@ -0,0 +1,32 @@
+/* TeensyMAC library code is placed under the MIT license
+ * Copyright (c) 2016 Frank Bösing
+ *
+ * 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 _TEENSYMAC_H_INCLUDED
+#define _TEENSYMAC_H_INCLUDED
+
+#include <stdint.h>
+uint32_t teensySerial(void);
+uint64_t teensyMAC(void);
+void teensyMAC(uint8_t *macArray);
+#endif

+ 22 - 0
HTequi-firmware/lib/TeensyMAC/examples/PrintInfo/PrintInfo.ino

@@ -0,0 +1,22 @@
+#include <TeensyMAC.h>
+
+void setup() {
+  Serial.begin(9600);
+}
+
+void loop() {
+  delay(500);
+  Serial.printf("Serial: %u\n", teensySerial());
+  Serial.printf("MAC: 0x%012llX\n", teensyMAC());
+
+  Serial.print("MAC as array: ");
+  uint8_t mac[6];
+  teensyMAC(mac);
+  for (uint8_t i = 0; i < 6; ++i) {
+    Serial.printf("%02X", mac[i]);
+    if (i < 5) {
+      Serial.print(":");
+    }
+  }
+  Serial.println("");
+}

+ 4 - 1
HTequi-firmware/platformio.ini

@@ -8,7 +8,10 @@
 ; Please visit documentation for the other options and examples
 ; https://docs.platformio.org/page/projectconf.html
 
-[env:teensy35]
+[env:teensy35_BLOBCNC_LOW]
 platform = teensy
 board = teensy35
 framework = arduino
+src_filter = +<*> +<blobcnc_low/>; -<slave/>
+;upload_port = /dev/ttyACM0
+;lib_ignore =

+ 88 - 5
HTequi-firmware/src/blobcnc_low/main.cpp

@@ -1,9 +1,92 @@
 #include <Arduino.h>
 
-void setup() {
-  // put your setup code here, to run once:
+#include <TeensyMAC.h>
+#include <SPI.h>
+#include <ArduinoOSC.h>
+
+// Ethernet stuff
+const IPAddress ip(192, 168, 1, 201);
+uint8_t mac[] = {0xAB, 0xCD, 0xEF, 0x01, 0x23, 0x45};
+
+// for ArduinoOSC
+OscEthernet osc;
+const char* host = "239.200.200.200";
+const int recv_port = 9977;
+const int send_port = 9977;
+
+void onOscReceived(OscMessage& m)
+{
+    Serial.print("callback : ");
+    Serial.print(m.ip()); Serial.print(" ");
+    Serial.print(m.port()); Serial.print(" ");
+    Serial.print(m.size()); Serial.print(" ");
+    Serial.print(m.address()); Serial.print(" ");
+    Serial.print(m.arg<int>(0)); Serial.print(" ");
+    Serial.print(m.arg<float>(1)); Serial.print(" ");
+    Serial.print(m.arg<String>(2)); Serial.println();
 }
 
-void loop() {
-  // put your main code here, to run repeatedly:
-}
+void setup() {
+
+  Serial.begin(115200);
+  while (!Serial) {
+    ; // wait for serial port to connect. Needed for native USB port only
+  }
+  SPI.setSCK(27);
+      Ethernet.init(10);
+      teensyMAC(mac);
+      Ethernet.begin(mac, ip);
+
+      // ArduinoOSC
+      osc.begin(recv_port);
+
+      // TODO: TBD
+      // osc.subscribe("/int32", i);
+      // osc.subscribe("/float", f);
+      // osc.subscribe("/string", s);
+      // osc.subscribe("/blob", b);
+
+      osc.subscribe("/callback", onOscReceived); // old style (v0.1.x)
+
+      osc.subscribe("/lambda", [](OscMessage& m)
+      {
+          Serial.print("lambda : ");
+          Serial.print(m.ip()); Serial.print(" ");
+          Serial.print(m.port()); Serial.print(" ");
+          Serial.print(m.size()); Serial.print(" ");
+          Serial.print(m.address()); Serial.print(" ");
+          Serial.print(m.arg<int>(0)); Serial.print(" ");
+          Serial.print(m.arg<float>(1)); Serial.print(" ");
+          Serial.print(m.arg<String>(2)); Serial.println();
+      });
+      osc.subscribe("/wildcard/*/test", [](OscMessage& m)
+      {
+          Serial.print("wildcard : ");
+          Serial.print(m.ip()); Serial.print(" ");
+          Serial.print(m.port()); Serial.print(" ");
+          Serial.print(m.size()); Serial.print(" ");
+          Serial.print(m.address()); Serial.print(" ");
+          Serial.print(m.arg<int>(0)); Serial.println();
+      });
+      osc.subscribe("/need/reply", [](OscMessage& m)
+      {
+          Serial.println("/need/reply");
+
+          int i = 12;
+          float f = 34.56F;
+          double d = 78.987;
+          String s = "hello";
+          bool b = true;
+
+          osc.send(host, send_port, "/send", i, f, d, s, b);
+      });
+
+      // TODO: TBD
+      // osc.publish(host, send_port, "/value", value);
+      // osc.publish(host, send_port, "/millis", &millis);
+  }
+
+  void loop()
+  {
+      osc.parse(); // should be called
+  }