diff --git a/dev/simba/.gitignore b/dev/simba/.gitignore new file mode 100644 index 0000000..5dac9f5 --- /dev/null +++ b/dev/simba/.gitignore @@ -0,0 +1,4 @@ +.pioenvs +.piolibdeps +.clang_complete +.gcc-flags.json diff --git a/dev/simba/.travis.yml b/dev/simba/.travis.yml new file mode 100644 index 0000000..52072ef --- /dev/null +++ b/dev/simba/.travis.yml @@ -0,0 +1,55 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < http://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < http://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < http://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choice one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# install: +# - pip install -U platformio +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to by used as a library with examples +# + +# language: python +# python: +# - "2.7" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/dev/simba/lib/readme.txt b/dev/simba/lib/readme.txt new file mode 100644 index 0000000..dbadc3d --- /dev/null +++ b/dev/simba/lib/readme.txt @@ -0,0 +1,36 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organized `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +More information about PlatformIO Library Dependency Finder +- http://docs.platformio.org/page/librarymanager/ldf.html diff --git a/dev/simba/platformio.ini b/dev/simba/platformio.ini new file mode 100644 index 0000000..6caf624 --- /dev/null +++ b/dev/simba/platformio.ini @@ -0,0 +1,6 @@ +[platformio] + +[env:nanoatmega328] +platform = atmelavr +board = nanoatmega328 +framework = simba diff --git a/dev/simba/src/main.cpp b/dev/simba/src/main.cpp new file mode 100644 index 0000000..038c2a4 --- /dev/null +++ b/dev/simba/src/main.cpp @@ -0,0 +1,57 @@ +/** + * @section License + * + * The MIT License (MIT) + * + * Copyright (c) 2014-2017, Erik Moqvist + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * This file is part of the Simba project. + */ + +#include "simba.h" +#include "pin_port.i" + +int main() +{ + struct pin_driver_t led; + struct pin_driver_t btn; + + /* Start the system. */ + sys_start(); + + /* Initialize the LED pin as output and set its value to 1. */ + pin_init(&led, &pin_led_dev, PIN_OUTPUT); + pin_init(&btn, &pin_d4_dev,PIN_INPUT); + // pin_init(&btn, &pin_d4_dev,PIN_INPUT_PULL_UP); + pin_write(&led, 1); + + while (1) { + /* Wait half a second. */ + thrd_sleep_ms(100); + + /* Toggle the LED on/off. */ + pin_toggle(&led); + } + + return (0); +} diff --git a/src/HAL/Mem.h b/src/HAL/Mem.h index 30b415d..056250b 100644 --- a/src/HAL/Mem.h +++ b/src/HAL/Mem.h @@ -7,10 +7,11 @@ // #include //memory handler -------------------------------------------------------- - template - struct Mem { - constexpr static inline T get(const T* addr) {return *addr;} - constexpr static inline T set(T* addr,const T v) {return *addr=v;} - }; + //now using OneBit + // template + // struct Mem { + // constexpr static inline T get(const T* addr) {return *addr;} + // constexpr static inline T set(T* addr,const T v) {return *addr=v;} + // }; // } // #endif diff --git a/src/HAL/Pin.h b/src/HAL/Pin.h index 7ba1c13..3926c1d 100644 --- a/src/HAL/Pin.h +++ b/src/HAL/Pin.h @@ -18,7 +18,7 @@ struct VoidPin { static inline void modeInUp() {} static inline void on() {} static inline void off() {} - static inline uint8_t in() {return false;} + static inline unsigned char in() {return false;} static inline bool rawIn() {return in();} static inline bool logicIn() {return in();} // static inline void setLast(bool) {} @@ -30,7 +30,7 @@ template class LogicPinBase:public O { public: NAMED("LogicPinBase") - static inline uint8_t in() {return O::in()^isOn;} + static inline unsigned char in() {return O::in()^isOn;} static inline bool logicIn() {return in();} static inline void on() {isOn?O::off():O::on();} static inline void off() {isOn?O::on():O::off();} @@ -43,11 +43,11 @@ class LastState:public O { protected: static inline bool getLast() {return lastState;} static inline bool setLast(bool v) {return lastState=v;} - static uint8_t lastState; + static unsigned char lastState; }; template -uint8_t LastState::lastState; +unsigned char LastState::lastState; //pin state record, update last pin state after reading input template @@ -55,10 +55,10 @@ class RecState:public O/*,protected virtual LastState*/ { public: NAMED("RecState") //TODO: also record output changes! - static inline uint8_t in() {return O::setLast(O::in());} + static inline unsigned char in() {return O::setLast(O::in());} static inline void on() {O::on();O::setLast(true);} static inline void off() {O::off();O::setLast(false);} - static inline void set(uint8_t v) {O::set(v);O::setLast(v);} + static inline void set(unsigned char v) {O::set(v);O::setLast(v);} }; //avoid self stack @@ -73,12 +73,12 @@ class OnChangeAction:public O/*,protected virtual LastState*/ { public: NAMED("OnChangeAction") OnChangeAction() {} - static inline uint8_t in() { + static inline unsigned char in() { bool n=O::in(); if (n!=O::getLast()) f(); return n; } - static inline void set(uint8_t v) { + static inline void set(unsigned char v) { O::set(v); if (v!=O::getLast()) f(); } @@ -98,12 +98,12 @@ template class OnRiseAction:public O/*,protected virtual LastState*/ { public: NAMED("OnRiseAction") - static inline uint8_t in() { + static inline unsigned char in() { bool n=O::in(); if (n&&n!=O::getLast()) f(); return n; } - // static inline void set(uint8_t v) { + // static inline void set(unsigned char v) { // O::set(v); // if (v&&v!=O::getLast()) f(); // } @@ -123,12 +123,12 @@ template class OnFallAction:public O/*,protected virtual LastState*/ { public: NAMED("OnFallAction") - static inline uint8_t in() { + static inline unsigned char in() { bool n=O::in(); if (!(n||n==O::getLast())) f(); return n; } - static inline void set(uint8_t v) { + static inline void set(unsigned char v) { O::set(v); if (!(v||(v==O::getLast()))) f(); } @@ -151,7 +151,7 @@ struct PinCap:public O { static inline void begin() {O::begin();} static inline void tog() {set(!O::in());} static inline void pulse() {tog();tog();} - static inline void set(uint8_t v) {O::set(v);} + static inline void set(unsigned char v) {O::set(v);} }; //remove LastState functionality (no-one else used it) diff --git a/src/OneArduino.h b/src/OneArduino.h index 1982e22..e3bcfca 100644 --- a/src/OneArduino.h +++ b/src/OneArduino.h @@ -7,9 +7,11 @@ namespace OneLib { namespace Arduino { - #define CHRONOMETER - - inline unsigned long getMillis() {return millis();} + struct API { + static inline unsigned long getMillis() {return millis();} + static inline void delay_ms(unsigned long ms) {delay(ms);} + static inline void delay_us(unsigned int us) {delayMicroseconds(us);} + }; #include diff --git a/src/OneAvr.h b/src/OneAvr.h index 01fec20..2f5595c 100644 --- a/src/OneAvr.h +++ b/src/OneAvr.h @@ -3,17 +3,23 @@ #define ONELIB_AVR_DEF // #include "OneLib.h" -#include "OneBit.h" namespace OneLib { namespace Avr { + struct API { + inline unsigned long getMillis() {static_assert(false,"AVR has no time elapse source by default, use a specific framework.");}//AVR has not this one! + static inline void delay_ms(double ms) {_delay_ms(ms);} + static inline void delay_us(double us) {_delay_ms(us);} + }; + + #include // #include "HAL/Mem.h" // #include "HAL/Func.h" #include "HAL/Pin.h" // #include "OneLib/Soft/Debounce.h"//avr has no millis functions, so cant have this - // #include "Soft/Wire.h" + #include "Soft/Wire.h" // #include "OnePin.h" diff --git a/src/OnePin.h b/src/OnePin.h index 95de0f7..9026d48 100644 --- a/src/OnePin.h +++ b/src/OnePin.h @@ -37,6 +37,7 @@ on the sequence of VirtualPins proposals done to Arduino framework virtual void on()=0; virtual void off()=0; virtual bool in()=0; + virtual bool set(bool v)=0; virtual bool rawIn()=0; virtual bool logicIn()=0; // template @@ -51,15 +52,16 @@ on the sequence of VirtualPins proposals done to Arduino framework class OnePinHook:public OnePin { public: OnePinHook(O& o):pin(o) {} - void begin() override {pin.begin();} - void modeOut() override {pin.modeOut();} - void modeIn() override {pin.modeIn();} - void modeInUp() override {pin.modeInUp();} - void on() override {pin.on();} - void off() override {pin.off();} - bool in() override {return pin.in();} - bool rawIn() override {return pin.rawIn();} - bool logicIn() override {return pin.logicIn();} + inline void begin() override {pin.begin();} + inline void modeOut() override {pin.modeOut();} + inline void modeIn() override {pin.modeIn();} + inline void modeInUp() override {pin.modeInUp();} + inline void on() override {pin.on();} + inline void off() override {pin.off();} + inline bool in() override {return pin.in();} + inline bool set() override {return pin.in();} + inline bool rawIn() override {return pin.rawIn();} + inline bool logicIn() override {return pin.logicIn();} protected: O& pin; }; diff --git a/src/OneSimba.h b/src/OneSimba.h index 5199ba1..78ce4d9 100644 --- a/src/OneSimba.h +++ b/src/OneSimba.h @@ -44,7 +44,7 @@ this is ongoin and still does not compile, some help is welcome template struct InputPin:public Pin { inline void begin() { - if (pin<0) pin_init(this,pin,input_pull_up);//TODO: not been able to do this with simba framework + if (pin<0) pin_init(this,pin,PIN_INPUT_PULL_UP);//TODO: not been able to do this with simba framework else pin_init(this,pin,PIN_INPUT); } }; diff --git a/src/Soft/Debounce.h b/src/Soft/Debounce.h index afa8fb8..b329562 100644 --- a/src/Soft/Debounce.h +++ b/src/Soft/Debounce.h @@ -24,8 +24,8 @@ class DebounceOnOff:public O/*,protected virtual LastState*/ { public: static inline bool in() { - if (getMillis()-lastSet