├── .gitignore ├── .gitmodules ├── .travis.yml ├── README.md ├── boards.txt ├── cores └── intiki │ ├── Arduino.h │ ├── Client.h │ ├── HardwareSerial.cpp │ ├── HardwareSerial.h │ ├── IPAddress.cpp │ ├── IPAddress.h │ ├── Print.cpp │ ├── Print.h │ ├── Printable.h │ ├── Reset.h │ ├── RingBuffer.h │ ├── Server.h │ ├── Stream.cpp │ ├── Stream.h │ ├── Tone.cpp │ ├── Tone.h │ ├── USB │ ├── PluggableUSB.h │ ├── USBAPI.h │ ├── USBCore.h │ ├── USBDesc.h │ └── USB_host.h │ ├── Uart.cpp │ ├── Uart.h │ ├── Udp.h │ ├── WCharacter.h │ ├── WInterrupts.c │ ├── WInterrupts.h │ ├── WMath.cpp │ ├── WMath.h │ ├── WString.cpp │ ├── WString.h │ ├── WVariant.h │ ├── abi.cpp │ ├── avr │ ├── dtostrf.c │ ├── dtostrf.h │ ├── interrupt.h │ ├── io.h │ └── pgmspace.h │ ├── binary.h │ ├── delay.c │ ├── delay.h │ ├── hooks.c │ ├── itoa.c │ ├── itoa.h │ ├── main.cpp │ ├── new.cpp │ ├── pulse.c │ ├── pulse.h │ ├── weak_pragmas.h │ ├── wiring.h │ ├── wiring_analog.c │ ├── wiring_analog.h │ ├── wiring_constants.h │ ├── wiring_digital.c │ ├── wiring_digital.h │ ├── wiring_private.h │ ├── wiring_shift.c │ └── wiring_shift.h ├── dist ├── ci_ba2toolchainversion.rb ├── ci_boardmanager.rb ├── ci_intikiversion.rb ├── ci_submodules.rb ├── ci_toolurl.rb ├── compile_examples.bats ├── platform_template.json ├── setup_env.sh ├── setup_tools.sh ├── submodules.json └── tool_template.json ├── keywords.txt ├── libraries ├── EEPROM │ ├── README.md │ ├── examples │ │ ├── eeprom_clear │ │ │ └── eeprom_clear.ino │ │ ├── eeprom_crc │ │ │ └── eeprom_crc.ino │ │ ├── eeprom_get │ │ │ └── eeprom_get.ino │ │ ├── eeprom_iteration │ │ │ └── eeprom_iteration.ino │ │ ├── eeprom_put │ │ │ └── eeprom_put.ino │ │ ├── eeprom_read │ │ │ └── eeprom_read.ino │ │ ├── eeprom_update │ │ │ └── eeprom_update.ino │ │ └── eeprom_write │ │ │ └── eeprom_write.ino │ ├── keywords.txt │ ├── library.properties │ └── src │ │ └── EEPROM.h ├── SPI │ ├── SPI.cpp │ ├── SPI.h │ ├── examples │ │ ├── BarometricPressureSensor │ │ │ └── BarometricPressureSensor.ino │ │ └── DigitalPotControl │ │ │ └── DigitalPotControl.ino │ ├── keywords.txt │ └── library.properties ├── Wire │ ├── Wire.cpp │ ├── Wire.h │ ├── examples │ │ ├── SFRRanger_reader │ │ │ └── SFRRanger_reader.ino │ │ ├── digital_potentiometer │ │ │ └── digital_potentiometer.ino │ │ ├── master_reader │ │ │ └── master_reader.ino │ │ ├── master_writer │ │ │ └── master_writer.ino │ │ ├── slave_receiver │ │ │ └── slave_receiver.ino │ │ └── slave_sender │ │ │ └── slave_sender.ino │ ├── keywords.txt │ └── library.properties └── uIP │ ├── README.adoc │ ├── examples │ ├── Udp7EchoClientServer │ │ └── Udp7EchoClientServer.ino │ ├── tcp-echo-client │ │ └── tcp-echo-client.ino │ ├── tcp-echo-server-rpl │ │ └── tcp-echo-server-rpl.ino │ ├── tcpv6-client-example │ │ └── tcpv6-client-example.ino │ ├── tiny-httpd │ │ └── tiny-httpd.ino │ ├── udp-echo-client │ │ └── udp-echo-client.ino │ └── udp-echo-server-rpl │ │ └── udp-echo-server-rpl.ino │ ├── keywords.txt │ ├── library.properties │ └── src │ ├── MicroIp.cpp │ ├── MicroIp.h │ ├── MicroIpClient.cpp │ ├── MicroIpClient.h │ ├── MicroIpRPL.cpp │ ├── MicroIpRPL.h │ ├── MicroIpServer.cpp │ ├── MicroIpServer.h │ ├── MicroIpUdp.cpp │ └── MicroIpUdp.h ├── platform.txt └── variants ├── jn516x ├── i2c-driver.c ├── i2c-driver.h ├── ldscript │ ├── intiki_JN5169.ld │ ├── intiki_JN516x.ld │ └── intiki_common.ld ├── makefile │ ├── Makefile.override │ └── Makefile.template ├── override │ └── override-contiki-jn516x-main.c ├── pin_location.c ├── pin_location.h ├── pins_arduino.h ├── platform.h ├── sam.h ├── spi-driver.c ├── spi-driver.h ├── variant.cpp ├── variant.h ├── w_analog.c ├── w_digital.c ├── w_interrupts.c └── w_private.c ├── minimal-net ├── Makefile.variant ├── PinControl.cpp ├── PinControl.h ├── README.md ├── minimal-net_spi.cpp ├── minimal-net_spi.h ├── minimal-net_uart.cpp ├── minimal-net_wire.cpp ├── minimal-net_wire.h ├── minimal-net_wiring.cpp ├── pins_arduino.h ├── platform.cpp ├── platform.h ├── variant.h └── watchdog.c └── native ├── Makefile.variant ├── PinControl.cpp ├── PinControl.h ├── README.md ├── native_spi.cpp ├── native_spi.h ├── native_uart.cpp ├── native_wire.cpp ├── native_wire.h ├── native_wiring.cpp ├── pins_arduino.h ├── platform.cpp ├── platform.h └── variant.h /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.bak 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "system/contiki"] 2 | path = system/contiki 3 | url = https://github.com/soburi/contiki 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: generic 2 | sudo: false 3 | dist: trusty 4 | addons: 5 | apt: 6 | sources: 7 | - ubuntu-toolchain-r-test 8 | packages: 9 | - gcc-6 10 | - libgit2-0 11 | - libgit2-dev 12 | env: 13 | global: 14 | - secure: s23FCXAYTELTC5XaizCh0rUkVF7kW/CQMgFhTL81me/v0lQsjhOlNR531KY8+RSHv3NXPRr32o/c4g4WURdxHE8BtggGU4/LzxqTTW6Ua9EEMumpQlIIpNi71qU5cTNv/B5LjvYiXBF3hl/SAvGt26EvMxTRwpQDPJm0ePWSEahMx+n5OzVh/C4RMnA4ZoJCVzEXQZ+NiuRtLu9JVwLpG7TRpecf2kBMtdz6VBgzOKvOY9zYaA+6ZW4qE/wC7e+5zWFyS9C9P9JU6D/0izrGiaT+amk8lZvjJCeBvNag/zIfySZy4aDHjwmoFB5vDWDQqGac/DSIv/xUAicCssoBkjvBk4YVxtKYEF6oXJg40XAWIErkz4AUp3wiHXtdTpovH0r8QT896jAwaU0zxdXXFjJidBXuO4DLMbxABj/9Ab4vzY7G6YcUHi9C9t5A7ISp0MAxB53MJcylWDCp5tpxbs1zbe5ndoxs1YrEvJIw4ezJ6u1NGJTwra/kSpdyIqYhRnCoK7z0HnkmPwykYhyMOz6K/g2DqJ8wtNU2642Zz4o4P5/pvgT/IWo1/qLnZvsQ+t4VvXNGKzupaJZG50rTrnlat4QTzwPa1gCpSeZiV+A5GtIdtYnhQYarl6b8EJI9SU2frsQ9fH7o9twppJlEb7bS4bJXcKk4cdRdN4MnXwE= 15 | - ARDUINO_VERSION=1.8.5 16 | - SDK_BASE_DIR=~/MWSDK/ChipLib/SW4063V1416/ 17 | deploy: 18 | provider: releases 19 | file: ../${ARCHIVENAME}.tar.bz2 20 | skip_cleanup: true 21 | api_key: 22 | secure: slp0FpIa6s7e7rW8Kk4mtyeiNHJW44ak2yGFo3/xN9LZxYLJZf1CdqiSm9x1g98yk7iO8Q+tWzFs4+aISYPOE9AZVSo4w3m4uvXS458ymg2M2IFPsXz0mH+C2uMJCRkaGZFT6C8Gg9cA5wRtwPd0MErFgffJssEAFXo3GP1N5YvRGpLn1CYleQzfArYKnskwI+EkMqCLqLVDzBTJ0Q8rotSyd1Es+ui5RPRKPoFNhG21Cyz9kIzyBVgG9ymDP3phNbKQqDcg5d/aeKAysKFnyqddgs2a5K6SunlFzA33OChzfFNdjKDsdGC+R2OurZ8GDHuTHvjFUkGWo8WHDDsJya1fYeRiG8akWiECIVfZc3lwDAXPae//DwOpjOq1jigQJjVwbwHdv9RR3tXso/ZWB5F1HPJB0q9te+rzTbqQ7+ooChF1rA2j8fDlY6lJ+uM8fzIVIAIJlK6Nm4CRhpXweTRMHEcQ5m6yRNLFT8P0CJNU02ehgmqSSykyBN+ktmAqo3WvC7JeH7QJFsFX7NUZ4SxHSfAWPzif6hGz0kJL0tqlaSyTSzkeeywBYfxHBWC6Q8FVd7PlMpjo7kteHG+pjDKikND+KvQ8esf0TAKm0NnadUGtmDaGXrUWtH8fdKONMqcBj6Amz8s5RRPi2e7lDUJdT+LAWLXZTUR8WXPnrVs= 23 | on: 24 | tags: true 25 | 26 | before_script: 27 | - env 28 | - gem install -V rugged 29 | - source dist/setup_env.sh 30 | - git remote add gh-origin "https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}" 31 | - git config --global user.email "travisci@example.com" 32 | - git config --global user.name "Travis-CI" 33 | - curl -l -L http://ftp.gnu.org/gnu/make/make-4.2.tar.bz2 | tar xfj - -C ~ 34 | - cd ~/make-4.2 && ./configure && make && cp make ~/bin 35 | - cd - 36 | - export PATH=~/bin:$PATH 37 | - curl -l -L https://downloads.arduino.cc/arduino-${ARDUINO_VERSION}-linux64.tar.xz | tar xfJ - -C ~ 38 | - if [ "$TRAVIS_TAG" != "" ] ; then bash dist/setup_tools.sh ; fi 39 | 40 | 41 | script: 42 | # check submojule.json 43 | - ruby dist/ci_submodules.rb -c dist/submodules.json 44 | # generate archive 45 | - EXCLUDEGIT=$(find . -name '.git' -printf '%f ' | xargs -i echo -n --exclude {}) 46 | - BZIP2=-9 tar cfj ../${ARCHIVENAME}.tar.bz2 -C .. ${EXCLUDEGIT} $(basename ${PWD}) 47 | after_script: 48 | - if [ ${TRAVIS_TEST_RESULT} -ne 0 ] ; then echo ${TRAVIS_TEST_RESULT} ; exit ${TRAVIS_TEST_RESULT} ; fi 49 | - echo ruby dist/ci_boardmanager.rb ${BM_FORCEOPT} -g ${GHREPO} -t dist/tool_template.json -p dist/platform_template.json -j ${PKGJSON} -u ${ARCHIVEURL} -r ${RELEASEVER} --package-name=intiki --package-maintainer=soburi --package-website='https://github.com/soburi/JN516x-arduino-package' --package-email='soburi@gmail.com' > ../tmp.json || exit $? 50 | - ruby dist/ci_boardmanager.rb ${BM_FORCEOPT} -g ${GHREPO} -t dist/tool_template.json -p dist/platform_template.json -j ${PKGJSON} -u ${ARCHIVEURL} -r ${RELEASEVER} --package-name=intiki --package-maintainer=soburi --package-website='https://github.com/soburi/JN516x-arduino-package' --package-email='soburi@gmail.com' > ../tmp.json || exit $? 51 | - git fetch --all || exit $? 52 | - if [ "$TRAVIS_TAG" != "" ] ; then echo twelite.build.options.sdkbase=SDK_BASE_DIR=${HOME}/MWSDK/ChipLib/SW4063V1416 > boards.local.txt ; fi 53 | - if [ "$TRAVIS_TAG" != "" ] ; then bats dist/compile_examples.bats ; fi 54 | - rm -rf boards.local.txt 55 | - git checkout gh-origin/gh-pages -b gh-pages || exit $? 56 | - cp ../tmp.json ${PKGJSON} || exit $? 57 | - git add ${PKGJSON} || exit $? 58 | - git commit -m ${TRAVIS_BUILD_ID} || exit $? 59 | - git push gh-origin gh-pages || exit $? 60 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | About 2 | ===== 3 | 4 | This is Arduino add-on package for NXP JN516x platform. 5 | This package is built on [ContikiOS](http://contiki-os.org/). 6 | 7 | Install 8 | ======= 9 | 10 | Install JN516x plugin to Arduino 11 | -------------------------------- 12 | 13 | Use this additional package definition of 'Additional Boards Manager URLs' option that is on Arduino's preferences. 14 | * [http://soburi.github.io/JN516x-arduino-package/package_soburi_intiki_index.json](http://soburi.github.io/JN516x-arduino-package/package_soburi_intiki_index.json) 15 | 16 | Install Compiler and SDK. 17 | ---------------------------- 18 | 19 | Download and install compiler and sdk from [NXP's JN516x page](https://www.nxp.com/products/wireless-connectivity/proprietary-ieee-802.15.4-based/ieee-802.15.4-for-jn516x-7x:IEEE802.15.4). 20 | 21 | * `JN-SW-4141` BeyondStudio for NXP 22 | * `JN-SW-4163` JN516x IEEE 802.15.4 SDK 23 | 24 | ### For Windows 25 | 26 | Install `JN-SW-4141` and `JN-SW-4163` to installer's default destination (C:\NXP). 27 | 28 | ### For Linux/MacOSX 29 | 30 | Install *JN516x IEEE 802.15.4 SDK* contents (JN-SW-4163 directory, need to extract on windows) under `/usr/jn516x-sdk/`(default directory as Contiki expects). 31 | If installed to another directory, set the path to `SDK_BASE_DIR` and export it. 32 | 33 | 34 | Limitations 35 | =========== 36 | 37 | ### Not support function. 38 | 39 | - analogReadResolution() 40 | - analogWriteResolution() 41 | - Keyboard 42 | - Mouse 43 | 44 | 45 | ### Interrupt mode 46 | JN516x does not support LEVEL triggerd and both edge triggerd interruption, support only RISING and FALLING. 47 | attatchInterrupt() treat HIGH, LOW, CHANGE as RISING. 48 | -------------------------------------------------------------------------------- /cores/intiki/Arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | Arduino.h - Main include file for the Arduino SDK 3 | Copyright (c) 2014 Arduino LLC. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Arduino_h 21 | #define Arduino_h 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | typedef bool boolean; 30 | typedef uint8_t byte; 31 | typedef uint16_t word; 32 | 33 | // some libraries and sketches depend on this AVR stuff, 34 | // assuming Arduino.h or WProgram.h automatically includes it... 35 | // 36 | #include "avr/pgmspace.h" 37 | #include "avr/interrupt.h" 38 | #include "avr/io.h" 39 | 40 | #include "binary.h" 41 | #include "itoa.h" 42 | 43 | #ifdef __cplusplus 44 | extern "C"{ 45 | #endif // __cplusplus 46 | 47 | // Include Atmel headers 48 | #include "sam.h" 49 | 50 | #include "wiring_constants.h" 51 | 52 | #define clockCyclesPerMicrosecond() ( SystemCoreClock / 1000000L ) 53 | #define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (SystemCoreClock / 1000L) ) 54 | #define microsecondsToClockCycles(a) ( (a) * (SystemCoreClock / 1000000L) ) 55 | 56 | void yield( void ) ; 57 | 58 | /* system functions */ 59 | int main( void ); 60 | void init( void ); 61 | 62 | /* sketch */ 63 | void setup( void ) ; 64 | void loop( void ) ; 65 | 66 | #include "WVariant.h" 67 | 68 | #ifdef __cplusplus 69 | } // extern "C" 70 | #endif 71 | 72 | // The following headers are for C++ only compilation 73 | #ifdef __cplusplus 74 | #include "WCharacter.h" 75 | #include "WString.h" 76 | #include "Tone.h" 77 | #include "WMath.h" 78 | #include "HardwareSerial.h" 79 | #include "pulse.h" 80 | #endif 81 | #include "delay.h" 82 | #ifdef __cplusplus 83 | #include "Uart.h" 84 | #endif 85 | 86 | // Include board variant 87 | #include "variant.h" 88 | 89 | #include "wiring.h" 90 | #include "wiring_digital.h" 91 | #include "wiring_analog.h" 92 | #include "wiring_shift.h" 93 | #include "WInterrupts.h" 94 | 95 | // undefine stdlib's abs if encountered 96 | #ifdef abs 97 | #undef abs 98 | #endif // abs 99 | 100 | #define min(a,b) ((a)<(b)?(a):(b)) 101 | #define max(a,b) ((a)>(b)?(a):(b)) 102 | #define abs(x) ((x)>0?(x):-(x)) 103 | #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) 104 | #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) 105 | #define radians(deg) ((deg)*DEG_TO_RAD) 106 | #define degrees(rad) ((rad)*RAD_TO_DEG) 107 | #define sq(x) ((x)*(x)) 108 | 109 | #define interrupts() __enable_irq() 110 | #define noInterrupts() __disable_irq() 111 | 112 | #define lowByte(w) ((uint8_t) ((w) & 0xff)) 113 | #define highByte(w) ((uint8_t) ((w) >> 8)) 114 | 115 | #define bitRead(value, bit) (((value) >> (bit)) & 0x01) 116 | #define bitSet(value, bit) ((value) |= (1UL << (bit))) 117 | #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) 118 | #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) 119 | 120 | #define bit(b) (1UL << (b)) 121 | 122 | #if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606) 123 | // Interrupts 124 | #define digitalPinToInterrupt(P) ( P ) 125 | #endif 126 | 127 | // USB Device 128 | #include "USB/USBDesc.h" 129 | #include "USB/USBCore.h" 130 | #include "USB/USBAPI.h" 131 | #include "USB/USB_host.h" 132 | 133 | #endif // Arduino_h 134 | -------------------------------------------------------------------------------- /cores/intiki/Client.h: -------------------------------------------------------------------------------- 1 | /* 2 | Client.h - Base class that provides Client 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef client_h 21 | #define client_h 22 | #include "Print.h" 23 | #include "Stream.h" 24 | #include "IPAddress.h" 25 | 26 | class Client : public Stream { 27 | 28 | public: 29 | virtual int connect(IPAddress ip, uint16_t port) =0; 30 | virtual int connect(const char *host, uint16_t port) =0; 31 | virtual size_t write(uint8_t) =0; 32 | virtual size_t write(const uint8_t *buf, size_t size) =0; 33 | virtual int available() = 0; 34 | virtual int read() = 0; 35 | virtual int read(uint8_t *buf, size_t size) = 0; 36 | virtual int peek() = 0; 37 | virtual void flush() = 0; 38 | virtual void stop() = 0; 39 | virtual uint8_t connected() = 0; 40 | virtual operator bool() = 0; 41 | protected: 42 | uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /cores/intiki/HardwareSerial.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015-2016 Tokita, Hiroshi 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 | #include "HardwareSerial.h" 20 | 21 | void HardwareSerial::begin(unsigned long x) { (void)x; } 22 | void HardwareSerial::begin(unsigned long baudrate, uint16_t config) { (void)baudrate; (void)config; } 23 | void HardwareSerial::end() { } 24 | -------------------------------------------------------------------------------- /cores/intiki/HardwareSerial.h: -------------------------------------------------------------------------------- 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 | #ifndef HardwareSerial_h 20 | #define HardwareSerial_h 21 | 22 | #include 23 | 24 | #include "Stream.h" 25 | 26 | #define HARDSER_PARITY_EVEN (0x1ul) 27 | #define HARDSER_PARITY_ODD (0x2ul) 28 | #define HARDSER_PARITY_NONE (0x3ul) 29 | #define HARDSER_PARITY_MASK (0xFul) 30 | 31 | #define HARDSER_STOP_BIT_1 (0x10ul) 32 | #define HARDSER_STOP_BIT_1_5 (0x20ul) 33 | #define HARDSER_STOP_BIT_2 (0x30ul) 34 | #define HARDSER_STOP_BIT_MASK (0xF0ul) 35 | 36 | #define HARDSER_DATA_5 (0x100ul) 37 | #define HARDSER_DATA_6 (0x200ul) 38 | #define HARDSER_DATA_7 (0x300ul) 39 | #define HARDSER_DATA_8 (0x400ul) 40 | #define HARDSER_DATA_MASK (0xF00ul) 41 | 42 | #define SERIAL_5N1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_NONE | HARDSER_DATA_5) 43 | #define SERIAL_6N1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_NONE | HARDSER_DATA_6) 44 | #define SERIAL_7N1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_NONE | HARDSER_DATA_7) 45 | #define SERIAL_8N1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_NONE | HARDSER_DATA_8) 46 | #define SERIAL_5N2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_NONE | HARDSER_DATA_5) 47 | #define SERIAL_6N2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_NONE | HARDSER_DATA_6) 48 | #define SERIAL_7N2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_NONE | HARDSER_DATA_7) 49 | #define SERIAL_8N2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_NONE | HARDSER_DATA_8) 50 | #define SERIAL_5E1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_EVEN | HARDSER_DATA_5) 51 | #define SERIAL_6E1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_EVEN | HARDSER_DATA_6) 52 | #define SERIAL_7E1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_EVEN | HARDSER_DATA_7) 53 | #define SERIAL_8E1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_EVEN | HARDSER_DATA_8) 54 | #define SERIAL_5E2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_EVEN | HARDSER_DATA_5) 55 | #define SERIAL_6E2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_EVEN | HARDSER_DATA_6) 56 | #define SERIAL_7E2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_EVEN | HARDSER_DATA_7) 57 | #define SERIAL_8E2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_EVEN | HARDSER_DATA_8) 58 | #define SERIAL_5O1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_ODD | HARDSER_DATA_5) 59 | #define SERIAL_6O1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_ODD | HARDSER_DATA_6) 60 | #define SERIAL_7O1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_ODD | HARDSER_DATA_7) 61 | #define SERIAL_8O1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_ODD | HARDSER_DATA_8) 62 | #define SERIAL_5O2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_ODD | HARDSER_DATA_5) 63 | #define SERIAL_6O2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_ODD | HARDSER_DATA_6) 64 | #define SERIAL_7O2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_ODD | HARDSER_DATA_7) 65 | #define SERIAL_8O2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_ODD | HARDSER_DATA_8) 66 | 67 | class HardwareSerial : public Stream 68 | { 69 | public: 70 | virtual void begin(unsigned long); 71 | virtual void begin(unsigned long baudrate, uint16_t config); 72 | virtual void end(); 73 | virtual int available(void) = 0; 74 | virtual int peek(void) = 0; 75 | virtual int read(void) = 0; 76 | virtual void flush(void) = 0; 77 | virtual size_t write(uint8_t) = 0; 78 | using Print::write; // pull in write(str) and write(buf, size) from Print 79 | virtual operator bool() = 0; 80 | }; 81 | 82 | extern void serialEventRun(void) __attribute__((weak)); 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /cores/intiki/Print.h: -------------------------------------------------------------------------------- 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 Print_h 20 | #define Print_h 21 | 22 | #include 23 | #include // for size_t 24 | 25 | #include "WString.h" 26 | #include "Printable.h" 27 | 28 | #define DEC 10 29 | #define HEX 16 30 | #define OCT 8 31 | #ifdef BIN // Prevent warnings if BIN is previously defined in "iotnx4.h" or similar 32 | #undef BIN 33 | #endif 34 | #define BIN 2 35 | 36 | class Print 37 | { 38 | private: 39 | int write_error; 40 | size_t printNumber(unsigned long, uint8_t); 41 | size_t printFloat(double, uint8_t); 42 | protected: 43 | void setWriteError(int err = 1) { write_error = err; } 44 | public: 45 | Print() : write_error(0) {} 46 | 47 | int getWriteError() { return write_error; } 48 | void clearWriteError() { setWriteError(0); } 49 | 50 | virtual size_t write(uint8_t) = 0; 51 | size_t write(const char *str) { 52 | if (str == NULL) return 0; 53 | return write((const uint8_t *)str, strlen(str)); 54 | } 55 | virtual size_t write(const uint8_t *buffer, size_t size); 56 | size_t write(const char *buffer, size_t size) { 57 | return write((const uint8_t *)buffer, size); 58 | } 59 | 60 | // default to zero, meaning "a single write may block" 61 | // should be overriden by subclasses with buffering 62 | virtual int availableForWrite() { return 0; } 63 | 64 | size_t print(const __FlashStringHelper *); 65 | size_t print(const String &); 66 | size_t print(const char[]); 67 | size_t print(char); 68 | size_t print(unsigned char, int = DEC); 69 | size_t print(int, int = DEC); 70 | size_t print(unsigned int, int = DEC); 71 | size_t print(long, int = DEC); 72 | size_t print(unsigned long, int = DEC); 73 | size_t print(double, int = 2); 74 | size_t print(const Printable&); 75 | 76 | size_t println(const __FlashStringHelper *); 77 | size_t println(const String &s); 78 | size_t println(const char[]); 79 | size_t println(char); 80 | size_t println(unsigned char, int = DEC); 81 | size_t println(int, int = DEC); 82 | size_t println(unsigned int, int = DEC); 83 | size_t println(long, int = DEC); 84 | size_t println(unsigned long, int = DEC); 85 | size_t println(double, int = 2); 86 | size_t println(const Printable&); 87 | size_t println(void); 88 | 89 | virtual void flush() { /* Empty implementation for backward compatibility */ } 90 | }; 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /cores/intiki/Printable.h: -------------------------------------------------------------------------------- 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 Printable_h 20 | #define Printable_h 21 | 22 | #include 23 | 24 | class Print; 25 | 26 | /** The Printable class provides a way for new classes to allow themselves to be printed. 27 | By deriving from Printable and implementing the printTo method, it will then be possible 28 | for users to print out instances of this class by passing them into the usual 29 | Print::print and Print::println methods. 30 | */ 31 | 32 | class Printable 33 | { 34 | public: 35 | virtual size_t printTo(Print& p) const = 0; 36 | }; 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /cores/intiki/Reset.h: -------------------------------------------------------------------------------- 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 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | void initiateReset(int ms); 26 | void tickReset(); 27 | void cancelReset(); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | -------------------------------------------------------------------------------- /cores/intiki/RingBuffer.h: -------------------------------------------------------------------------------- 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 | #ifdef __cplusplus 20 | 21 | #ifndef _RING_BUFFER_ 22 | #define _RING_BUFFER_ 23 | 24 | #include 25 | 26 | // Define constants and variables for buffering incoming serial data. We're 27 | // using a ring buffer (I think), in which head is the index of the location 28 | // to which to write the next incoming character and tail is the index of the 29 | // location from which to read. 30 | #define SERIAL_BUFFER_SIZE 64 31 | 32 | template 33 | class RingBufferN 34 | { 35 | public: 36 | uint8_t _aucBuffer[N] ; 37 | volatile int _iHead ; 38 | volatile int _iTail ; 39 | 40 | public: 41 | RingBufferN( void ) ; 42 | void store_char( uint8_t c ) ; 43 | void clear(); 44 | int read_char(); 45 | int available(); 46 | int availableForStore(); 47 | int peek(); 48 | bool isFull(); 49 | 50 | private: 51 | int nextIndex(int index); 52 | }; 53 | 54 | typedef RingBufferN RingBuffer; 55 | 56 | 57 | template 58 | RingBufferN::RingBufferN( void ) 59 | { 60 | memset( _aucBuffer, 0, N ) ; 61 | clear(); 62 | } 63 | 64 | template 65 | void RingBufferN::store_char( uint8_t c ) 66 | { 67 | int i = nextIndex(_iHead); 68 | 69 | // if we should be storing the received character into the location 70 | // just before the tail (meaning that the head would advance to the 71 | // current location of the tail), we're about to overflow the buffer 72 | // and so we don't write the character or advance the head. 73 | if ( i != _iTail ) 74 | { 75 | _aucBuffer[_iHead] = c ; 76 | _iHead = i ; 77 | } 78 | } 79 | 80 | template 81 | void RingBufferN::clear() 82 | { 83 | _iHead = 0; 84 | _iTail = 0; 85 | } 86 | 87 | template 88 | int RingBufferN::read_char() 89 | { 90 | if(_iTail == _iHead) 91 | return -1; 92 | 93 | uint8_t value = _aucBuffer[_iTail]; 94 | _iTail = nextIndex(_iTail); 95 | 96 | return value; 97 | } 98 | 99 | template 100 | int RingBufferN::available() 101 | { 102 | int delta = _iHead - _iTail; 103 | 104 | if(delta < 0) 105 | return N + delta; 106 | else 107 | return delta; 108 | } 109 | 110 | template 111 | int RingBufferN::availableForStore() 112 | { 113 | if (_iHead >= _iTail) 114 | return N - 1 - _iHead + _iTail; 115 | else 116 | return _iTail - _iHead - 1; 117 | } 118 | 119 | template 120 | int RingBufferN::peek() 121 | { 122 | if(_iTail == _iHead) 123 | return -1; 124 | 125 | return _aucBuffer[_iTail]; 126 | } 127 | 128 | template 129 | int RingBufferN::nextIndex(int index) 130 | { 131 | return (uint32_t)(index + 1) % N; 132 | } 133 | 134 | template 135 | bool RingBufferN::isFull() 136 | { 137 | return (nextIndex(_iHead) == _iTail); 138 | } 139 | 140 | #endif /* _RING_BUFFER_ */ 141 | 142 | #endif /* __cplusplus */ 143 | -------------------------------------------------------------------------------- /cores/intiki/Server.h: -------------------------------------------------------------------------------- 1 | /* 2 | Server.h - Base class that provides Server 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef server_h 21 | #define server_h 22 | 23 | #include "Print.h" 24 | 25 | class Server : public Print { 26 | public: 27 | virtual void begin() =0; 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /cores/intiki/Tone.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 Tokita, Hiroshi 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 | #include 20 | #include "wiring_digital.h" 21 | #include "wiring_constants.h" 22 | #include "platform.h" 23 | 24 | extern "C" { 25 | #include 26 | } 27 | 28 | #ifndef TONE_INTERVAL_OFFSET 29 | #define TONE_INTERVAL_OFFSET(f) 0 30 | #endif 31 | 32 | void tone(uint32_t _pin, uint32_t frequency, uint32_t duration) __attribute__((weak)); 33 | void noTone(uint32_t _pin) __attribute__((weak)); 34 | 35 | static uint32_t output_pin; 36 | static uint32_t output_state; 37 | static uint32_t interval; 38 | static uint32_t count; 39 | static struct rtimer tone_rtimer; 40 | 41 | static void rtimer_callback(struct rtimer* /*timer*/, void* /*ptr*/) 42 | { 43 | //DBG_PRINTF("rtimer_callback()\r\n"); 44 | if(count > 0) { 45 | count--; 46 | } 47 | else if(count == 0) { 48 | digitalWrite(output_pin, LOW); 49 | return; 50 | } 51 | output_state = (output_state == HIGH ? LOW : HIGH); 52 | digitalWrite(output_pin, output_state); 53 | rtimer_clock_t next = RTIMER_NOW() + interval; 54 | rtimer_set(&tone_rtimer, next, 0, rtimer_callback, NULL); 55 | } 56 | 57 | void tone(uint32_t pin, uint32_t frequency, uint32_t duration) 58 | { 59 | DBG_PRINTF("tone(%d, %d, %d)\r\n", pin, frequency, duration); 60 | output_pin = pin; 61 | output_state = LOW; 62 | digitalWrite(output_pin, output_state); 63 | interval = (RTIMER_SECOND / (frequency*2)) + TONE_INTERVAL_OFFSET(frequency); 64 | if(duration == 0) { 65 | count = -1; 66 | } 67 | else { 68 | count = frequency * 2 * duration / 1000; 69 | } 70 | rtimer_clock_t next = RTIMER_NOW() + interval; 71 | DBG_PRINTF("rtimer_set(%d) interval:%d count:%d\r\n", next, 0, count); 72 | rtimer_set(&tone_rtimer, next, 0, rtimer_callback, NULL); 73 | } 74 | 75 | void noTone(uint32_t pin) 76 | { 77 | count = 0; 78 | digitalWrite(pin, LOW); 79 | } 80 | 81 | -------------------------------------------------------------------------------- /cores/intiki/Tone.h: -------------------------------------------------------------------------------- 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 | #ifdef __cplusplus 22 | 23 | #include "Arduino.h" 24 | 25 | void tone(uint32_t _pin, uint32_t frequency, uint32_t duration = 0); 26 | void noTone(uint32_t _pin); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /cores/intiki/USB/PluggableUSB.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soburi/JN516x-arduino-package/68f697058ed418cb57d0d0cff0ab849f5cbeee19/cores/intiki/USB/PluggableUSB.h -------------------------------------------------------------------------------- /cores/intiki/USB/USBAPI.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soburi/JN516x-arduino-package/68f697058ed418cb57d0d0cff0ab849f5cbeee19/cores/intiki/USB/USBAPI.h -------------------------------------------------------------------------------- /cores/intiki/USB/USBCore.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soburi/JN516x-arduino-package/68f697058ed418cb57d0d0cff0ab849f5cbeee19/cores/intiki/USB/USBCore.h -------------------------------------------------------------------------------- /cores/intiki/USB/USBDesc.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soburi/JN516x-arduino-package/68f697058ed418cb57d0d0cff0ab849f5cbeee19/cores/intiki/USB/USBDesc.h -------------------------------------------------------------------------------- /cores/intiki/USB/USB_host.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soburi/JN516x-arduino-package/68f697058ed418cb57d0d0cff0ab849f5cbeee19/cores/intiki/USB/USB_host.h -------------------------------------------------------------------------------- /cores/intiki/Uart.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015-2018 Tokita, Hiroshi 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 | #include "Uart.h" 20 | #include "Arduino.h" 21 | #include "wiring_private.h" 22 | 23 | Uart::Uart(struct uart_device *_s) 24 | { 25 | uart=_s; 26 | } 27 | 28 | void Uart::begin(unsigned long baudrate) 29 | { 30 | begin(baudrate, SERIAL_8N1); 31 | } 32 | 33 | void Uart::begin(unsigned long baudrate, uint16_t config) 34 | { 35 | uint8_t parity = config & HARDSER_PARITY_MASK; 36 | uint8_t stopbit = (config & HARDSER_STOP_BIT_MASK) >> 4; 37 | uint8_t wordlen = ((config & HARDSER_DATA_MASK) >> 8) + 4; 38 | uint8_t flowctrl = 0; 39 | 40 | uart->init(uart->portinfo, baudrate, parity, stopbit, wordlen, flowctrl); 41 | uart->set_input(uart->portinfo, uart->input); 42 | } 43 | 44 | void Uart::end() 45 | { 46 | flush(); 47 | uart->deinit(uart->portinfo); 48 | } 49 | 50 | void Uart::flush() 51 | { 52 | while (uart->busy(uart->portinfo) ) ; 53 | } 54 | 55 | void Uart::IrqHandler() 56 | { 57 | rxBuffer.store_char(uart->received); 58 | } 59 | 60 | int Uart::available() 61 | { 62 | return (uint32_t)(SERIAL_BUFFER_SIZE + rxBuffer._iHead - rxBuffer._iTail) % SERIAL_BUFFER_SIZE; 63 | } 64 | 65 | int Uart::availableForWrite() 66 | { 67 | return uart->txbuffer_availables(uart->portinfo); 68 | } 69 | 70 | int Uart::peek() 71 | { 72 | return rxBuffer.peek(); 73 | } 74 | 75 | int Uart::read() 76 | { 77 | return rxBuffer.read_char(); 78 | } 79 | 80 | size_t Uart::write(const uint8_t data) 81 | { 82 | uart->writeb(uart->portinfo, data); 83 | return 1; 84 | } 85 | -------------------------------------------------------------------------------- /cores/intiki/Uart.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015 Arduino LLC. All right reserved. 3 | Copyright (c) 2015-2018 Tokita, Hiroshi 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 | See the GNU Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #pragma once 21 | 22 | #include "HardwareSerial.h" 23 | #include "RingBuffer.h" 24 | 25 | #include 26 | 27 | struct uart_device; 28 | 29 | class Uart : public HardwareSerial 30 | { 31 | public: 32 | Uart(struct uart_device *_s); 33 | void begin(unsigned long baudRate); 34 | void begin(unsigned long baudrate, uint16_t config); 35 | void end(); 36 | int available(); 37 | int availableForWrite(); 38 | int peek(); 39 | int read(); 40 | void flush(); 41 | size_t write(const uint8_t data); 42 | using Print::write; // pull in write(str) and write(buf, size) from Print 43 | 44 | void IrqHandler(); 45 | 46 | operator bool() { return true; } 47 | 48 | private: 49 | struct uart_device *uart; 50 | RingBuffer rxBuffer; 51 | #if 0 52 | RingBuffer txBuffer; 53 | 54 | uint8_t uc_pinRX; 55 | uint8_t uc_pinTX; 56 | SercomRXPad uc_padRX; 57 | SercomUartTXPad uc_padTX; 58 | uint8_t uc_pinRTS; 59 | volatile uint32_t* pul_outsetRTS; 60 | volatile uint32_t* pul_outclrRTS; 61 | uint32_t ul_pinMaskRTS; 62 | uint8_t uc_pinCTS; 63 | 64 | SercomNumberStopBit extractNbStopBit(uint16_t config); 65 | SercomUartCharSize extractCharSize(uint16_t config); 66 | SercomParityMode extractParity(uint16_t config); 67 | #endif 68 | }; 69 | -------------------------------------------------------------------------------- /cores/intiki/Udp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Udp.cpp: Library to send/receive UDP packets. 3 | * 4 | * NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these) 5 | * 1) UDP does not guarantee the order in which assembled UDP packets are received. This 6 | * might not happen often in practice, but in larger network topologies, a UDP 7 | * packet can be received out of sequence. 8 | * 2) UDP does not guard against lost packets - so packets *can* disappear without the sender being 9 | * aware of it. Again, this may not be a concern in practice on small local networks. 10 | * For more information, see http://www.cafeaulait.org/course/week12/35.html 11 | * 12 | * MIT License: 13 | * Copyright (c) 2008 Bjoern Hartmann 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | * 32 | * bjoern@cs.stanford.edu 12/30/2008 33 | */ 34 | 35 | #ifndef udp_h 36 | #define udp_h 37 | 38 | #include 39 | #include 40 | 41 | class UDP : public Stream { 42 | 43 | public: 44 | virtual uint8_t begin(uint16_t) =0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use 45 | virtual uint8_t beginMulticast(IPAddress, uint16_t) { return 0; } // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure 46 | virtual void stop() =0; // Finish with the UDP socket 47 | 48 | // Sending UDP packets 49 | 50 | // Start building up a packet to send to the remote host specific in ip and port 51 | // Returns 1 if successful, 0 if there was a problem with the supplied IP address or port 52 | virtual int beginPacket(IPAddress ip, uint16_t port) =0; 53 | // Start building up a packet to send to the remote host specific in host and port 54 | // Returns 1 if successful, 0 if there was a problem resolving the hostname or port 55 | virtual int beginPacket(const char *host, uint16_t port) =0; 56 | // Finish off this packet and send it 57 | // Returns 1 if the packet was sent successfully, 0 if there was an error 58 | virtual int endPacket() =0; 59 | // Write a single byte into the packet 60 | virtual size_t write(uint8_t) =0; 61 | // Write size bytes from buffer into the packet 62 | virtual size_t write(const uint8_t *buffer, size_t size) =0; 63 | 64 | // Start processing the next available incoming packet 65 | // Returns the size of the packet in bytes, or 0 if no packets are available 66 | virtual int parsePacket() =0; 67 | // Number of bytes remaining in the current packet 68 | virtual int available() =0; 69 | // Read a single byte from the current packet 70 | virtual int read() =0; 71 | // Read up to len bytes from the current packet and place them into buffer 72 | // Returns the number of bytes read, or 0 if none are available 73 | virtual int read(unsigned char* buffer, size_t len) =0; 74 | // Read up to len characters from the current packet and place them into buffer 75 | // Returns the number of characters read, or 0 if none are available 76 | virtual int read(char* buffer, size_t len) =0; 77 | // Return the next byte from the current packet without moving on to the next byte 78 | virtual int peek() =0; 79 | virtual void flush() =0; // Finish reading the current packet 80 | 81 | // Return the IP address of the host who sent the current incoming packet 82 | virtual IPAddress remoteIP() =0; 83 | // Return the port of the host who sent the current incoming packet 84 | virtual uint16_t remotePort() =0; 85 | protected: 86 | uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; 87 | }; 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /cores/intiki/WInterrupts.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015-2017 Tokita, Hiroshi 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 | #ifdef USE_WINTERRUPTS_PSEUDO_IMPLEMENT 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "Arduino.h" 27 | 28 | #include "wiring_private.h" 29 | 30 | #pragma GCC diagnostic push 31 | #pragma GCC diagnostic ignored "-Wmissing-field-initializers" 32 | PROCESS(buttons_callback, "Buttons callback"); 33 | #pragma GCC diagnostic pop 34 | 35 | static void winterrupts_c_constructor() __attribute__((constructor)); 36 | static void winterrupts_c_constructor() 37 | { 38 | static start_process_t button_l; 39 | button_l.process = &buttons_callback; 40 | add_start_process(&button_l); 41 | } 42 | 43 | PROCESS_THREAD(buttons_callback, ev, data) 44 | { 45 | PROCESS_BEGIN(); 46 | 47 | while(true) 48 | { 49 | PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event); 50 | 51 | struct sensors_sensor* button = (struct sensors_sensor*)data; 52 | int value = button->value(0); 53 | 54 | const struct buttonCallback* cb = button2ButtonCallback(button); 55 | 56 | if(cb) 57 | { 58 | if( (cb->mode == CHANGE) 59 | || (cb->mode == RISING && value == 1) 60 | || (cb->mode == FALLING && value == 0) ) 61 | { 62 | cb->callback(); 63 | } 64 | } 65 | } 66 | 67 | PROCESS_END(); 68 | } 69 | 70 | void _attachInterruptDefault(uint32_t pin, voidFuncPtr callback, uint32_t mode) 71 | { 72 | struct sensors_sensor* button = NULL; 73 | struct buttonCallback* cb = NULL; 74 | 75 | button = gpioPin2Button(pin); 76 | 77 | if(!button) return; 78 | 79 | cb = button2ButtonCallback(button); 80 | 81 | if(!cb) return; 82 | 83 | cb->callback = callback; 84 | cb->mode = mode; 85 | SENSORS_ACTIVATE(*button); 86 | } 87 | 88 | void _detachInterruptDefault(uint32_t pin) 89 | { 90 | struct sensors_sensor* button = gpioPin2Button(pin); 91 | if(!button) return; 92 | SENSORS_DEACTIVATE(*button); 93 | } 94 | 95 | struct sensors_sensor* _gpioPin2ButtonDefault(uint32_t pin) 96 | { 97 | (void)pin; 98 | return (struct sensors_sensor*)&button_sensor; 99 | } 100 | 101 | struct buttonCallback buttonCB = {0}; 102 | struct buttonCallback* _button2ButtonCallbackDefault(const struct sensors_sensor* button) 103 | { 104 | (void)button; 105 | return &buttonCB; 106 | } 107 | 108 | void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode) __attribute__((weak,alias("_attachInterruptDefault"))); 109 | void detachInterrupt(uint32_t pin) __attribute__((weak,alias("_detachInterruptDefault"))); 110 | 111 | struct sensors_sensor* gpioPin2Button(uint32_t pin) __attribute__((weak,alias("_gpioPin2ButtonDefault"))); 112 | struct buttonCallback* button2ButtonCallback(struct sensors_sensor*) __attribute__((weak,alias("_button2ButtonCallbackDefault"))); 113 | 114 | #endif /* USE_WINTERRUPTS_PSEUDO_IMPLEMENT */ 115 | 116 | -------------------------------------------------------------------------------- /cores/intiki/WInterrupts.h: -------------------------------------------------------------------------------- 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 | #ifndef _WIRING_INTERRUPTS_ 20 | #define _WIRING_INTERRUPTS_ 21 | 22 | #include 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | // LOW 0 29 | // HIGH 1 30 | #define CHANGE 2 31 | #define FALLING 3 32 | #define RISING 4 33 | 34 | #define DEFAULT 1 35 | #define EXTERNAL 0 36 | 37 | typedef void (*voidFuncPtr)(void); 38 | 39 | /* 40 | * \brief Specifies a named Interrupt Service Routine (ISR) to call when an interrupt occurs. 41 | * Replaces any previous function that was attached to the interrupt. 42 | */ 43 | void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode); 44 | 45 | /* 46 | * \brief Turns off the given interrupt. 47 | */ 48 | void detachInterrupt(uint32_t pin); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /cores/intiki/WMath.cpp: -------------------------------------------------------------------------------- 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 | } 69 | -------------------------------------------------------------------------------- /cores/intiki/WMath.h: -------------------------------------------------------------------------------- 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_ */ 34 | -------------------------------------------------------------------------------- /cores/intiki/WVariant.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soburi/JN516x-arduino-package/68f697058ed418cb57d0d0cff0ab849f5cbeee19/cores/intiki/WVariant.h -------------------------------------------------------------------------------- /cores/intiki/abi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014 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 | #include 20 | 21 | extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__)); 22 | extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__)); 23 | 24 | void __cxa_pure_virtual(void) { 25 | // We might want to write some diagnostics to uart in this case 26 | //std::terminate(); 27 | while (1) 28 | ; 29 | } 30 | 31 | void __cxa_deleted_virtual(void) { 32 | // We might want to write some diagnostics to uart in this case 33 | //std::terminate(); 34 | while (1) 35 | ; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /cores/intiki/avr/dtostrf.c: -------------------------------------------------------------------------------- 1 | /* 2 | dtostrf - Emulation for dtostrf function from avr-libc 3 | Copyright (c) 2015 Arduino LLC. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | 22 | char *dtostrf (double val, signed char width, unsigned char prec, char *sout) { 23 | asm(".global _printf_float"); 24 | 25 | char fmt[20]; 26 | sprintf(fmt, "%%%d.%df", width, prec); 27 | sprintf(sout, fmt, val); 28 | return sout; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /cores/intiki/avr/dtostrf.h: -------------------------------------------------------------------------------- 1 | /* 2 | dtostrf - Emulation for dtostrf function from avr-libc 3 | Copyright (c) 2015 Arduino LLC. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #pragma once 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | char *dtostrf(double val, signed char width, unsigned char prec, char *sout); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | -------------------------------------------------------------------------------- /cores/intiki/avr/interrupt.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015 Arduino LCC. 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 | /* 20 | Empty file. 21 | This file is here to allow compatibility with sketches (made for AVR) 22 | that includes 23 | */ 24 | -------------------------------------------------------------------------------- /cores/intiki/avr/io.h: -------------------------------------------------------------------------------- 1 | /* 2 | io.h - Definitions for compatibility with AVR io macros 3 | 4 | Copyright (c) 2016 Arduino LLC 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE 23 | */ 24 | 25 | #ifndef _IO_H_ 26 | #define _IO_H_ 27 | 28 | #define RAMSTART (HMCRAMC0_ADDR) 29 | #define RAMSIZE (HMCRAMC0_SIZE) 30 | #define RAMEND (RAMSTART + RAMSIZE - 1) 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /cores/intiki/delay.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015-2017 Tokita, Hiroshi 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 | #include "delay.h" 20 | #include "Arduino.h" 21 | 22 | #include "platform.h" 23 | 24 | #include "wiring_private.h" 25 | 26 | #include 27 | 28 | unsigned long millis( void ) 29 | { 30 | return clock_seconds() * 1000 + (RTIMER_NOW() % RTIMER_ARCH_SECOND) * 1000 / RTIMER_ARCH_SECOND; 31 | } 32 | 33 | // Interrupt-compatible version of micros 34 | // Theory: repeatedly take readings of SysTick counter, millis counter and SysTick interrupt pending flag. 35 | // When it appears that millis counter and pending is stable and SysTick hasn't rolled over, use these 36 | // values to calculate micros. If there is a pending SysTick, add one to the millis counter in the calculation. 37 | unsigned long micros( void ) 38 | { 39 | return RTIMER_NOW() /(RTIMER_ARCH_SECOND/1000000); 40 | } 41 | 42 | static struct etimer delay_timer; 43 | 44 | static void delay_timer_start(void* data) 45 | { 46 | uint32_t ms = *(uint32_t*)data; 47 | etimer_set(&delay_timer, CLOCK_SECOND * ms /1000); 48 | } 49 | 50 | static int delay_timer_expired(process_event_t ev, process_data_t data, void* param) 51 | { 52 | (void)ev; (void)data; (void)param; 53 | return etimer_expired(&delay_timer); 54 | } 55 | 56 | void delay( unsigned long ms ) 57 | { 58 | yield_until(delay_timer_start, &ms, delay_timer_expired, NULL); 59 | } 60 | 61 | void _delayMicrosecondsDefault( unsigned int usec ) 62 | { 63 | clock_delay_usec(usec); 64 | } 65 | 66 | #ifndef OVERLOAD_DELAYMICROSECONDS 67 | void delayMicroseconds( unsigned int usec ) __attribute__((weak,alias("_delayMicrosecondsDefault"))); 68 | #endif 69 | -------------------------------------------------------------------------------- /cores/intiki/delay.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015 Arduino LLC. All right reserved. 3 | Copyright (c) 2015-2018 Tokita, Hiroshi 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 | See the GNU Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef _DELAY_ 21 | #define _DELAY_ 22 | 23 | #include 24 | #include "variant.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /** 31 | * \brief Returns the number of milliseconds since the Arduino board began running the current program. 32 | * 33 | * This number will overflow (go back to zero), after approximately 50 days. 34 | * 35 | * \return Number of milliseconds since the program started (uint32_t) 36 | */ 37 | extern unsigned long millis( void ) ; 38 | 39 | /** 40 | * \brief Returns the number of microseconds since the Arduino board began running the current program. 41 | * 42 | * This number will overflow (go back to zero), after approximately 70 minutes. On 16 MHz Arduino boards 43 | * (e.g. Duemilanove and Nano), this function has a resolution of four microseconds (i.e. the value returned is 44 | * always a multiple of four). On 8 MHz Arduino boards (e.g. the LilyPad), this function has a resolution 45 | * of eight microseconds. 46 | * 47 | * \note There are 1,000 microseconds in a millisecond and 1,000,000 microseconds in a second. 48 | */ 49 | extern unsigned long micros( void ) ; 50 | 51 | /** 52 | * \brief Pauses the program for the amount of time (in miliseconds) specified as parameter. 53 | * (There are 1000 milliseconds in a second.) 54 | * 55 | * \param dwMs the number of milliseconds to pause (uint32_t) 56 | */ 57 | extern void delay( unsigned long dwMs ) ; 58 | 59 | /** 60 | * \brief Pauses the program for the amount of time (in microseconds) specified as parameter. 61 | * 62 | * \param dwUs the number of microseconds to pause (uint32_t) 63 | */ 64 | #ifndef OVERLOAD_DELAYMICROSECONDS 65 | extern void delayMicroseconds( unsigned int usec ); 66 | #endif 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | #endif /* _DELAY_ */ 73 | -------------------------------------------------------------------------------- /cores/intiki/hooks.c: -------------------------------------------------------------------------------- 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 | /** 20 | * Empty yield() hook. 21 | * 22 | * This function is intended to be used by library writers to build 23 | * libraries or sketches that supports cooperative threads. 24 | * 25 | * Its defined as a weak symbol and it can be redefined to implement a 26 | * real cooperative scheduler. 27 | */ 28 | static void __empty() { 29 | // Empty 30 | } 31 | void yield(void) __attribute__ ((weak, alias("__empty"))); 32 | 33 | /** 34 | * SysTick hook 35 | * 36 | * This function is called from SysTick handler, before the default 37 | * handler provided by Arduino. 38 | */ 39 | static int __false() { 40 | // Return false 41 | return 0; 42 | } 43 | int sysTickHook(void) __attribute__ ((weak, alias("__false"))); 44 | 45 | /** 46 | * SVC hook 47 | * PendSV hook 48 | * 49 | * These functions are called from SVC handler, and PensSV handler. 50 | * Default action is halting. 51 | */ 52 | static void __halt() { 53 | // Halts 54 | while (1) 55 | ; 56 | } 57 | void svcHook(void) __attribute__ ((weak, alias("__halt"))); 58 | void pendSVHook(void) __attribute__ ((weak, alias("__halt"))); 59 | -------------------------------------------------------------------------------- /cores/intiki/itoa.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014 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 | #include "itoa.h" 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /* reverse: reverse string s in place */ 27 | /* 28 | static void reverse( char s[] ) 29 | { 30 | int i, j ; 31 | char c ; 32 | 33 | for ( i = 0, j = strlen(s)-1 ; i < j ; i++, j-- ) 34 | { 35 | c = s[i] ; 36 | s[i] = s[j] ; 37 | s[j] = c ; 38 | } 39 | } 40 | */ 41 | 42 | /* itoa: convert n to characters in s */ 43 | /* 44 | extern void itoa( int n, char s[] ) 45 | { 46 | int i, sign ; 47 | 48 | if ( (sign = n) < 0 ) // record sign 49 | { 50 | n = -n; // make n positive 51 | } 52 | 53 | i = 0; 54 | do 55 | { // generate digits in reverse order 56 | s[i++] = n % 10 + '0'; // get next digit 57 | } while ((n /= 10) > 0) ; // delete it 58 | 59 | if (sign < 0 ) 60 | { 61 | s[i++] = '-'; 62 | } 63 | 64 | s[i] = '\0'; 65 | 66 | reverse( s ) ; 67 | } 68 | */ 69 | 70 | extern char* itoa( int value, char *string, int radix ) 71 | { 72 | return ltoa( value, string, radix ) ; 73 | } 74 | 75 | extern char* ltoa( long value, char *string, int radix ) 76 | { 77 | char tmp[33]; 78 | char *tp = tmp; 79 | long i; 80 | unsigned long v; 81 | int sign; 82 | char *sp; 83 | 84 | if ( string == NULL ) 85 | { 86 | return 0 ; 87 | } 88 | 89 | if (radix > 36 || radix <= 1) 90 | { 91 | return 0 ; 92 | } 93 | 94 | sign = (radix == 10 && value < 0); 95 | if (sign) 96 | { 97 | v = -value; 98 | } 99 | else 100 | { 101 | v = (unsigned long)value; 102 | } 103 | 104 | while (v || tp == tmp) 105 | { 106 | i = v % radix; 107 | v = v / radix; 108 | if (i < 10) 109 | *tp++ = i+'0'; 110 | else 111 | *tp++ = i + 'a' - 10; 112 | } 113 | 114 | sp = string; 115 | 116 | if (sign) 117 | *sp++ = '-'; 118 | while (tp > tmp) 119 | *sp++ = *--tp; 120 | *sp = 0; 121 | 122 | return string; 123 | } 124 | 125 | extern char* utoa( unsigned int value, char *string, int radix ) 126 | { 127 | return ultoa( value, string, radix ) ; 128 | } 129 | 130 | extern char* ultoa( unsigned long value, char *string, int radix ) 131 | { 132 | char tmp[33]; 133 | char *tp = tmp; 134 | long i; 135 | unsigned long v = value; 136 | char *sp; 137 | 138 | if ( string == NULL ) 139 | { 140 | return 0; 141 | } 142 | 143 | if (radix > 36 || radix <= 1) 144 | { 145 | return 0; 146 | } 147 | 148 | while (v || tp == tmp) 149 | { 150 | i = v % radix; 151 | v = v / radix; 152 | if (i < 10) 153 | *tp++ = i+'0'; 154 | else 155 | *tp++ = i + 'a' - 10; 156 | } 157 | 158 | sp = string; 159 | 160 | 161 | while (tp > tmp) 162 | *sp++ = *--tp; 163 | *sp = 0; 164 | 165 | return string; 166 | } 167 | 168 | #ifdef __cplusplus 169 | } // extern "C" 170 | #endif 171 | -------------------------------------------------------------------------------- /cores/intiki/itoa.h: -------------------------------------------------------------------------------- 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 | #ifdef __cplusplus 22 | extern "C"{ 23 | #endif 24 | 25 | //extern void itoa( int n, char s[] ) ; 26 | 27 | extern char* itoa( int value, char *string, int radix ) ; 28 | extern char* ltoa( long value, char *string, int radix ) ; 29 | extern char* utoa( unsigned int value, char *string, int radix ) ; 30 | extern char* ultoa( unsigned long value, char *string, int radix ) ; 31 | 32 | #ifdef __cplusplus 33 | } // extern "C" 34 | #endif 35 | 36 | -------------------------------------------------------------------------------- /cores/intiki/new.cpp: -------------------------------------------------------------------------------- 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 | #include 20 | 21 | void *operator new(size_t size) { 22 | return malloc(size); 23 | } 24 | 25 | void *operator new[](size_t size) { 26 | return malloc(size); 27 | } 28 | 29 | void operator delete(void * ptr) { 30 | free(ptr); 31 | } 32 | 33 | void operator delete[](void * ptr) { 34 | free(ptr); 35 | } 36 | 37 | -------------------------------------------------------------------------------- /cores/intiki/pulse.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015-2017 Tokita, Hiroshi 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 | #include 20 | #include "Arduino.h" 21 | #include "wiring_private.h" 22 | 23 | static uint32_t pulsein_pin; 24 | static uint32_t pulsein_state; 25 | static uint32_t pulse_start_time; 26 | static uint32_t pulse_end_time; 27 | 28 | static void pulse_end_callback() 29 | { 30 | pulse_end_time = micros(); 31 | } 32 | 33 | static void pulse_start_callback() 34 | { 35 | pulse_start_time = micros(); 36 | attachInterrupt(pulsein_pin, pulse_end_callback, pulsein_state == HIGH ? FALLING : RISING); 37 | } 38 | 39 | uint32_t _pulseInDefault(uint32_t pin, uint32_t state, uint32_t timeout) 40 | { 41 | DBG_PRINTF("_pulseInDefault(%d, %d, %d)\r\n", pin, state, timeout); 42 | pulse_start_time = 0; 43 | pulse_end_time = 0; 44 | pulsein_pin = pin; 45 | pulsein_state = state; 46 | attachInterrupt(pulsein_pin, pulse_start_callback, pulsein_state == HIGH ? RISING : FALLING); 47 | clock_delay_usec(timeout); 48 | uint32_t end = timeout + micros(); 49 | while (micros() < end && pulse_end_time == 0) { 50 | yield(); 51 | } 52 | detachInterrupt(pulsein_pin); 53 | 54 | DBG_PRINTF("end: %d start: %d width: %d)\r\n", pulse_end_time, pulse_start_time, pulse_end_time - pulse_start_time); 55 | if(pulse_end_time != 0) { 56 | return pulse_end_time - pulse_start_time; 57 | } 58 | 59 | return 0; 60 | } 61 | 62 | uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout) __attribute__ ((weak, alias("_pulseInDefault")) ); 63 | -------------------------------------------------------------------------------- /cores/intiki/pulse.h: -------------------------------------------------------------------------------- 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 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | /* 26 | * \brief Measures the length (in microseconds) of a pulse on the pin; state is HIGH 27 | * or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds 28 | * to 3 minutes in length, but must be called at least a few dozen microseconds 29 | * before the start of the pulse. 30 | */ 31 | uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout); 32 | 33 | #ifdef __cplusplus 34 | // Provides a version of pulseIn with a default argument (C++ only) 35 | uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout = 1000000L); 36 | 37 | } // extern "C" 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /cores/intiki/weak_pragmas.h: -------------------------------------------------------------------------------- 1 | #pragma weak autostart_start 2 | #pragma weak autostart_end 3 | -------------------------------------------------------------------------------- /cores/intiki/wiring.h: -------------------------------------------------------------------------------- 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 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | extern void init(void); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | -------------------------------------------------------------------------------- /cores/intiki/wiring_analog.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015-2017 Tokita, Hiroshi 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 | #ifdef USE_WIRING_ANALOG_PSEUDO_IMPLEMENT 20 | 21 | #include "Arduino.h" 22 | #include "wiring_private.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | 29 | void _analogReferenceDefault( eAnalogReference ulMode ) { (void)ulMode; } 30 | void _analogWriteDefault( uint32_t ulPin, uint32_t ulValue ) { (void)ulPin; (void)ulValue; } 31 | uint32_t _analogReadDefault( uint32_t ulPin ) { (void)ulPin; return 0; } 32 | void _analogReadResolutionDefault(int res) { (void)res; } 33 | void _analogWriteResolutionDefault(int res) { (void)res; } 34 | void _analogOutputInitDefault( void ) { } 35 | 36 | void analogReference( eAnalogReference ulMode ) __attribute__((weak,alias("_analogReferenceDefault"))); 37 | void analogWrite( uint32_t ulPin, uint32_t ulValue ) __attribute__((weak,alias("_analogWriteDefault"))); 38 | uint32_t analogRead( uint32_t ulPin ) __attribute__((weak,alias("_analogReadDefault"))); 39 | void analogReadResolution(int res) __attribute__((weak,alias("_analogReadResolutionDefault"))); 40 | void analogWriteResolution(int res) __attribute__((weak,alias("_analogWriteResolutionDefault"))); 41 | void analogOutputInit( void ) __attribute__((weak,alias("_analogOutputInitDefault"))); 42 | 43 | 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif /* USE_WIRING_ANALOG_PSEUDO_IMPLEMENT */ 50 | 51 | -------------------------------------------------------------------------------- /cores/intiki/wiring_analog.h: -------------------------------------------------------------------------------- 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 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* 28 | * \brief SAMD products have only one reference for ADC 29 | */ 30 | typedef enum _eAnalogReference 31 | { 32 | AR_DEFAULT, 33 | AR_INTERNAL, 34 | AR_EXTERNAL, 35 | AR_INTERNAL1V0, 36 | AR_INTERNAL1V65, 37 | AR_INTERNAL2V23 38 | } eAnalogReference ; 39 | 40 | 41 | /* 42 | * \brief Configures the reference voltage used for analog input (i.e. the value used as the top of the input range). 43 | * This function is kept only for compatibility with existing AVR based API. 44 | * 45 | * \param ulMmode Should be set to AR_DEFAULT. 46 | */ 47 | extern void analogReference( eAnalogReference ulMode ) ; 48 | 49 | /* 50 | * \brief Writes an analog value (PWM wave) to a pin. 51 | * 52 | * \param ulPin 53 | * \param ulValue 54 | */ 55 | extern void analogWrite( uint32_t ulPin, uint32_t ulValue ) ; 56 | 57 | /* 58 | * \brief Reads the value from the specified analog pin. 59 | * 60 | * \param ulPin 61 | * 62 | * \return Read value from selected pin, if no error. 63 | */ 64 | extern uint32_t analogRead( uint32_t ulPin ) ; 65 | 66 | /* 67 | * \brief Set the resolution of analogRead return values. Default is 10 bits (range from 0 to 1023). 68 | * 69 | * \param res 70 | */ 71 | extern void analogReadResolution(int res); 72 | 73 | /* 74 | * \brief Set the resolution of analogWrite parameters. Default is 8 bits (range from 0 to 255). 75 | * 76 | * \param res 77 | */ 78 | extern void analogWriteResolution(int res); 79 | 80 | extern void analogOutputInit( void ) ; 81 | 82 | #ifdef __cplusplus 83 | } 84 | #endif 85 | -------------------------------------------------------------------------------- /cores/intiki/wiring_constants.h: -------------------------------------------------------------------------------- 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_CONSTANTS_ 20 | #define _WIRING_CONSTANTS_ 21 | 22 | #ifdef __cplusplus 23 | extern "C"{ 24 | #endif // __cplusplus 25 | 26 | #define LOW (0x0) 27 | #define HIGH (0x1) 28 | 29 | #define INPUT (0x0) 30 | #define OUTPUT (0x1) 31 | #define INPUT_PULLUP (0x2) 32 | #define INPUT_PULLDOWN (0x3) 33 | 34 | #define PI 3.1415926535897932384626433832795 35 | #define HALF_PI 1.5707963267948966192313216916398 36 | #define TWO_PI 6.283185307179586476925286766559 37 | #define DEG_TO_RAD 0.017453292519943295769236907684886 38 | #define RAD_TO_DEG 57.295779513082320876798154814105 39 | #define EULER 2.718281828459045235360287471352 40 | 41 | #define SERIAL 0x0 42 | #define DISPLAY 0x1 43 | 44 | enum BitOrder { 45 | LSBFIRST = 0, 46 | MSBFIRST = 1 47 | }; 48 | 49 | // moved to WInterrupts.h 50 | //// LOW 0 51 | //// HIGH 1 52 | //#define CHANGE 2 53 | //#define FALLING 3 54 | //#define RISING 4 55 | // 56 | //#define DEFAULT 1 57 | //#define EXTERNAL 0 58 | 59 | #ifdef __cplusplus 60 | } // extern "C" 61 | #endif // __cplusplus 62 | 63 | #endif /* _WIRING_CONSTANTS_ */ 64 | -------------------------------------------------------------------------------- /cores/intiki/wiring_digital.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015-2017 Tokita, Hiroshi 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 | #ifdef USE_WIRING_DIGITAL_PSEUDO_IMPLEMENT 20 | 21 | #include "Arduino.h" 22 | 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | uint32_t gpioPin2LedBits(uint32_t ulPin) __attribute__((weak)); 30 | uint32_t gpioPin2LedBits(uint32_t ulPin) 31 | { 32 | return ulPin; 33 | } 34 | 35 | void _pinModeDefault( uint32_t ulPin, uint32_t ulMode ) 36 | { 37 | (void)ulPin; (void)ulMode; 38 | } 39 | 40 | 41 | void _digitalWriteDefault( uint32_t ulPin, uint32_t ulVal ) 42 | { 43 | if(ulVal == LOW) 44 | { 45 | leds_off( gpioPin2LedBits(ulPin) ); 46 | } 47 | else 48 | { 49 | leds_on( gpioPin2LedBits(ulPin) ); 50 | } 51 | } 52 | 53 | 54 | int _digitalReadDefault( uint32_t ulPin ) 55 | { 56 | if( leds_get() & gpioPin2LedBits(ulPin) ) 57 | { 58 | return HIGH; 59 | } 60 | 61 | return LOW; 62 | } 63 | 64 | void pinMode( uint32_t ulPin, uint32_t ulMode ) __attribute__((weak, alias("_pinModeDefault"))); 65 | void digitalWrite( uint32_t ulPin, uint32_t ulVal ) __attribute__((weak, alias("_digitalWriteDefault"))); 66 | int digitalRead( uint32_t ulPin ) __attribute__((weak, alias("_digitalReadDefault"))); 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* USE_WIRING_DIGITAL_PSEUDO_IMPLEMENT */ 72 | 73 | -------------------------------------------------------------------------------- /cores/intiki/wiring_digital.h: -------------------------------------------------------------------------------- 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_DIGITAL_ 20 | #define _WIRING_DIGITAL_ 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include "WVariant.h" 27 | 28 | /** 29 | * \brief Configures the specified pin to behave either as an input or an output. See the description of digital pins for details. 30 | * 31 | * \param ulPin The number of the pin whose mode you wish to set 32 | * \param ulMode Can be INPUT, OUTPUT, INPUT_PULLUP or INPUT_PULLDOWN 33 | */ 34 | extern void pinMode( uint32_t dwPin, uint32_t dwMode ) ; 35 | 36 | /** 37 | * \brief Write a HIGH or a LOW value to a digital pin. 38 | * 39 | * If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the 40 | * corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW. 41 | * 42 | * If the pin is configured as an INPUT, writing a HIGH value with digitalWrite() will enable an internal 43 | * 20K pullup resistor (see the tutorial on digital pins). Writing LOW will disable the pullup. The pullup 44 | * resistor is enough to light an LED dimly, so if LEDs appear to work, but very dimly, this is a likely 45 | * cause. The remedy is to set the pin to an output with the pinMode() function. 46 | * 47 | * \note Digital pin PIN_LED is harder to use as a digital input than the other digital pins because it has an LED 48 | * and resistor attached to it that's soldered to the board on most boards. If you enable its internal 20k pull-up 49 | * resistor, it will hang at around 1.7 V instead of the expected 5V because the onboard LED and series resistor 50 | * pull the voltage level down, meaning it always returns LOW. If you must use pin PIN_LED as a digital input, use an 51 | * external pull down resistor. 52 | * 53 | * \param dwPin the pin number 54 | * \param dwVal HIGH or LOW 55 | */ 56 | extern void digitalWrite( uint32_t dwPin, uint32_t dwVal ) ; 57 | 58 | /** 59 | * \brief Reads the value from a specified digital pin, either HIGH or LOW. 60 | * 61 | * \param ulPin The number of the digital pin you want to read (int) 62 | * 63 | * \return HIGH or LOW 64 | */ 65 | extern int digitalRead( uint32_t ulPin ) ; 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* _WIRING_DIGITAL_ */ 72 | -------------------------------------------------------------------------------- /cores/intiki/wiring_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2018 Tokita, Hiroshi 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 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #include 26 | #include 27 | 28 | #include "platform.h" 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include "WInterrupts.h" 36 | #include "wiring_constants.h" 37 | 38 | typedef int (*fp_condition)(process_event_t, process_data_t, void*); 39 | typedef void (*fp_run)(void*); 40 | 41 | enum main_thread_wait_type 42 | { 43 | WT_NONE, 44 | WT_WAIT_UNTIL, 45 | WT_YIELD_UNTIL, 46 | WT_YIELD, 47 | WT_PAUSE 48 | }; 49 | 50 | extern void yield_to_main_thread(enum main_thread_wait_type type, fp_run run, void* run_param, fp_condition condition, void* condition_param); 51 | extern void yield_until(fp_run run, void* run_param, fp_condition condition, void* condition_param); 52 | 53 | extern void yield_continue(fp_run run, void* run_param); 54 | 55 | extern void post_continue(); 56 | 57 | typedef struct 58 | { 59 | struct start_process_list_t* next; 60 | struct process* process; 61 | } start_process_t; 62 | 63 | extern void add_start_process(start_process_t* p); 64 | 65 | struct buttonCallback 66 | { 67 | const struct sensors_sensor* button; 68 | voidFuncPtr callback; 69 | uint32_t mode; 70 | }; 71 | struct buttonCallback* button2ButtonCallback(struct sensors_sensor*); 72 | 73 | struct sensors_sensor* gpioPin2Button(uint32_t pin); 74 | 75 | 76 | struct uart_device { 77 | int (*input)( uint8_t c); 78 | void (*init)(void*, uint32_t, uint8_t, uint8_t, uint8_t, uint8_t); 79 | void (*set_input)(void*, int (*input)(unsigned char)); 80 | void (*writeb)(void*, unsigned char); 81 | uint8_t (*busy)(void*); 82 | int (*txbuffer_availables)(void*); 83 | void (*deinit)(void*); 84 | void* portinfo; 85 | uint8_t received; 86 | }; 87 | 88 | 89 | struct i2c_device { 90 | int (*init)(void*); 91 | int (*master_enable)(void*, uint32_t); 92 | int (*slave_enable)(void*, uint8_t); 93 | void (*disable)(void*); 94 | int (*master_start)(void*, uint8_t, int); 95 | int (*master_read)(void*, size_t); 96 | int (*master_write)(void*); 97 | void (*master_stop)(void*); 98 | int (*slave_write)(void*); 99 | int (*rx_available)(void*); 100 | void (*rx_clear)(void*); 101 | int (*rx_read)(void*); 102 | int (*rx_peek)(void*); 103 | int (*tx_available)(void*); 104 | void (*tx_clear)(void*); 105 | int (*tx_put)(void*, uint8_t); 106 | int (*tx_full)(void*); 107 | int (*request_received)(void*); 108 | int (*data_received)(void*); 109 | void* devinfo; 110 | }; 111 | 112 | struct spi_device { 113 | int (*init)(void*); 114 | int (*configure)(void*, bool, bool, bool, uint32_t); 115 | int (*start)(void*); 116 | void (*stop)(void*); 117 | uint8_t (*transfer)(void*, uint8_t); 118 | int (*mask_interrupt_on_transaction)(void*, int); 119 | int (*deinit)(void*); 120 | void* devinfo; 121 | }; 122 | 123 | #ifdef __cplusplus 124 | } // extern "C" 125 | #endif 126 | -------------------------------------------------------------------------------- /cores/intiki/wiring_shift.c: -------------------------------------------------------------------------------- 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 | #include 20 | #include "wiring_shift.h" 21 | #include "wiring_digital.h" 22 | #include "wiring_private.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C"{ 26 | #endif 27 | 28 | uint32_t shiftIn( uint32_t ulDataPin, uint32_t ulClockPin, uint32_t ulBitOrder ) 29 | { 30 | uint8_t value = 0 ; 31 | uint8_t i ; 32 | 33 | for ( i=0 ; i < 8 ; ++i ) 34 | { 35 | digitalWrite( ulClockPin, HIGH ) ; 36 | 37 | if ( ulBitOrder == LSBFIRST ) 38 | { 39 | value |= digitalRead( ulDataPin ) << i ; 40 | } 41 | else 42 | { 43 | value |= digitalRead( ulDataPin ) << (7 - i) ; 44 | } 45 | 46 | digitalWrite( ulClockPin, LOW ) ; 47 | } 48 | 49 | return value ; 50 | } 51 | 52 | void shiftOut( uint32_t ulDataPin, uint32_t ulClockPin, uint32_t ulBitOrder, uint32_t ulVal ) 53 | { 54 | uint8_t i ; 55 | 56 | for ( i=0 ; i < 8 ; i++ ) 57 | { 58 | if ( ulBitOrder == LSBFIRST ) 59 | { 60 | digitalWrite( ulDataPin, !!(ulVal & (1 << i)) ) ; 61 | } 62 | else 63 | { 64 | digitalWrite( ulDataPin, !!(ulVal & (1 << (7 - i))) ) ; 65 | } 66 | 67 | digitalWrite( ulClockPin, HIGH ) ; 68 | digitalWrite( ulClockPin, LOW ) ; 69 | } 70 | } 71 | 72 | #ifdef __cplusplus 73 | } // extern "C" 74 | #endif 75 | -------------------------------------------------------------------------------- /cores/intiki/wiring_shift.h: -------------------------------------------------------------------------------- 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_SHIFT_ 20 | #define _WIRING_SHIFT_ 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /* 27 | * \brief 28 | */ 29 | extern uint32_t shiftIn( uint32_t ulDataPin, uint32_t ulClockPin, uint32_t ulBitOrder ) ; 30 | 31 | 32 | /* 33 | * \brief 34 | */ 35 | extern void shiftOut( uint32_t ulDataPin, uint32_t ulClockPin, uint32_t ulBitOrder, uint32_t ulVal ) ; 36 | 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif /* _WIRING_SHIFT_ */ 43 | -------------------------------------------------------------------------------- /dist/ci_ba2toolchainversion.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | 3 | require 'json' 4 | require 'optparse' 5 | 6 | open(ARGV[0]) do |f| 7 | js = JSON.load(f) 8 | ver = js['toolsDependencies'].select {|t| t['name'] == 'BA2-toolchain'}[0]['version'] 9 | print ver 10 | end 11 | -------------------------------------------------------------------------------- /dist/ci_intikiversion.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | 3 | require 'json' 4 | require 'optparse' 5 | 6 | open(ARGV[0]) do |f| 7 | js = JSON.load(f) 8 | ver = js['toolsDependencies'].select {|t| t['name'] == 'intiki'}[0]['version'] 9 | print ver 10 | end 11 | -------------------------------------------------------------------------------- /dist/ci_submodules.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | 3 | require 'json' 4 | require 'optparse' 5 | require 'rugged' 6 | require 'pp' 7 | 8 | comparefile = nil 9 | outfile = nil 10 | 11 | opt = OptionParser.new 12 | opt.on('-c FILE', '--compare=FILE') {|o| comparefile = o } 13 | opt.on('-o FILE', '--output=FILE') {|o| outfile = o } 14 | opt.parse!(ARGV) 15 | 16 | repo = Rugged::Repository.new('.') 17 | 18 | def submodules_paths_recursive(repo, coll=nil, path="") 19 | coll = [] if coll == nil 20 | repo.submodules.each do |sm| 21 | coll.push( 22 | { 23 | :path=>path+sm.path, 24 | :url=>sm.repository.remotes['origin'].url, 25 | :hash=>sm.head_oid 26 | } 27 | ) 28 | submodules_paths_recursive(sm.repository, coll, sm.path + '/') 29 | end 30 | coll 31 | end 32 | 33 | submods = submodules_paths_recursive(repo) 34 | 35 | modlines = submods.collect do |sub| 36 | "{ \"path\":\"" + sub[:path] + "\", \"url\":\"" + sub[:url] + "\", \"revision\":\"" + sub[:hash] + "\" }" 37 | end 38 | 39 | jsonstr = "[" + modlines.join(",") + "]" 40 | 41 | jsobj = JSON.parse(jsonstr) 42 | 43 | if comparefile != nil 44 | compare = open(comparefile) {|f| JSON.load(f) } 45 | if (jsobj == compare) 46 | STDERR.puts('identical') 47 | exit 0 48 | else 49 | STDERR.puts('differ') 50 | STDERR.puts("==============================\n") 51 | STDERR.puts(jsobj) 52 | STDERR.puts("==============================\n") 53 | STDERR.puts(compare) 54 | STDERR.puts("==============================\n") 55 | exit -1 56 | end 57 | end 58 | 59 | if outfile != nil 60 | open(outfile, 'w') do |f| 61 | f.write(JSON.pretty_unparse(jsobj) ) 62 | end 63 | exit 0 64 | end 65 | 66 | print JSON.pretty_unparse(jsobj) 67 | -------------------------------------------------------------------------------- /dist/ci_toolurl.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | 3 | require 'json' 4 | require 'optparse' 5 | 6 | version = 'XXXXX' 7 | name = 'xxx' 8 | 9 | opt = OptionParser.new 10 | opt.on('-v SET_VERSION', '--version=SET_VERSION') {|o| version = o } 11 | opt.on('-n TOOL_NAME', '--name=TOOL_NAME') {|o| name= o } 12 | argv = opt.parse(ARGV) 13 | 14 | open(argv[0]) do |f| 15 | js = JSON.load(f) 16 | es = js.select{|e| e["name"] == name } 17 | e= es[0] 18 | url = e['systems'][0]['url'] 19 | print url.gsub("${NAME}", e["name"]).gsub("${VERSION}", version).gsub("${ARCH}", "x86_64-pc-linux-gnu") 20 | end 21 | 22 | -------------------------------------------------------------------------------- /dist/platform_template.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "JN516x Boards", 3 | "architecture": "jn516x", 4 | "category": "Contributed", 5 | "version": "XXXXXXXXXXXXXX", 6 | "url": "XXXXXXXXXXXXXXXXXX", 7 | "archiveFileName": "XXXXXX", 8 | "checksum": "XXXXXXXXXXXXX", 9 | "size": "XXXXXXXXXXXXXXXXX", 10 | "boards": [ 11 | { 12 | "name": "Generic JN516x board" 13 | }, 14 | { 15 | "name": "TOCOS TWE Lite" 16 | }, 17 | { 18 | "name": "SeeedStudio Mesh Bee" 19 | } 20 | ], 21 | "toolsDependencies": [ 22 | { 23 | "packager": "intiki", 24 | "name": "intiki", 25 | "version": "1.0.0" 26 | }, 27 | { 28 | "packager": "intiki", 29 | "name": "msys2-contiki-build", 30 | "version": "0.0.1" 31 | }, 32 | { 33 | "packager": "intiki", 34 | "name": "BA2-toolchain", 35 | "version": "4.7.4-r36379" 36 | }, 37 | { 38 | "packager": "intiki", 39 | "name": "jenprog", 40 | "version": "1.1.20180614" 41 | } 42 | ] 43 | } 44 | -------------------------------------------------------------------------------- /dist/setup_env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | GHREPO="https://github.com/${TRAVIS_REPO_SLUG}" 4 | GHREPO_USER=$(dirname ${TRAVIS_REPO_SLUG}) 5 | GHREPO_NAME=$(basename ${TRAVIS_REPO_SLUG}) 6 | if [ "${TRAVIS_TAG}" == "" ] ; then 7 | PKGJSON=package_${GHREPO_USER}_${GHREPO_NAME}-${TRAVIS_BRANCH}_index.json 8 | ARCHIVENAME=${TRAVIS_COMMIT} 9 | ARCHIVEURL="https://github.com/${TRAVIS_REPO_SLUG}/archive/${ARCHIVENAME}.tar.gz" 10 | RELEASEVER=${TRAVIS_BRANCH}-0.0.$(date -d @`git log -1 ${TRAVIS_COMMIT} --pretty=medium --format=%ct` +%y%m%d%H%M) 11 | BM_FORCEOPT='-f' 12 | else 13 | RELEASELINE=${GHREPO_NAME} 14 | RELEASELINE_=$(echo ${TRAVIS_TAG} | sed 's/-.*$//') 15 | if [[ $TRAVIS_TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] ; then 16 | RELEASELINE="intiki" 17 | elif [ "${RELEASELINE_}" != "${TRAVIS_TAG}" ] ; then 18 | RELEASELINE=${RELEASELINE_} 19 | fi 20 | 21 | PKGJSON=package_${GHREPO_USER}_${RELEASELINE}_index.json 22 | ARCHIVENAME=${GHREPO_NAME}-${TRAVIS_TAG} 23 | ARCHIVEURL="https://github.com/${TRAVIS_REPO_SLUG}/releases/download/${TRAVIS_TAG}/${ARCHIVENAME}.tar.bz2" 24 | RELEASEVER=$(echo ${TRAVIS_TAG} | rev | sed 's/^\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' | rev ) 25 | BM_FORCEOPT= 26 | fi 27 | 28 | echo GHREPO=${GHREPO} 29 | echo ARCHIVENAME=${ARCHIVENAME} 30 | echo ARCHIVEURL=${ARCHIVEURL} 31 | echo PKGJSON=${PKGJSON} 32 | echo RELEASEVER=${RELEASEVER} 33 | 34 | -------------------------------------------------------------------------------- /dist/setup_tools.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | BA2TOOLCHAIN_VERSION=$(ruby dist/ci_ba2toolchainversion.rb dist/platform_template.json) 3 | echo ${BA2TOOLCHAIN_VERSION} 4 | curl -l -L $(ruby dist/ci_toolurl.rb dist/tool_template.json -n BA2-toolchain -v ${BA2TOOLCHAIN_VERSION}) | tar xfj - -C ~ 5 | echo intiki.BA2-toolchain=${BA2TOOLCHAIN_VERSION} >> ~/BA2-toolchain/builtin_tools_versions.txt 6 | 7 | INTIKI_VERSION=$(ruby dist/ci_intikiversion.rb dist/platform_template.json) 8 | echo ${INTIKI_VERSION} 9 | curl -l -L $(ruby dist/ci_toolurl.rb dist/tool_template.json -n intiki -v ${INTIKI_VERSION}) | tar xfj - -C ~ 10 | echo intiki.intiki=${INTIKI_VERSION} >> ~/intiki/builtin_tools_versions.txt 11 | mkdir -p ~/packages/intiki/hardware/intiki/ 12 | ln -s $PWD ~/packages/intiki/hardware/intiki/`basename $PWD` 13 | 14 | (cd ~; curl -l -L https://mono-wireless.com/download/SDK/MWSDK_201805/MWSDK_Linux-i386_201805.tgz | tar xvfz -) 15 | 16 | -------------------------------------------------------------------------------- /dist/submodules.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "path": "system/contiki", 4 | "url": "https://github.com/soburi/contiki", 5 | "revision": "b89fd608d843284a697004fe436f00cfeae10c0b" 6 | }, 7 | { 8 | "path": "system/contiki/cpu/cc26xx-cc13xx/lib/cc13xxware", 9 | "url": "https://github.com/contiki-os/cc13xxware.git", 10 | "revision": "0f44f949b4a7862ae3273739279df6297a4a4e45" 11 | }, 12 | { 13 | "path": "system/contiki/cpu/cc26xx-cc13xx/lib/cc26xxware", 14 | "url": "https://github.com/contiki-os/cc26xxware.git", 15 | "revision": "e816e3508b87744186acae2c5f792ad378836ae3" 16 | }, 17 | { 18 | "path": "system/contiki/platform/stm32nucleo-spirit1/stm32cube-lib", 19 | "url": "https://github.com/STclab/stm32nucleo-spirit1-lib", 20 | "revision": "34e784ff39a5dc4da288ce696235f41b1db4bf5c" 21 | }, 22 | { 23 | "path": "system/contiki/tools/cc2538-bsl", 24 | "url": "https://github.com/JelmerT/cc2538-bsl.git", 25 | "revision": "c6100a7794c7b530923145c03e37412013a4551e" 26 | }, 27 | { 28 | "path": "system/contiki/tools/mspsim", 29 | "url": "https://github.com/contiki-os/mspsim.git", 30 | "revision": "47ae45cb0f36337115e32adb2a5ba0bf6e1e4437" 31 | }, 32 | { 33 | "path": "system/contiki/tools/sensniff", 34 | "url": "https://github.com/g-oikonomou/sensniff.git", 35 | "revision": "0d57c1129b601d29a58bffe6e34803af5e1701af" 36 | } 37 | ] -------------------------------------------------------------------------------- /dist/tool_template.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "msys2-contiki-build", 4 | "version": "XXXXX", 5 | "systems": [ 6 | { 7 | "url": "https://github.com/soburi/${NAME}/releases/download/${VERSION}/${NAME}_${ARCH}_${VERSION}.tar.bz2", 8 | "host": "XXXXXXXXXXXXXXXX", 9 | "archiveFileName": "XXXXX", 10 | "checksum": "XXXXXXXXXXXX", 11 | "size": "XXXXXXXXXXXXXXXX" 12 | } 13 | ] 14 | }, 15 | { 16 | "name": "intiki", 17 | "version": "XXXXX", 18 | "systems": [ 19 | { 20 | "url": "https://github.com/soburi/${NAME}/releases/download/${VERSION}/${NAME}_${ARCH}_${VERSION}.tar.bz2", 21 | "host": "XXXXXXXXXXXXXXXX", 22 | "archiveFileName": "XXXXX", 23 | "checksum": "XXXXXXXXXXXX", 24 | "size": "XXXXXXXXXXXXXXXX" 25 | } 26 | ] 27 | }, 28 | { 29 | "name": "BA2-toolchain", 30 | "version": "XXXXX", 31 | "systems": [ 32 | { 33 | "url": "https://github.com/soburi/${NAME}/releases/download/${VERSION}/${NAME}_${ARCH}_${VERSION}.tar.bz2", 34 | "host": "XXXXXXXXXXXXXXXX", 35 | "archiveFileName": "XXXXX", 36 | "checksum": "XXXXXXXXXXXX", 37 | "size": "XXXXXXXXXXXXXXXX" 38 | } 39 | ] 40 | }, 41 | { 42 | "name": "jenprog", 43 | "version": "XXXXX", 44 | "systems": [ 45 | { 46 | "url": "https://github.com/soburi/${NAME}/releases/download/${VERSION}/${NAME}_${ARCH}_${VERSION}.tar.bz2", 47 | "host": "XXXXXXXXXXXXXXXX", 48 | "archiveFileName": "XXXXX", 49 | "checksum": "XXXXXXXXXXXX", 50 | "size": "XXXXXXXXXXXXXXXX" 51 | } 52 | ] 53 | } 54 | ] 55 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | INPUT_PULLDOWN LITERAL1 Constants RESERVED_WORD_2 2 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * EEPROM Clear 3 | * 4 | * Sets all of the bytes of the EEPROM to 0. 5 | * Please see eeprom_iteration for a more in depth 6 | * look at how to traverse the EEPROM. 7 | * 8 | * This example code is in the public domain. 9 | */ 10 | 11 | #include 12 | 13 | void setup() { 14 | // initialize the LED pin as an output. 15 | pinMode(13, OUTPUT); 16 | 17 | /*** 18 | Iterate through each byte of the EEPROM storage. 19 | 20 | Larger AVR processors have larger EEPROM sizes, E.g: 21 | - Arduno Duemilanove: 512b EEPROM storage. 22 | - Arduino Uno: 1kb EEPROM storage. 23 | - Arduino Mega: 4kb EEPROM storage. 24 | 25 | Rather than hard-coding the length, you should use the pre-provided length function. 26 | This will make your code portable to all AVR processors. 27 | ***/ 28 | 29 | for (int i = 0 ; i < EEPROM.length() ; i++) { 30 | EEPROM.write(i, 0); 31 | } 32 | 33 | // turn the LED on when we're done 34 | digitalWrite(13, HIGH); 35 | } 36 | 37 | void loop() { 38 | /** Empty loop. **/ 39 | } 40 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino: -------------------------------------------------------------------------------- 1 | /*** 2 | Written by Christopher Andrews. 3 | CRC algorithm generated by pycrc, MIT licence ( https://github.com/tpircher/pycrc ). 4 | 5 | A CRC is a simple way of checking whether data has changed or become corrupted. 6 | This example calculates a CRC value directly on the EEPROM values. 7 | The purpose of this example is to highlight how the EEPROM object can be used just like an array. 8 | ***/ 9 | 10 | #include 11 | #include 12 | 13 | void setup() { 14 | 15 | //Start serial 16 | Serial.begin(9600); 17 | while (!Serial) { 18 | ; // wait for serial port to connect. Needed for native USB port only 19 | } 20 | 21 | //Print length of data to run CRC on. 22 | Serial.print("EEPROM length: "); 23 | Serial.println(EEPROM.length()); 24 | 25 | //Print the result of calling eeprom_crc() 26 | Serial.print("CRC32 of EEPROM data: 0x"); 27 | Serial.println(eeprom_crc(), HEX); 28 | Serial.print("\n\nDone!"); 29 | } 30 | 31 | void loop() { 32 | /* Empty loop */ 33 | } 34 | 35 | unsigned long eeprom_crc(void) { 36 | 37 | const unsigned long crc_table[16] = { 38 | 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 39 | 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, 40 | 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 41 | 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c 42 | }; 43 | 44 | unsigned long crc = ~0L; 45 | 46 | for (int index = 0 ; index < EEPROM.length() ; ++index) { 47 | crc = crc_table[(crc ^ EEPROM[index]) & 0x0f] ^ (crc >> 4); 48 | crc = crc_table[(crc ^ (EEPROM[index] >> 4)) & 0x0f] ^ (crc >> 4); 49 | crc = ~crc; 50 | } 51 | return crc; 52 | } 53 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_get/eeprom_get.ino: -------------------------------------------------------------------------------- 1 | /*** 2 | eeprom_get example. 3 | 4 | This shows how to use the EEPROM.get() method. 5 | 6 | To pre-set the EEPROM data, run the example sketch eeprom_put. 7 | This sketch will run without it, however, the values shown 8 | will be shown from what ever is already on the EEPROM. 9 | 10 | This may cause the serial object to print out a large string 11 | of garbage if there is no null character inside one of the strings 12 | loaded. 13 | 14 | Written by Christopher Andrews 2015 15 | Released under MIT licence. 16 | ***/ 17 | 18 | #include 19 | 20 | void setup() { 21 | 22 | float f = 0.00f; //Variable to store data read from EEPROM. 23 | int eeAddress = 0; //EEPROM address to start reading from 24 | 25 | Serial.begin(9600); 26 | while (!Serial) { 27 | ; // wait for serial port to connect. Needed for native USB port only 28 | } 29 | Serial.print("Read float from EEPROM: "); 30 | 31 | //Get the float data from the EEPROM at position 'eeAddress' 32 | EEPROM.get(eeAddress, f); 33 | Serial.println(f, 3); //This may print 'ovf, nan' if the data inside the EEPROM is not a valid float. 34 | 35 | /*** 36 | As get also returns a reference to 'f', you can use it inline. 37 | E.g: Serial.print( EEPROM.get( eeAddress, f ) ); 38 | ***/ 39 | 40 | /*** 41 | Get can be used with custom structures too. 42 | I have separated this into an extra function. 43 | ***/ 44 | 45 | secondTest(); //Run the next test. 46 | } 47 | 48 | struct MyObject { 49 | float field1; 50 | byte field2; 51 | char name[10]; 52 | }; 53 | 54 | void secondTest() { 55 | int eeAddress = sizeof(float); //Move address to the next byte after float 'f'. 56 | 57 | MyObject customVar; //Variable to store custom object read from EEPROM. 58 | EEPROM.get(eeAddress, customVar); 59 | 60 | Serial.println("Read custom object from EEPROM: "); 61 | Serial.println(customVar.field1); 62 | Serial.println(customVar.field2); 63 | Serial.println(customVar.name); 64 | } 65 | 66 | void loop() { 67 | /* Empty loop */ 68 | } 69 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino: -------------------------------------------------------------------------------- 1 | /*** 2 | eeprom_iteration example. 3 | 4 | A set of example snippets highlighting the 5 | simplest methods for traversing the EEPROM. 6 | 7 | Running this sketch is not necessary, this is 8 | simply highlighting certain programming methods. 9 | 10 | Written by Christopher Andrews 2015 11 | Released under MIT licence. 12 | ***/ 13 | 14 | #include 15 | 16 | void setup() { 17 | 18 | /*** 19 | Iterate the EEPROM using a for loop. 20 | ***/ 21 | 22 | for (int index = 0 ; index < EEPROM.length() ; index++) { 23 | 24 | //Add one to each cell in the EEPROM 25 | EEPROM[ index ] += 1; 26 | } 27 | 28 | /*** 29 | Iterate the EEPROM using a while loop. 30 | ***/ 31 | 32 | int index = 0; 33 | 34 | while (index < EEPROM.length()) { 35 | 36 | //Add one to each cell in the EEPROM 37 | EEPROM[ index ] += 1; 38 | index++; 39 | } 40 | 41 | /*** 42 | Iterate the EEPROM using a do-while loop. 43 | ***/ 44 | 45 | int idx = 0; //Used 'idx' to avoid name conflict with 'index' above. 46 | 47 | do { 48 | 49 | //Add one to each cell in the EEPROM 50 | EEPROM[ idx ] += 1; 51 | idx++; 52 | } while (idx < EEPROM.length()); 53 | 54 | 55 | } //End of setup function. 56 | 57 | void loop() {} -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_put/eeprom_put.ino: -------------------------------------------------------------------------------- 1 | /*** 2 | eeprom_put example. 3 | 4 | This shows how to use the EEPROM.put() method. 5 | Also, this sketch will pre-set the EEPROM data for the 6 | example sketch eeprom_get. 7 | 8 | Note, unlike the single byte version EEPROM.write(), 9 | the put method will use update semantics. As in a byte 10 | will only be written to the EEPROM if the data is actually 11 | different. 12 | 13 | Written by Christopher Andrews 2015 14 | Released under MIT licence. 15 | ***/ 16 | 17 | #include 18 | 19 | struct MyObject { 20 | float field1; 21 | byte field2; 22 | char name[10]; 23 | }; 24 | 25 | void setup() { 26 | 27 | Serial.begin(9600); 28 | while (!Serial) { 29 | ; // wait for serial port to connect. Needed for native USB port only 30 | } 31 | 32 | float f = 123.456f; //Variable to store in EEPROM. 33 | int eeAddress = 0; //Location we want the data to be put. 34 | 35 | 36 | //One simple call, with the address first and the object second. 37 | EEPROM.put(eeAddress, f); 38 | 39 | Serial.println("Written float data type!"); 40 | 41 | /** Put is designed for use with custom structures also. **/ 42 | 43 | //Data to store. 44 | MyObject customVar = { 45 | 3.14f, 46 | 65, 47 | "Working!" 48 | }; 49 | 50 | eeAddress += sizeof(float); //Move address to the next byte after float 'f'. 51 | 52 | EEPROM.put(eeAddress, customVar); 53 | Serial.print("Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!"); 54 | } 55 | 56 | void loop() { 57 | /* Empty loop */ 58 | } 59 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_read/eeprom_read.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * EEPROM Read 3 | * 4 | * Reads the value of each byte of the EEPROM and prints it 5 | * to the computer. 6 | * This example code is in the public domain. 7 | */ 8 | 9 | #include 10 | 11 | // start reading from the first byte (address 0) of the EEPROM 12 | int address = 0; 13 | byte value; 14 | 15 | void setup() { 16 | // initialize serial and wait for port to open: 17 | Serial.begin(9600); 18 | while (!Serial) { 19 | ; // wait for serial port to connect. Needed for native USB port only 20 | } 21 | } 22 | 23 | void loop() { 24 | // read a byte from the current address of the EEPROM 25 | value = EEPROM.read(address); 26 | 27 | Serial.print(address); 28 | Serial.print("\t"); 29 | Serial.print(value, DEC); 30 | Serial.println(); 31 | 32 | /*** 33 | Advance to the next address, when at the end restart at the beginning. 34 | 35 | Larger AVR processors have larger EEPROM sizes, E.g: 36 | - Arduno Duemilanove: 512b EEPROM storage. 37 | - Arduino Uno: 1kb EEPROM storage. 38 | - Arduino Mega: 4kb EEPROM storage. 39 | 40 | Rather than hard-coding the length, you should use the pre-provided length function. 41 | This will make your code portable to all AVR processors. 42 | ***/ 43 | address = address + 1; 44 | if (address == EEPROM.length()) { 45 | address = 0; 46 | } 47 | 48 | /*** 49 | As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an 50 | EEPROM address is also doable by a bitwise and of the length - 1. 51 | 52 | ++address &= EEPROM.length() - 1; 53 | ***/ 54 | 55 | delay(500); 56 | } 57 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_update/eeprom_update.ino: -------------------------------------------------------------------------------- 1 | /*** 2 | EEPROM Update method 3 | 4 | Stores values read from analog input 0 into the EEPROM. 5 | These values will stay in the EEPROM when the board is 6 | turned off and may be retrieved later by another sketch. 7 | 8 | If a value has not changed in the EEPROM, it is not overwritten 9 | which would reduce the life span of the EEPROM unnecessarily. 10 | 11 | Released using MIT licence. 12 | ***/ 13 | 14 | #include 15 | 16 | /** the current address in the EEPROM (i.e. which byte we're going to write to next) **/ 17 | int address = 0; 18 | 19 | void setup() { 20 | /** EMpty setup **/ 21 | } 22 | 23 | void loop() { 24 | /*** 25 | need to divide by 4 because analog inputs range from 26 | 0 to 1023 and each byte of the EEPROM can only hold a 27 | value from 0 to 255. 28 | ***/ 29 | int val = analogRead(0) / 4; 30 | 31 | /*** 32 | Update the particular EEPROM cell. 33 | these values will remain there when the board is 34 | turned off. 35 | ***/ 36 | EEPROM.update(address, val); 37 | 38 | /*** 39 | The function EEPROM.update(address, val) is equivalent to the following: 40 | 41 | if( EEPROM.read(address) != val ){ 42 | EEPROM.write(address, val); 43 | } 44 | ***/ 45 | 46 | 47 | /*** 48 | Advance to the next address, when at the end restart at the beginning. 49 | 50 | Larger AVR processors have larger EEPROM sizes, E.g: 51 | - Arduno Duemilanove: 512b EEPROM storage. 52 | - Arduino Uno: 1kb EEPROM storage. 53 | - Arduino Mega: 4kb EEPROM storage. 54 | 55 | Rather than hard-coding the length, you should use the pre-provided length function. 56 | This will make your code portable to all AVR processors. 57 | ***/ 58 | address = address + 1; 59 | if (address == EEPROM.length()) { 60 | address = 0; 61 | } 62 | 63 | /*** 64 | As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an 65 | EEPROM address is also doable by a bitwise and of the length - 1. 66 | 67 | ++address &= EEPROM.length() - 1; 68 | ***/ 69 | 70 | delay(100); 71 | } 72 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_write/eeprom_write.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * EEPROM Write 3 | * 4 | * Stores values read from analog input 0 into the EEPROM. 5 | * These values will stay in the EEPROM when the board is 6 | * turned off and may be retrieved later by another sketch. 7 | */ 8 | 9 | #include 10 | 11 | /** the current address in the EEPROM (i.e. which byte we're going to write to next) **/ 12 | int addr = 0; 13 | 14 | void setup() { 15 | /** Empty setup. **/ 16 | } 17 | 18 | void loop() { 19 | /*** 20 | Need to divide by 4 because analog inputs range from 21 | 0 to 1023 and each byte of the EEPROM can only hold a 22 | value from 0 to 255. 23 | ***/ 24 | 25 | int val = analogRead(0) / 4; 26 | 27 | /*** 28 | Write the value to the appropriate byte of the EEPROM. 29 | these values will remain there when the board is 30 | turned off. 31 | ***/ 32 | 33 | EEPROM.write(addr, val); 34 | 35 | /*** 36 | Advance to the next address, when at the end restart at the beginning. 37 | 38 | Larger AVR processors have larger EEPROM sizes, E.g: 39 | - Arduno Duemilanove: 512b EEPROM storage. 40 | - Arduino Uno: 1kb EEPROM storage. 41 | - Arduino Mega: 4kb EEPROM storage. 42 | 43 | Rather than hard-coding the length, you should use the pre-provided length function. 44 | This will make your code portable to all AVR processors. 45 | ***/ 46 | addr = addr + 1; 47 | if (addr == EEPROM.length()) { 48 | addr = 0; 49 | } 50 | 51 | /*** 52 | As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an 53 | EEPROM address is also doable by a bitwise and of the length - 1. 54 | 55 | ++addr &= EEPROM.length() - 1; 56 | ***/ 57 | 58 | 59 | delay(100); 60 | } 61 | -------------------------------------------------------------------------------- /libraries/EEPROM/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For EEPROM 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | EEPROM KEYWORD1 10 | EERef KEYWORD1 11 | EEPtr KEYWORD2 12 | 13 | ####################################### 14 | # Methods and Functions (KEYWORD2) 15 | ####################################### 16 | 17 | update KEYWORD2 18 | 19 | ####################################### 20 | # Constants (LITERAL1) 21 | ####################################### 22 | 23 | -------------------------------------------------------------------------------- /libraries/EEPROM/library.properties: -------------------------------------------------------------------------------- 1 | name=EEPROM 2 | version=2.0 3 | author=Arduino, Christopher Andrews 4 | maintainer=Arduino 5 | sentence=Enables reading and writing to the permanent board storage. 6 | paragraph=This library allows to read and write data in a memory type, the EEPROM, that keeps its content also when the board is powered off. The amount of EEPROM available depends on the microcontroller type. 7 | category=Data Storage 8 | url=http://www.arduino.cc/en/Reference/EEPROM 9 | architectures=intiki 10 | 11 | -------------------------------------------------------------------------------- /libraries/SPI/SPI.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPI Master library for Arduino Zero. 3 | * Copyright (c) 2015 Arduino LLC 4 | * Copyright (c) 2015-2018 Tokita, Hiroshi 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef _SPI_H_INCLUDED 22 | #define _SPI_H_INCLUDED 23 | 24 | #include "variant.h" 25 | #include 26 | 27 | #include "wiring_private.h" 28 | 29 | // SPI_HAS_TRANSACTION means SPI has 30 | // - beginTransaction() 31 | // - endTransaction() 32 | // - usingInterrupt() 33 | // - SPISetting(clock, bitOrder, dataMode) 34 | #define SPI_HAS_TRANSACTION 1 35 | 36 | #define SPI_MODE0 0x02 37 | #define SPI_MODE1 0x00 38 | #define SPI_MODE2 0x03 39 | #define SPI_MODE3 0x01 40 | 41 | #if defined(__SAMD21G18A__) 42 | // Even if not specified on the datasheet, the SAMD21G18A MCU 43 | // doesn't operate correctly with clock dividers lower than 4. 44 | // This allows a theoretical maximum SPI clock speed of 12Mhz 45 | #define SPI_MIN_CLOCK_DIVIDER 4 46 | // Other SAMD21xxxxx MCU may be affected as well 47 | #else 48 | #define SPI_MIN_CLOCK_DIVIDER 2 49 | #endif 50 | 51 | enum SPITransferMode { 52 | SPI_CONTINUE, 53 | SPI_LAST 54 | }; 55 | 56 | class SPISettings { 57 | public: 58 | SPISettings(uint32_t clock, BitOrder bitOrder, uint8_t dataMode) { 59 | if (__builtin_constant_p(clock)) { 60 | init_AlwaysInline(clock, bitOrder, dataMode); 61 | } else { 62 | init_MightInline(clock, bitOrder, dataMode); 63 | } 64 | } 65 | 66 | // Default speed set to 4MHz, SPI mode set to MODE 0 and Bit order set to MSB first. 67 | SPISettings() { init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0); } 68 | 69 | private: 70 | void init_MightInline(uint32_t clock, BitOrder bitOrder, uint8_t dataMode) { 71 | init_AlwaysInline(clock, bitOrder, dataMode); 72 | } 73 | 74 | void init_AlwaysInline(uint32_t clock, BitOrder bitOrder, uint8_t dataMode) __attribute__((__always_inline__)) { 75 | this->clock = clock; 76 | this->bitOrder = bitOrder; 77 | this->dataMode = dataMode; 78 | } 79 | 80 | uint32_t clock; 81 | uint8_t dataMode; 82 | BitOrder bitOrder; 83 | 84 | friend class SPIClass; 85 | }; 86 | 87 | class SPIClass { 88 | public: 89 | SPIClass(struct spi_device* _spi); 90 | 91 | 92 | byte transfer(uint8_t data); 93 | uint16_t transfer16(uint16_t data); 94 | void transfer(void *buf, size_t count); 95 | 96 | // Transaction Functions 97 | void usingInterrupt(int interruptNumber); 98 | void beginTransaction(SPISettings settings); 99 | void endTransaction(void); 100 | 101 | // SPI Configuration methods 102 | void attachInterrupt(); 103 | void detachInterrupt(); 104 | 105 | void begin(); 106 | void end(); 107 | 108 | void setBitOrder(BitOrder order); 109 | void setDataMode(uint8_t uc_mode); 110 | void setClockDivider(uint8_t uc_div); 111 | 112 | protected: 113 | void init(); 114 | void config(SPISettings settings); 115 | 116 | struct spi_device* spi; 117 | uint32_t divider; 118 | BitOrder bitOrder; 119 | uint32_t dataMode; 120 | 121 | bool initialized; 122 | }; 123 | 124 | #if SPI_INTERFACES_COUNT > 0 125 | extern SPIClass SPI; 126 | #endif 127 | #if SPI_INTERFACES_COUNT > 1 128 | extern SPIClass SPI1; 129 | #endif 130 | #if SPI_INTERFACES_COUNT > 2 131 | extern SPIClass SPI2; 132 | #endif 133 | #if SPI_INTERFACES_COUNT > 3 134 | extern SPIClass SPI3; 135 | #endif 136 | #if SPI_INTERFACES_COUNT > 4 137 | extern SPIClass SPI4; 138 | #endif 139 | #if SPI_INTERFACES_COUNT > 5 140 | extern SPIClass SPI5; 141 | #endif 142 | 143 | // For compatibility with sketches designed for AVR @ 16 MHz 144 | // New programs should use SPI.beginTransaction to set the SPI clock 145 | #define SPI_CLOCK_DIV2 2 146 | #define SPI_CLOCK_DIV4 4 147 | #define SPI_CLOCK_DIV8 8 148 | #define SPI_CLOCK_DIV16 16 149 | #define SPI_CLOCK_DIV32 32 150 | #define SPI_CLOCK_DIV64 64 151 | #define SPI_CLOCK_DIV128 64 152 | 153 | #endif 154 | -------------------------------------------------------------------------------- /libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Digital Pot Control 3 | 4 | This example controls an Analog Devices AD5206 digital potentiometer. 5 | The AD5206 has 6 potentiometer channels. Each channel's pins are labeled 6 | A - connect this to voltage 7 | W - this is the pot's wiper, which changes when you set it 8 | B - connect this to ground. 9 | 10 | The AD5206 is SPI-compatible,and to command it, you send two bytes, 11 | one with the channel number (0 - 5) and one with the resistance value for the 12 | channel (0 - 255). 13 | 14 | The circuit: 15 | * All A pins of AD5206 connected to +5V 16 | * All B pins of AD5206 connected to ground 17 | * An LED and a 220-ohm resisor in series connected from each W pin to ground 18 | * CS - to digital pin 10 (SS pin) 19 | * SDI - to digital pin 11 (MOSI pin) 20 | * CLK - to digital pin 13 (SCK pin) 21 | 22 | created 10 Aug 2010 23 | by Tom Igoe 24 | 25 | Thanks to Heather Dewey-Hagborg for the original tutorial, 2005 26 | 27 | */ 28 | 29 | 30 | // inslude the SPI library: 31 | #include 32 | 33 | 34 | // set pin 10 as the slave select for the digital pot: 35 | const int slaveSelectPin = 10; 36 | 37 | void setup() { 38 | // set the slaveSelectPin as an output: 39 | pinMode(slaveSelectPin, OUTPUT); 40 | // initialize SPI: 41 | SPI.begin(); 42 | } 43 | 44 | void loop() { 45 | // go through the six channels of the digital pot: 46 | for (int channel = 0; channel < 6; channel++) { 47 | // change the resistance on this channel from min to max: 48 | for (int level = 0; level < 255; level++) { 49 | digitalPotWrite(channel, level); 50 | delay(10); 51 | } 52 | // wait a second at the top: 53 | delay(100); 54 | // change the resistance on this channel from max to min: 55 | for (int level = 0; level < 255; level++) { 56 | digitalPotWrite(channel, 255 - level); 57 | delay(10); 58 | } 59 | } 60 | 61 | } 62 | 63 | void digitalPotWrite(int address, int value) { 64 | // take the SS pin low to select the chip: 65 | digitalWrite(slaveSelectPin, LOW); 66 | // send in the address and value via SPI: 67 | SPI.transfer(address); 68 | SPI.transfer(value); 69 | // take the SS pin high to de-select the chip: 70 | digitalWrite(slaveSelectPin, HIGH); 71 | } 72 | -------------------------------------------------------------------------------- /libraries/SPI/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map SPI 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | SPI KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | begin KEYWORD2 15 | end KEYWORD2 16 | transfer KEYWORD2 17 | #setBitOrder KEYWORD2 18 | setDataMode KEYWORD2 19 | setClockDivider KEYWORD2 20 | 21 | 22 | ####################################### 23 | # Constants (LITERAL1) 24 | ####################################### 25 | SPI_MODE0 LITERAL1 26 | SPI_MODE1 LITERAL1 27 | SPI_MODE2 LITERAL1 28 | SPI_MODE3 LITERAL1 29 | 30 | SPI_CONTINUE LITERAL1 31 | SPI_LAST LITERAL1 32 | -------------------------------------------------------------------------------- /libraries/SPI/library.properties: -------------------------------------------------------------------------------- 1 | name=SPI 2 | version=1.0 3 | author=Tokita, Hiroshi 4 | maintainer=Tokita, Hiroshi 5 | sentence=Enables the communication with devices that use the Serial Peripheral Interface (SPI) Bus. For ContikiOS. 6 | paragraph= 7 | category=Communication 8 | url= 9 | architectures=intiki 10 | 11 | -------------------------------------------------------------------------------- /libraries/Wire/Wire.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TWI/I2C library for Arduino Zero 3 | * Copyright (c) 2015 Arduino LLC. All rights reserved. 4 | * Copyright (c) 2015-2018 Tokita, Hiroshi 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef TwoWire_h 22 | #define TwoWire_h 23 | 24 | #include "Stream.h" 25 | #include "variant.h" 26 | 27 | #include "wiring_private.h" 28 | #include "RingBuffer.h" 29 | 30 | // WIRE_HAS_END means Wire has end() 31 | #define WIRE_HAS_END 1 32 | 33 | class TwoWire : public Stream 34 | { 35 | public: 36 | TwoWire(struct i2c_device *i2cdev); 37 | void begin(); 38 | void begin(uint8_t); 39 | void end(); 40 | void setClock(uint32_t); 41 | 42 | void beginTransmission(uint8_t); 43 | uint8_t endTransmission(bool stopBit); 44 | uint8_t endTransmission(void); 45 | 46 | uint8_t requestFrom(uint8_t address, size_t quantity, bool stopBit); 47 | uint8_t requestFrom(uint8_t address, size_t quantity); 48 | 49 | size_t write(uint8_t data); 50 | size_t write(const uint8_t * data, size_t quantity); 51 | 52 | virtual int available(void); 53 | virtual int read(void); 54 | virtual int peek(void); 55 | virtual void flush(void); 56 | void onReceive(void(*)(int)); 57 | void onRequest(void(*)(void)); 58 | 59 | inline size_t write(unsigned long n) { return write((uint8_t)n); } 60 | inline size_t write(long n) { return write((uint8_t)n); } 61 | inline size_t write(unsigned int n) { return write((uint8_t)n); } 62 | inline size_t write(int n) { return write((uint8_t)n); } 63 | using Print::write; 64 | 65 | void onService(void); 66 | 67 | private: 68 | struct i2c_device* i2c; 69 | uint32_t clock; 70 | bool master_mode; 71 | 72 | bool transmissionBegun; 73 | uint8_t txAddress; 74 | 75 | // Callback user functions 76 | void (*onRequestCallback)(void); 77 | void (*onReceiveCallback)(int); 78 | 79 | // TWI clock frequency 80 | static const uint32_t TWI_CLOCK = 100000; 81 | }; 82 | 83 | #if WIRE_INTERFACES_COUNT > 0 84 | extern TwoWire Wire; 85 | #endif 86 | #if WIRE_INTERFACES_COUNT > 1 87 | extern TwoWire Wire1; 88 | #endif 89 | #if WIRE_INTERFACES_COUNT > 2 90 | extern TwoWire Wire2; 91 | #endif 92 | #if WIRE_INTERFACES_COUNT > 3 93 | extern TwoWire Wire3; 94 | #endif 95 | #if WIRE_INTERFACES_COUNT > 4 96 | extern TwoWire Wire4; 97 | #endif 98 | #if WIRE_INTERFACES_COUNT > 5 99 | extern TwoWire Wire5; 100 | #endif 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino: -------------------------------------------------------------------------------- 1 | // I2C SRF10 or SRF08 Devantech Ultrasonic Ranger Finder 2 | // by Nicholas Zambetti 3 | // and James Tichenor 4 | 5 | // Demonstrates use of the Wire library reading data from the 6 | // Devantech Utrasonic Rangers SFR08 and SFR10 7 | 8 | // Created 29 April 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | 13 | #include 14 | 15 | void setup() { 16 | Wire.begin(); // join i2c bus (address optional for master) 17 | Serial.begin(9600); // start serial communication at 9600bps 18 | } 19 | 20 | int reading = 0; 21 | 22 | void loop() { 23 | // step 1: instruct sensor to read echoes 24 | Wire.beginTransmission(112); // transmit to device #112 (0x70) 25 | // the address specified in the datasheet is 224 (0xE0) 26 | // but i2c adressing uses the high 7 bits so it's 112 27 | Wire.write(byte(0x00)); // sets register pointer to the command register (0x00) 28 | Wire.write(byte(0x50)); // command sensor to measure in "inches" (0x50) 29 | // use 0x51 for centimeters 30 | // use 0x52 for ping microseconds 31 | Wire.endTransmission(); // stop transmitting 32 | 33 | // step 2: wait for readings to happen 34 | delay(70); // datasheet suggests at least 65 milliseconds 35 | 36 | // step 3: instruct sensor to return a particular echo reading 37 | Wire.beginTransmission(112); // transmit to device #112 38 | Wire.write(byte(0x02)); // sets register pointer to echo #1 register (0x02) 39 | Wire.endTransmission(); // stop transmitting 40 | 41 | // step 4: request reading from sensor 42 | Wire.requestFrom(112, 2); // request 2 bytes from slave device #112 43 | 44 | // step 5: receive reading from sensor 45 | if (2 <= Wire.available()) { // if two bytes were received 46 | reading = Wire.read(); // receive high byte (overwrites previous reading) 47 | reading = reading << 8; // shift high byte to be high 8 bits 48 | reading |= Wire.read(); // receive low byte as lower 8 bits 49 | Serial.println(reading); // print the reading 50 | } 51 | 52 | delay(250); // wait a bit since people have to read the output :) 53 | } 54 | 55 | 56 | /* 57 | 58 | // The following code changes the address of a Devantech Ultrasonic Range Finder (SRF10 or SRF08) 59 | // usage: changeAddress(0x70, 0xE6); 60 | 61 | void changeAddress(byte oldAddress, byte newAddress) 62 | { 63 | Wire.beginTransmission(oldAddress); 64 | Wire.write(byte(0x00)); 65 | Wire.write(byte(0xA0)); 66 | Wire.endTransmission(); 67 | 68 | Wire.beginTransmission(oldAddress); 69 | Wire.write(byte(0x00)); 70 | Wire.write(byte(0xAA)); 71 | Wire.endTransmission(); 72 | 73 | Wire.beginTransmission(oldAddress); 74 | Wire.write(byte(0x00)); 75 | Wire.write(byte(0xA5)); 76 | Wire.endTransmission(); 77 | 78 | Wire.beginTransmission(oldAddress); 79 | Wire.write(byte(0x00)); 80 | Wire.write(newAddress); 81 | Wire.endTransmission(); 82 | } 83 | 84 | */ 85 | -------------------------------------------------------------------------------- /libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino: -------------------------------------------------------------------------------- 1 | // I2C Digital Potentiometer 2 | // by Nicholas Zambetti 3 | // and Shawn Bonkowski 4 | 5 | // Demonstrates use of the Wire library 6 | // Controls AD5171 digital potentiometer via I2C/TWI 7 | 8 | // Created 31 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | // This example code is in the public domain. 13 | 14 | 15 | #include 16 | 17 | void setup() { 18 | Wire.begin(); // join i2c bus (address optional for master) 19 | } 20 | 21 | byte val = 0; 22 | 23 | void loop() { 24 | Wire.beginTransmission(44); // transmit to device #44 (0x2c) 25 | // device address is specified in datasheet 26 | Wire.write(byte(0x00)); // sends instruction byte 27 | Wire.write(val); // sends potentiometer value byte 28 | Wire.endTransmission(); // stop transmitting 29 | 30 | val++; // increment value 31 | if (val == 64) { // if reached 64th position (max) 32 | val = 0; // start over from lowest value 33 | } 34 | delay(500); 35 | } 36 | 37 | -------------------------------------------------------------------------------- /libraries/Wire/examples/master_reader/master_reader.ino: -------------------------------------------------------------------------------- 1 | // Wire Master Reader 2 | // by Nicholas Zambetti 3 | 4 | // Demonstrates use of the Wire library 5 | // Reads data from an I2C/TWI slave device 6 | // Refer to the "Wire Slave Sender" example for use with this 7 | 8 | // Created 29 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | 13 | #include 14 | 15 | void setup() { 16 | Wire.begin(); // join i2c bus (address optional for master) 17 | Serial.begin(9600); // start serial for output 18 | } 19 | 20 | void loop() { 21 | Wire.requestFrom(8, 6); // request 6 bytes from slave device #8 22 | 23 | while (Wire.available()) { // slave may send less than requested 24 | char c = Wire.read(); // receive a byte as character 25 | Serial.print(c); // print the character 26 | } 27 | 28 | delay(500); 29 | } 30 | -------------------------------------------------------------------------------- /libraries/Wire/examples/master_writer/master_writer.ino: -------------------------------------------------------------------------------- 1 | // Wire Master Writer 2 | // by Nicholas Zambetti 3 | 4 | // Demonstrates use of the Wire library 5 | // Writes data to an I2C/TWI slave device 6 | // Refer to the "Wire Slave Receiver" example for use with this 7 | 8 | // Created 29 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | 13 | #include 14 | 15 | void setup() { 16 | Wire.begin(); // join i2c bus (address optional for master) 17 | } 18 | 19 | byte x = 0; 20 | 21 | void loop() { 22 | Wire.beginTransmission(8); // transmit to device #8 23 | Wire.write("x is "); // sends five bytes 24 | Wire.write(x); // sends one byte 25 | Wire.endTransmission(); // stop transmitting 26 | 27 | x++; 28 | delay(500); 29 | } 30 | -------------------------------------------------------------------------------- /libraries/Wire/examples/slave_receiver/slave_receiver.ino: -------------------------------------------------------------------------------- 1 | // Wire Slave Receiver 2 | // by Nicholas Zambetti 3 | 4 | // Demonstrates use of the Wire library 5 | // Receives data as an I2C/TWI slave device 6 | // Refer to the "Wire Master Writer" example for use with this 7 | 8 | // Created 29 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | 13 | #include 14 | 15 | void setup() { 16 | Wire.begin(8); // join i2c bus with address #8 17 | Wire.onReceive(receiveEvent); // register event 18 | Serial.begin(9600); // start serial for output 19 | } 20 | 21 | void loop() { 22 | delay(100); 23 | } 24 | 25 | // function that executes whenever data is received from master 26 | // this function is registered as an event, see setup() 27 | void receiveEvent(int howMany) { 28 | while (1 < Wire.available()) { // loop through all but the last 29 | char c = Wire.read(); // receive byte as a character 30 | Serial.print(c); // print the character 31 | } 32 | int x = Wire.read(); // receive byte as an integer 33 | Serial.println(x); // print the integer 34 | } 35 | -------------------------------------------------------------------------------- /libraries/Wire/examples/slave_sender/slave_sender.ino: -------------------------------------------------------------------------------- 1 | // Wire Slave Sender 2 | // by Nicholas Zambetti 3 | 4 | // Demonstrates use of the Wire library 5 | // Sends data as an I2C/TWI slave device 6 | // Refer to the "Wire Master Reader" example for use with this 7 | 8 | // Created 29 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | 13 | #include 14 | 15 | void setup() { 16 | Wire.begin(8); // join i2c bus with address #8 17 | Wire.onRequest(requestEvent); // register event 18 | } 19 | 20 | void loop() { 21 | delay(100); 22 | } 23 | 24 | // function that executes whenever data is requested by master 25 | // this function is registered as an event, see setup() 26 | void requestEvent() { 27 | Wire.write("hello "); // respond with message of 6 bytes 28 | // as expected by master 29 | } 30 | -------------------------------------------------------------------------------- /libraries/Wire/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Wire 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | ####################################### 10 | # Methods and Functions (KEYWORD2) 11 | ####################################### 12 | 13 | begin KEYWORD2 14 | beginTransmission KEYWORD2 15 | endTransmission KEYWORD2 16 | requestFrom KEYWORD2 17 | onReceive KEYWORD2 18 | onRequest KEYWORD2 19 | 20 | ####################################### 21 | # Instances (KEYWORD2) 22 | ####################################### 23 | 24 | Wire KEYWORD2 25 | Wire1 KEYWORD2 26 | 27 | ####################################### 28 | # Constants (LITERAL1) 29 | ####################################### 30 | 31 | -------------------------------------------------------------------------------- /libraries/Wire/library.properties: -------------------------------------------------------------------------------- 1 | name=Wire 2 | version=1.0 3 | author=Tokita, Hiroshi 4 | maintainer=Tokita, Hiroshi 5 | sentence=Allows the communication between devices or sensors connected via Two Wire Interface Bus. For ContikiOS. 6 | paragraph= 7 | category=Communication 8 | url= 9 | architectures=intiki 10 | -------------------------------------------------------------------------------- /libraries/uIP/README.adoc: -------------------------------------------------------------------------------- 1 | = uIP library = 2 | 3 | This library enable to connect TCP/IP networks. This is frontend-API of contiki's uIP functions. Specification and limitation depends on contiki's implementation. 4 | 5 | == License == 6 | 7 | Copyright (c) 2016-2018 Tokita, Hiroshi All right reserved. 8 | 9 | This library is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Lesser General Public 11 | License as published by the Free Software Foundation; either 12 | version 2.1 of the License, or (at your option) any later version. 13 | 14 | This library is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public 20 | License along with this library; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | -------------------------------------------------------------------------------- /libraries/uIP/examples/Udp7EchoClientServer/Udp7EchoClientServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Udp7EchoClientServer: 3 | 4 | This is a client / server program which communicate 5 | by "well-known udp/7" echo protocol. 6 | 7 | Write same program to 2 nodes to use. 8 | One is act as server, the other is client. 9 | 10 | Program is start as echo server at boot up. 11 | Server send response same data what if data received. 12 | Enter the IPv6 address of the server to serial, 13 | and act as a client when the address is recognized. 14 | 15 | This program must compile with [RPL: "disabled"] configuration. 16 | 17 | created 29 May 2018 18 | by Tokita Hiroshi 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | IPAddress destAddr; 25 | 26 | const size_t MAX_PAYLOAD_LEN = 33; 27 | const size_t MAX_V6_ADDR_STR = 40; 28 | 29 | const unsigned int ECHO_PORT = 7; 30 | 31 | char packetBuffer[MAX_PAYLOAD_LEN]; 32 | char serialBuffer[MAX_V6_ADDR_STR]; 33 | size_t serialBufferLen; 34 | 35 | MicroIPUDP Udp; 36 | 37 | void setup() { 38 | Serial.begin(1000000); 39 | 40 | Serial.print("Echo protocol ("); 41 | Serial.print(ECHO_PORT); 42 | Serial.println("/udp) listen start."); 43 | Serial.println(); 44 | 45 | MicroIP.begin(); 46 | 47 | // Show link-local address 48 | Serial.print("This linklocal Address is "); 49 | Serial.println(MicroIP.linklocalAddress()); 50 | Serial.println(); 51 | 52 | Udp.begin(ECHO_PORT); 53 | 54 | Serial.println(); 55 | Serial.println("Enter destination IP address."); 56 | Serial.println("Or invalid IP address is entered, stop sending."); 57 | Serial.println(); 58 | } 59 | 60 | void loop() { 61 | 62 | if (Serial.available()) 63 | { 64 | memset(serialBuffer, 0, MAX_V6_ADDR_STR); 65 | serialBufferLen = Serial.readBytes(serialBuffer, MAX_V6_ADDR_STR); 66 | 67 | // Set destination IPaddress when string received from serial line. 68 | if (destAddr == IN6ADDR_ANY_INIT) 69 | { 70 | bool valid = destAddr.fromString(serialBuffer); 71 | if (valid) 72 | { 73 | Serial.print("Destination IP is "); 74 | Serial.println(destAddr); 75 | Serial.println("Enter message to send."); 76 | } 77 | else 78 | { 79 | Serial.print(serialBuffer); 80 | Serial.println(" is invalid. Stop sending."); 81 | } 82 | serialBufferLen = 0; 83 | } 84 | } 85 | 86 | // When destination is set, send serial buffer 87 | if (!(destAddr == IN6ADDR_ANY_INIT) && serialBufferLen != 0) 88 | { 89 | // construct send data 90 | memcpy(packetBuffer, serialBuffer, serialBufferLen); 91 | 92 | Serial.print("Send to ["); 93 | Serial.print(destAddr); 94 | Serial.print("]:"); 95 | Serial.print(ECHO_PORT); 96 | Serial.print(" :"); 97 | Serial.println(serialBuffer); 98 | 99 | // send packet 100 | Udp.beginPacket(destAddr, ECHO_PORT); 101 | Udp.write(serialBuffer, min(MAX_PAYLOAD_LEN, serialBufferLen) ); 102 | Udp.endPacket(); 103 | 104 | serialBufferLen = 0; 105 | } 106 | 107 | // print received data. 108 | while (int packetSize = Udp.parsePacket()) { 109 | Serial.print("Received packet from ["); 110 | Serial.print(Udp.remoteIP()); 111 | Serial.print("]:"); 112 | Serial.print(Udp.remotePort()); 113 | Serial.print(" datasize="); 114 | Serial.println(packetSize); 115 | 116 | // Read the packet into packetBufffer 117 | memset(packetBuffer, 0, MAX_PAYLOAD_LEN); 118 | Udp.read(packetBuffer, MAX_PAYLOAD_LEN); 119 | 120 | if (destAddr == Udp.remoteIP()) { 121 | // Not response to echo. 122 | Serial.print("Received: "); 123 | Serial.println(packetBuffer); 124 | } 125 | else { 126 | // Send echo 127 | Serial.print("Echo: "); 128 | Serial.println(packetBuffer); 129 | Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); 130 | Udp.write(packetBuffer, packetSize); 131 | Udp.endPacket(); 132 | } 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /libraries/uIP/examples/tcp-echo-client/tcp-echo-client.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define BUFLEN 64 4 | 5 | unsigned char buf[BUFLEN]; 6 | 7 | MicroIPClient client; 8 | 9 | void setup() { 10 | Serial.begin(115200); 11 | Serial.println("Start Echo Client."); 12 | 13 | MicroIP.begin(); 14 | delay(1000); 15 | } 16 | 17 | void loop() { 18 | if( !client.connected() ) { 19 | int ret = client.connect("echo-server.local", 7); 20 | Serial.print("connect "); 21 | Serial.println(ret); 22 | delay(1000); 23 | } 24 | else { 25 | int count = 0; 26 | while(client.available() ) { 27 | buf[count] = client.read(); 28 | count++; 29 | if(count == 64) break; 30 | } 31 | if(count > 0) { 32 | Serial.write(buf, count); 33 | } 34 | 35 | count = 0; 36 | while(Serial.available() ) { 37 | buf[count] = Serial.read(); 38 | count++; 39 | if(count == BUFLEN) break; 40 | } 41 | if(count > 0) { 42 | client.write(buf, count); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /libraries/uIP/examples/tcp-echo-server-rpl/tcp-echo-server-rpl.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define BUFLEN 64 4 | 5 | unsigned char buf[BUFLEN]; 6 | 7 | MicroIPServer server(7); 8 | IPAddress prefix(0xaaaa, 0, 0, 0, 0, 0, 0, 0); 9 | 10 | void setup() { 11 | Serial.begin(115200); 12 | Serial.println("Start Echo Server."); 13 | 14 | MicroIP.setHostname("echo-server"); 15 | MicroIP.begin(); 16 | 17 | Serial.print("Start RPL with prefix "); 18 | Serial.println(prefix); 19 | RPL.begin(prefix); 20 | 21 | delay(1000); 22 | 23 | server.begin(); 24 | } 25 | 26 | void loop() { 27 | // API will be change... 28 | MicroIPClient& client = server.available(); 29 | if(client) { 30 | if( client.connected() ) { 31 | Serial.println("connected"); 32 | 33 | int count = 0; 34 | while(client.available() ) { 35 | buf[count] = client.read(); 36 | count++; 37 | if(count == BUFLEN) break; 38 | } 39 | if(count > 0) { 40 | client.write(buf, count); 41 | } 42 | } 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /libraries/uIP/examples/tcpv6-client-example/tcpv6-client-example.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | IPAddress server(0xaaaa, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001); 4 | MicroIPClient client; 5 | 6 | void setup() { 7 | Serial.begin(115200); 8 | 9 | // start the uIP connection: 10 | Serial.println("MicroIP.begin"); 11 | 12 | MicroIP.begin(); 13 | delay(1000); 14 | 15 | // if you get a connection, report back via serial: 16 | Serial.println("connecting...\n"); 17 | if (!client.connect(server, 80)) { 18 | // if you didn't get a connection to the server: 19 | Serial.println("connection failed."); 20 | 21 | while(true) { yield(); } 22 | } 23 | else { 24 | Serial.println("connected."); 25 | Serial.println("send GET request..."); 26 | client.print("GET /\n"); 27 | } 28 | } 29 | 30 | void loop() { 31 | if (client.available()) { 32 | char c = client.read(); 33 | Serial.print(c); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /libraries/uIP/examples/tiny-httpd/tiny-httpd.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | MicroIPServer server(80); 4 | 5 | void setup() { 6 | Serial.begin(115200); 7 | Serial.println("MicroIP.begin"); 8 | 9 | MicroIP.begin(); 10 | delay(1000); 11 | 12 | server.begin(); 13 | Serial.println("Tiny HTTPd started."); 14 | } 15 | 16 | void loop() { 17 | // API will be change... 18 | MicroIPClient& client = server.available(); 19 | if(client) { 20 | Serial.println("new client"); 21 | 22 | bool respond = false; 23 | 24 | while( client.connected() ) { 25 | if (client.available() ) { 26 | char c = client.read(); 27 | Serial.write(c); 28 | 29 | if(c == '\n' && !respond) { 30 | client.println("HTTP/1.1 200 OK"); 31 | client.println("Content-Type: text/html"); 32 | client.println("Connection: close"); 33 | client.println(); 34 | client.println("Tiny HTTPd</tile>"); 35 | client.println("<html>"); 36 | client.println("</html>"); 37 | respond = true; 38 | } 39 | } 40 | else if(respond) { 41 | Serial.println("stop"); 42 | client.stop(); 43 | } 44 | } 45 | delay(1); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /libraries/uIP/examples/udp-echo-client/udp-echo-client.ino: -------------------------------------------------------------------------------- 1 | /* 2 | UDP Echo client 3 | 4 | A simple UDP communication demo. 5 | The program send simple message to 'udp-echo-server-rpl' node, 6 | the server node send echo on the message received. 7 | The received echo message shows on serial port. 8 | 9 | Even if RPL is enabled or disabled works. 10 | Use same settings to compile server side programs. 11 | This programs behavior is based on contiki os's 12 | example(examples/udp-ipv6/udp-client.c). 13 | 14 | created 24 Jan 2016 15 | modified 29 May 2018 16 | by Tokita Hiroshi 17 | */ 18 | 19 | #include <MicroIp.h> 20 | #include <MicroIpUdp.h> 21 | #include <IPAddress.h> 22 | 23 | const size_t MAX_PAYLOAD_LEN = 40; 24 | const char* UDP_CONNECTION_ADDR = "contiki-udp-server.local"; 25 | const unsigned short LOCAL_PORT = 3001; 26 | const unsigned short DEST_PORT = 3000; 27 | const int INTERVAL = 15; 28 | 29 | MicroIPUDP Udp; 30 | IPAddress server; 31 | 32 | char packetBuffer[MAX_PAYLOAD_LEN]; 33 | long lastsend; 34 | long seq_id; 35 | 36 | void setup() { 37 | Serial.begin(1000000); 38 | Serial.println("Start udp-echo-cleint"); 39 | MicroIP.begin(); 40 | 41 | server = MicroIP.lookup(UDP_CONNECTION_ADDR); 42 | 43 | if (server == IN6ADDR_ANY_INIT) { 44 | Serial.print("Server ["); 45 | Serial.print(UDP_CONNECTION_ADDR); 46 | Serial.println("] is not found."); 47 | while (true) { 48 | yield(); 49 | } 50 | } 51 | 52 | Serial.print("Server "); 53 | Serial.print(UDP_CONNECTION_ADDR); 54 | Serial.print(" is ["); 55 | Serial.print(server); 56 | Serial.println("]"); 57 | 58 | Udp.begin(LOCAL_PORT); 59 | Serial.print("Start listen port:"); 60 | Serial.println(LOCAL_PORT); 61 | } 62 | 63 | void loop() { 64 | 65 | long now = millis(); 66 | 67 | // Periodically send. 68 | if ((now - lastsend) > (INTERVAL * 1000)) { 69 | // format message 70 | memset(packetBuffer, 0, MAX_PAYLOAD_LEN); 71 | strcpy(packetBuffer, "Hello "); 72 | itoa(++seq_id, packetBuffer + strlen(packetBuffer), 10); 73 | strcpy(packetBuffer + strlen(packetBuffer), " from the client"); 74 | 75 | Serial.print("Client sending to "); 76 | Serial.print(server); 77 | Serial.print(" (msg: "); 78 | Serial.print(packetBuffer); 79 | Serial.println(");"); 80 | 81 | // send packet 82 | Udp.beginPacket(server, DEST_PORT); 83 | Udp.write(packetBuffer, strlen(packetBuffer)); 84 | Udp.endPacket(); 85 | 86 | lastsend = now; 87 | } 88 | 89 | while (int packetSize = Udp.parsePacket()) { 90 | /* 91 | //more info 92 | Serial.print("Receive from "); 93 | Serial.print(Udp.remoteIP()); 94 | Serial.print(":"); 95 | Serial.print(Udp.remotePort()); 96 | Serial.print(" size:"); 97 | Serial.println(packetSize); 98 | */ 99 | 100 | // read the packet into packetBufffer 101 | Udp.read(packetBuffer, packetSize); 102 | Serial.print("Response from the server: '"); 103 | Serial.print(packetBuffer); 104 | Serial.println("'"); 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /libraries/uIP/examples/udp-echo-server-rpl/udp-echo-server-rpl.ino: -------------------------------------------------------------------------------- 1 | /* 2 | UDP Echo server 3 | 4 | A simple UDP communication demo. 5 | The program wait a message from 'udp-echo-client'. 6 | Send response message to the sender node on message received. 7 | The udp port 3000 uses to send client to server, 8 | the 3001 to send response. 9 | 10 | Even if RPL is enabled or disabled works. 11 | Use same settings to compile server side programs. 12 | This programs behavior is based on contiki os's 13 | example(examples/udp-ipv6/udp-server.c). 14 | 15 | created 24 Jan 2016 16 | modified 29 May 2018 17 | by Tokita Hiroshi 18 | */ 19 | 20 | #include <MicroIp.h> 21 | #include <MicroIpUdp.h> 22 | #include <IPAddress.h> 23 | 24 | const size_t MAX_PAYLOAD_LEN = 40; 25 | const char* HOSTNAME = "contiki-udp-server"; 26 | const char* PREFIX = "AAAA::0"; 27 | const unsigned short LOCAL_PORT = 3000; 28 | const unsigned short DEST_PORT = 3001; 29 | 30 | MicroIPUDP Udp; 31 | 32 | char packetBuffer[MAX_PAYLOAD_LEN]; 33 | long seq_id; 34 | 35 | void setup() { 36 | Serial.begin(1000000); 37 | Serial.println("Start udp-echo-server-rpl"); 38 | 39 | MicroIP.begin(); 40 | 41 | // set hostname to mDNS announcing 42 | MicroIP.setHostname(HOSTNAME); 43 | 44 | // start RPL to find neighbors 45 | IPAddress rpl_prefix; 46 | rpl_prefix.fromString(PREFIX); 47 | RPL.begin(rpl_prefix); 48 | 49 | Udp.begin(LOCAL_PORT); 50 | Serial.print("Start listen port:"); 51 | Serial.println(LOCAL_PORT); 52 | } 53 | 54 | void loop() { 55 | 56 | // if there's data available, read a packet 57 | if (int packetSize = Udp.parsePacket() ) { 58 | Udp.read(packetBuffer, packetSize); 59 | Serial.print("Server received("); 60 | Serial.print(packetSize); 61 | Serial.print("bytes): '"); 62 | Serial.print(packetBuffer); 63 | Serial.print("' from "); 64 | Serial.print(Udp.remoteIP()); 65 | Serial.println(); 66 | 67 | // format message 68 | strcpy(packetBuffer, "Hello from the server! ("); 69 | itoa(++seq_id, packetBuffer + strlen(packetBuffer), 10); 70 | strcpy(packetBuffer + strlen(packetBuffer), ")"); 71 | 72 | Serial.print("Responding with message: "); 73 | Serial.println(packetBuffer); 74 | 75 | // send echo 76 | Udp.beginPacket(Udp.remoteIP(), DEST_PORT); 77 | Udp.write(packetBuffer, strlen(packetBuffer) ); 78 | Udp.endPacket(); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /libraries/uIP/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For MicroIP 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | MicroIP KEYWORD1 MicroIPClass 10 | MicroIPClient KEYWORD1 MicroIPClient 11 | MicroIPServer KEYWORD1 MicroIPServer 12 | MicroIPUDP KEYWORD1 MicroIPUDP 13 | RPL KEYWORD1 MicroIPRPL 14 | 15 | ####################################### 16 | # Methods and Functions (KEYWORD2) 17 | ####################################### 18 | 19 | 20 | localIP KEYWORD2 21 | subnetMask KEYWORD2 22 | gatewayIP KEYWORD2 23 | dnsServerIP KEYWORD2 24 | 25 | interfaceID KEYWORD2 26 | prefix KEYWORD2 27 | prefixLength KEYWORD2 28 | lookup KEYWORD2 29 | setHostname KEYWORD2 30 | addDNS KEYWORD2 31 | removeDNS KEYWORD2 32 | 33 | status KEYWORD2 34 | connect KEYWORD2 35 | write KEYWORD2 36 | available KEYWORD2 37 | read KEYWORD2 38 | peek KEYWORD2 39 | flush KEYWORD2 40 | stop KEYWORD2 41 | connected KEYWORD2 42 | 43 | begin KEYWORD2 44 | stop KEYWORD2 45 | beginPacket KEYWORD2 46 | endPacket KEYWORD2 47 | parsePacket KEYWORD2 48 | remoteIP KEYWORD2 49 | remotePort KEYWORD2 50 | 51 | maintain KEYWORD2 52 | 53 | ####################################### 54 | # Constants (LITERAL1) 55 | ####################################### 56 | 57 | -------------------------------------------------------------------------------- /libraries/uIP/library.properties: -------------------------------------------------------------------------------- 1 | name=uIP 2 | version=0.0.1 3 | author=Tokita, Hiroshi 4 | maintainer=Tokita, Hiroshi <tokita.hiroshi@gmail.com> 5 | sentence=The uIP is an implementation of the TCP/IP network protocol stack designed for tiny microcontrollers. 6 | paragraph=This library enable to connect TCP/IP networks. This is frontend-API of contiki's uIP functions. Specification and limitation depends on contiki's implementation. 7 | category=Communication 8 | url=https://github.com/soburi/JN516x-arduino-package 9 | architectures=intiki 10 | -------------------------------------------------------------------------------- /libraries/uIP/src/MicroIp.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016-2018 Tokita, Hiroshi 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 MICROIP_H 20 | #define MICROIP_H 21 | 22 | #include <inttypes.h> 23 | #include "IPAddress.h" 24 | 25 | #include "MicroIpClient.h" 26 | #include "MicroIpServer.h" 27 | #include "MicroIpRPL.h" 28 | 29 | #if NETSTACK_CONF_WITH_IPV6 30 | #define uip_ipaddr_IPAddress(addr, ipaddr) \ 31 | uip_ip6addr((addr), (ipaddr).v6[0], (ipaddr).v6[1], (ipaddr).v6[2], (ipaddr).v6[3],\ 32 | (ipaddr).v6[4], (ipaddr).v6[5], (ipaddr).v6[6], (ipaddr).v6[7]) 33 | 34 | #define IPAddress_from_uip(addr) \ 35 | IPAddress((addr).u16[0], (addr).u16[1], (addr).u16[2], (addr).u16[3], \ 36 | (addr).u16[4], (addr).u16[5], (addr).u16[6], (addr).u16[7]) 37 | #else 38 | #define uip_ipaddr_IPAddress(addr, ipaddr) \ 39 | uip_(ipaddr)((addr), (ipaddr)[0], (ipaddr)[1], (ipaddr)[2], (ipaddr)[3]) 40 | #define IPAddress_from_uip(addr) \ 41 | IPAddress((addr).u8[0], (addr).u8[1], (addr).u8[2], (addr).u8[3]) 42 | #endif 43 | 44 | class MicroIPClass { 45 | public: 46 | 47 | int begin(); 48 | int maintain(); 49 | 50 | IPAddress localIP() { return globalAddress(); } 51 | IPAddress subnetMask(); 52 | IPAddress gatewayIP(); 53 | IPAddress dnsServerIP(); 54 | 55 | #if NETSTACK_CONF_WITH_IPV6 56 | IPAddress linklocalAddress(int state); 57 | IPAddress linklocalAddress(); 58 | IPAddress globalAddress(int state); 59 | IPAddress globalAddress(); 60 | 61 | IPAddress interfaceID(); 62 | IPAddress prefix(); 63 | unsigned int prefixLength(); 64 | IPAddress lookup(const char* host); 65 | void setHostname(const char* hostname); 66 | void addDNS(const IPAddress& addr, uint32_t lifetime=0xFFFFFFFF); 67 | void removeDNS(const IPAddress& addr) { addDNS(addr, 0); } 68 | #endif 69 | 70 | private: 71 | friend class MicroIPClient; 72 | friend class MicroIPServer; 73 | }; 74 | 75 | extern MicroIPClass MicroIP; 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /libraries/uIP/src/MicroIpClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016-2018 Tokita, Hiroshi 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 MICROIPCLIENT_H 20 | #define MICROIPCLIENT_H 21 | 22 | #include <stdint.h> 23 | 24 | extern "C" { 25 | #include <net/ip/tcp-socket.h> 26 | #include <lib/ringbuf.h> 27 | } 28 | 29 | #include "Arduino.h" 30 | #include "Print.h" 31 | #include "Client.h" 32 | #include "IPAddress.h" 33 | 34 | #ifndef MICROIPCLIENT_TXBUF_SIZE 35 | #define MICROIPCLIENT_TXBUF_SIZE 128 36 | #endif 37 | 38 | #ifndef MICROIPCLIENT_RXBUF_SIZE 39 | #define MICROIPCLIENT_RXBUF_SIZE UIP_BUFSIZE 40 | #endif 41 | 42 | class MicroIPClient : public Client { 43 | 44 | public: 45 | MicroIPClient(); 46 | 47 | uint8_t status(); 48 | virtual int connect(IPAddress ip, uint16_t port); 49 | virtual int connect(const char *host, uint16_t port); 50 | virtual size_t write(uint8_t); 51 | virtual size_t write(const uint8_t *buf, size_t size); 52 | virtual int available(); 53 | virtual int read(); 54 | virtual int read(uint8_t *buf, size_t size); 55 | virtual int peek(); 56 | virtual void flush(); 57 | virtual void stop(); 58 | virtual uint8_t connected(); 59 | virtual operator bool(); 60 | 61 | friend class MicroIPServer; 62 | 63 | using Print::write; 64 | 65 | private: 66 | MicroIPClient(struct tcp_socket* psock); 67 | size_t receive(const uint8_t *input_data_ptr, int input_data_len); 68 | 69 | int listen(uint16_t port); 70 | 71 | static void do_tcp_socket_register(void* pthis); 72 | static void do_tcp_socket_connect(void* pthis); 73 | static void do_tcp_socket_send(void* ptr); 74 | static void do_tcp_socket_listen(void* ptr); 75 | static void do_tcp_socket_close(void* ptr); 76 | 77 | static int wait_tcp_socket_event(process_event_t ev, process_data_t data, void* param); 78 | 79 | static int data_callback(struct tcp_socket *s, void *ptr, const unsigned char* input_data_ptr, int input_data_len); 80 | static void event_callback(struct tcp_socket *s, void *ptr, tcp_socket_event_t event); 81 | 82 | struct tcp_socket* _psock; 83 | struct tcp_socket sock; 84 | struct ringbuf rxbuf; 85 | uint8_t rbuf[MICROIPCLIENT_RXBUF_SIZE]; 86 | 87 | uint8_t socket_rxbuf[4]; 88 | uint8_t socket_txbuf[MICROIPCLIENT_TXBUF_SIZE]; 89 | 90 | tcp_socket_event_t state; 91 | 92 | bool event_wait; 93 | }; 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /libraries/uIP/src/MicroIpRPL.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016-2018 Tokita, Hiroshi 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 <net/ip/uip.h> 21 | #include <net/ipv6/uip-ds6.h> 22 | #include <net/rpl/rpl.h> 23 | #define DEBUG DEBUG_NONE 24 | #include <net/ip/uip-debug.h> 25 | } 26 | 27 | #include "MicroIpRPL.h" 28 | 29 | int MicroIPRPL::begin(const IPAddress& prefix, uint32_t prefix_length) 30 | { 31 | #if UIP_CONF_IPV6_RPL 32 | rpl_dag_t *dag; 33 | uip_ipaddr_t ipaddr; 34 | uip_ipaddr_t prefix_; 35 | 36 | PRINTF("MicroIPClass::begin(prefix)\n"); 37 | 38 | uip_ip6addr_u8(&ipaddr, 39 | prefix[0], prefix[1], prefix[2], prefix[3], 40 | prefix[4], prefix[5], prefix[6], prefix[7], 41 | prefix[8], prefix[9],prefix[10],prefix[11], 42 | prefix[12],prefix[13],prefix[14],prefix[15]); 43 | 44 | dag = rpl_set_root(RPL_DEFAULT_INSTANCE, &ipaddr); 45 | if(dag != NULL) { 46 | rpl_set_prefix(dag, &prefix_, prefix_length); 47 | PRINTF("created a new RPL dag\n"); 48 | return 1; 49 | } 50 | #else 51 | (void)prefix; 52 | (void)prefix_length; 53 | #endif 54 | return 0; 55 | } 56 | 57 | MicroIPRPL RPL; 58 | -------------------------------------------------------------------------------- /libraries/uIP/src/MicroIpRPL.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016-2018 Tokita, Hiroshi 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 MICROIPRPL_H 20 | #define MICROIPRPL_H 21 | 22 | #include "IPAddress.h" 23 | 24 | class MicroIPRPL { 25 | public: 26 | int begin(const IPAddress& prefix, uint32_t prefix_length=64); 27 | }; 28 | 29 | extern MicroIPRPL RPL; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /libraries/uIP/src/MicroIpServer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016-2018 Tokita, Hiroshi 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 | #define DEBUG DEBUG_NONE 21 | #include <net/ip/uip-debug.h> 22 | } 23 | 24 | #include "MicroIp.h" 25 | #include "MicroIpClient.h" 26 | #include "MicroIpServer.h" 27 | 28 | MicroIPClient MicroIPServer::null_client(0); 29 | 30 | MicroIPServer::MicroIPServer(uint16_t port_) 31 | { 32 | port = port_; 33 | } 34 | 35 | void MicroIPServer::begin() 36 | { 37 | PRINTF("MicroIPServer::begin\n"); 38 | 39 | internal_client.listen(port); 40 | } 41 | 42 | MicroIPClient& MicroIPServer::available() 43 | { 44 | //printf("MicroIPServer::available\n"); 45 | uint8_t s = internal_client.status(); 46 | if (s == TCP_SOCKET_CONNECTED || s == TCP_SOCKET_DATA_SENT) { 47 | if (internal_client.available()) { 48 | return internal_client; 49 | } 50 | } 51 | 52 | return null_client; 53 | } 54 | 55 | size_t MicroIPServer::write(uint8_t b) 56 | { 57 | return internal_client.write(&b, 1); 58 | } 59 | 60 | size_t MicroIPServer::write(const uint8_t *buffer, size_t size) 61 | { 62 | return internal_client.write(buffer, size); 63 | } 64 | -------------------------------------------------------------------------------- /libraries/uIP/src/MicroIpServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016-2018 Tokita, Hiroshi 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 MICROIPSERVER_H 20 | #define MICROIPSERVER_H 21 | 22 | #include "Server.h" 23 | 24 | #include "MicroIpClient.h" 25 | 26 | class MicroIPServer : 27 | public Server { 28 | private: 29 | static MicroIPClient null_client; 30 | MicroIPClient internal_client; 31 | uint16_t port; 32 | public: 33 | MicroIPServer(uint16_t); 34 | MicroIPClient& available(); 35 | virtual void begin(); 36 | virtual size_t write(uint8_t); 37 | virtual size_t write(const uint8_t *buf, size_t size); 38 | using Print::write; 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /libraries/uIP/src/MicroIpUdp.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016-2018 Tokita, Hiroshi 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 MICROIPUDP_H 20 | #define MICROIPUDP_H 21 | 22 | extern "C" { 23 | #include <net/ip/udp-socket.h> 24 | #include <lib/ringbuf.h> 25 | } 26 | 27 | #include <Udp.h> 28 | 29 | #define UDP_TX_PACKET_MAX_SIZE 24 30 | 31 | #ifndef MICROIPUDP_TXBUF_SIZE 32 | #define MICROIPUDP_TXBUF_SIZE 128 33 | #endif 34 | 35 | #ifndef MICROIPUDP_RXBUF_SIZE 36 | #define MICROIPUDP_RXBUF_SIZE UIP_BUFSIZE 37 | #endif 38 | 39 | class MicroIPUDP : public UDP { 40 | private: 41 | IPAddress _remoteIP; 42 | uint16_t _remotePort; 43 | uint16_t remaining; 44 | 45 | struct udp_socket sock; 46 | 47 | struct ringbuf rxbuf; 48 | uint8_t rbuf[MICROIPUDP_RXBUF_SIZE]; 49 | uint8_t tbuf[MICROIPUDP_TXBUF_SIZE]; 50 | uint32_t txidx; 51 | 52 | public: 53 | MicroIPUDP(); 54 | virtual uint8_t begin(uint16_t); 55 | virtual void stop(); 56 | virtual int beginPacket(IPAddress ip, uint16_t port); 57 | virtual int beginPacket(const char *host, uint16_t port); 58 | virtual int endPacket(); 59 | virtual size_t write(uint8_t); 60 | virtual size_t write(const uint8_t *buffer, size_t size); 61 | using Print::write; 62 | virtual int parsePacket(); 63 | 64 | virtual int available(); 65 | virtual int read(); 66 | virtual int read(unsigned char* buffer, size_t len); 67 | virtual int read(char* buffer, size_t len) { return read((unsigned char*)buffer, len); }; 68 | virtual int peek(); 69 | virtual void flush(); 70 | 71 | virtual IPAddress remoteIP() { return _remoteIP; }; 72 | virtual uint16_t remotePort() { return _remotePort; }; 73 | 74 | private: 75 | int raw_read(); 76 | int raw_read(unsigned char* buffer, size_t len); 77 | 78 | void receive(const uip_ipaddr_t *source_addr, uint16_t source_port, 79 | const uip_ipaddr_t *dest_addr, uint16_t dest_port, 80 | const uint8_t *data, uint16_t datalen); 81 | 82 | 83 | static void input_callback(struct udp_socket *c, void *ptr, 84 | const uip_ipaddr_t *source_addr, uint16_t source_port, 85 | const uip_ipaddr_t *dest_addr, uint16_t dest_port, 86 | const uint8_t *data, uint16_t datalen); 87 | 88 | static void do_udp_socket_register(void* ptr); 89 | static void do_udp_socket_bind(void* ptr); 90 | static void do_udp_socket_connect(void* ptr); 91 | static void do_udp_socket_send(void* ptr); 92 | }; 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /variants/jn516x/i2c-driver.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017-2018 Tokita, Hiroshi 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 I2CDRIVER_H__ 20 | #define I2CDRIVER_H__ 21 | 22 | #if defined __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include <jendefs.h> 27 | #include "contiki-conf.h" 28 | #include <ringbuf.h> 29 | 30 | #define JN516x_I2C_BUFFERSIZE 64 31 | 32 | struct jn516x_i2c_devinfo 33 | { 34 | bool req_received; 35 | bool data_received; 36 | 37 | struct ringbuf txbuf; 38 | uint8_t tbuf[JN516x_I2C_BUFFERSIZE]; 39 | struct ringbuf rxbuf; 40 | uint8_t rbuf[JN516x_I2C_BUFFERSIZE]; 41 | }; 42 | 43 | extern struct jn516x_i2c_devinfo jn516x_i2c_info; 44 | 45 | int jn516x_i2c_init(void* dev); 46 | int jn516x_i2c_master_enable(void* dev, uint32_t clock); 47 | int jn516x_i2c_slave_enable(void* dev, uint8_t address); 48 | void jn516x_i2c_disable(void* dev); 49 | 50 | int jn516x_i2c_master_start(void* dev, uint8_t address, int readflag); 51 | int jn516x_i2c_master_read(void* dev, size_t length); 52 | int jn516x_i2c_master_write(void* dev); 53 | int jn516x_i2c_slave_write(void* dev); 54 | void jn516x_i2c_master_stop(void* dev); 55 | 56 | int jn516x_i2c_rx_available(void* dev); 57 | void jn516x_i2c_rx_clear(void* dev); 58 | int jn516x_i2c_rx_read(void* dev); 59 | int jn516x_i2c_rx_peek(void* dev); 60 | int jn516x_i2c_tx_available(void* dev); 61 | void jn516x_i2c_tx_clear(void* dev); 62 | int jn516x_i2c_tx_put(void* dev, uint8_t data); 63 | int jn516x_i2c_tx_full(void* dev); 64 | 65 | int jn516x_i2c_request_received(void* dev); 66 | int jn516x_i2c_data_received(void* dev); 67 | 68 | #if defined __cplusplus 69 | } 70 | #endif 71 | 72 | #endif //I2C_DRIVER_H__ 73 | 74 | -------------------------------------------------------------------------------- /variants/jn516x/ldscript/intiki_JN5169.ld: -------------------------------------------------------------------------------- 1 | /* Set minimum heap size unless it is already set from App_Stack_Size.ld */ 2 | INCLUDE App_Stack_Size.ld 3 | INCLUDE AppBuildStart.ld 4 | INCLUDE AppBuildExceptionHandlers.ld 5 | _minimum_heap_size = __minimum_heap_size; 6 | INCLUDE intiki_common.ld 7 | -------------------------------------------------------------------------------- /variants/jn516x/ldscript/intiki_JN516x.ld: -------------------------------------------------------------------------------- 1 | INCLUDE App_Stack_Size.ld 2 | INCLUDE AppBuildStart.ld 3 | INCLUDE AppBuildExceptionHandlers.ld 4 | INCLUDE intiki_common.ld 5 | -------------------------------------------------------------------------------- /variants/jn516x/makefile/Makefile.override: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2015-2018 Tokita, Hiroshi 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 | JN516X_OVERRIDE_DIR := $(ARDUINO_VARIANT_PATH)/override 19 | 20 | EXTERNALDIRS += $(JN516X_OVERRIDE_DIR) 21 | 22 | LDFLAGS += -L$(ARDUINO_VARIANT_PATH)/ldscript 23 | 24 | ifeq ($(TRACE),1) 25 | LDMYLIBS += DBG_JN516x 26 | endif 27 | 28 | ARDUINO_CFLAGS += -Wextra 29 | 30 | ARDUINO_VARIANT_SRCS := $(filter-out $(JN516X_OVERRIDE_DIR)/%,$(ARDUINO_VARIANT_SRCS)) 31 | 32 | 33 | CUSTOM_RULE_CPP_TO_ARDUINO_OBJECTDIR_O = 1 34 | $(ARDUINO_OBJECTDIR)/%.o: %.cpp | $(ARDUINO_OBJECTDIR)/ 35 | $(TRACE_CC) 36 | $(Q)$(CC) $(ARDUINO_CFLAGS) $(CPPFLAGS) -MMD -c $< -o $@ 37 | @$(FINALIZE_DEPENDENCY_) 38 | 39 | CUSTOM_RULE_C_TO_ARDUINO_OBJECTDIR_O = 1 40 | $(ARDUINO_OBJECTDIR)/%.o: %.c | $(ARDUINO_OBJECTDIR)/ 41 | $(TRACE_CC) 42 | $(Q)$(CC) $(ARDUINO_CFLAGS) $(CFLAGS) -MMD -c $< -o $@ 43 | @$(FINALIZE_DEPENDENCY_) 44 | 45 | $(ARDUINO_PROJECT_NAME).$(TARGET).bin: $(ARDUINO_PROJECT_NAME).bin 46 | cp $< $@ 47 | 48 | override target_makefile := $(CONTIKI)/platform/$(TARGET)/Makefile.$(TARGET) 49 | include $(CONTIKI)/platform/$(TARGET)/Makefile.$(TARGET) 50 | -------------------------------------------------------------------------------- /variants/jn516x/pins_arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-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 | // API compatibility 20 | #include "variant.h" 21 | 22 | -------------------------------------------------------------------------------- /variants/jn516x/platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015-2018 Tokita, Hiroshi 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 _VARIANT_PLATFORM_H 20 | #define _VARIANT_PLATFORM_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #undef F_CPU 27 | 28 | #include <jendefs.h> 29 | #include <MicroSpecific.h> 30 | #include <AppHardwareApi.h> 31 | 32 | #pragma GCC diagnostic push 33 | #pragma GCC diagnostic ignored "-Wunused-parameter" 34 | #include <dbg.h> 35 | #include <dbg_uart.h> 36 | #pragma GCC diagnostic pop 37 | 38 | #define DBG_PRINTF(...) DBG_vPrintf(DBG_VPRINTF_ENABLE, __VA_ARGS__) 39 | #ifdef DBG_ENABLE 40 | #define DBG_VPRINTF_ENABLE true 41 | #else 42 | #define DBG_VPRINTF_ENABLE false 43 | #endif 44 | 45 | #define F_INTERNAL_SYSCLOCK (F_CPU/2) 46 | 47 | #define SystemCoreClock F_INTERNAL_SYSCLOCK 48 | 49 | #define __disable_irq() MICRO_DISABLE_INTERRUPTS() 50 | #define __enable_irq() MICRO_ENABLE_INTERRUPTS() 51 | 52 | #define TONE_INTERVAL_OFFSET(freq) (-((RTIMER_SECOND / 1000000) * 8)) 53 | 54 | typedef uint8_t IRQn_Type; 55 | 56 | typedef uint8_t Pio; 57 | //typedef enum { PioType_NONE } EPioType; 58 | 59 | #define DIO_NUM 20 60 | 61 | extern void DIO_interrupt_handler(uint32_t device, uint32_t bits); 62 | 63 | extern uint8_t segmentLength; 64 | extern uint16_t segmentNumber; 65 | 66 | static inline void eeprom_init() 67 | { 68 | segmentNumber = u16AHI_InitialiseEEP(&segmentLength); 69 | DBG_PRINTF("u16AHI_InitialiseEEP() num:%d, len:%d\n", segmentNumber, segmentLength); 70 | } 71 | 72 | static inline uint8_t eeprom_read_byte(const uint8_t* index) 73 | { 74 | uint8_t buf; 75 | int ret = iAHI_ReadDataFromEEPROMsegment( ((uint32_t)index)/segmentLength, 76 | ((uint32_t)index)%segmentLength, &buf, 1); 77 | DBG_PRINTF("iAHI_ReadDataFromEEPROMsegment(%d, %d) ret:%d, buf:%x\n", 78 | ((uint32_t)index)/segmentLength, 79 | ((uint32_t)index)%segmentLength, ret, buf); 80 | return buf; 81 | } 82 | 83 | static inline void eeprom_write_byte(const uint8_t* index, uint8_t data) 84 | { 85 | int ret = iAHI_WriteDataIntoEEPROMsegment(((uint32_t)index)/segmentLength, 86 | ((uint32_t)index)%segmentLength, &data, 1); 87 | DBG_PRINTF("iAHI_WriteDataFromEEPROMsegment(%d, %d) ret:%d\n", 88 | ((uint32_t)index)/segmentLength, 89 | ((uint32_t)index)%segmentLength, ret); 90 | } 91 | 92 | static inline size_t eeprom_size() { 93 | return segmentLength * segmentNumber; 94 | } 95 | 96 | #ifdef __cplusplus 97 | } 98 | #endif 99 | 100 | #endif //PLATFORM_DEPEND_INCLUDES_H 101 | -------------------------------------------------------------------------------- /variants/jn516x/sam.h: -------------------------------------------------------------------------------- 1 | #include "platform.h" 2 | -------------------------------------------------------------------------------- /variants/jn516x/spi-driver.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017-2018 Tokita, Hiroshi 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 | #include "spi-driver.h" 20 | #include <AppHardwareApi.h> 21 | #include "platform.h" 22 | 23 | extern uint8_t spi_txbuf_; 24 | extern uint8_t spi_rxbuf_; 25 | 26 | static size_t last_tx_bitlen; 27 | 28 | void spi_init() 29 | { 30 | spi_configure(0, 0, 0, 0, 8); 31 | spi_slave_select(0); 32 | } 33 | 34 | void spi_deinit() 35 | { 36 | vAHI_SpiDisable(); 37 | } 38 | 39 | void spi_configure(uint8_t slave_num, bool lsb_first, 40 | bool polarity, bool phase, uint8_t divider) 41 | { 42 | DBG_PRINTF("vAHI_SpiConfigure(%d, %d %d, %d, %d, INT_DISABLE, AUTOSLAVE_DSABL)\n", 43 | slave_num, lsb_first, polarity, phase, divider, 44 | E_AHI_SPIM_INT_DISABLE, E_AHI_SPIM_AUTOSLAVE_DSABL); 45 | vAHI_SpiConfigure(slave_num, lsb_first, polarity, phase, divider, 46 | E_AHI_SPIM_INT_DISABLE, E_AHI_SPIM_AUTOSLAVE_DSABL); 47 | } 48 | 49 | void spi_slave_select(uint8_t slave_bits) 50 | { 51 | vAHI_SpiSelect(slave_bits); 52 | } 53 | 54 | void spi_start(int slave) 55 | { 56 | vAHI_SpiSelect(1<<slave); 57 | } 58 | 59 | void spi_stop() 60 | { 61 | spi_slave_select(0); 62 | } 63 | 64 | static void spi_write_bits(uint32_t txbuf, size_t bitlen) 65 | { 66 | if(bitlen <= 0) 67 | bitlen = 1; 68 | if(bitlen > 32) 69 | bitlen = 32; 70 | DBG_PRINTF("vAHI_SpiStartTransfer(%d, %08x)\n", bitlen-1, txbuf); 71 | vAHI_SpiStartTransfer(bitlen-1, txbuf); 72 | vAHI_SpiWaitBusy(); 73 | last_tx_bitlen = bitlen; 74 | } 75 | 76 | void spi_write(uint8_t txbuf) 77 | { 78 | spi_write_bits(txbuf, 8); 79 | } 80 | 81 | void spi_write16(uint16_t txbuf) 82 | { 83 | spi_write_bits(txbuf, 16); 84 | } 85 | 86 | void spi_write32(uint32_t txbuf) 87 | { 88 | spi_write_bits(txbuf, 32); 89 | } 90 | #if 0 91 | static uint32_t spi_read_bits(size_t bitlen) 92 | { 93 | size_t i = 0; 94 | uint32_t mask = 0; 95 | if(bitlen <= 0) 96 | bitlen = 1; 97 | if(bitlen > 32) 98 | bitlen = 32; 99 | for(i=0; i<bitlen; i++) { 100 | mask |= (1<<i); 101 | } 102 | uint32_t ret = u32AHI_SpiReadTransfer32() & mask; 103 | return ret; 104 | } 105 | #endif 106 | 107 | uint8_t spi_read() 108 | { 109 | uint32_t ret = u32AHI_SpiReadTransfer32() & 0xFF; 110 | DBG_PRINTF("spi_read() %x\n", ret); 111 | return ret & 0xFF; 112 | } 113 | 114 | uint16_t spi_read16() 115 | { 116 | uint32_t ret = u32AHI_SpiReadTransfer32() & 0xFF; 117 | DBG_PRINTF("spi_read16() %x\n", ret); 118 | return ret & 0xFFFF; 119 | } 120 | 121 | uint32_t spi_read32() 122 | { 123 | uint32_t ret = u32AHI_SpiReadTransfer32() & 0xFF; 124 | DBG_PRINTF("spi_read32() %x\n", ret); 125 | return ret; 126 | } 127 | -------------------------------------------------------------------------------- /variants/jn516x/spi-driver.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017-2018 Tokita, Hiroshi 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 SPIDRIVER_H__ 20 | #define SPIDRIVER_H__ 21 | 22 | #define SPI_TXBUF spi_txbuf_ 23 | #define SPI_RXBUF spi_rxbuf_ 24 | 25 | #define SPI_WAITFOREOTx() \ 26 | do {\ 27 | spi_write(SPI_TXBUF);\ 28 | } while(0) 29 | 30 | #define SPI_WAITFOREORx(); \ 31 | do {\ 32 | SPI_RXBUF = spi_read();\ 33 | } while(0) 34 | 35 | #include <stdint.h> 36 | #include <stdbool.h> 37 | #include <dev/spi.h> 38 | 39 | extern uint8_t spi_txbuf_; 40 | extern uint8_t spi_rxbuf_; 41 | 42 | extern void spi_deinit(); 43 | 44 | extern void spi_configure(uint8_t slave_num, bool lsbFirst, 45 | bool polarity, bool phase, uint8_t clockDivider); 46 | 47 | extern void spi_slave_select(uint8_t slave_bits); 48 | 49 | extern void spi_start(int slave); 50 | extern void spi_stop(); 51 | 52 | extern void spi_write(uint8_t txbuf); 53 | extern void spi_write16(uint16_t txbuf); 54 | extern void spi_write32(uint32_t txbuf); 55 | 56 | extern uint8_t spi_read(); 57 | extern uint16_t spi_read16(); 58 | extern uint32_t spi_read32(); 59 | 60 | #endif /* SPIDRIVER_H__ */ 61 | 62 | -------------------------------------------------------------------------------- /variants/jn516x/w_digital.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015 Tokita, Hiroshi 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 | #include "Arduino.h" 20 | #include "wiring_private.h" 21 | 22 | #include <AppHardwareApi.h> 23 | 24 | void pinMode( uint32_t ulPin, uint32_t ulMode ) 25 | { 26 | if (ulMode == INPUT) { 27 | vAHI_DioSetDirection((1UL<<ulPin), 0); 28 | vAHI_DioSetPullup(0, (1UL<<ulPin)); 29 | DBG_PRINTF("input p:"); 30 | DBG_PRINTF("%d\r\n", ulPin); 31 | DBG_PRINTF(" m:"); 32 | DBG_PRINTF("%d\r\n", ulMode); 33 | DBG_PRINTF("\r\n"); 34 | } else if (ulMode == INPUT_PULLUP) { 35 | vAHI_DioSetDirection(0, (1UL<<ulPin)); 36 | vAHI_DioSetPullup((1UL<<ulPin), 0 ); 37 | DBG_PRINTF("pullup p:"); 38 | DBG_PRINTF("%d\r\n", ulPin); 39 | DBG_PRINTF(" m:"); 40 | DBG_PRINTF("%d\r\n", ulMode); 41 | DBG_PRINTF("\r\n"); 42 | 43 | } else { 44 | vAHI_DioSetDirection(0, (1UL<<ulPin) ); 45 | DBG_PRINTF("output p:"); 46 | DBG_PRINTF("%d\r\n", ulPin); 47 | DBG_PRINTF(" m:"); 48 | DBG_PRINTF("%d\r\n", ulMode); 49 | DBG_PRINTF("\r\n"); 50 | } 51 | } 52 | 53 | void digitalWrite( uint32_t ulPin, uint32_t ulVal ) 54 | { 55 | if (ulVal == LOW) { 56 | DBG_PRINTF("LOW p:"); 57 | DBG_PRINTF("%d\r\n", ulPin); 58 | DBG_PRINTF(" v:"); 59 | DBG_PRINTF("%d\r\n", ulVal); 60 | DBG_PRINTF("\r\n"); 61 | vAHI_DioSetOutput(0, (1UL<<ulPin)); 62 | } else { 63 | DBG_PRINTF("HIGH p:"); 64 | DBG_PRINTF("%d\r\n", ulPin); 65 | DBG_PRINTF(" v:"); 66 | DBG_PRINTF("%d\r\n", ulVal); 67 | DBG_PRINTF("\r\n"); 68 | vAHI_DioSetOutput((1UL<<ulPin), 0); 69 | } 70 | } 71 | 72 | int digitalRead( uint32_t ulPin ) 73 | { 74 | if (u32AHI_DioReadInput() & (1<<ulPin)) return HIGH; 75 | return LOW; 76 | } 77 | -------------------------------------------------------------------------------- /variants/jn516x/w_interrupts.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015-2018 Tokita, Hiroshi 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 | #include "WInterrupts.h" 20 | 21 | #include "wiring_private.h" 22 | 23 | #include <AppHardwareApi.h> 24 | #include "variant.h" 25 | 26 | static void nop() { } 27 | 28 | voidFuncPtr handler_table[DIO_NUM] = {nop}; 29 | 30 | void DIO_interrupt_handler(uint32_t device, uint32_t bits) 31 | { 32 | (void)device; 33 | DBG_PRINTF("DIO_interrupt_handler "); 34 | DBG_PRINTF("%x", bits); 35 | DBG_PRINTF("\n"); 36 | int i=0; 37 | uint32_t dio_bits = (bits & 0x1FFFFF); 38 | for(i=0; i<DIO_NUM; i++) { 39 | if( dio_bits& (0x1U<<i) ) { 40 | DBG_PRINTF("call "); 41 | DBG_PRINTF("%d\r\n", i); 42 | DBG_PRINTF("\n"); 43 | handler_table[i](); 44 | } 45 | } 46 | DBG_PRINTF("end DIO_interrupt_handler \n"); 47 | } 48 | 49 | void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode) 50 | { 51 | if(pin > DIO_NUM) return; 52 | 53 | handler_table[pin] = callback; 54 | 55 | vAHI_DioInterruptEnable((1UL<<pin), 0); 56 | if(mode == RISING || mode == LOW || mode == CHANGE || mode ==HIGH) { 57 | vAHI_DioInterruptEdge((1UL<<pin), 0); 58 | } 59 | else { 60 | vAHI_DioInterruptEdge(0, (1UL<<pin)); 61 | } 62 | } 63 | 64 | void detachInterrupt(uint32_t pin) 65 | { 66 | if(pin > DIO_NUM) return; 67 | 68 | handler_table[pin] = nop; 69 | 70 | vAHI_DioInterruptEnable(0, (1UL<<pin)); 71 | } 72 | -------------------------------------------------------------------------------- /variants/jn516x/w_private.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015-2018 Tokita, Hiroshi 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 | #include "wiring_private.h" 20 | #include "variant.h" 21 | 22 | #define ALL_DIO_INT_MASK ( \ 23 | E_AHI_DIO0_INT | E_AHI_DIO1_INT | E_AHI_DIO2_INT | E_AHI_DIO3_INT | \ 24 | E_AHI_DIO4_INT | E_AHI_DIO5_INT | E_AHI_DIO6_INT | E_AHI_DIO7_INT | \ 25 | E_AHI_DIO8_INT | E_AHI_DIO9_INT | E_AHI_DIO10_INT | E_AHI_DIO11_INT | \ 26 | E_AHI_DIO12_INT | E_AHI_DIO13_INT | E_AHI_DIO14_INT | E_AHI_DIO15_INT | \ 27 | E_AHI_DIO16_INT | E_AHI_DIO17_INT | E_AHI_DIO18_INT | E_AHI_DIO19_INT ) 28 | 29 | uint8_t segmentLength; 30 | uint16_t segmentNumber; 31 | 32 | void sysctrl_callback(uint32_t u32Device, uint32_t u32ItemBitmap) 33 | { 34 | DBG_PRINTF("sysctrl_callback(%x, %x)\n", u32Device, u32ItemBitmap); 35 | if(u32ItemBitmap & ALL_DIO_INT_MASK) { 36 | DIO_interrupt_handler(u32Device, u32ItemBitmap); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /variants/minimal-net/Makefile.variant: -------------------------------------------------------------------------------- 1 | include $(dir $(lastword $(MAKEFILE_LIST)))/../native/Makefile.variant 2 | -------------------------------------------------------------------------------- /variants/minimal-net/PinControl.cpp: -------------------------------------------------------------------------------- 1 | #include "../native/PinControl.cpp" 2 | -------------------------------------------------------------------------------- /variants/minimal-net/PinControl.h: -------------------------------------------------------------------------------- 1 | #include "../native/PinControl.h" 2 | -------------------------------------------------------------------------------- /variants/minimal-net/README.md: -------------------------------------------------------------------------------- 1 | See [../native/README.md](../native/README.md). 2 | -------------------------------------------------------------------------------- /variants/minimal-net/minimal-net_spi.cpp: -------------------------------------------------------------------------------- 1 | #include "../native/native_spi.cpp" 2 | -------------------------------------------------------------------------------- /variants/minimal-net/minimal-net_spi.h: -------------------------------------------------------------------------------- 1 | #include "../native/native_spi.h" 2 | -------------------------------------------------------------------------------- /variants/minimal-net/minimal-net_uart.cpp: -------------------------------------------------------------------------------- 1 | #include "../native/native_uart.cpp" 2 | -------------------------------------------------------------------------------- /variants/minimal-net/minimal-net_wire.cpp: -------------------------------------------------------------------------------- 1 | #include "../native/native_wire.cpp" 2 | -------------------------------------------------------------------------------- /variants/minimal-net/minimal-net_wire.h: -------------------------------------------------------------------------------- 1 | #include "../native/native_wire.h" 2 | -------------------------------------------------------------------------------- /variants/minimal-net/minimal-net_wiring.cpp: -------------------------------------------------------------------------------- 1 | #include "../native/native_wiring.cpp" 2 | -------------------------------------------------------------------------------- /variants/minimal-net/pins_arduino.h: -------------------------------------------------------------------------------- 1 | #include "../native/pins_arduino.h" 2 | -------------------------------------------------------------------------------- /variants/minimal-net/platform.cpp: -------------------------------------------------------------------------------- 1 | #include "../native/platform.cpp" 2 | -------------------------------------------------------------------------------- /variants/minimal-net/platform.h: -------------------------------------------------------------------------------- 1 | #include "../native/platform.h" 2 | -------------------------------------------------------------------------------- /variants/minimal-net/variant.h: -------------------------------------------------------------------------------- 1 | #include "../native/variant.h" 2 | -------------------------------------------------------------------------------- /variants/minimal-net/watchdog.c: -------------------------------------------------------------------------------- 1 | 2 | void watchdog_init(void) { } 3 | void watchdog_start(void) { } 4 | void watchdog_periodic(void) { } 5 | void watchdog_stop(void) { } 6 | void watchdog_reboot(void) { } 7 | 8 | 9 | -------------------------------------------------------------------------------- /variants/native/Makefile.variant: -------------------------------------------------------------------------------- 1 | CFLAGS += -g -pthread 2 | LDFLAGS += -g -pthread -lstdc++ 3 | 4 | ARDUINO_CFLAGS += -Wextra 5 | 6 | PLATFORM_CONF_H=$(ARDUINO_VARIANT_PATH)/$(ARDUINO_VARIANT)-platform-conf.h 7 | 8 | override target_makefile := $(CONTIKI)/platform/$(TARGET)/Makefile.$(TARGET) 9 | include $(CONTIKI)/platform/$(TARGET)/Makefile.$(TARGET) 10 | 11 | %.upload: %.elf 12 | x-terminal-emulator -e sh -c "$(CURDIR)/$<" 13 | 14 | -------------------------------------------------------------------------------- /variants/native/PinControl.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Tokita, Hiroshi 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 | #include <stdint.h> 20 | #include <poll.h> 21 | #include <pthread.h> 22 | #include "wiring_private.h" 23 | 24 | class PinControl { 25 | public: 26 | virtual ~PinControl() {} 27 | 28 | virtual int setMode(uint32_t mode) = 0; 29 | virtual int getMode() = 0; 30 | 31 | virtual int setValue(uint32_t value) = 0; 32 | virtual int getValue() = 0; 33 | 34 | virtual int exportPin() = 0; 35 | virtual bool isExported() = 0; 36 | 37 | virtual int startInterruptPolling(uint32_t ulMode, voidFuncPtr callback) = 0; 38 | virtual int stopInterruptPolling() = 0; 39 | 40 | static int sysfs_read(const char* path, char* buf, size_t buflen); 41 | static int sysfs_write_buf(const char* path, const char* buf); 42 | static int sysfs_write(const char* path, int value); 43 | 44 | static int sysfs_set(int fd, int value, int (val2str)(int, char*) ); 45 | static int sysfs_get(int fd, int& value, int (str2val)(const char*) ); 46 | 47 | static int value2string(int value, char* buf); 48 | 49 | protected: 50 | PinControl(uint32_t pin_, int* fds_) : pin(pin_), fds(fds_) { } 51 | 52 | void setFd(uint32_t fdid, int fd) { fds[fdid] = fd; } 53 | int getFd(uint32_t fdid) { return fds[fdid]; } 54 | 55 | int openFd(uint32_t fdid, const char* pathfmt, int value); 56 | int openFd(uint32_t fdid, const char* pathfmt) { return openFd(fdid, pathfmt, pin); } 57 | 58 | uint32_t pin; 59 | int* fds; 60 | }; 61 | 62 | class GpioPinControl : public PinControl { 63 | public: 64 | GpioPinControl(uint32_t pin); 65 | 66 | int setMode(uint32_t mode); 67 | int getMode(); 68 | 69 | int setValue(uint32_t value); 70 | int getValue(); 71 | 72 | int exportPin(); 73 | bool isExported(); 74 | 75 | int startInterruptPolling(uint32_t ulMode, voidFuncPtr callback); 76 | int stopInterruptPolling(); 77 | 78 | static int direction_val2str(int value, char* buf); 79 | static int direction_str2val(const char* str); 80 | static int edge_val2str(int value, char* buf); 81 | static int edge_str2val(const char* str); 82 | 83 | private: 84 | enum { 85 | VALUE, 86 | DIRECTION, 87 | EDGE 88 | }; 89 | 90 | int getFdValue() { return openFd(VALUE, "/sys/class/gpio/gpio%d/value"); } 91 | int getFdDirection() { return openFd(DIRECTION, "/sys/class/gpio/gpio%d/direction"); } 92 | int getFdEdge() { return openFd(EDGE, "/sys/class/gpio/gpio%d/edge"); } 93 | 94 | int setEdge(uint32_t value); 95 | int getEdge(); 96 | 97 | static void delete_buffer(void* arg); 98 | static void* poll_interrupt_proc(void* arg); 99 | 100 | int fds_[3]; 101 | 102 | voidFuncPtr callback; 103 | uint32_t interrupt_mode; 104 | 105 | pthread_t thread; 106 | struct pollfd poll_params; 107 | 108 | }; 109 | 110 | class PwmPinControl : public PinControl { 111 | friend void initVariant(); 112 | public: 113 | PwmPinControl(uint32_t pin); 114 | 115 | int setMode(uint32_t) { return 0; } 116 | int getMode() { return OUTPUT; } 117 | 118 | int setValue(uint32_t value); 119 | int getValue(); 120 | 121 | int exportPin(); 122 | bool isExported(); 123 | 124 | int startInterruptPolling(uint32_t, voidFuncPtr) { return 0; } 125 | int stopInterruptPolling() { return 0; } 126 | 127 | static int pwm_id(uint32_t pin); 128 | 129 | private: 130 | enum { 131 | DUTY_CYCLE, 132 | PERIOD, 133 | ENABLE 134 | }; 135 | 136 | int getFdDutyCycle() { return openFd(DUTY_CYCLE, "/sys/class/pwm/pwmchip0/pwm%d/duty_cycle", pwm_id(pin) ); } 137 | int getFdPeriod() { return openFd(PERIOD, "/sys/class/pwm/pwmchip0/pwm%d/period", pwm_id(pin) ); } 138 | int getFdEnable() { return openFd(ENABLE, "/sys/class/pwm/pwmchip0/pwm%d/enable", pwm_id(pin) ); } 139 | 140 | static void set_pwm_pins(const char* pwm_pins_str); 141 | 142 | int fds_[3]; 143 | 144 | static uint32_t* pwm_pins; 145 | static size_t pwm_num; 146 | }; 147 | -------------------------------------------------------------------------------- /variants/native/README.md: -------------------------------------------------------------------------------- 1 | RaspberryPi 2 | =========== 3 | 4 | Prerequirement 5 | -------------- 6 | 7 | ### Target system 8 | 9 | This package works on RPi3 and Raspbian disk image. 10 | It may work with other RPi. 11 | 12 | 13 | ### libncurses-dev 14 | 15 | ``` 16 | $ sudo apt-get install libncurses5-dev 17 | ``` 18 | 19 | 20 | ### OnBoard LED setup (optional) 21 | 22 | RPi's ACT LED is controlled by LED driver. 23 | It's can control by SYSFS not GPIO. 24 | But LED driver can set blink according to the specific GPIO pin state. 25 | 26 | Run following commands. 27 | 28 | ``` 29 | echo gpio > /sys/class/leds/led0/trigger 30 | echo 27 > /sys/class/leds/led0/gpio # this program define BUILTIN_LED as 27 31 | ``` 32 | 33 | 34 | ### PWM settings (optional) 35 | 36 | librpip project shows good description of the difficulties of to work RPi's PWM. 37 | http://librpip.frasersdev.net/peripheral-config/pwm0and1/ 38 | 39 | 40 | #### overlay 41 | 42 | analogWrite() uses SYSFS interface which provided by PWM driver. 43 | PWM driver is not load default system setting. 44 | So, we must add overlay to /boot/config.txt. 45 | 46 | Append this line to the end of /boot/config.txt 47 | 48 | ``` 49 | dtoverlay=pwm 50 | ``` 51 | 52 | or 53 | 54 | ``` 55 | dtoverlay=pwm-2chan 56 | ``` 57 | 58 | and resolv pimux conflict to comment out audio. 59 | ``` 60 | # dtparam=audio=on 61 | ``` 62 | 63 | More parameter to pwm overlay, see /boot/overlays/README. 64 | 65 | ### PWM CLK 66 | 67 | Pwm overlay not start PWM CLK by default. 68 | librpip project provides EXCELLENT workaround. 69 | 70 | ``` 71 | wget http://librpip.frasersdev.net/wp-content/uploads/2016/06/librpip-0.4.0.tar.gz 72 | tar xvfz librpip-0.4.0.tar.gz 73 | cd librpip-0.4.0 74 | ./configure 75 | make 76 | sudo ./bin/pwmclk 77 | 78 | ``` 79 | 80 | #### udev 81 | 82 | PWM's SYSFS file default owner is set root:root. 83 | We set root:gpio to owner when device loaded. 84 | 85 | Add new rules-file to /etc/udev/rules.d. 86 | 87 | ``` 88 | # /etc/udev/rules.d/90-pwm.rules 89 | SUBSYSTEM=="pwm", PROGRAM="/bin/sh -c '\ 90 | chown -R root:gpio /sys$devpath && chmod -R 770 /sys$devpath\ 91 | '" 92 | ``` 93 | 94 | 95 | #### directory watch and enforce permission 96 | 97 | PWM SYSFS interface owned by XXX when pin was exported. 98 | It cannot change by udev, 99 | Run such program to enforce permission as background process. 100 | 101 | ``` 102 | #!/bin/sh 103 | 104 | # enforce_pwm_permission 105 | 106 | PWMPATH=/sys/class/pwm/pwmchip0 107 | while [ ! -e ${PWMPATH}/export ] ; do true ; done 108 | 109 | while [ -e ${PWMPATH}/export ] ; do 110 | inotifywait -e modify ${PWMPATH}/export 111 | for XXX in `seq 0 10` ; do 112 | chown -R root:gpio ${PWMPATH}/pwm* 113 | chmod -R 770 ${PWMPATH}/pwm* 114 | done 115 | done 116 | ``` 117 | 118 | 119 | Limitation 120 | ---------- 121 | 122 | - RPi has no ADC. analogRead() is not work. 123 | - TCP/IP function was not tested. 124 | -------------------------------------------------------------------------------- /variants/native/native_spi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPI Master library for Arduino Zero. 3 | * Copyright (c) 2015 Arduino LLC 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef _SPI_H_INCLUDED 21 | #define _SPI_H_INCLUDED 22 | 23 | #include <Arduino.h> 24 | #include <linux/spi/spidev.h> 25 | 26 | class SPIDevFile { 27 | public: 28 | SPIDevFile(const char* path_, uint32_t pin_) : path(path_), pin(pin_) {} 29 | const char* path; 30 | uint32_t pin; 31 | }; 32 | 33 | // SPI_HAS_TRANSACTION means SPI has 34 | // - beginTransaction() 35 | // - endTransaction() 36 | // - usingInterrupt() 37 | // - SPISetting(clock, bitOrder, dataMode) 38 | #define SPI_HAS_TRANSACTION 1 39 | 40 | #define SPI_MODE0 SPI_MODE_0 41 | #define SPI_MODE1 SPI_MODE_1 42 | #define SPI_MODE2 SPI_MODE_2 43 | #define SPI_MODE3 SPI_MODE_3 44 | 45 | class SPISettings { 46 | public: 47 | SPISettings(uint32_t clock, BitOrder bitOrder, uint8_t dataMode) : clock(0), mode(0) { 48 | //if (__builtin_constant_p(clock)) { 49 | init_AlwaysInline(clock, bitOrder, dataMode); 50 | //} else { 51 | // init_MightInline(clock, bitOrder, dataMode); 52 | //} 53 | } 54 | 55 | // Default speed set to 4MHz, SPI mode set to MODE 0 and Bit order set to MSB first. 56 | SPISettings() { init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0); } 57 | 58 | private: 59 | void init_MightInline(uint32_t clock, BitOrder bitOrder, uint8_t dataMode) { 60 | init_AlwaysInline(clock, bitOrder, dataMode); 61 | } 62 | 63 | void init_AlwaysInline(uint32_t clock, BitOrder bitOrder, uint8_t dataMode) __attribute__((__always_inline__)) { 64 | this->clock = clock; 65 | this->mode |= (bitOrder == LSBFIRST) ? SPI_LSB_FIRST : 0; 66 | this->mode |= dataMode; 67 | } 68 | uint32_t clock; 69 | BitOrder order; 70 | uint8_t mode; 71 | 72 | friend class SPIClass; 73 | }; 74 | 75 | class SPIClass { 76 | public: 77 | SPIClass(const SPIDevFile devfile[]); 78 | 79 | 80 | byte transfer(uint8_t data); 81 | uint16_t transfer16(uint16_t data); 82 | void transfer(void *buf, size_t count); 83 | 84 | // Transaction Functions 85 | void usingInterrupt(int interruptNumber); 86 | void beginTransaction(SPISettings settings); 87 | void endTransaction(void); 88 | 89 | // SPI Configuration methods 90 | void attachInterrupt(); 91 | void detachInterrupt(); 92 | 93 | void begin(); 94 | void end(); 95 | 96 | void setBitOrder(BitOrder order); 97 | void setDataMode(uint8_t uc_mode); 98 | void setClockDivider(uint8_t uc_div); 99 | 100 | private: 101 | void init(); 102 | void config(SPISettings settings); 103 | 104 | struct spi_ioc_transfer spi; 105 | BitOrder bitOrder; 106 | uint32_t clock; 107 | uint32_t mode; 108 | 109 | int fd; 110 | const SPIDevFile* spiDev; 111 | bool initialized; 112 | }; 113 | 114 | extern SPIClass SPI; 115 | 116 | // For compatibility with sketches designed for AVR @ 16 MHz 117 | // New programs should use SPI.beginTransaction to set the SPI clock 118 | #define SPI_CLOCK_DIV2 2 // 7.8MHz 119 | #define SPI_CLOCK_DIV4 4 // 3.9MHz 120 | #define SPI_CLOCK_DIV8 8 // 1953kHz 121 | #define SPI_CLOCK_DIV16 16 // 976kHz 122 | #define SPI_CLOCK_DIV32 32 // 488kHz 123 | #define SPI_CLOCK_DIV64 64 // 244kHz 124 | #define SPI_CLOCK_DIV128 128 // 122kHz 125 | 126 | #endif 127 | -------------------------------------------------------------------------------- /variants/native/native_wire.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TWI/I2C library for Arduino Zero 3 | * Copyright (c) 2015 Arduino LLC. All rights reserved. 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef TwoWire_h 21 | #define TwoWire_h 22 | 23 | #include "Stream.h" 24 | #include "variant.h" 25 | 26 | 27 | #include "RingBuffer.h" 28 | 29 | // WIRE_HAS_END means Wire has end() 30 | #define WIRE_HAS_END 1 31 | 32 | class TwoWire : public Stream 33 | { 34 | public: 35 | TwoWire(const char *s, uint8_t pinSDA, uint8_t pinSCL); 36 | void begin(); 37 | void begin(uint8_t); 38 | void end(); 39 | void setClock(uint32_t); 40 | 41 | void beginTransmission(uint8_t); 42 | uint8_t endTransmission(bool stopBit); 43 | uint8_t endTransmission(void); 44 | 45 | uint8_t requestFrom(uint8_t address, size_t quantity, bool stopBit); 46 | uint8_t requestFrom(uint8_t address, size_t quantity); 47 | 48 | size_t write(uint8_t data); 49 | size_t write(const uint8_t * data, size_t quantity); 50 | 51 | virtual int available(void); 52 | virtual int read(void); 53 | virtual int peek(void); 54 | virtual void flush(void); 55 | void onReceive(void(*)(int)); 56 | void onRequest(void(*)(void)); 57 | 58 | inline size_t write(unsigned long n) { return write((uint8_t)n); } 59 | inline size_t write(long n) { return write((uint8_t)n); } 60 | inline size_t write(unsigned int n) { return write((uint8_t)n); } 61 | inline size_t write(int n) { return write((uint8_t)n); } 62 | using Print::write; 63 | 64 | void onService(void); 65 | 66 | private: 67 | int fd; 68 | const char* devfile; 69 | 70 | bool transmissionBegun; 71 | 72 | // RX Buffer 73 | RingBuffer rxBuffer; 74 | 75 | //TX buffer 76 | RingBuffer txBuffer; 77 | uint8_t txAddress; 78 | 79 | // Callback user functions 80 | void (*onRequestCallback)(void); 81 | void (*onReceiveCallback)(int); 82 | 83 | // TWI clock frequency 84 | static const uint32_t TWI_CLOCK = 100000; 85 | }; 86 | 87 | #if WIRE_INTERFACES_COUNT > 0 88 | extern TwoWire Wire; 89 | #endif 90 | #if WIRE_INTERFACES_COUNT > 1 91 | extern TwoWire Wire1; 92 | #endif 93 | #if WIRE_INTERFACES_COUNT > 2 94 | extern TwoWire Wire2; 95 | #endif 96 | #if WIRE_INTERFACES_COUNT > 3 97 | extern TwoWire Wire3; 98 | #endif 99 | #if WIRE_INTERFACES_COUNT > 4 100 | extern TwoWire Wire4; 101 | #endif 102 | #if WIRE_INTERFACES_COUNT > 5 103 | extern TwoWire Wire5; 104 | #endif 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /variants/native/native_wiring.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Tokita, Hiroshi 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 | #include <cstdio> 20 | #include <cstdlib> 21 | #include <stdint.h> 22 | #include "platform.h" 23 | #include "PinControl.h" 24 | #include "wiring_digital.h" 25 | #include "wiring_analog.h" 26 | 27 | #include <unistd.h> 28 | 29 | extern "C" { 30 | 31 | static PinControl* pins[PIN_NUM]; 32 | 33 | void pinMode( uint32_t ulPin, uint32_t ulMode ) 34 | { 35 | int ret = 0; 36 | PinControl* pc = NULL; 37 | if( PwmPinControl::pwm_id(ulPin) >= 0) { 38 | pc = new PwmPinControl(ulPin); 39 | ABORT_ON_ERROR(pc==NULL, "PwmPinControl(%u) failed\n", ulPin); 40 | } 41 | else { 42 | pc = new GpioPinControl(ulPin); 43 | ABORT_ON_ERROR(pc==NULL, "GpioPinControl(%u) failed\n", ulPin); 44 | } 45 | 46 | 47 | ret = pc->exportPin(); 48 | ABORT_ON_ERROR(ret<0, "PinControl::exportPin() pin=%u return:%d\n", ulPin, ret); 49 | 50 | ret = pc->setMode(ulMode); 51 | ABORT_ON_ERROR(ret<0, "PinControl::setMode(%u) return:%d\n", ulPin, ret); 52 | 53 | pins[ulPin] = pc; 54 | return; 55 | } 56 | 57 | 58 | void digitalWrite( uint32_t ulPin, uint32_t ulVal ) 59 | { 60 | if( PwmPinControl::pwm_id(ulPin) >= 0) return; 61 | 62 | LOG_DEBUG("%s(%u, %u)\n", __PRETTY_FUNCTION__, ulPin, ulVal); 63 | ABORT_ON_ERROR(pins[ulPin] == NULL, "pins[%u] is NULL\n", ulPin); 64 | 65 | int ret = pins[ulPin]->setValue(ulVal); 66 | WARN_ON_ERROR(ret<0, "PinControl::setValue(%u) pin=%u return:%d\n", ulVal, ulPin, ret); 67 | } 68 | 69 | int digitalRead( uint32_t ulPin ) 70 | { 71 | if( PwmPinControl::pwm_id(ulPin) >= 0) return 0; 72 | 73 | LOG_DEBUG("%s(%u)\n", __PRETTY_FUNCTION__, ulPin); 74 | ABORT_ON_ERROR(pins[ulPin] == NULL, "pins[%u] is NULL\n", ulPin); 75 | 76 | int ret = pins[ulPin]->getValue(); 77 | WARN_ON_ERROR(ret<0, "PinControl::getValue() pin=%u return:%d\n", ulPin, ret); 78 | return ret; 79 | } 80 | 81 | void analogWrite( uint32_t ulPin, uint32_t ulValue ) 82 | { 83 | if( PwmPinControl::pwm_id(ulPin) < 0) return; 84 | 85 | if( pins[ulPin] == NULL) { 86 | pinMode(ulPin, OUTPUT); 87 | } 88 | 89 | LOG_DEBUG("%s(%u, %u)\n", __PRETTY_FUNCTION__, ulPin, ulValue); 90 | ABORT_ON_ERROR(pins[ulPin] == NULL, "pins[%u] is NULL\n", ulPin); 91 | 92 | int ret = pins[ulPin]->setValue(ulValue); 93 | WARN_ON_ERROR(ret<0, "PinControl::setValue(%u) pin=%u return:%d\n", ulValue, ulPin, ret); 94 | } 95 | 96 | void analogReference( eAnalogReference /*ulMode*/ ) 97 | { 98 | // not support in linux platform 99 | } 100 | 101 | uint32_t analogRead( uint32_t /*ulPin*/ ) 102 | { 103 | // not support in linux platform 104 | return 0; 105 | } 106 | 107 | void attachInterrupt(uint32_t ulPin, voidFuncPtr callback, uint32_t ulMode) 108 | { 109 | LOG_DEBUG("%s\n", __FUNCTION__); 110 | if( PwmPinControl::pwm_id(ulPin) >= 0) return; 111 | 112 | pins[ulPin]->startInterruptPolling(ulMode, callback); 113 | 114 | } 115 | 116 | void detachInterrupt(uint32_t ulPin) 117 | { 118 | LOG_DEBUG("%s\n", __FUNCTION__); 119 | if( PwmPinControl::pwm_id(ulPin) >= 0) return; 120 | 121 | pins[ulPin]->stopInterruptPolling(); 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /variants/native/pins_arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | pins_arduino.h - Pin definition functions for Arduino 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2007 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $ 23 | */ 24 | 25 | #ifndef Pins_Arduino_h 26 | #define Pins_Arduino_h 27 | 28 | static const uint8_t A1 = 0xA1; 29 | static const uint8_t A2 = 0xA2; 30 | static const uint8_t A3 = 0; 31 | static const uint8_t A4 = 1; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /variants/native/platform.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Tokita, Hiroshi 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 | #include <stdint.h> 20 | #include "variant.h" 21 | #include "PinControl.h" 22 | 23 | extern "C" { 24 | 25 | void initVariant(void) 26 | { 27 | Console.begin(0); 28 | Stderr.begin(0); 29 | 30 | char pwmstr[16]; 31 | sprintf(pwmstr, "%d,%d", PWM0, PWM1); 32 | PwmPinControl::set_pwm_pins(pwmstr); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /variants/native/platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Tokita, Hiroshi 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 _VARIANT_PLATFORM_H 20 | #define _VARIANT_PLATFORM_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #undef F_CPU 27 | 28 | #include <contiki.h> 29 | #include <net/netstack.h> 30 | #include <dev/watchdog.h> 31 | #include <lib/random.h> 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #define PLATFORM_SPI_HEADER "native_spi.h" 38 | #define PLATFORM_WIRE_HEADER "native_wire.h" 39 | 40 | #define DBG_PRINTF(...) { \ 41 | char* dbg_printf_buf_ = (char*)malloc(1024); \ 42 | sprintf(dbg_printf_buf_ , __VA_ARGS__); \ 43 | fwrite(dbg_printf_buf_, 1, strnlen(dbg_printf_buf_, 1024), stderr); \ 44 | free(dbg_printf_buf_); \ 45 | } 46 | 47 | #ifndef LOGLEVEL 48 | #define LOGLEVEL 4 49 | #endif 50 | 51 | #if LOGLEVEL <= 1 52 | #define LOG_TRACE(...) DBG_PRINTF(__VA_ARGS__) 53 | #else 54 | #define LOG_TRACE(...) 55 | #endif 56 | 57 | #if LOGLEVEL <= 2 58 | #define LOG_VERBOSE(...) DBG_PRINTF(__VA_ARGS__) 59 | #else 60 | #define LOG_VERBOSE(...) 61 | #endif 62 | 63 | #if LOGLEVEL <= 3 64 | #define LOG_DEBUG(...) DBG_PRINTF(__VA_ARGS__) 65 | #else 66 | #define LOG_DEBUG(...) 67 | #endif 68 | 69 | #if LOGLEVEL <= 4 70 | #define LOG_INFO(...) DBG_PRINTF(__VA_ARGS__) 71 | #else 72 | #define LOG_INFO(...) 73 | #endif 74 | 75 | #if LOGLEVEL <= 5 76 | #define LOG_WARN(...) DBG_PRINTF(__VA_ARGS__) 77 | #else 78 | #define LOG_WARN(...) 79 | #endif 80 | 81 | #if LOGLEVEL <= 6 82 | #define LOG_ERROR(...) DBG_PRINTF(__VA_ARGS__) 83 | #else 84 | #define LOG_ERROR(...) 85 | #endif 86 | 87 | 88 | #define ABORT_ON_ERROR(cond, ...) { \ 89 | if(cond) { \ 90 | DBG_PRINTF("ABORT_ON_ERROR @ %s:%d\n", __FILE__, __LINE__); \ 91 | DBG_PRINTF(__VA_ARGS__); \ 92 | exit(-1); \ 93 | }\ 94 | } 95 | 96 | #define WARN_ON_ERROR(cond, ...) { \ 97 | if(cond) { \ 98 | DBG_PRINTF("WARN @ %s:%d\n", __FILE__, __LINE__); \ 99 | DBG_PRINTF(__VA_ARGS__); \ 100 | } \ 101 | } 102 | 103 | #define WARNONCE_ON_ERROR(cond, ...) { \ 104 | static int check = 0; \ 105 | if(!check) { \ 106 | check = 1; \ 107 | WARN_ON_ERROR(__VA_ARGS__); \ 108 | } \ 109 | } 110 | 111 | #define PIN_NUM 54 112 | 113 | #endif //PLATFORM_DEPEND_INCLUDES_H 114 | --------------------------------------------------------------------------------