Commit e704cc11 authored by Daniel Friesel's avatar Daniel Friesel
Browse files

Add mmsubstate driver for sub-state detection evaluation

mmsubstate is a synthetic peripheral which uses a LED to create well-defined
power sub-states in select power states.
parent 583ece21
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -88,6 +88,11 @@ ifneq ($(findstring mmsimple,${drivers}), )
	COMMON_FLAGS += -DDRIVER_MMSIMPLE
endif

ifneq ($(findstring mmsubstate,${drivers}), )
	CXX_TARGETS += src/driver/mmsubstate.cc
	COMMON_FLAGS += -DDRIVER_MMSUBSTATE
endif

ifneq ($(findstring nrf24l01,${drivers}), )
	CXX_TARGETS += src/driver/nrf24l01.cc
	ifeq (${arch}, msp430fr5994lp)
+24 −0
Original line number Diff line number Diff line
#ifndef MMSUBSTATE_H
#define MMSUBSTATE_H

class MicroMoodySubstate {
	private:
		MicroMoodySubstate(const MicroMoodySubstate &copy);

		unsigned char const address;
		unsigned char txbuf[3];

	public:
		MicroMoodySubstate(unsigned char const addr) : address(addr) {}

		void sleep();
		void noSubstates(unsigned char power1, unsigned char power2);
		void twoSubstates(unsigned char switchDutarion, unsigned char power);
		void fourSubstates(unsigned char switchDutarion, unsigned char power);
		void eightSubstates(unsigned char switchDutarion, unsigned char power);
		void setSubstates(unsigned char substateCount, unsigned char switchDuration, unsigned char power);
};

extern MicroMoodySubstate moody;

#endif
+85 −0
Original line number Diff line number Diff line
codegen:
  instance: moody
  includes:
    - driver/i2c.h
    - driver/mmsubstate.h
  flags:
    - arch_drivers=i2c
    - drivers=mmsubstate
  setup:
    i2c.setup();

parameters:
  - substate_count
  - substate_duration
  - substate_power
  - static_p1
  - static_p2

states:
  - UNINITIALIZED
  - SLEEP
  - STATIC
  - SUB2
  - SUB8
  - SUBVAR

transition:
  sleep:
    src: [UNINITIALIZED, STATIC, SUB2, SUB8, SUBVAR]
    dst: SLEEP
    set_param:
      substate_count: 0
      substate_duration: 0
      substate_power: 0
  noSubstates:
    src: [SLEEP, STATIC, SUB2, SUB8, SUBVAR]
    dst: STATIC
    arguments:
    - name: power1
      values: [30, 50, 80]
      parameter: static_p1
    - name: power2
      values: [30, 50, 80]
      parameter: static_p2
    set_param:
      substate_count: 0
      substate_duration: 0
      substate_power: 0
  twoSubstates:
    src: [SLEEP, STATIC, SUB2, SUB8, SUBVAR]
    dst: SUB2
    set_param:
      substate_count: 2
    arguments:
    - name: switchDuration
      values: [5, 10, 15, 20]
      parameter: substate_duration
    - name: power
      values: [50, 100, 150]
      parameter: substate_power
  eightSubstates:
    src: [SLEEP, STATIC, SUB2, SUB8, SUBVAR]
    dst: SUB8
    set_param:
      substate_count: 8
    arguments:
    - name: switchDuration
      values: [5, 10, 15, 20]
      parameter: substate_duration
    - name: power
      values: [50, 100, 150]
      parameter: substate_power
  setSubstates:
    src: [SLEEP, STATIC, SUB2, SUB8, SUBVAR]
    dst: SUBVAR
    arguments:
    - name: substateCount
      values: [2, 4, 10, 12]
      parameter: substate_count
    - name: switchDuration
      values: [5, 10, 15, 20]
      parameter: substate_duration
    - name: power
      values: [255]
      parameter: substate_power
+41 −0
Original line number Diff line number Diff line
#include "driver/mmsubstate.h"
#if defined(MULTIPASS_ARCH_HAS_I2C) && !defined(DRIVER_SOFTI2C)
#include "driver/i2c.h"
#else
#include "driver/soft_i2c.h"
#endif

void MicroMoodySubstate::setSubstates(unsigned char substateCount, unsigned char switchDuration, unsigned char power)
{
	txbuf[0] = substateCount;
	txbuf[1] = power;
	txbuf[2] = switchDuration;
	i2c.xmit(address, 3, txbuf, 0, txbuf);
}

void MicroMoodySubstate::sleep()
{
	setSubstates(1, 0, 0);
}

void MicroMoodySubstate::noSubstates(unsigned char power1, unsigned char power2)
{
	setSubstates(1, power1, power2);
}

void MicroMoodySubstate::twoSubstates(unsigned char switchDuration, unsigned char power)
{
	setSubstates(2, switchDuration, power);
}

void MicroMoodySubstate::fourSubstates(unsigned char switchDuration, unsigned char power)
{
	setSubstates(4, switchDuration, power);
}

void MicroMoodySubstate::eightSubstates(unsigned char switchDuration, unsigned char power)
{
	setSubstates(8, switchDuration, power);
}

MicroMoodySubstate moody(0x11);