Skip to content

Commit

Permalink
preparing for param. Value introduction
Browse files Browse the repository at this point in the history
  • Loading branch information
neu-rah committed Jan 3, 2018
1 parent 3453b97 commit 4a2d0a9
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 35 deletions.
4 changes: 4 additions & 0 deletions dev/simba/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.pioenvs
.piolibdeps
.clang_complete
.gcc-flags.json
55 changes: 55 additions & 0 deletions dev/simba/.travis.yml
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions dev/simba/lib/readme.txt
Original file line number Diff line number Diff line change
@@ -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 <Foo.h>
#include <Bar.h>

// 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
6 changes: 6 additions & 0 deletions dev/simba/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[platformio]

[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = simba
57 changes: 57 additions & 0 deletions dev/simba/src/main.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
11 changes: 6 additions & 5 deletions src/HAL/Mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
// #include <OneBit.h>

//memory handler --------------------------------------------------------
template<class T>
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<class T>
// 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
26 changes: 13 additions & 13 deletions src/HAL/Pin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand All @@ -30,7 +30,7 @@ template<class O,bool isOn>
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();}
Expand All @@ -43,22 +43,22 @@ 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<class O>
uint8_t LastState<O>::lastState;
unsigned char LastState<O>::lastState;

//pin state record, update last pin state after reading input
template<class O>
class RecState:public O/*,protected virtual LastState<O>*/ {
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
Expand All @@ -73,12 +73,12 @@ class OnChangeAction:public O/*,protected virtual LastState<O>*/ {
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();
}
Expand All @@ -98,12 +98,12 @@ template<class O,void(*f)()>
class OnRiseAction:public O/*,protected virtual LastState<O>*/ {
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();
// }
Expand All @@ -123,12 +123,12 @@ template<class O,void(*f)()>
class OnFallAction:public O/*,protected virtual LastState<O>*/ {
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();
}
Expand All @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions src/OneArduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <OneBit.h>

Expand Down
10 changes: 8 additions & 2 deletions src/OneAvr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <OneBit.h>
// #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"

Expand Down
20 changes: 11 additions & 9 deletions src/OnePin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool T>
Expand All @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion src/OneSimba.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ this is ongoin and still does not compile, some help is welcome
template<int pin>
struct InputPin:public Pin<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);
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/Soft/Debounce.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
class DebounceOnOff:public O/*,protected virtual LastState*/ {
public:
static inline bool in() {
if (getMillis()-lastSet<delta) return O::getLast();
lastSet=getMillis();
if (API::getMillis()-lastSet<delta) return O::getLast();
lastSet=API::getMillis();
return O::in();
}
// inline operator bool() {return in();}
Expand Down

0 comments on commit 4a2d0a9

Please sign in to comment.